sampo.structurator.prepare_wg_copy#

Overview#

Function#

copy_graph_node(node, new_id, change_id)

Makes a deep copy of GraphNode without edges. It’s id can be changed to a new randomly generated or specified one

restore_parents(new_nodes, original_wg, old_to_new_ids, excluded_ids)

Restores edges in GraphNode for copied WorkGraph with changed ids

prepare_work_graph_copy(wg, excluded_nodes, use_ids_simplification, id_offset, change_id)

Makes a deep copy of the GraphNodes of the original graph with new ids and updated edges,

new_start_finish(original_wg, copied_nodes, old_to_new_ids)

Prepares new start and finish to create WorkGraph after copying it

Functions#

sampo.structurator.prepare_wg_copy.copy_graph_node(node: sampo.schemas.graph.GraphNode, new_id: int | str | None = None, change_id: bool = True) tuple[sampo.schemas.graph.GraphNode, tuple[str, str]]#

Makes a deep copy of GraphNode without edges. It’s id can be changed to a new randomly generated or specified one :param node: original GraphNode :param new_id: specified new id :param change_id: do ids in the new graph need to be changed :return: copy of GraphNode and pair(old node id, new node id)

sampo.structurator.prepare_wg_copy.restore_parents(new_nodes: dict[str, sampo.schemas.graph.GraphNode], original_wg: sampo.schemas.graph.WorkGraph, old_to_new_ids: dict[str, str], excluded_ids: set[str]) None#

Restores edges in GraphNode for copied WorkGraph with changed ids :param new_nodes: needed copied nodes :param original_wg: original WorkGraph for edge restoring for new nodes :param excluded_ids: dictionary of relationships between old ids and new ids :param old_to_new_ids: a dictionary linking the ids of GraphNodes of the original graph and the new GraphNode ids :return:

sampo.structurator.prepare_wg_copy.prepare_work_graph_copy(wg: sampo.schemas.graph.WorkGraph, excluded_nodes: list[sampo.schemas.graph.GraphNode] = [], use_ids_simplification: bool = False, id_offset: int = 0, change_id: bool = True)#

Makes a deep copy of the GraphNodes of the original graph with new ids and updated edges, ignores all GraphNodes specified in the exception list and GraphEdges associated with them :param wg: original WorkGraph for copy :param excluded_nodes: GraphNodes to be excluded from the graph :param use_ids_simplification: If true, creates short numeric ids converted to strings, otherwise uses uuid to generate id :param id_offset: Shift for numeric ids, used only if param use_ids_simplification is True :param change_id: Do IDs in the new graph need to be changed :return: A dictionary with GraphNodes by their id and a dictionary linking the ids of GraphNodes of the original graph and the new GraphNode ids

sampo.structurator.prepare_wg_copy.new_start_finish(original_wg: sampo.schemas.graph.WorkGraph, copied_nodes: dict[str, sampo.schemas.graph.GraphNode], old_to_new_ids: dict[str, str])#

Prepares new start and finish to create WorkGraph after copying it :param original_wg: WorkGraph, on which base prepare_work_graph_copy was run :param copied_nodes: New nodes, on which to create new WorkGraph :param old_to_new_ids: Dictionary to translate old nodes to new, using their IDs :return: new start and new finish nodes, on the base of which to create a WorkGraph