protected ExactEstimate getTodaysStartValueWithScoping(
      IterationHistoryEntry yesterdayEntry, IterationHistoryEntry todayEntry) {

    long minorUnits = yesterdayEntry.getEffortLeftSum();
    minorUnits += todayEntry.getDeltaOriginalEstimate();

    return new ExactEstimate(minorUnits);
  }
 protected TimeSeriesDataItem getBurndownDataItemForDay(IterationHistoryEntry entry) {
   TimeSeriesDataItem item =
       new TimeSeriesDataItem(
           new Second(
               entry
                   .getTimestamp()
                   .toDateTimeAtCurrentTime()
                   .minusMinutes(timeDifferenceMinutes)
                   .toDateMidnight()
                   .plusDays(1)
                   .toDate()),
           ExactEstimateUtils.extractMajorUnits(new ExactEstimate(entry.getEffortLeftSum())));
   return item;
 }
 protected IterationHistoryEntry getHistoryEntryForDate(
     List<IterationHistoryEntry> entries, LocalDate date) {
   IterationHistoryEntry foundEntry = new IterationHistoryEntry();
   for (IterationHistoryEntry entry : entries) {
     if (entry.getTimestamp().equals(date)) {
       return entry;
     }
     if (entry.getTimestamp().compareTo(date) > 0) {
       break;
     }
     foundEntry = entry;
   }
   IterationHistoryEntry returnable = new IterationHistoryEntry();
   returnable.setTimestamp(date.toDateMidnight().toLocalDate());
   returnable.setEffortLeftSum(foundEntry.getEffortLeftSum());
   returnable.setOriginalEstimateSum(foundEntry.getOriginalEstimateSum());
   return returnable;
 }
  /** Assembles all the needed <code>TimeSeries</code>. */
  protected TimeSeriesCollection getDataset(Iteration iteration) {
    TimeSeriesCollection chartDataset = new TimeSeriesCollection();

    List<IterationHistoryEntry> iterationEntries =
        iterationHistoryEntryBusiness.getHistoryEntriesForIteration(iteration);

    LocalDate yesterday = new LocalDate().minusDays(1);
    LocalDate today = new LocalDate();
    IterationHistoryEntry yesterdayEntry = getHistoryEntryForDate(iterationEntries, yesterday);
    IterationHistoryEntry todayEntry = getHistoryEntryForDate(iterationEntries, today);
    DateTime iterationStartDate = new DateTime(iteration.getStartDate());
    DateTime iterationEndDate = new DateTime(iteration.getEndDate());

    chartDataset.addSeries(
        getBurndownTimeSeries(
            iterationEntries,
            new LocalDate(iteration.getStartDate()),
            determineEndDate(new LocalDate(iteration.getEndDate()))));

    chartDataset.addSeries(getCurrentDayTimeSeries(yesterdayEntry, todayEntry));

    chartDataset.addSeries(
        getScopingTimeSeries(
            iterationEntries, iterationStartDate.toLocalDate(), iterationEndDate.toLocalDate()));

    chartDataset.addSeries(
        getReferenceVelocityTimeSeries(
            iterationStartDate,
            iterationEndDate,
            new ExactEstimate(todayEntry.getOriginalEstimateSum())));

    TimeSeries predictedVelocity =
        getPredictedVelocityTimeSeries(
            iterationStartDate.toLocalDate(),
            iterationEndDate.toLocalDate(),
            yesterdayEntry,
            todayEntry);
    if (predictedVelocity != null) {
      chartDataset.addSeries(predictedVelocity);
    }

    return chartDataset;
  }
  protected Pair<TimeSeriesDataItem, TimeSeriesDataItem> getBurndownScopedDataItemForDay(
      IterationHistoryEntry yesterdayEntry, IterationHistoryEntry todayEntry) {
    DateTime timestamp =
        todayEntry
            .getTimestamp()
            .toDateTimeAtCurrentTime()
            .minusMinutes(timeDifferenceMinutes)
            .toDateMidnight()
            .toDateTime()
            .plusSeconds(2);
    Second period = new Second(timestamp.toDate());

    long longValue = yesterdayEntry.getEffortLeftSum() + todayEntry.getDeltaOriginalEstimate();
    ExactEstimate scopedValue = new ExactEstimate(longValue);

    TimeSeriesDataItem nullItem =
        new TimeSeriesDataItem(new Second(timestamp.minusSeconds(1).toDate()), null);
    TimeSeriesDataItem scopedItem =
        new TimeSeriesDataItem(period, ExactEstimateUtils.extractMajorUnits(scopedValue));

    return Pair.create(nullItem, scopedItem);
  }
  /**
   * Get the <code>TimeSeries</code> for drawing the current day line.
   *
   * @param timeDifferenceHours
   */
  protected TimeSeries getCurrentDayTimeSeries(
      IterationHistoryEntry yesterdayEntry, IterationHistoryEntry todayEntry) {
    ExactEstimate startValue = this.getTodaysStartValueWithScoping(yesterdayEntry, todayEntry);

    ExactEstimate endValue = new ExactEstimate(todayEntry.getEffortLeftSum());

    return this.getSeriesByStartAndEndPoints(
        CURRENT_DAY_SERIES_NAME,
        todayEntry
            .getTimestamp()
            .toDateTimeAtCurrentTime()
            .minusMinutes(timeDifferenceMinutes)
            .toDateMidnight()
            .toDateTime(),
        startValue,
        todayEntry
            .getTimestamp()
            .toDateTimeAtCurrentTime()
            .minusMinutes(timeDifferenceMinutes)
            .toDateMidnight()
            .toDateTime()
            .plusDays(1),
        endValue);
  }
  protected List<TimeSeriesDataItem> getScopeSeriesDataItems(
      IterationHistoryEntry yesterdayEntry, IterationHistoryEntry todayEntry) {

    // Second item is places 2 seconds after the first
    // Resulting in a almost vertical line in the graph
    // Null value is added to break the line
    Second firstItemPeriod =
        new Second(
            todayEntry
                .getTimestamp()
                .toDateTimeAtCurrentTime()
                .minusMinutes(timeDifferenceMinutes)
                .toDateMidnight()
                .toDate());
    Second secondItemPeriod =
        new Second(
            todayEntry
                .getTimestamp()
                .toDateTimeAtCurrentTime()
                .minusMinutes(timeDifferenceMinutes)
                .toDateMidnight()
                .toDateTime()
                .plusSeconds(2)
                .toDate());
    Second nullItemPeriod =
        new Second(
            todayEntry
                .getTimestamp()
                .toDateTimeAtCurrentTime()
                .minusMinutes(timeDifferenceMinutes)
                .toDateMidnight()
                .toDateTime()
                .plusSeconds(3)
                .toDate());

    ExactEstimate firstValue = new ExactEstimate(yesterdayEntry.getEffortLeftSum());
    long secondValueAsLong =
        yesterdayEntry.getEffortLeftSum() + todayEntry.getDeltaOriginalEstimate();
    ExactEstimate secondValue = new ExactEstimate(secondValueAsLong);

    TimeSeriesDataItem firstItem =
        new TimeSeriesDataItem(firstItemPeriod, ExactEstimateUtils.extractMajorUnits(firstValue));
    TimeSeriesDataItem secondItem =
        new TimeSeriesDataItem(secondItemPeriod, ExactEstimateUtils.extractMajorUnits(secondValue));
    TimeSeriesDataItem nullItem = new TimeSeriesDataItem(nullItemPeriod, null);

    return Arrays.asList(firstItem, secondItem, nullItem);
  }
 protected boolean isScopingDone(IterationHistoryEntry entry) {
   return (entry.getDeltaOriginalEstimate() != 0);
 }