use of net.sourceforge.processdash.ev.EVSchedule.Period in project processdash by dtuma.
the class HierarchySynchronizer method mergeSchedules.
private void mergeSchedules(EVSchedule currentSchedule, EVSchedule lastSyncedSchedule, double syncPdt) {
// look at the three schedule end dates, and determine when the merged
// schedule should end.
int currentEndWeek = getEndWeekOfSchedule(currentSchedule, startDate);
int syncedEndWeek = getEndWeekOfSchedule(lastSyncedSchedule, startDate);
int mergedEndWeek;
if (currentEndWeek == syncedEndWeek)
mergedEndWeek = endWeek;
else
mergedEndWeek = currentEndWeek;
// Keep a list of manual edits the user has made, for reverse sync
Map<Date, Double> userExceptions = new HashMap<Date, Double>();
// Make a list of "merged exceptions." Begin with the ones that came
// from the current WBS.
Map mergedExceptions = new HashMap(scheduleExceptions);
// manually after receiving the last schedule from the WBS.
for (int i = 0; i < currentSchedule.getRowCount(); i++) {
Period c = currentSchedule.get(i + 1);
// we can stop looking for manual edits
if (c.isAutomatic())
break;
Date beg = c.getBeginDate();
Date end = c.getEndDate();
long midTime = (beg.getTime() + end.getTime()) / 2;
Date mid = new Date(midTime);
// if the time in this period matches the value that came from the
// last synced schedule, it isn't a manual edit.
double currentTime = c.planDirectTime();
Period s = lastSyncedSchedule.get(mid);
if (s != null && eq(s.planDirectTime(), currentTime))
continue;
// if the manual edit happened in a week that preceeds the start or
// follows the end of our new schedule, it isn't relevant.
int week = (int) ((midTime - startDate.getTime()) / WEEK_MILLIS);
if (week < 0)
continue;
if (mergedEndWeek != -1 && week >= mergedEndWeek)
continue;
if (eq(currentTime, syncPdt)) {
// the user erased an exception that they received from the
// WBS. We should do the same thing for the new WBS data.
mergedExceptions.remove(week);
userExceptions.put(mid, null);
} else {
// the user created a new exception in the schedule. Add it
// to our map.
Double hours = new Double(currentTime / 60.0);
mergedExceptions.put(week, hours);
userExceptions.put(mid, hours);
}
}
// build a schedule from the information we've merged, and reset the
// current schedule to use that information.
double levelOfEffort = currentSchedule.getLevelOfEffort();
EVSchedule mergedSchedule = new EVSchedule(startDate, hoursPerWeek, mergedEndWeek, mergedExceptions, levelOfEffort, true);
currentSchedule.copyFrom(mergedSchedule);
// save information about user edits for delivery to the WBS
if (!userExceptions.isEmpty())
discrepancies.add(new SyncDiscrepancy.EVSchedule(userExceptions));
}
Aggregations