| 288 | signature = (timestamp, id, properties = None, node_type = None, event_id = None, layer = None) |
| 289 | )] |
| 290 | pub fn add_node( |
| 291 | &self, |
| 292 | timestamp: EventTimeComponent, |
| 293 | id: GID, |
| 294 | properties: Option<Bound<PyDict>>, |
| 295 | node_type: Option<&str>, |
| 296 | event_id: Option<usize>, |
| 297 | layer: Option<&str>, |
| 298 | ) -> Result<NodeView<'static, Graph>, GraphError> { |
| 299 | let props = properties |
| 300 | .into_iter() |
| 301 | .flat_map(|map| { |
| 302 | map.into_iter().map(|(k, v)| { |
| 303 | k.extract::<String>() |
| 304 | .and_then(|k| v.extract::<Prop>().map(move |v| (k, v))) |
| 305 | }) |
| 306 | }) |
| 307 | .collect::<Result<Vec<_>, _>>()?; |
| 308 | match event_id { |
| 309 | None => self.graph.add_node(timestamp, id, props, node_type, layer), |
| 310 | Some(event_id) => { |
| 311 | self.graph |
| 312 | .add_node((timestamp, event_id), id, props, node_type, layer) |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | /// Creates a new node with the given id and properties to the graph. It fails if the node already exists. |
| 318 | /// |