def node_visible(key: str) -> bool: k: Kind = graph.nodes[key]["data"] if hide and exist(lambda r: r.fullmatch(k.fqn), hide): return False if show is None: return True else: return exist(lambda r: r.fullmatch(k.fqn), show)
def current_step_done(self) -> bool: """ This step is done, when the event it is waiting for has arrived. """ return self.timed_out or exist( lambda x: isinstance(x, Event) and x.message_type == self.perform. wait_for_message_type, self.instance.received_messages, )
async def query_cost(graph_db: Any, model: QueryModel, with_edges: bool) -> EstimatedSearchCost: q_string, bind = to_query(graph_db, model, with_edges=with_edges) nr_nodes = await graph_db.db.count(graph_db.vertex_name) plan = await graph_db.db.explain(query=q_string, bind_vars=bind) full_collection_scan = exist( lambda node: node["type"] == "EnumerateCollectionNode", plan["nodes"]) estimated_cost = int(plan["estimatedCost"]) estimated_items = int(plan["estimatedNrItems"]) # If the number of returned items is small, most of the computation happens on the db side # A higher factor (==estimated cost) is acceptable in this case. factor = 20 if estimated_items < 3 else 2.1 # max upper bound, if the number of nodes is very small ratio = estimated_cost / max(10000, nr_nodes * factor) # the best rating is complex, if a full collection scan is required. best = Rating.complex if full_collection_scan else Rating.simple rating = best if ratio < 0.2 else ( Rating.complex if ratio < 1 else Rating.bad) return EstimatedSearchCost(estimated_cost, estimated_items, nr_nodes, full_collection_scan, rating)
def not_hidden(key: str) -> bool: k: Kind = graph.nodes[key]["data"] return not (hide and exist(lambda r: r.fullmatch(k.fqn), hide))