Commit 9ecc63e8 authored by Tim Bleimehl's avatar Tim Bleimehl 🤸🏼
Browse files

improve filter system

parent a2fc3d4a
Pipeline #1657 passed with stage
in 50 seconds
......@@ -49,7 +49,8 @@ class GraphSchema(py2neo.Subgraph):
# copy all nodes to track if they are involed in a relation
nodes_without_relation = list(neo4j_schema_vis_data["nodes"])
for rel in neo4j_schema_vis_data["relationships"]:
if not parent_capture_point.parent_logger.rel_filter_func(rel):
continue
rel_nodes = [None, None]
for node in neo4j_schema_vis_data["nodes"]:
if rel_nodes[0] and rel_nodes[1]:
......
......@@ -12,6 +12,8 @@ class NeoMetaTracker:
self.capture_points: List[CapturePoint] = []
self.all_schema_nodes: Dict[tuple, py2neo.Node] = None
self.all_schema_rels: Dict[str, py2neo.Relationship] = None
self.ignore_labels: List[str] = []
self.ignore_reliations_types: List[str] = []
if isinstance(connection, dict):
self.graph: py2neo.Graph = py2neo.Graph(**connection)
elif isinstance(connection, py2neo.Graph):
......@@ -42,15 +44,36 @@ class NeoMetaTracker:
mlog = NeoMetaTracker(test_graph)
def node_filter(node: py2neo.Node):
if list(node.labels)[0].startswith("_"):
node_label = list(node.labels)[0]
if node_label.startswith("_") or node_label in self.ignore_labels:
return None
return node
mlog.node_filter_func = node_filter
"""
if list(node.labels)[0] in self.ignore_labels:
return None
return node
def rel_filter_func(self, rel: py2neo.Relationship):
"""This function can be overiden to filter specifics nodes out of the schema tracker
example; Remove all schema-nodes with label starting with "_":
mlog = NeoMetaTracker(test_graph)
def my_filter_func(self, rel: py2neo.Relationship):
if type(rel).__name__.startwith("_") or type(rel).__name__ in self.ignore_reliations_types:
return None
return rel
mlog.rel_filter_func = my_filter_func
"""
if type(rel).__name__ in self.ignore_reliations_types:
return None
return rel
def visualize(
self, visualizer_class: BaseVisualizer, to_file: Union[str, Path] = None
):
......@@ -82,6 +105,8 @@ class NeoMetaTracker:
).data()[0]["res"]
labels_count: Dict[str, int] = {}
for label in all_labels:
if label in self.ignore_labels:
continue
query_label_count = f"""
MATCH (n:{label})
RETURN count(n) AS res
......@@ -95,7 +120,8 @@ class NeoMetaTracker:
).data()[0]["res"]
rels_count: Dict[str, int] = {}
for rel in all_rels:
if rel in self.ignore_reliations_types:
continue
query_rel_count = f"""
MATCH ()-[:{rel}]->()
return count(*) AS res
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment