From baeb0952cac76737dd1bb423a20d35d10db06f3c Mon Sep 17 00:00:00 2001 From: Wey Gu Date: Fri, 15 Mar 2024 14:29:56 +0000 Subject: [PATCH] pop rank to prop --- nebula3/data/ResultSet.py | 133 ++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 70 deletions(-) diff --git a/nebula3/data/ResultSet.py b/nebula3/data/ResultSet.py index 2f87a8d9..c101d931 100644 --- a/nebula3/data/ResultSet.py +++ b/nebula3/data/ResultSet.py @@ -197,81 +197,68 @@ def dict_for_vis(self): Example: { - "nodes":[ - { - "id":"player100", - "labels":[ - "player" - ], - "props":{ - "name":"Tim Duncan", - "age":"42", - "id":"player100" - } - }, - { - "id":"player101", - "labels":[ - "player" - ], - "props":{ - "age":"36", - "name":"Tony Parker", - "id":"player101" + 'nodes': [ + { + 'id': 'player100', + 'labels': ['player'], + 'props': { + 'name': 'Tim Duncan', + 'age': '42', + 'id': 'player100' + } + }, + { + 'id': 'player101', + 'labels': ['player'], + 'props': { + 'age': '36', + 'name': 'Tony Parker', + 'id': 'player101' + } } - } - ], - "edges":[ - { - "src":"player100", - "dst":"player101", - "name":"follow", - "rank":0, - "props":{ - "degree":"95" + ], + 'edges': [ + { + 'src': 'player100', + 'dst': 'player101', + 'name': 'follow', + 'props': { + 'degree': '95' + } } - } - ], - "nodes_dict":{ - "player100":{ - "id":"player100", - "labels":[ - "player" - ], - "props":{ - "name":"Tim Duncan", - "age":"42", - "id":"player100" + ], + 'nodes_dict': { + 'player100': { + 'id': 'player100', + 'labels': ['player'], + 'props': { + 'name': 'Tim Duncan', + 'age': '42', + 'id': 'player100' + } + }, + 'player101': { + 'id': 'player101', + 'labels': ['player'], + 'props': { + 'age': '36', + 'name': 'Tony Parker', + 'id': 'player101' + } } }, - "player101":{ - "id":"player101", - "labels":[ - "player" - ], - "props":{ - "age":"36", - "name":"Tony Parker", - "id":"player101" - } - } - }, - "edges_dict":{ - "(""player100", - "player101", - 0, - "follow"")":{ - "src":"player100", - "dst":"player101", - "name":"follow", - "rank":0, - "props":{ - "degree":"95" + 'edges_dict': { + ('player100', 'player101', 0, 'follow'): { + 'src': 'player100', + 'dst': 'player101', + 'name': 'follow', + 'props': { + 'degree': '95' + } } - } - }, - "nodes_count":2, - "edges_count":1 + }, + 'nodes_count': 2, + 'edges_count': 1 } :return: dict with keys: @@ -346,6 +333,12 @@ def add_to_nodes_or_edges(nodes_dict, edges_dict, item): ) nodes = list(nodes_dict.values()) edges = list(edges_dict.values()) + # move rank to props, omit rank 0 + for edge in edges: + if "rank" in edge: + rank = edge.pop("rank") + if rank != 0: + edge["props"]["rank"] = rank return { "nodes": nodes,