double newL2BaseRate = origL2BaseRate - totalL6BaseRate; if (newL2BaseRate != origL2BaseRate) {
double durationMillis = (endTime - countedStartTime); double durationSecs = (durationMillis / 1000); double newL2BaseRate = ((origL2BaseQty - totalL6BaseQty) / durationSecs); if (newL2BaseRate != expL2BaseRate) { double origL2BaseRate = getBaseUnitPerSecond(origL2Rate); if (logger.isDebugEnabled()) { logger.debug("Level2Expander:Original Rate per day:" + (origL2BaseRate * TimeUtils.SEC_PER_DAY) + ".  Changing expanded rate from " + (expL2BaseRate * TimeUtils.SEC_PER_DAY) + " to " + (newL2BaseRate * TimeUtils.SEC_PER_DAY)); logger.debug("     and L2 Start time is " + new Date(startTime) + " and end time is " + new Date(endTime) + ", but last actual seen is " + new Date(lastActualSeen)); logger.debug("  and also origL2BaseQty:" + origL2BaseQty + " totalL6BaseQty:" + totalL6BaseQty); }
  private Task translateLevel2Task(Task level2Task,                                     Collection relevantL6Tasks) {    Task doneLevel2Task = null;    long lastActualSeen = ((Long) endTimeMap.get(getTaskUtils().getCustomer(level2Task))).longValue();    long endTime = getTaskUtils().getEndTime(level2Task);    long startTime = getTaskUtils().getStartTime(level2Task);    boolean alreadyDisposed = false;    double expL2BaseRate = 0;    PlanElement pe = level2Task.getPlanElement();    if (pe != null) {      if (pe instanceof Expansion) {        Expansion exp = (Expansion) pe;        Enumeration subtasks = exp.getWorkflow().getTasks();        while (subtasks.hasMoreElements()) {          Task subtask = (Task) subtasks.nextElement();          expL2BaseRate += getBaseUnitPerSecond(getTaskUtils().getRate(subtask));        }      } else if (pe instanceof Disposition) {        alreadyDisposed = true;      }    }    if (lastActualSeen >= endTime) {      doneLevel2Task = level2Task;    } else {      long countedStartTime = Math.max(startTime, lastActualSeen);      double totalL6BaseRate = deriveTotalQty(countedStartTime, endTime, relevantL6Tasks);      Rate origL2Rate = getTaskUtils().getRate(level2Task);      double origL2BaseRate = deriveTotalQty(countedStartTime, endTime, level2Task);//      double origL2BaseRate = getBaseUnitPerSecond(origL2Rate);      if (totalL6BaseRate >= origL2BaseRate) {        doneLevel2Task = level2Task;      } else {        double newL2BaseRate = origL2BaseRate - totalL6BaseRate;        if (newL2BaseRate != origL2BaseRate) {          Rate newL2Rate = newRateFromUnitPerSecond(origL2Rate, newL2BaseRate);          expandLevel2Task(level2Task, newL2Rate, lastActualSeen);        }      }    }    if (alreadyDisposed) {      return null;    }    return doneLevel2Task;  }