1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package edu.nju.algorithm.progress;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.TreeMap;
- /**
- * @Author JiaWei Xu
- * @Date 2021-01-06 15:54
- * @Email xjwhhh233@outlook.com
- */
- public class M0CRCAlgorithm {
- public Integer[] obtainRecaptureResults(TreeMap<Integer, ArrayList<BugForProgress>> captureProcess) {
- HashSet<String> distinctBugs = new HashSet<String>();
- for (Integer cap : captureProcess.keySet()) {
- ArrayList<BugForProgress> reportList = captureProcess.get(cap);
- for (int i = 0; i < reportList.size(); i++) {
- String dupTag = reportList.get(i).getBugPage();
- distinctBugs.add(dupTag);
- }
- }
- int captureSize = captureProcess.size();
- int sep1 = captureSize / 2;
- int sep2 = sep1;
- int sep3 = sep1;
- if (sep1 > 3) {
- sep2 = sep1 - 1;
- sep3 = sep1 + 1;
- }
- if (sep1 > 5) {
- sep2 = sep1 - 2;
- sep3 = sep1 + 2;
- }
- int estBugs1 = this.estimateTotalBugNum(captureProcess, sep1);
- int estBugs2 = this.estimateTotalBugNum(captureProcess, sep2);
- int estBugs3 = this.estimateTotalBugNum(captureProcess, sep3);
- int estBugs = (estBugs1 + estBugs2 + estBugs3) / 3;
- return new Integer[]{estBugs, estBugs, estBugs, distinctBugs.size()};
- }
- public Integer estimateTotalBugNum(TreeMap<Integer, ArrayList<BugForProgress>> captureProcess, int sep) {
- HashSet<String> priorNoDupBugs = new HashSet<String>();
- HashSet<String> laterNoDupBugs = new HashSet<String>();
- int count = 0;
- for (Integer cap : captureProcess.keySet()) {
- count++;
- ArrayList<BugForProgress> reportList = captureProcess.get(cap);
- for (int i = 0; i < reportList.size(); i++) {
- BugForProgress report = reportList.get(i);
- if (count <= sep) {
- priorNoDupBugs.add(report.getBugPage());
- } else {
- laterNoDupBugs.add(report.getBugPage());
- }
- }
- }
- int overlapBugs = 0;
- for (String dupTag : priorNoDupBugs) {
- if (laterNoDupBugs.contains(dupTag)) {
- overlapBugs++;
- }
- }
- int priorBugs = priorNoDupBugs.size();
- int laterBugs = laterNoDupBugs.size();
- int estimateBugs = priorBugs * laterBugs;
- if (overlapBugs > 0) {
- estimateBugs = estimateBugs / overlapBugs;
- }
- return estimateBugs;
- }
- }
|