7
7
from networkx .readwrite import json_graph
8
8
from persper .analytics .devrank import devrank
9
9
from persper .analytics .score import normalize
10
- from typing import Union , Set , List , Dict
10
+ from typing import Union , Set , List , Dict , Optional
11
11
12
12
13
13
class CommitIdGenerators :
@@ -30,14 +30,23 @@ class CallCommitGraph:
30
30
and edit histories across commits.
31
31
"""
32
32
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 ))
36
37
else :
37
38
self ._digraph = self ._new_graph ()
38
39
self ._commit_id_generator = commit_id_generator
39
40
self ._current_commit_id = None
40
41
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
+
41
50
def reset (self ):
42
51
"""Reset all internal states"""
43
52
self ._digraph = self ._new_graph ()
0 commit comments