Search in sources :

Example 6 with ContributorViewResponse

use of com.linkedin.thirdeye.dashboard.views.contributor.ContributorViewResponse in project pinot by linkedin.

the class DataReportHelper method getDimensionReportList.

// report list metric vs groupByKey vs dimensionVal vs timeBucket vs values
public List<MetricDimensionReport> getDimensionReportList(List<ContributorViewResponse> reports) {
    List<MetricDimensionReport> ultimateResult = new ArrayList<>();
    for (ContributorViewResponse report : reports) {
        MetricDimensionReport metricDimensionReport = new MetricDimensionReport();
        String metric = report.getMetrics().get(0);
        String groupByDimension = report.getDimensions().get(0);
        metricDimensionReport.setMetricName(metric);
        metricDimensionReport.setDimensionName(groupByDimension);
        int valIndex = report.getResponseData().getSchema().getColumnsToIndexMapping().get("percentageChange");
        int dimensionIndex = report.getResponseData().getSchema().getColumnsToIndexMapping().get("dimensionValue");
        int numDimensions = report.getDimensionValuesMap().get(groupByDimension).size();
        int numBuckets = report.getTimeBuckets().size();
        // this is dimension vs timeBucketValue map, this should be sorted based on first bucket value
        Map<String, Map<String, String>> dimensionValueMap = new LinkedHashMap<>();
        // Lets populate 'OverAll' contribution
        Map<String, String> overAllValueMap = new LinkedHashMap<>();
        populateOverAllValuesMap(report, overAllValueMap);
        dimensionValueMap.put(OVER_ALL, overAllValueMap);
        Map<String, Map<String, String>> dimensionValueMapUnordered = new HashMap<>();
        for (int p = 0; p < numDimensions; p++) {
            if (p == 0) {
                metricDimensionReport.setCurrentStartTime(report.getTimeBuckets().get(0).getCurrentStart());
                metricDimensionReport.setCurrentEndTime(report.getTimeBuckets().get(numBuckets - 1).getCurrentEnd());
                metricDimensionReport.setBaselineStartTime(report.getTimeBuckets().get(0).getBaselineStart());
                metricDimensionReport.setBaselineEndTime(report.getTimeBuckets().get(numBuckets - 1).getBaselineEnd());
            }
            // valueMap is timeBucket vs value map
            LinkedHashMap<String, String> valueMap = new LinkedHashMap<>();
            String currentDimension = "";
            for (int q = 0; q < numBuckets; q++) {
                int index = p * numBuckets + q;
                currentDimension = report.getResponseData().getResponseData().get(index)[dimensionIndex];
                valueMap.put(String.valueOf(report.getTimeBuckets().get(q).getCurrentStart()), String.format(DECIMAL_FORMATTER, Double.valueOf(report.getResponseData().getResponseData().get(index)[valIndex])));
            }
            dimensionValueMapUnordered.put(currentDimension, valueMap);
        }
        orderDimensionValueMap(dimensionValueMapUnordered, dimensionValueMap, report.getDimensionValuesMap().get(groupByDimension));
        metricDimensionReport.setSubDimensionValueMap(dimensionValueMap);
        populateShareAndTotalMap(report, metricDimensionReport, metric, groupByDimension);
        ultimateResult.add(metricDimensionReport);
    }
    return ultimateResult;
}
Also used : ContributorViewResponse(com.linkedin.thirdeye.dashboard.views.contributor.ContributorViewResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) MetricDimensionReport(com.linkedin.thirdeye.anomaly.alert.template.pojo.MetricDimensionReport) HashMap(java.util.HashMap) DimensionMap(com.linkedin.thirdeye.api.DimensionMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ContributorViewResponse (com.linkedin.thirdeye.dashboard.views.contributor.ContributorViewResponse)6 ArrayList (java.util.ArrayList)5 DateTimeZone (org.joda.time.DateTimeZone)4 MetricDimensionReport (com.linkedin.thirdeye.anomaly.alert.template.pojo.MetricDimensionReport)3 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)3 ContributorViewHandler (com.linkedin.thirdeye.dashboard.views.contributor.ContributorViewHandler)3 ContributorViewRequest (com.linkedin.thirdeye.dashboard.views.contributor.ContributorViewRequest)3 HashMap (java.util.HashMap)3 DateTime (org.joda.time.DateTime)3 ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)2 DataReportHelper (com.linkedin.thirdeye.anomaly.alert.util.DataReportHelper)2 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)2 Configuration (freemarker.template.Configuration)2 Template (freemarker.template.Template)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 LinkedHashMap (java.util.LinkedHashMap)2 EmailException (org.apache.commons.mail.EmailException)2 HtmlEmail (org.apache.commons.mail.HtmlEmail)2