Skip to content

Commit

Permalink
pop rank to prop
Browse files Browse the repository at this point in the history
  • Loading branch information
wey-gu committed Mar 15, 2024
1 parent 1970cd3 commit baeb095
Showing 1 changed file with 63 additions and 70 deletions.
133 changes: 63 additions & 70 deletions nebula3/data/ResultSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit baeb095

Please sign in to comment.