use of com.linkedin.thirdeye.dashboard.views.GenericResponse in project pinot by linkedin.
the class TabularViewHandler method addColumnData.
public void addColumnData(Map<String, GenericResponse> data, String metric, String[] columnData, String[] columns) {
GenericResponse rowData;
if (data.containsKey(metric)) {
rowData = data.get(metric);
rowData.getResponseData().add(columnData);
} else {
ResponseSchema schema = new ResponseSchema();
for (int i = 0; i < columns.length; i++) {
String column = columns[i];
schema.add(column, i);
}
rowData = new GenericResponse();
List<String[]> genericResponseData = new ArrayList<>();
genericResponseData.add(columnData);
rowData.setResponseData(genericResponseData);
rowData.setSchema(schema);
data.put(metric, rowData);
}
}
use of com.linkedin.thirdeye.dashboard.views.GenericResponse in project pinot by linkedin.
the class TabularViewHandler method process.
@Override
public TabularViewResponse process(TabularViewRequest request) throws Exception {
// query 1 for everything from baseline start to baseline end
// query 2 for everything from current start to current end
// for each dimension group by top 100
// query 1 for everything from baseline start to baseline end
// query for everything from current start to current end
TimeOnTimeComparisonRequest comparisonRequest = generateTimeOnTimeComparisonRequest(request);
TimeOnTimeComparisonHandler handler = new TimeOnTimeComparisonHandler(queryCache);
TimeOnTimeComparisonResponse response = handler.handle(comparisonRequest);
List<TimeBucket> timeBuckets = getTimeBuckets(response);
List<Row> rows = getRowsSortedByTime(response);
TabularViewResponse tabularViewResponse = new TabularViewResponse();
Map<String, String> summary = new HashMap<>();
summary.put("baselineStart", Long.toString(comparisonRequest.getBaselineStart().getMillis()));
summary.put("baselineEnd", Long.toString(comparisonRequest.getBaselineEnd().getMillis()));
summary.put("currentStart", Long.toString(comparisonRequest.getCurrentStart().getMillis()));
summary.put("currentEnd", Long.toString(comparisonRequest.getCurrentEnd().getMillis()));
tabularViewResponse.setSummary(summary);
List<String> expressionNames = new ArrayList<>();
for (MetricExpression expression : request.getMetricExpressions()) {
expressionNames.add(expression.getExpressionName());
}
tabularViewResponse.setMetrics(expressionNames);
tabularViewResponse.setTimeBuckets(timeBuckets);
String[] columns = new String[] { "baselineValue", "currentValue", "ratio", "cumulativeBaselineValue", "cumulativeCurrentValue", "cumulativeRatio" };
// maintain same order in response
Map<String, GenericResponse> data = new LinkedHashMap<>();
for (String metric : expressionNames) {
ResponseSchema schema = new ResponseSchema();
for (int i = 0; i < columns.length; i++) {
String column = columns[i];
schema.add(column, i);
}
GenericResponse rowData = new GenericResponse();
rowData.setSchema(schema);
List<String[]> genericResponseData = new ArrayList<>();
rowData.setResponseData(genericResponseData);
data.put(metric, rowData);
}
tabularViewResponse.setData(data);
Map<String, Double[]> runningTotalMap = new HashMap<>();
for (Row row : rows) {
for (Metric metric : row.getMetrics()) {
String metricName = metric.getMetricName();
if (!expressionNames.contains(metricName)) {
continue;
}
Double baselineValue = metric.getBaselineValue();
Double currentValue = metric.getCurrentValue();
String baselineValueStr = HeatMapCell.format(baselineValue);
String currentValueStr = HeatMapCell.format(currentValue);
double ratio = ((currentValue - baselineValue) * 100) / baselineValue;
if (Double.isNaN(ratio)) {
ratio = 0;
} else if (Double.isInfinite(ratio)) {
ratio = 100;
}
String ratioStr = HeatMapCell.format(ratio);
Double cumulativeBaselineValue;
Double cumulativeCurrentValue;
if (runningTotalMap.containsKey(metricName)) {
Double[] totalValues = runningTotalMap.get(metricName);
cumulativeBaselineValue = totalValues[0] + baselineValue;
cumulativeCurrentValue = totalValues[1] + currentValue;
} else {
cumulativeBaselineValue = baselineValue;
cumulativeCurrentValue = currentValue;
}
Double[] runningTotalPerMetric = new Double[] { cumulativeBaselineValue, cumulativeCurrentValue };
runningTotalMap.put(metricName, runningTotalPerMetric);
String cumulativeBaselineValueStr = HeatMapCell.format(cumulativeBaselineValue);
String cumulativeCurrentValueStr = HeatMapCell.format(cumulativeCurrentValue);
double cumulativeRatio = ((cumulativeCurrentValue - cumulativeBaselineValue) * 100) / cumulativeBaselineValue;
if (Double.isNaN(ratio)) {
cumulativeRatio = 0;
} else if (Double.isInfinite(cumulativeRatio)) {
cumulativeRatio = 100;
}
String cumulativeRatioStr = HeatMapCell.format(cumulativeRatio);
String[] columnData = { baselineValueStr, currentValueStr, ratioStr, cumulativeBaselineValueStr, cumulativeCurrentValueStr, cumulativeRatioStr };
GenericResponse rowData = data.get(metric.getMetricName());
rowData.getResponseData().add(columnData);
}
}
return tabularViewResponse;
}
Aggregations