M0CRCAlgorithm.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package edu.nju.algorithm.progress;
  2. import java.util.ArrayList;
  3. import java.util.HashSet;
  4. import java.util.TreeMap;
  5. /**
  6. * @Author JiaWei Xu
  7. * @Date 2021-01-06 15:54
  8. * @Email xjwhhh233@outlook.com
  9. */
  10. public class M0CRCAlgorithm {
  11. public Integer[] obtainRecaptureResults(TreeMap<Integer, ArrayList<BugForProgress>> captureProcess) {
  12. HashSet<String> distinctBugs = new HashSet<String>();
  13. for (Integer cap : captureProcess.keySet()) {
  14. ArrayList<BugForProgress> reportList = captureProcess.get(cap);
  15. for (int i = 0; i < reportList.size(); i++) {
  16. String dupTag = reportList.get(i).getBugPage();
  17. distinctBugs.add(dupTag);
  18. }
  19. }
  20. int captureSize = captureProcess.size();
  21. int sep1 = captureSize / 2;
  22. int sep2 = sep1;
  23. int sep3 = sep1;
  24. if (sep1 > 3) {
  25. sep2 = sep1 - 1;
  26. sep3 = sep1 + 1;
  27. }
  28. if (sep1 > 5) {
  29. sep2 = sep1 - 2;
  30. sep3 = sep1 + 2;
  31. }
  32. int estBugs1 = this.estimateTotalBugNum(captureProcess, sep1);
  33. int estBugs2 = this.estimateTotalBugNum(captureProcess, sep2);
  34. int estBugs3 = this.estimateTotalBugNum(captureProcess, sep3);
  35. int estBugs = (estBugs1 + estBugs2 + estBugs3) / 3;
  36. return new Integer[]{estBugs, estBugs, estBugs, distinctBugs.size()};
  37. }
  38. public Integer estimateTotalBugNum(TreeMap<Integer, ArrayList<BugForProgress>> captureProcess, int sep) {
  39. HashSet<String> priorNoDupBugs = new HashSet<String>();
  40. HashSet<String> laterNoDupBugs = new HashSet<String>();
  41. int count = 0;
  42. for (Integer cap : captureProcess.keySet()) {
  43. count++;
  44. ArrayList<BugForProgress> reportList = captureProcess.get(cap);
  45. for (int i = 0; i < reportList.size(); i++) {
  46. BugForProgress report = reportList.get(i);
  47. if (count <= sep) {
  48. priorNoDupBugs.add(report.getBugPage());
  49. } else {
  50. laterNoDupBugs.add(report.getBugPage());
  51. }
  52. }
  53. }
  54. int overlapBugs = 0;
  55. for (String dupTag : priorNoDupBugs) {
  56. if (laterNoDupBugs.contains(dupTag)) {
  57. overlapBugs++;
  58. }
  59. }
  60. int priorBugs = priorNoDupBugs.size();
  61. int laterBugs = laterNoDupBugs.size();
  62. int estimateBugs = priorBugs * laterBugs;
  63. if (overlapBugs > 0) {
  64. estimateBugs = estimateBugs / overlapBugs;
  65. }
  66. return estimateBugs;
  67. }
  68. }