Пример #1
0
    def _add_node(self, node, depth=0):
        if depth > self._depth_threshold:
            raise DagException("Node dependency too deep")

        if node.id in self._nodes:
            return self._nodes[id]
        else:
            self._nodes[id] = node

        if self._is_node_terminal(node):
            node.satisfied = True
            return node

        # find node ancestors and generators
        for generator_class in self._generators:
            required_events = generator_class.required_events(node.params)
            if required_events is None:
                continue
            for events_join in required_events:
                edge = Edge(generator_class)
                for event in events_join:
                    parent_node = self._add_node(Node(event), depth + 1)
                    edge.nodes[parent_node.id] = parent_node
                if edge.id in self._edges:
                    edge = self._edges[edge.id]
                else:
                    self._edges[edge.id] = edge
                node.edges[edge.id] = edge
        return node
Пример #2
0
 def add_node(self, params, demand, depth=0, session=None):
     session_was_none = session is None
     if session_was_none:
         session = self._open_session()
     node, created = Node.get_or_create(params, session)
     if not created:
         return node
     if depth < self.depth_threshold:
         self._extend_graph(node, depth, session)
     if demand > 0:
         node.add_demand(demand)
     if session_was_none:
         session.commit()
     return node
Пример #3
0
 def add_event(self, params):
     session = self._open_session()
     node, _ = Node.get_or_create(params, session)
     node.satisfy(session)
     session.commit()