@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; }
@Override public List<ProximityDescriptor> computeProximity(Task wi) { // TODO must retrieve FULL set of open Tasks somehow // (directly from the DB) List<Task> relatedTasks = new ArrayList<Task>(); List<ProximityDescriptor> BinaryProximities = new ArrayList<ProximityDescriptor>(); int totalEvents = 0; for (Task t : relatedTasks) { if (!(t.getUUID() .equals(wi.getUUID()))) { // TODO: is this the criterion for equals() between Tasks ?? ProximityDescriptor pairProximity = computeProximity(wi, t); totalEvents += countOverlappingEvents(pairProximity.getOverlappingItems()); BinaryProximities.add(pairProximity); } } double averageEvents = totalEvents / relatedTasks.size(); for (ProximityDescriptor pd : BinaryProximities) { double scalingFactor = pd.getOverlappingItems().size() / averageEvents; pd.setScalingFactor(scalingFactor); pd.setScaledDistance(roundProximityScore(pd.getPreliminaryDistance() * scalingFactor)); } return BinaryProximities; }