void RangeData::summarizeMonthly(RangeData& newData) const { newData.clear(); // nothing to do if we have no data! if (size() <= 0) { return; } size_type totalPoints = size(); size_type startIdx = 0; size_type endIdx = 1; int currMonth = get(0).tradeTime.date().month(); while (endIdx < totalPoints) { int newMonth = get(endIdx).tradeTime.date().month(); // if we are in a new month, then we create a point for up to the // previous end index if (newMonth != currMonth) { // the new data point Point point = getSummaryPoint(startIdx, endIdx - 1); // add the data point! newData.add(point); // update startIdx to consider next window startIdx = endIdx; currMonth = newMonth; } ++endIdx; } newData.add(getSummaryPoint(startIdx, endIdx - 1)); }
void RangeData::summarize(RangeData& newData, int points) const { assert(points > 0); newData.clear(); // nothing to do if we have no data! if (size() <= 0) { return; } size_type totalPoints = size(); size_type startIdx = 0; while (startIdx < totalPoints) { // [startIdx, endIdx] are the data points we're summarizing size_type endIdx = startIdx + points - 1; if (endIdx >= totalPoints) { endIdx = totalPoints - 1; } // actual number of data points (may be less than points for last // batch) // the new data point Point point = getSummaryPoint(startIdx, endIdx); // add the data point! newData.add(point); // update startIdx to consider next window startIdx = endIdx + 1; } }