-
Notifications
You must be signed in to change notification settings - Fork 0
/
EdgeCalculator.py
96 lines (78 loc) · 4.43 KB
/
EdgeCalculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#This class is designed to calculate where edges should be between nodes
class EdgeCalculator:
#@param commit: list of all the commits from the log
def __init__(self,commits,programmers):
self.commitlist = commits
self.programmerslist = programmers
#function that calculates which nodes have a pair programming relation + weight
#@returns dictionary with sourceNodeID, targetNodeID as key and weight, commits as value
def getPairProgrammingEdges(self):
edgeDict = {}
for commit in self.commitlist:
contrib = commit.getContributors()
commitNumber = commit.getRevisionNumber()
for source in contrib:
for target in contrib:
sourceID = source.getID()
targetID = target.getID()
if(sourceID != targetID):
#2 situations: dict already contains this tuple or doesnt
if((sourceID,targetID) in edgeDict):
#check if it is a different commits, else ignore
if(not commit in edgeDict[(sourceID,targetID)]['commits']):
#increase the weight
edgeDict[(sourceID,targetID)]['weight'] += 1
#add commit to commitList
if(not commit in edgeDict[(sourceID,targetID)]['commits']):
edgeDict[(sourceID,targetID)]['commits'].append(commit)
elif((targetID,sourceID) in edgeDict):
if(not commit in edgeDict[(targetID,sourceID)]['commits']):
#increase the weight
edgeDict[(targetID,sourceID)]['weight'] += 1
#add commit to commitList
if(not commit in edgeDict[(targetID,sourceID)]['commits']):
edgeDict[(targetID,sourceID)]['commits'].append(commit)
else:
#tuple doesn not yet exist, make a new one
edgeDict[(sourceID,targetID)] = {'weight': 1,'commits':[commit]}
return edgeDict
#function that calculates whether or not there exists an edge between 2 programmers
#collects all revelant commits for smoother future processing
#@returns dictionary with sourceNodeID, targetNodeID as key and commits as value
def getDisjunctColloborationEdges(self):
edgeDict = {}
#check for each pair of programmers
for sourceIterator in range(0,len(self.programmerslist)-2):
source = self.programmerslist[sourceIterator]
for targetIterator in range(sourceIterator+1,len(self.programmerslist)-1):
target = self.programmerslist[targetIterator]
#compare source & target
comlist = self.collectMutualCommits(source,target)
if(len(comlist)>0):
#there exists an edge
edgeDict[(source.getID(),target.getID())] = {'commits':comlist}
return edgeDict
def collectMutualCommits(self,sourceProg,targetProg):
mutualCommits = []
sourceCommits = sourceProg.getCommitList()
targetCommits = targetProg.getCommitList()
for sourceCom in sourceCommits:
for targetCom in targetCommits:
#check if it isnt pair programming:
#condition: pair program ifandonlyif their names are mentioned in both commits
if (not (sourceCom.hasAsContributor(targetProg) and targetCom.hasAsContributor(sourceProg))):
#if they have 1 file in common it's OK
files1 = sourceCom.getFiles()
files2 = targetCom.getFiles()
filepaths1 = self.makeListOfFilePaths(files1)
filepaths2 = self.makeListOfFilePaths(files2)
files1_set = set(filepaths1)
files2_set = set(filepaths2)
if(files1_set & files2_set):
mutualCommits.append([sourceCom,targetCom])
return mutualCommits
def makeListOfFilePaths(self,files):
list = []
for file in files:
list.append(file.getPath())
return list