Set<AuxFileFileMetrics> fileFileMetrics = new HashSet<>();
out.printLog("Calculando metricas SNA...");
GlobalMeasure global = GlobalMeasureCalculator.calcule(graph);
out.printLog("Global measures: " + global.toString());
// Map<String, Double> barycenter = BarycenterCalculator.calcule(graph, edgesWeigth);
Map<String, Double> betweenness = BetweennessCalculator.calcule(graph, edgesWeigth);
Map<String, Double> closeness = ClosenessCalculator.calcule(graph, edgesWeigth);
Map<String, Integer> degree = DegreeCalculator.calcule(graph);
Map<String, Double> eigenvector = EigenvectorCalculator.calcule(graph, edgesWeigth);
Map<String, EgoMeasure<String>> ego = EgoMeasureCalculator.calcule(graph, edgesWeigth);
Map<String, StructuralHolesMeasure<String>> structuralHoles = StructuralHolesCalculator.calcule(graph, edgesWeigth);
// number of pull requests in date interval
Long numberOfAllPullrequestFuture = pairFileDAO.calculeNumberOfPullRequest(getRepository(), null, null, futureBeginDate, futureEndDate, true);
// cache for optimization number of pull requests where file is in,
// reducing access to database
Map<String, Long> pullRequestFileMap = new HashMap<>();
// cache for optimization file code churn (add, del, change),
// reducing access to database
Map<String, AuxCodeChurn> codeChurnRequestFileMap = new HashMap<>();
Map<String, AuxCodeChurn> cummulativeCodeChurnRequestFileMap = new HashMap<>();
// cache for optimization file commits made by user,
// reducing access to database
Map<String, AuxCodeChurn> fileUserCommitMap = new HashMap<>();
out.printLog("Calculando somas, máximas, médias, updates, code churn e apriori para cada par de arquivos...");
count = 0;
final int size = commitersPairFile.entrySet().size();
out.printLog("Número de pares de arquivos: " + commitersPairFile.keySet().size());
for (Map.Entry<AuxFileFile, Set<String>> entry : commitersPairFile.entrySet()) {
if (count++ % 100 == 0 || count == size) {
System.out.println(count + "/" + size);
}
AuxFileFile fileFile = entry.getKey();
Set<String> devsCommentters = entry.getValue();
// pair file network
GlobalMeasure pairFileGlobal = GlobalMeasureCalculator.calcule(pairFileNetwork.get(fileFile));
// Double barycenterSum = 0d, barycenterAvg, barycenterMax = Double.NEGATIVE_INFINITY;
Double betweennessSum = 0d, betweennessAvg, betweennessMax = Double.NEGATIVE_INFINITY;
Double closenessSum = 0d, closenessAvg, closenessMax = Double.NEGATIVE_INFINITY;
Integer degreeSum = 0, degreeMax = Integer.MIN_VALUE;
Double degreeAvg;
Double eigenvectorSum = 0d, eigenvectorAvg, eigenvectorMax = Double.NEGATIVE_INFINITY;
Double egoBetweennessSum = 0d, egoBetweennessAvg, egoBetweennessMax = Double.NEGATIVE_INFINITY;
Long egoSizeSum = 0l, egoSizeMax = Long.MIN_VALUE;
// Long egoPairsSum = 0l, egoPairsMax = Long.MIN_VALUE;
Long egoTiesSum = 0l, egoTiesMax = Long.MIN_VALUE;
Double egoSizeAvg, /*egoPairsAvg,*/ egoTiesAvg;
Double egoDensitySum = 0d, egoDensityAvg, egoDensityMax = Double.NEGATIVE_INFINITY;
Double efficiencySum = 0.0d, efficiencyAvg, efficiencyMax = Double.NEGATIVE_INFINITY;
Double effectiveSizeSum = 0.0d, effectiveSizeAvg, effectiveSizeMax = Double.NEGATIVE_INFINITY;
Double constraintSum = 0.0d, constraintAvg, constraintMax = Double.NEGATIVE_INFINITY;
Double hierarchySum = 0.0d, hierarchyAvg, hierarchyMax = Double.NEGATIVE_INFINITY;
for (String commenter : devsCommentters) {
// sums calculation
// barycenterSum += barycenter.get(commenter);
betweennessSum += betweenness.get(commenter);
closenessSum += Double.isInfinite(closeness.get(commenter)) ? 0 : closeness.get(commenter);
degreeSum += degree.get(commenter);
// eigenvectorSum += eigenvector.get(commenter);
egoBetweennessSum += ego.get(commenter).getBetweennessCentrality();
egoSizeSum += ego.get(commenter).getSize();
// egoPairsSum += ego.get(commenter).getPairs();
egoTiesSum += ego.get(commenter).getTies();
egoDensitySum += ego.get(commenter).getDensity();
efficiencySum += structuralHoles.get(commenter).getEfficiency();
effectiveSizeSum += structuralHoles.get(commenter).getEffectiveSize();
constraintSum += structuralHoles.get(commenter).getConstraint();
hierarchySum += structuralHoles.get(commenter).getHierarchy();
// maximum calculation
// barycenterMax = Math.max(barycenterMax, barycenter.get(commenter));
betweennessMax = Math.max(betweennessMax, betweenness.get(commenter));
closenessMax = Math.max(closenessMax, Double.isInfinite(closeness.get(commenter)) ? 0 : closeness.get(commenter));
degreeMax = Math.max(degreeMax, degree.get(commenter));
eigenvectorMax = Math.max(eigenvectorMax, eigenvector.get(commenter));
egoBetweennessMax = Math.max(egoBetweennessMax, ego.get(commenter).getBetweennessCentrality());
egoSizeMax = Math.max(egoSizeMax, ego.get(commenter).getSize());
// egoPairsMax = Math.max(egoPairsMax, ego.get(commenter).getPairs());
egoTiesMax = Math.max(egoTiesMax, ego.get(commenter).getTies());
egoDensityMax = Math.max(egoDensityMax, ego.get(commenter).getDensity());
efficiencyMax = Math.max(efficiencyMax, structuralHoles.get(commenter).getEfficiency());
effectiveSizeMax = Math.max(effectiveSizeMax, structuralHoles.get(commenter).getEffectiveSize());
constraintMax = Math.max(constraintMax, structuralHoles.get(commenter).getConstraint());
hierarchyMax = Math.max(hierarchyMax, structuralHoles.get(commenter).getHierarchy());
}
// Average calculation /////////////////////////////////////////////
Integer distinctCommentersCount = devsCommentters.size();
// barycenterAvg = barycenterSum / (double) distinctCommentersCount;
betweennessAvg = betweennessSum / distinctCommentersCount.doubleValue();
closenessAvg = closenessSum / distinctCommentersCount.doubleValue();
degreeAvg = degreeSum / distinctCommentersCount.doubleValue();
eigenvectorAvg = eigenvectorSum / distinctCommentersCount.doubleValue();
egoBetweennessAvg = egoBetweennessSum / distinctCommentersCount.doubleValue();
egoSizeAvg = egoSizeSum / distinctCommentersCount.doubleValue();
// egoPairsAvg = egoPairsSum / distinctCommentersCount;
egoTiesAvg = egoTiesSum / distinctCommentersCount.doubleValue();
egoDensityAvg = egoDensitySum / distinctCommentersCount.doubleValue();
efficiencyAvg = efficiencySum / distinctCommentersCount.doubleValue();
effectiveSizeAvg = effectiveSizeSum / distinctCommentersCount.doubleValue();
constraintAvg = constraintSum / distinctCommentersCount.doubleValue();
hierarchyAvg = hierarchySum / distinctCommentersCount.doubleValue();
// Weighted geometric average: issue > committers + commits ////////
final long[][] committersCommitsPerIssue = pairFileDAO.calculeCommittersXCommits(
repository, fileFile.getFileName(), fileFile.getFileName2(), beginDate, endDate);
final double geometricAverageCommittersCommits
= MathUtils.calculateWeightedGeometricAverage(committersCommitsPerIssue);
// Commit-based metrics ////////////////////////////////////////////
final long changes = calculeFileCodeChurn(codeChurnRequestFileMap, fileFile.getFileName(), fileDAO, beginDate, endDate);
final long changes2 = calculeFileCodeChurn(codeChurnRequestFileMap, fileFile.getFileName2(), fileDAO, beginDate, endDate);
final long cummulativeChanges = calculeFileCodeChurn(cummulativeCodeChurnRequestFileMap, fileFile.getFileName(), fileDAO, null, endDate);
final long cummulativeChanges2 = calculeFileCodeChurn(cummulativeCodeChurnRequestFileMap, fileFile.getFileName2(), fileDAO, null, endDate);
Set<AuxUser> devsCommitters = pairFileDAO.selectCommitters(repository,
fileFile.getFileName(), fileFile.getFileName2(), beginDate, endDate);
Long devCommitsSum = 0l, devCommitsMax = 0l;
Double devCommitsAvg;
Double ownershipSum = 0.0d, ownershipAvg, ownershipMax = 0.0d;
Long minorContributors = 0l, majorContributors = 0l;
Double ownerExperience = 0.0d, ownerExperience2 = 0.0d, cummulativeOwnerExperience = 0.0d, cummulativeOwnerExperience2 = 0.0d;
long committers = devsCommitters.size();
long distinctCommitters = pairFileDAO.calculeCommitters(repository,
fileFile.getFileName(), fileFile.getFileName2(), null, endDate);
Long commits = pairFileDAO.calculeCommits(repository,
fileFile.getFileName(), fileFile.getFileName2(),
beginDate, endDate);
for (AuxUser devCommitter : devsCommitters) {
Long devCommits = pairFileDAO.calculeCommits(repository,
fileFile.getFileName(), fileFile.getFileName2(), devCommitter.getUser(),
beginDate, endDate);
devCommitsSum += devCommits;
Double ownership = devCommits.doubleValue() / commits.doubleValue();
ownershipSum += ownership;
if (ownership <= 0.05) { // menor ou igual que 5% = minor
minorContributors++;
} else { // maior que 5% = major
majorContributors++;
}
devCommitsMax = Math.max(devCommitsMax, devCommits);
ownershipMax = Math.max(ownershipMax, ownership);
// Calculing OEXP of each file
Double experience = calculeDevFileExperience(changes, fileUserCommitMap, fileFile.getFileName(), devCommitter.getUser(), fileDAO, beginDate, endDate);
ownerExperience = Math.max(experience, ownerExperience);
Double experience2 = calculeDevFileExperience(changes2, fileUserCommitMap, fileFile.getFileName2(), devCommitter.getUser(), fileDAO, beginDate, endDate);
ownerExperience2 = Math.max(experience2, ownerExperience2);
// Calculing OWN
Double cumulativeExperience = calculeDevFileExperience(cummulativeChanges, fileUserCommitMap, fileFile.getFileName(), devCommitter.getUser(), fileDAO, null, endDate);
cummulativeOwnerExperience = Math.max(cummulativeOwnerExperience, cumulativeExperience);
Double cumulativeExperience2 = calculeDevFileExperience(cummulativeChanges2, fileUserCommitMap, fileFile.getFileName2(), devCommitter.getUser(), fileDAO, null, endDate);
cummulativeOwnerExperience2 = Math.max(cummulativeOwnerExperience2, cumulativeExperience2);
}
devCommitsAvg = (double) devCommitsSum / (double) committers;
ownershipAvg = (double) ownershipSum / (double) committers;
// double majorContributorsRate = (double) majorContributors / (double) committers; // % de major
// double minorContributorsRate = (double) minorContributors / (double) committers; // % de minor
Long updates = pairFileDAO.calculeNumberOfPullRequest(repository,
fileFile.getFileName(), fileFile.getFileName2(),
beginDate, endDate, true);
Long futureUpdates;
if (beginDate.equals(futureBeginDate) && endDate.equals(futureEndDate)) {
futureUpdates = updates;
} else {
futureUpdates = pairFileDAO.calculeNumberOfPullRequest(repository,
fileFile.getFileName(), fileFile.getFileName2(),
futureBeginDate, futureEndDate, true);
}
// list all issues and its comments
List<AuxWordiness> issuesAndComments = pairFileDAO.listIssues(repository,
fileFile.getFileName(), fileFile.getFileName2(), beginDate, endDate, true);
long wordiness = 0;
for (AuxWordiness auxWordiness : issuesAndComments) {
wordiness += WordinessCalculator.calcule(auxWordiness);
}
Long commentsSum = pairFileDAO.calculeComments(repository,
fileFile.getFileName(), fileFile.getFileName2(),
beginDate, endDate, true);
Long codeChurn = fileDAO.calculeCodeChurn(repository,
fileFile.getFileName(), beginDate, endDate);
Long codeChurn2 = fileDAO.calculeCodeChurn(repository,
fileFile.getFileName2(), beginDate, endDate);
AuxCodeChurn pairFileCodeChurn = pairFileDAO.calculeCodeChurnAddDelChange(repository,
fileFile.getFileName2(), fileFile.getFileName(),
beginDate, endDate);
double codeChurnAvg = (codeChurn + codeChurn2) / 2.0d;
closenessSum = MathUtils.zeroIfNaN(closenessSum);
closenessAvg = MathUtils.zeroIfNaN(closenessAvg);
closenessMax = MathUtils.zeroIfNaN(closenessMax);
// pair file age in release interval (days)
int ageRelease = pairFileDAO.calculePairFileDaysAge(repository, fileFile.getFileName(), fileFile.getFileName2(), beginDate, endDate, true);
// pair file age in total until final date (days)
int ageTotal = pairFileDAO.calculePairFileDaysAge(repository, fileFile.getFileName(), fileFile.getFileName2(), null, endDate, true);
boolean samePackage = PathUtils.isSameFullPath(fileFile.getFileName(), fileFile.getFileName2());
AuxFileFileMetrics auxFileFileMetrics = new AuxFileFileMetrics(
fileFile.getFileName(), fileFile.getFileName2(), BooleanUtils.toInteger(samePackage),
// barycenterSum, barycenterAvg, barycenterMax,
betweennessSum, betweennessAvg, betweennessMax,
closenessSum, closenessAvg, closenessMax,
degreeSum, degreeAvg, degreeMax,
eigenvectorSum, eigenvectorAvg, eigenvectorMax,
egoBetweennessSum, egoBetweennessAvg, egoBetweennessMax,
egoSizeSum, egoSizeAvg, egoSizeMax,
egoTiesSum, egoTiesAvg, egoTiesMax,
// egoPairsSum, egoPairsAvg, egoPairsMax,
egoDensitySum, egoDensityAvg, egoDensityMax,
efficiencySum, efficiencyAvg, efficiencyMax,
effectiveSizeSum, effectiveSizeAvg, effectiveSizeMax,
constraintSum, constraintAvg, constraintMax,
hierarchySum, hierarchyAvg, hierarchyMax,
pairFileGlobal.getSize(), pairFileGlobal.getTies(),
pairFileGlobal.getDensity(), pairFileGlobal.getDiameter(),
devCommitsSum, devCommitsAvg, devCommitsMax,
ownershipSum, ownershipAvg, ownershipMax,
majorContributors, minorContributors,
ownerExperience, ownerExperience2,
cummulativeOwnerExperience, cummulativeOwnerExperience2,