Long currentMillis = millisStart;
//Iterate over the time-range given and average ticks based on resolution
while (currentMillis <= (millisEnd - (resolution * 1000))) {
XYDataPoint currentTick = new XYDataPoint();
currentTick.setX(currentMillis);
currentTick.setY(null);
double aggregatedValue = 0.0d;
double averageValue = 0.0d;
ValueType valueType = null;
int numStatsInCurrentTick = 0;
for (int i = 0; i < numTicksInResolution; i++) {
LiveStatistics currStat = liveHash.get(currentMillis);
if (currStat == null || currStat.getValue() == null) {
//No stat for this timeperiod, skipping
} else {
if (valueType == null) {
valueType = ValueType.fromValue(currStat.getValueType());
}
//Add to current
aggregatedValue += currStat.getValue();
numStatsInCurrentTick++;
}
currentMillis += 15000;
}
if (numStatsInCurrentTick > 0) {
//If value type is aggregate, return the aggregate value
if (ValueType.AGGREGATE.equals(valueType)) {
currentTick.setY(aggregatedValue);
} else {
//Otherwise return the average
currentTick.setY(aggregatedValue / numStatsInCurrentTick);
}
}
valueList.addDataPoint(currentTick);
}