def create_demo_graphs(user): res = [] for graph_id in DemoUserManager.demo_config.graph_ids: graph = Graph.load(graph_id) graph._id = ObjectId() graph.author = user._id graph.save() res.append(graph._id) return res
def __init__(self, graph, node_collection=None): if isinstance(graph, Graph): self.graph_id = graph._id self.graph = graph else: self.graph_id = graph self.graph = Graph.load(self.graph_id) self.node_id_to_node = {node._id: node for node in self.graph.nodes} # number of dependencies to ids self.dependency_index_to_node_ids = defaultdict(lambda: set()) self.node_id_to_dependents = defaultdict(lambda: set()) self.node_id_to_dependency_index = defaultdict(lambda: 0) self.uncompleted_nodes_count = 0 if node_collection: self.node_collection = node_collection else: self.node_collection = NodeCollection() for node in self.graph.nodes: # ignore nodes in finished statuses if node.node_running_status in { NodeRunningStatus.SUCCESS, NodeRunningStatus.FAILED, NodeRunningStatus.STATIC, NodeRunningStatus.RESTORED, NodeRunningStatus.CANCELED }: continue node_id = node._id dependency_index = 0 for node_input in node.inputs: for input_value in node_input.values: parent_node_id = to_object_id(input_value.node_id) self.node_id_to_dependents[parent_node_id].add(node_id) if self.node_id_to_node[ parent_node_id].node_running_status not in { NodeRunningStatus.SUCCESS, NodeRunningStatus.FAILED, NodeRunningStatus.STATIC, NodeRunningStatus.RESTORED, NodeRunningStatus.CANCELED }: dependency_index += 1 if node.node_running_status not in { NodeRunningStatus.SUCCESS, NodeRunningStatus.FAILED, NodeRunningStatus.STATIC, NodeRunningStatus.RESTORED, NodeRunningStatus.CANCELED }: self.uncompleted_nodes_count += 1 self.dependency_index_to_node_ids[dependency_index].add(node_id) self.node_id_to_dependency_index[node_id] = dependency_index