@Override public ProximityDescriptor computeProximity(Task wi1, Task wi2) { List<CodeContext> c1 = getContextEvents(wi1); List<CodeContext> c2 = getContextEvents(wi2); int totaItems = 0; int overlappingItems = 0; Hashtable<String, OverlapItem> allElements = new Hashtable<String, OverlapItem>(); OverlapItem oi; String elementID; ProximityDescriptor pd = new ProximityDescriptor(); ArrayList<Task> relatedTasks = new ArrayList<Task>(); // go through the 2 working sets one by one: first one ... relatedTasks.add(wi1); for (CodeContext eventC1 : c1) { if (granularity == ProximityGranularity.FILE_LEVEL) elementID = eventC1.getFileName(); else elementID = eventC1.getHandle(); if (allElements.containsKey(elementID) == false) { oi = new OverlapItem(elementID); allElements.put(elementID, oi); } else oi = allElements.get(elementID); if (eventC1.wasEdited()) oi.setEdit1(oi.getEdit1() + 1); else oi.setSelection1(oi.getSelection1() + 1); } // ... and now second one relatedTasks.add(wi2); for (CodeContext eventC2 : c2) { if (granularity == ProximityGranularity.FILE_LEVEL) elementID = eventC2.getFileName(); else elementID = eventC2.getHandle(); if (allElements.containsKey(elementID) == false) { oi = new OverlapItem(elementID); allElements.put(elementID, oi); } else oi = allElements.get(elementID); if (eventC2.wasEdited()) oi.setEdit1(oi.getEdit1() + 1); else oi.setSelection1(oi.getSelection1() + 1); } totaItems = allElements.keySet().size(); List<OverlapItem> actualOverlaps = new ArrayList<OverlapItem>(); for (OverlapItem overlap : allElements.values()) { if (overlap.isActualOverlap()) actualOverlaps.add(overlap); } overlappingItems = actualOverlaps.size(); pd.setOverlappingItems(actualOverlaps); pd.setPreliminaryDistance(computeRawProximity(actualOverlaps)); pd.setInvolvedTasks(relatedTasks); return pd; }
private double computeRawProximity(List<OverlapItem> overlaps) { double potential = 0; double actual = 0; for (OverlapItem item : overlaps) { if (item.getEdit1() > 0 && item.getEdit2() > 0) { potential += ProximityWeight.EDIT_OVERLAP.weight(); actual += ProximityWeight.EDIT_OVERLAP.weight(); } else if (item.getEdit1() > 0 || item.getEdit2() > 0) { potential += ProximityWeight.EDIT_OVERLAP.weight(); if (item.getSelection1() > 0 && item.getSelection2() > 0) actual += ProximityWeight.MIXED_OVERLAP.weight(); } else { potential += ProximityWeight.SELECTION_OVERLAP.weight(); if (item.getSelection1() > 0 && item.getSelection2() > 0) actual += ProximityWeight.SELECTION_OVERLAP.weight(); } } return roundProximityScore(actual / potential); }
private int countOverlappingEvents(List<OverlapItem> overlaps) { int overlapCount = 0; // calculate number of overlapping events for (OverlapItem oi : overlaps) { overlapCount = overlapCount + Math.min(oi.getEdit1(), oi.getEdit2()) + Math.min(oi.getSelection1(), oi.getSelection2()); } return overlapCount; }