use of com.linkedin.thirdeye.client.timeseries.TimeSeriesRow.Builder in project pinot by linkedin.
the class TimeSeriesResponseParser method parseGroupByTimeResponse.
private void parseGroupByTimeResponse() {
responseMap = ResponseParserUtils.createResponseMapByTime(response);
for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
Range<DateTime> timeRange = ranges.get(timeBucketId);
ThirdEyeResponseRow responseRow = responseMap.get(String.valueOf(timeBucketId));
TimeSeriesRow.Builder builder = new TimeSeriesRow.Builder();
builder.setStart(timeRange.lowerEndpoint());
builder.setEnd(timeRange.upperEndpoint());
addMetric(responseRow, builder);
TimeSeriesRow row = builder.build();
rows.add(row);
}
}
use of com.linkedin.thirdeye.client.timeseries.TimeSeriesRow.Builder in project pinot by linkedin.
the class TimeSeriesResponseParser method parseGroupByTimeDimensionResponse.
private void parseGroupByTimeDimensionResponse() {
responseMap = ResponseParserUtils.createResponseMapByTimeAndDimension(response);
Map<Integer, List<Double>> metricSums = ResponseParserUtils.getMetricSumsByTime(response);
// group by time and dimension values
Set<String> timeDimensionValues = new HashSet<>();
timeDimensionValues.addAll(responseMap.keySet());
Set<List<String>> dimensionValuesList = new HashSet<>();
for (String timeDimensionValue : timeDimensionValues) {
List<String> dimensionValues = ResponseParserUtils.extractDimensionValues(timeDimensionValue);
dimensionValuesList.add(dimensionValues);
}
// group by dimension names (the 0th dimension, which is the time bucket, is skipped).
List<String> groupKeyColumns = response.getGroupKeyColumns();
List<String> dimensionNameList = new ArrayList<>(groupKeyColumns.size() - 1);
for (int i = 1; i < groupKeyColumns.size(); ++i) {
dimensionNameList.add(groupKeyColumns.get(i));
}
// other row
List<TimeSeriesRow.Builder> otherBuilders = new ArrayList<>();
List<double[]> otherMetrics = new ArrayList<>();
boolean includeOther = false;
// constructing an OTHER rows, 1 for each time bucket
for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
Range<DateTime> timeRange = ranges.get(timeBucketId);
TimeSeriesRow.Builder builder = new TimeSeriesRow.Builder();
builder.setStart(timeRange.lowerEndpoint());
builder.setEnd(timeRange.upperEndpoint());
builder.setDimensionNames(dimensionNameList);
List<String> dimensionValues = new ArrayList(dimensionNameList.size());
for (int i = 0; i < dimensionNameList.size(); ++i) {
dimensionValues.add(OTHER);
}
builder.setDimensionValues(dimensionValues);
otherBuilders.add(builder);
double[] other = new double[numMetrics];
Arrays.fill(other, 0);
otherMetrics.add(other);
}
// else, we add the metric values to the OTHER row
for (List<String> dimensionValues : dimensionValuesList) {
List<TimeSeriesRow> thresholdRows = new ArrayList<>();
for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
Range<DateTime> timeRange = ranges.get(timeBucketId);
// compute the time|dimension key
String timeDimensionValue = ResponseParserUtils.computeTimeDimensionValues(timeBucketId, dimensionValues);
ThirdEyeResponseRow responseRow = responseMap.get(timeDimensionValue);
TimeSeriesRow.Builder builder = new TimeSeriesRow.Builder();
builder.setStart(timeRange.lowerEndpoint());
builder.setEnd(timeRange.upperEndpoint());
builder.setDimensionNames(dimensionNameList);
builder.setDimensionValues(dimensionValues);
addMetric(responseRow, builder);
TimeSeriesRow row = builder.build();
thresholdRows.add(row);
}
// check if rows pass threshold
boolean passedThreshold = false;
for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
if (checkMetricSums(thresholdRows.get(timeBucketId), metricSums.get(timeBucketId))) {
passedThreshold = true;
break;
}
}
// if any of the cells of a contributor row passes threshold, add all those cells
if (passedThreshold && !dimensionValues.contains(OTHER)) {
rows.addAll(thresholdRows);
} else {
// else that row of cells goes into OTHER
includeOther = true;
for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
TimeSeriesRow row = thresholdRows.get(timeBucketId);
List<TimeSeriesMetric> metrics = row.getMetrics();
for (int i = 0; i < metrics.size(); i++) {
TimeSeriesMetric metricToAdd = metrics.get(i);
otherMetrics.get(timeBucketId)[i] += metricToAdd.getValue();
}
}
}
}
// create other row using the other sums
if (includeOther) {
for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
Builder otherBuilder = otherBuilders.get(timeBucketId);
double[] other = otherMetrics.get(timeBucketId);
for (int i = 0; i < numMetrics; i++) {
otherBuilder.addMetric(metricFunctions.get(i).getMetricName(), other[i]);
}
rows.add(otherBuilder.build());
}
}
}
Aggregations