Skip to content

Commit

Permalink
Use accurate history to calculate devrank
Browse files Browse the repository at this point in the history
Merge branch 'dev-rank' into 'develop'

See merge request persper/code-analytics!91
  • Loading branch information
hezyin committed May 26, 2019
2 parents 36c1571 + 4ba1a22 commit 2271e66
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
23 changes: 13 additions & 10 deletions persper/analytics/call_commit_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ def _set_all_nodes_size(self, black_set=None):
"""
for node in self.nodes():
node_history = self._get_node_history(node)
if black_set is not None:
size = 0
for cid, chist in node_history.items():
sha = self.commits()[cid]['hexsha']
if sha not in black_set:
size += (chist['adds'] + chist['dels'])
else:
size = sum([chist['adds'] + chist['dels'] for chist in node_history.values()])

size = 0
for cid, chist in node_history.items():
sha = self.commits()[cid]['hexsha']
if black_set is not None and sha in black_set:
continue
if 'added_units' in chist.keys() and 'removed_units' in chist.keys():
size += (chist['added_units'] + chist['removed_units'])
else:
size += (chist['adds'] + chist['dels'])
# set default size to 1 to avoid zero division error
if size == 0:
size = 1
Expand Down Expand Up @@ -206,7 +206,10 @@ def commit_devranks(self, alpha, black_set=None):
continue

for cid, chist in history.items():
csize = chist['adds'] + chist['dels']
if 'added_units' in chist.keys() and 'removed_units' in chist.keys():
csize = (chist['added_units'] + chist['removed_units'])
else:
csize = (chist['adds'] + chist['dels'])
sha = self.commits()[cid]['hexsha']
if black_set is None or sha not in black_set:
dr = (csize / size) * func_devranks[func]
Expand Down
27 changes: 27 additions & 0 deletions test/test_analytics/test_call_commit_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ def test_call_commit_graph():
assert isclose(dev_drs3[second_commit['authorEmail']], 0.201, rel_tol=1e-2)


def test_devrank_with_accurate_history():
ccgraph = CallCommitGraph()
first_commit = {
'hexsha': '0x01',
'authorName': 'koala',
'authorEmail': '[email protected]',
'message': 'first commit'
}
ccgraph.add_commit(first_commit['hexsha'],
first_commit['authorName'],
first_commit['authorEmail'],
first_commit['message'])
ccgraph.add_node('f1')
ccgraph.update_node_history_accurate('f1', {'adds': 10, 'dels': 0, 'added_units': 20, 'removed_units': 0})
ccgraph.add_node('f2')
ccgraph.update_node_history_accurate('f2', {'adds': 10, 'dels': 0, 'added_units': 40, 'removed_units': 0})
ccgraph.add_edge('f1', 'f2')

func_drs = ccgraph.function_devranks(0.85)
commit_drs = ccgraph.commit_devranks(0.85)
dev_drs = ccgraph.developer_devranks(0.85)
assert isclose(func_drs['f1'], 0.26, rel_tol=1e-2)
assert isclose(func_drs['f2'], 0.74, rel_tol=1e-2)
assert isclose(commit_drs[first_commit['hexsha']], 1)
assert isclose(dev_drs[first_commit['authorEmail']], 1)


@pytest.mark.asyncio
async def test_black_set():
"""
Expand Down

0 comments on commit 2271e66

Please sign in to comment.