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;
 }
 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());
     }
   }
 }
 private List<Double> getBugFixTimes(String projectId, Date from, Date to) {
   List<Double> result = new ArrayList<>();
   Collection<VcsCommitInfo> commits = myVcsProvider.getHistoryChunk(projectId, from, to);
   Date start = commits.iterator().next().getDate();
   for (VcsCommitInfo commitInfo : commits) {
     if (VcsCommitInfoUtils.isRelatedToBugIssue(commitInfo)) {
       result.add(1.0 * (commitInfo.getDate().getTime() - start.getTime()) / (86400 * 1000));
     }
   }
   return result;
 }
 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);
         }
       }
     }
   }
 }
 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;
 }
 private Map<String, List<Double>> getIntervals(
     Map<String, List<VcsCommitInfo>> first, Map<String, List<VcsCommitInfo>> second) {
   System.out.println("Processing intervals...");
   Map<String, List<Double>> 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<Double> intervals = new ArrayList<>();
     if (commitsFromSecond == null) result.put(filename, Arrays.asList(-1.0));
     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(
                 1.0 / 86400000 * (bugCommit.getDate().getTime() - topCommit.getDate().getTime()));
             break;
           }
         }
       }
       if (firstIt.hasNext() && !secondIt.hasNext()) intervals.add(-1.0);
     }
     result.put(filename, intervals);
   }
   return result;
 }