Search in sources :

Example 6 with TimeOnTimeComparisonRequest

use of com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest in project pinot by linkedin.

the class ContributorViewHandler method generateTimeOnTimeComparisonRequest.

private TimeOnTimeComparisonRequest generateTimeOnTimeComparisonRequest(ContributorViewRequest request) throws Exception {
    TimeOnTimeComparisonRequest comparisonRequest = new TimeOnTimeComparisonRequest();
    String collection = request.getCollection();
    DateTime baselineStart = request.getBaselineStart();
    DateTime baselineEnd = request.getBaselineEnd();
    DateTime currentStart = request.getCurrentStart();
    DateTime currentEnd = request.getCurrentEnd();
    DatasetConfigDTO datasetConfig = CACHE_REGISTRY.getDatasetConfigCache().get(collection);
    TimeSpec timespec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
    if (!request.getTimeGranularity().getUnit().equals(TimeUnit.DAYS) || !StringUtils.isBlank(timespec.getFormat())) {
        comparisonRequest.setEndDateInclusive(true);
    }
    Multimap<String, String> filters = request.getFilters();
    List<String> dimensionsToGroupBy = request.getGroupByDimensions();
    if (dimensionsToGroupBy == null || dimensionsToGroupBy.isEmpty()) {
        List<String> allDimensions = Utils.getDimensionsToGroupBy(collection, filters);
        dimensionsToGroupBy = Lists.newArrayList(allDimensions.get(0));
    }
    List<MetricExpression> metricExpressions = request.getMetricExpressions();
    comparisonRequest.setCollectionName(collection);
    comparisonRequest.setBaselineStart(baselineStart);
    comparisonRequest.setBaselineEnd(baselineEnd);
    comparisonRequest.setCurrentStart(currentStart);
    comparisonRequest.setCurrentEnd(currentEnd);
    comparisonRequest.setFilterSet(filters);
    comparisonRequest.setMetricExpressions(metricExpressions);
    comparisonRequest.setAggregationTimeGranularity(request.getTimeGranularity());
    comparisonRequest.setGroupByDimensions(dimensionsToGroupBy);
    return comparisonRequest;
}
Also used : DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) TimeOnTimeComparisonRequest(com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTime(org.joda.time.DateTime) TimeSpec(com.linkedin.thirdeye.api.TimeSpec)

Example 7 with TimeOnTimeComparisonRequest

use of com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest 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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) TimeOnTimeComparisonResponse(com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonResponse) GenericResponse(com.linkedin.thirdeye.dashboard.views.GenericResponse) TimeOnTimeComparisonHandler(com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonHandler) TimeBucket(com.linkedin.thirdeye.dashboard.views.TimeBucket) TimeOnTimeComparisonRequest(com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) ResponseSchema(com.linkedin.thirdeye.dashboard.views.GenericResponse.ResponseSchema) Metric(com.linkedin.thirdeye.client.comparison.Row.Metric) Row(com.linkedin.thirdeye.client.comparison.Row)

Example 8 with TimeOnTimeComparisonRequest

use of com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest in project pinot by linkedin.

the class HeatMapViewHandler method getTimeOnTimeComparisonResponses.

private List<Future<TimeOnTimeComparisonResponse>> getTimeOnTimeComparisonResponses(List<String> groupByDimensions, TimeOnTimeComparisonRequest comparisonRequest, final TimeOnTimeComparisonHandler handler) {
    ExecutorService service = Executors.newFixedThreadPool(10);
    List<Future<TimeOnTimeComparisonResponse>> timeOnTimeComparisonResponseFutures = new ArrayList<>();
    for (final String groupByDimension : groupByDimensions) {
        final TimeOnTimeComparisonRequest comparisonRequestByDimension = getComparisonRequestByDimension(comparisonRequest, groupByDimension);
        Callable<TimeOnTimeComparisonResponse> callable = new Callable<TimeOnTimeComparisonResponse>() {

            @Override
            public TimeOnTimeComparisonResponse call() throws Exception {
                return handler.handle(comparisonRequestByDimension);
            }
        };
        timeOnTimeComparisonResponseFutures.add(service.submit(callable));
    }
    service.shutdown();
    return timeOnTimeComparisonResponseFutures;
}
Also used : TimeOnTimeComparisonResponse(com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonResponse) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) TimeOnTimeComparisonRequest(com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest) Callable(java.util.concurrent.Callable)

Example 9 with TimeOnTimeComparisonRequest

use of com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest in project pinot by linkedin.

the class HeatMapViewHandler method getComparisonRequestByDimension.

private TimeOnTimeComparisonRequest getComparisonRequestByDimension(TimeOnTimeComparisonRequest comparisonRequest, String groupByDimension) {
    TimeOnTimeComparisonRequest request = new TimeOnTimeComparisonRequest(comparisonRequest);
    request.setGroupByDimensions(Lists.newArrayList(groupByDimension));
    return request;
}
Also used : TimeOnTimeComparisonRequest(com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest)

Aggregations

TimeOnTimeComparisonRequest (com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest)9 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)7 TimeOnTimeComparisonResponse (com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonResponse)5 ArrayList (java.util.ArrayList)5 Row (com.linkedin.thirdeye.client.comparison.Row)3 Metric (com.linkedin.thirdeye.client.comparison.Row.Metric)3 TimeOnTimeComparisonHandler (com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonHandler)3 GenericResponse (com.linkedin.thirdeye.dashboard.views.GenericResponse)3 ResponseSchema (com.linkedin.thirdeye.dashboard.views.GenericResponse.ResponseSchema)3 HashMap (java.util.HashMap)3 DateTime (org.joda.time.DateTime)3 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)2 Info (com.linkedin.thirdeye.dashboard.views.GenericResponse.Info)2 TimeBucket (com.linkedin.thirdeye.dashboard.views.TimeBucket)2 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Future (java.util.concurrent.Future)2 MetricFunction (com.linkedin.thirdeye.client.MetricFunction)1 MetricDataset (com.linkedin.thirdeye.client.cache.MetricDataset)1