use of com.linkedin.thirdeye.client.ThirdEyeResponseRow in project pinot by linkedin.
the class TimeOnTimeResponseParser method parseGroupByDimensionResponse.
private void parseGroupByDimensionResponse() {
baselineResponseMap = ResponseParserUtils.createResponseMapByDimension(baselineResponse);
currentResponseMap = ResponseParserUtils.createResponseMapByDimension(currentResponse);
List<Double> baselineMetricSums = ResponseParserUtils.getMetricSums(baselineResponse);
List<Double> currentMetricSums = ResponseParserUtils.getMetricSums(currentResponse);
// group by dimension name
String dimensionName = baselineResponse.getGroupKeyColumns().get(0);
// group by dimension values
Set<String> dimensionValues = new HashSet<>();
dimensionValues.addAll(baselineResponseMap.keySet());
dimensionValues.addAll(currentResponseMap.keySet());
// Construct OTHER row
Row.Builder otherBuilder = new Row.Builder();
otherBuilder.setBaselineStart(baselineRanges.get(0).lowerEndpoint());
otherBuilder.setBaselineEnd(baselineRanges.get(0).upperEndpoint());
otherBuilder.setCurrentStart(currentRanges.get(0).lowerEndpoint());
otherBuilder.setCurrentEnd(currentRanges.get(0).upperEndpoint());
otherBuilder.setDimensionName(dimensionName);
otherBuilder.setDimensionValue(OTHER);
Double[] otherBaseline = new Double[numMetrics];
Arrays.fill(otherBaseline, 0.0);
Double[] otherCurrent = new Double[numMetrics];
Arrays.fill(otherCurrent, 0.0);
boolean includeOther = false;
// else, include it in the OTHER row
for (String dimensionValue : dimensionValues) {
Row.Builder builder = new Row.Builder();
builder.setBaselineStart(baselineRanges.get(0).lowerEndpoint());
builder.setBaselineEnd(baselineRanges.get(0).upperEndpoint());
builder.setCurrentStart(currentRanges.get(0).lowerEndpoint());
builder.setCurrentEnd(currentRanges.get(0).upperEndpoint());
builder.setDimensionName(dimensionName);
builder.setDimensionValue(dimensionValue);
ThirdEyeResponseRow baselineRow = baselineResponseMap.get(dimensionValue);
ThirdEyeResponseRow currentRow = currentResponseMap.get(dimensionValue);
addMetric(baselineRow, currentRow, builder);
Row row = builder.build();
boolean passedThreshold = checkMetricSums(row, baselineMetricSums, currentMetricSums);
// if any non-OTHER metric passes threshold, include it
if (passedThreshold && !dimensionValue.equalsIgnoreCase(OTHER)) {
rows.add(row);
} else {
// else add it to OTHER
includeOther = true;
List<Metric> metrics = row.getMetrics();
for (int i = 0; i < numMetrics; i++) {
Metric metric = metrics.get(i);
otherBaseline[i] += metric.getBaselineValue();
otherCurrent[i] += metric.getCurrentValue();
}
}
}
if (includeOther) {
for (int i = 0; i < numMetrics; i++) {
otherBuilder.addMetric(metricFunctions.get(i).getMetricName(), otherBaseline[i], otherCurrent[i]);
}
Row row = otherBuilder.build();
if (isValidMetric(row, Arrays.asList(otherBaseline), Arrays.asList(otherCurrent))) {
rows.add(row);
}
}
}
use of com.linkedin.thirdeye.client.ThirdEyeResponseRow in project pinot by linkedin.
the class TimeOnTimeResponseParser method parseGroupByTimeResponse.
private void parseGroupByTimeResponse() {
baselineResponseMap = ResponseParserUtils.createResponseMapByTime(baselineResponse);
currentResponseMap = ResponseParserUtils.createResponseMapByTime(currentResponse);
for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
Range<DateTime> baselineTimeRange = baselineRanges.get(timeBucketId);
ThirdEyeResponseRow baselineRow = baselineResponseMap.get(String.valueOf(timeBucketId));
Range<DateTime> currentTimeRange = currentRanges.get(timeBucketId);
ThirdEyeResponseRow currentRow = currentResponseMap.get(String.valueOf(timeBucketId));
Row.Builder builder = new Row.Builder();
builder.setBaselineStart(baselineTimeRange.lowerEndpoint());
builder.setBaselineEnd(baselineTimeRange.upperEndpoint());
builder.setCurrentStart(currentTimeRange.lowerEndpoint());
builder.setCurrentEnd(currentTimeRange.upperEndpoint());
addMetric(baselineRow, currentRow, builder);
Row row = builder.build();
rows.add(row);
}
}
use of com.linkedin.thirdeye.client.ThirdEyeResponseRow 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.ThirdEyeResponseRow 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());
}
}
}
use of com.linkedin.thirdeye.client.ThirdEyeResponseRow in project pinot by linkedin.
the class SeverityComputationUtil method getSum.
private double getSum(ThirdEyeRequest thirdEyeRequest) throws Exception {
double sum = 0;
ThirdEyeResponse response = thirdEyeClient.execute(thirdEyeRequest);
if (response.getNumRows() == 1) {
ThirdEyeResponseRow row = response.getRow(0);
sum = row.getMetrics().get(0);
}
return sum;
}
Aggregations