Exemplo n.º 1
0
 private Map<String, List<Integer>> getCommitsBetween(
     Map<String, List<VcsCommitInfo>> first, Map<String, List<VcsCommitInfo>> second) {
   Map<String, List<Integer>> result = new HashMap<>();
   for (String filename : first.keySet()) {
     //            System.out.println(filename+":");
     List<VcsCommitInfo> commitsFromFirst = first.get(filename);
     List<VcsCommitInfo> commitsFromSecond = second.get(filename);
     List<Integer> intervals = new ArrayList<>();
     if (commitsFromSecond == null) result.put(filename, Arrays.asList(-1));
     else {
       Iterator<VcsCommitInfo> firstIt = commitsFromFirst.iterator();
       Iterator<VcsCommitInfo> secondIt = commitsFromSecond.iterator();
       while (firstIt.hasNext() && secondIt.hasNext()) {
         VcsCommitInfo topCommit = firstIt.next();
         //                    System.out.println("top: "+topCommit);
         while (secondIt.hasNext()) {
           VcsCommitInfo bugCommit = secondIt.next();
           //                        System.out.println("bugfix: "+bugCommit);
           if (bugCommit.getDate().after(topCommit.getDate())) {
             intervals.add(
                 getNumberOfCommitsBetween(topCommit.getCommitId(), bugCommit.getCommitId()));
             break;
           }
         }
       }
       if (firstIt.hasNext() && !secondIt.hasNext()) intervals.add(-1);
     }
     result.put(filename, intervals);
   }
   return result;
 }
Exemplo n.º 2
0
 private void generateTestAndTrainSets(Collection<VcsCommitInfo> allCommits) {
   testSet = new ArrayList<>();
   trainSet = new ArrayList<>();
   for (VcsCommitInfo commit : allCommits) {
     if (Math.random() > TEST_SET_FRACTION) {
       trainSet.add(commit.getCommitId());
     } else {
       testSet.add(commit.getCommitId());
     }
   }
 }
Exemplo n.º 3
0
 public void process(String projectId, Date from, Date to) {
   reset();
   Collection<VcsCommitInfo> allCommits = getCommitsForProject(projectId, from, to);
   generateTestAndTrainSets(allCommits);
   System.out.println("Processing commits...");
   int total = allCommits.size();
   int counter = 0;
   long startTime = System.currentTimeMillis();
   for (VcsCommitInfo commitInfo : allCommits) {
     counter++;
     if (counter % 100 == 0) {
       System.out.println(
           counter
               + " / "
               + total
               + " | last 100 processed in "
               + (System.currentTimeMillis() - startTime)
               + " ms");
       startTime = System.currentTimeMillis();
     }
     for (String filename : commitInfo.getAffectedFiles()) {
       if (!commitAffections.containsKey(filename)) {
         commitAffections.put(filename, new ArrayList<VcsCommitInfo>());
       }
       commitAffections.get(filename).add(commitInfo);
     }
     if (VcsCommitInfoUtils.isRelatedToBugIssue(commitInfo)) {
       for (String filename : commitInfo.getAffectedFiles()) {
         if (!bugFixCommitAffections.containsKey(filename)) {
           bugFixCommitAffections.put(filename, new ArrayList<VcsCommitInfo>());
         }
         bugFixCommitAffections.get(filename).add(commitInfo);
       }
     }
     for (PredictionModel model : myModels) {
       if (trainSet.contains(commitInfo.getCommitId())) {
         // train the model
         model.update(commitInfo, true);
       }
       if (testSet.contains(commitInfo.getCommitId())) {
         // update the model without training and get prediction data
         Map<String, List<VcsCommitInfo>> topAppearanceMapForCurrentModel =
             appearancesInTop.get(model);
         for (String fileInTop : model.getPredictionData().keySet()) {
           if (!topAppearanceMapForCurrentModel.containsKey(fileInTop)) {
             topAppearanceMapForCurrentModel.put(fileInTop, new ArrayList<VcsCommitInfo>());
           }
           topAppearanceMapForCurrentModel.get(fileInTop).add(commitInfo);
         }
       }
     }
   }
 }
Exemplo n.º 4
0
 private Map<String, Integer> processIndices(Collection<VcsCommitInfo> commits) {
   int index = 0;
   Map<String, Integer> result = new HashMap<>();
   for (VcsCommitInfo commitInfo : commits) {
     result.put(commitInfo.getCommitId(), ++index);
   }
   return result;
 }