Search in sources :

Example 1 with Builder

use of com.linkedin.thirdeye.client.comparison.Row.Builder 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);
        }
    }
}
Also used : Builder(com.linkedin.thirdeye.client.comparison.Row.Builder) ThirdEyeResponseRow(com.linkedin.thirdeye.client.ThirdEyeResponseRow) Metric(com.linkedin.thirdeye.client.comparison.Row.Metric) ThirdEyeResponseRow(com.linkedin.thirdeye.client.ThirdEyeResponseRow) Builder(com.linkedin.thirdeye.client.comparison.Row.Builder) HashSet(java.util.HashSet)

Example 2 with Builder

use of com.linkedin.thirdeye.client.comparison.Row.Builder 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);
    }
}
Also used : Builder(com.linkedin.thirdeye.client.comparison.Row.Builder) ThirdEyeResponseRow(com.linkedin.thirdeye.client.ThirdEyeResponseRow) ThirdEyeResponseRow(com.linkedin.thirdeye.client.ThirdEyeResponseRow) Builder(com.linkedin.thirdeye.client.comparison.Row.Builder) DateTime(org.joda.time.DateTime)

Example 3 with Builder

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

the class TimeOnTimeResponseParser method parseGroupByTimeDimensionResponse.

private void parseGroupByTimeDimensionResponse() {
    baselineResponseMap = ResponseParserUtils.createResponseMapByTimeAndDimension(baselineResponse);
    currentResponseMap = ResponseParserUtils.createResponseMapByTimeAndDimension(currentResponse);
    Map<Integer, List<Double>> baselineMetricSums = ResponseParserUtils.getMetricSumsByTime(baselineResponse);
    Map<Integer, List<Double>> currentMetricSums = ResponseParserUtils.getMetricSumsByTime(currentResponse);
    // group by time and dimension values
    Set<String> timeDimensionValues = new HashSet<>();
    timeDimensionValues.addAll(baselineResponseMap.keySet());
    timeDimensionValues.addAll(currentResponseMap.keySet());
    Set<String> dimensionValues = new HashSet<>();
    for (String timeDimensionValue : timeDimensionValues) {
        String dimensionValue = ResponseParserUtils.extractFirstDimensionValue(timeDimensionValue);
        dimensionValues.add(dimensionValue);
    }
    // group by dimension name
    String dimensionName = baselineResponse.getGroupKeyColumns().get(1);
    // other row
    List<Row.Builder> otherBuilders = new ArrayList<>();
    List<Double[]> otherBaselineMetrics = new ArrayList<>();
    List<Double[]> otherCurrentMetrics = new ArrayList<>();
    boolean includeOther = false;
    // constructing an OTHER rows, 1 for each time bucket
    for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
        Range<DateTime> baselineTimeRange = baselineRanges.get(timeBucketId);
        Range<DateTime> currentTimeRange = currentRanges.get(timeBucketId);
        Row.Builder builder = new Row.Builder();
        builder.setBaselineStart(baselineTimeRange.lowerEndpoint());
        builder.setBaselineEnd(baselineTimeRange.upperEndpoint());
        builder.setCurrentStart(currentTimeRange.lowerEndpoint());
        builder.setCurrentEnd(currentTimeRange.upperEndpoint());
        builder.setDimensionName(dimensionName);
        builder.setDimensionValue(OTHER);
        otherBuilders.add(builder);
        Double[] otherBaseline = new Double[numMetrics];
        Arrays.fill(otherBaseline, 0.0);
        Double[] otherCurrent = new Double[numMetrics];
        Arrays.fill(otherCurrent, 0.0);
        otherBaselineMetrics.add(otherBaseline);
        otherCurrentMetrics.add(otherCurrent);
    }
    // else, we add the metric values to the OTHER row
    for (String dimensionValue : dimensionValues) {
        List<Row> thresholdRows = new ArrayList<>();
        for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
            Range<DateTime> baselineTimeRange = baselineRanges.get(timeBucketId);
            Range<DateTime> currentTimeRange = currentRanges.get(timeBucketId);
            // compute the time|dimension key
            String baselineTimeDimensionValue = ResponseParserUtils.computeTimeDimensionValue(timeBucketId, dimensionValue);
            String currentTimeDimensionValue = baselineTimeDimensionValue;
            ThirdEyeResponseRow baselineRow = baselineResponseMap.get(baselineTimeDimensionValue);
            ThirdEyeResponseRow currentRow = currentResponseMap.get(currentTimeDimensionValue);
            Row.Builder builder = new Row.Builder();
            builder.setBaselineStart(baselineTimeRange.lowerEndpoint());
            builder.setBaselineEnd(baselineTimeRange.upperEndpoint());
            builder.setCurrentStart(currentTimeRange.lowerEndpoint());
            builder.setCurrentEnd(currentTimeRange.upperEndpoint());
            builder.setDimensionName(dimensionName);
            builder.setDimensionValue(dimensionValue);
            addMetric(baselineRow, currentRow, builder);
            Row 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), baselineMetricSums.get(timeBucketId), currentMetricSums.get(timeBucketId))) {
                passedThreshold = true;
                break;
            }
        }
        if (passedThreshold) {
            // if any of the cells of a contributor row passes threshold, add all
            // those cells
            rows.addAll(thresholdRows);
        } else {
            // else that row of cells goes into OTHER
            includeOther = true;
            for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
                Row row = thresholdRows.get(timeBucketId);
                List<Metric> metrics = row.getMetrics();
                for (int i = 0; i < metrics.size(); i++) {
                    Metric metricToAdd = metrics.get(i);
                    otherBaselineMetrics.get(timeBucketId)[i] += metricToAdd.getBaselineValue();
                    otherCurrentMetrics.get(timeBucketId)[i] += metricToAdd.getCurrentValue();
                }
            }
        }
    }
    // create other row using the other baseline and current sums
    if (includeOther) {
        for (int timeBucketId = 0; timeBucketId < numTimeBuckets; timeBucketId++) {
            Builder otherBuilder = otherBuilders.get(timeBucketId);
            Double[] otherBaseline = otherBaselineMetrics.get(timeBucketId);
            Double[] otherCurrent = otherCurrentMetrics.get(timeBucketId);
            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);
            }
        }
    }
}
Also used : Builder(com.linkedin.thirdeye.client.comparison.Row.Builder) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) ThirdEyeResponseRow(com.linkedin.thirdeye.client.ThirdEyeResponseRow) ArrayList(java.util.ArrayList) List(java.util.List) Metric(com.linkedin.thirdeye.client.comparison.Row.Metric) ThirdEyeResponseRow(com.linkedin.thirdeye.client.ThirdEyeResponseRow) Builder(com.linkedin.thirdeye.client.comparison.Row.Builder) HashSet(java.util.HashSet)

Aggregations

ThirdEyeResponseRow (com.linkedin.thirdeye.client.ThirdEyeResponseRow)3 Builder (com.linkedin.thirdeye.client.comparison.Row.Builder)3 Metric (com.linkedin.thirdeye.client.comparison.Row.Metric)2 HashSet (java.util.HashSet)2 DateTime (org.joda.time.DateTime)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1