Skip to content

Commit 8e1e55b

Browse files
committed
Fix transforming graph_data to networkx's node link format
1 parent 2c9bd18 commit 8e1e55b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

persper/analytics/call_commit_graph.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from networkx.readwrite import json_graph
88
from persper.analytics.devrank import devrank
99
from persper.analytics.score import normalize
10-
from typing import Union, Set, List, Dict
10+
from typing import Union, Set, List, Dict, Optional
1111

1212

1313
class CommitIdGenerators:
@@ -30,14 +30,23 @@ class CallCommitGraph:
3030
and edit histories across commits.
3131
"""
3232

33-
def __init__(self, node_link_data=None, commit_id_generator=CommitIdGenerators.fromHexsha):
34-
if node_link_data:
35-
self._digraph = json_graph.node_link_graph(node_link_data)
33+
def __init__(self, graph_data: Optional[Dict] = None, commit_id_generator=CommitIdGenerators.fromHexsha):
34+
if graph_data:
35+
self._digraph = json_graph.node_link_graph(
36+
CallCommitGraph._to_networkx_format(graph_data))
3637
else:
3738
self._digraph = self._new_graph()
3839
self._commit_id_generator = commit_id_generator
3940
self._current_commit_id = None
4041

42+
@staticmethod
43+
def _to_networkx_format(graph_data: Dict) -> Dict:
44+
graph_data['multigraph'] = False
45+
graph_data['directed'] = True
46+
for node in graph_data['nodes']:
47+
node['files'] = set(node['files'])
48+
return graph_data
49+
4150
def reset(self):
4251
"""Reset all internal states"""
4352
self._digraph = self._new_graph()

persper/analytics/go.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ def update_graph(self, old_filename, old_src,
4040
def get_graph(self):
4141
graph_url = self.server_addr + '/callgraph'
4242
r = requests.get(graph_url)
43-
graph_data = r.json()
44-
graph_data['directed'] = True
45-
graph_data['multigraph'] = False
46-
return CallCommitGraph(graph_data)
43+
return CallCommitGraph(graph_data=r.json())
4744

4845
def reset_graph(self):
4946
reset_url = urllib.parse.urljoin(self.server_addr, '/reset')

0 commit comments

Comments
 (0)