Skip to content

Commit

Permalink
Fix transforming graph_data to networkx's node link format
Browse files Browse the repository at this point in the history
  • Loading branch information
hezyin committed Mar 11, 2019
1 parent 2c9bd18 commit 8e1e55b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 13 additions & 4 deletions persper/analytics/call_commit_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from networkx.readwrite import json_graph
from persper.analytics.devrank import devrank
from persper.analytics.score import normalize
from typing import Union, Set, List, Dict
from typing import Union, Set, List, Dict, Optional


class CommitIdGenerators:
Expand All @@ -30,14 +30,23 @@ class CallCommitGraph:
and edit histories across commits.
"""

def __init__(self, node_link_data=None, commit_id_generator=CommitIdGenerators.fromHexsha):
if node_link_data:
self._digraph = json_graph.node_link_graph(node_link_data)
def __init__(self, graph_data: Optional[Dict] = None, commit_id_generator=CommitIdGenerators.fromHexsha):
if graph_data:
self._digraph = json_graph.node_link_graph(
CallCommitGraph._to_networkx_format(graph_data))
else:
self._digraph = self._new_graph()
self._commit_id_generator = commit_id_generator
self._current_commit_id = None

@staticmethod
def _to_networkx_format(graph_data: Dict) -> Dict:
graph_data['multigraph'] = False
graph_data['directed'] = True
for node in graph_data['nodes']:
node['files'] = set(node['files'])
return graph_data

def reset(self):
"""Reset all internal states"""
self._digraph = self._new_graph()
Expand Down
5 changes: 1 addition & 4 deletions persper/analytics/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ def update_graph(self, old_filename, old_src,
def get_graph(self):
graph_url = self.server_addr + '/callgraph'
r = requests.get(graph_url)
graph_data = r.json()
graph_data['directed'] = True
graph_data['multigraph'] = False
return CallCommitGraph(graph_data)
return CallCommitGraph(graph_data=r.json())

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

0 comments on commit 8e1e55b

Please sign in to comment.