Search in sources :

Example 1 with ChartStatisticsContent

use of com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent in project service-api by reportportal.

the class AbstractStatisticsContentLoader method groupByDate.

/**
 * Return lists of objects grouped by specified period
 *
 * @param input
 * @param period
 * @return
 */
protected Map<String, ChartStatisticsContent> groupByDate(List<ChartStatisticsContent> input, Period period) {
    final LongSummaryStatistics statistics = input.stream().mapToLong(object -> object.getStartTime().getTime()).summaryStatistics();
    final DateTime start = new DateTime(statistics.getMin());
    final DateTime end = new DateTime(statistics.getMax());
    if (input.isEmpty()) {
        return Collections.emptyMap();
    }
    final Map<String, ChartStatisticsContent> chart = new LinkedHashMap<>();
    switch(period) {
        case DAY:
            proceedDailyChart(chart, start, end, input);
            groupStatistics(DATE_PATTERN, input, chart);
            break;
        case WEEK:
            proceedDailyChart(chart, start, end, input);
            groupStatistics(DATE_PATTERN, input, chart);
            break;
        case MONTH:
            proceedMonthlyChart(chart, start, end, input);
            groupStatistics("yyyy-MM", input, chart);
            break;
    }
    return chart;
}
Also used : ChartStatisticsContent(com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent) java.util(java.util) MapUtils(org.apache.commons.collections.MapUtils) Optional.ofNullable(java.util.Optional.ofNullable) DateTime(org.joda.time.DateTime) DATE_PATTERN(net.sf.jasperreports.types.date.FixedDate.DATE_PATTERN) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) DateTime(org.joda.time.DateTime) ChartStatisticsContent(com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent)

Example 2 with ChartStatisticsContent

use of com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent in project service-api by reportportal.

the class AbstractStatisticsContentLoader method maxByDate.

protected Map<String, ChartStatisticsContent> maxByDate(List<ChartStatisticsContent> statisticsContents, Period period, String contentField) {
    final Function<ChartStatisticsContent, String> chartObjectToDate = chartObject -> new DateTime(chartObject.getStartTime().getTime()).toString(DATE_PATTERN);
    final BinaryOperator<ChartStatisticsContent> chartObjectReducer = (o1, o2) -> Integer.parseInt(o1.getValues().get(contentField)) > Integer.parseInt(o2.getValues().get(contentField)) ? o1 : o2;
    final Map<String, Optional<ChartStatisticsContent>> groupByDate = statisticsContents.stream().filter(content -> MapUtils.isNotEmpty(content.getValues()) && ofNullable(content.getValues().get(contentField)).isPresent()).sorted(Comparator.comparing(ChartStatisticsContent::getStartTime)).collect(Collectors.groupingBy(chartObjectToDate, LinkedHashMap::new, Collectors.reducing(chartObjectReducer)));
    final Map<String, ChartStatisticsContent> range = groupByDate(statisticsContents, period);
    final LinkedHashMap<String, ChartStatisticsContent> result = new LinkedHashMap<>();
    // used forEach cause aspectj compiler can't infer types properly
    range.forEach((key, value) -> result.put(key, groupByDate.getOrDefault(key, Optional.of(createChartObject(statisticsContents.get(0)))).get()));
    return result;
}
Also used : ChartStatisticsContent(com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent) java.util(java.util) MapUtils(org.apache.commons.collections.MapUtils) Optional.ofNullable(java.util.Optional.ofNullable) DateTime(org.joda.time.DateTime) DATE_PATTERN(net.sf.jasperreports.types.date.FixedDate.DATE_PATTERN) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) DateTime(org.joda.time.DateTime) ChartStatisticsContent(com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent)

Example 3 with ChartStatisticsContent

use of com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent in project service-api by reportportal.

the class AbstractStatisticsContentLoader method createChartObject.

private ChartStatisticsContent createChartObject(ChartStatisticsContent input) {
    final ChartStatisticsContent chartObject = new ChartStatisticsContent();
    chartObject.setValues(input.getValues().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> "0")));
    return chartObject;
}
Also used : ChartStatisticsContent(com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent)

Example 4 with ChartStatisticsContent

use of com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent in project service-api by reportportal.

the class CasesTrendContentLoader method calculateDelta.

private void calculateDelta(Map<String, ChartStatisticsContent> statistics, Sort sort, String contentField) {
    if (sort.get().anyMatch(Sort.Order::isAscending)) {
        ArrayList<String> keys = new ArrayList<>(statistics.keySet());
        /* Last element in map */
        int previous = Integer.parseInt(statistics.get(keys.get(keys.size() - 1)).getValues().get(contentField));
        /* Iteration in reverse order */
        for (int i = keys.size() - 1; i >= 0; i--) {
            int current = Integer.parseInt(statistics.get(keys.get(i)).getValues().get(contentField));
            statistics.get(keys.get(i)).getValues().put(DELTA, String.valueOf(current - previous));
            previous = current;
        }
    } else {
        int previousValue = Integer.parseInt(new ArrayList<>(statistics.values()).get(0).getValues().get(contentField));
        for (ChartStatisticsContent content : statistics.values()) {
            Map<String, String> values = content.getValues();
            int currentValue = Integer.parseInt(values.get(contentField));
            values.put(DELTA, String.valueOf(currentValue - previousValue));
            previousValue = currentValue;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ChartStatisticsContent(com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent)

Example 5 with ChartStatisticsContent

use of com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent in project service-api by reportportal.

the class CasesTrendContentLoader method loadContent.

@Override
public Map<String, ?> loadContent(List<String> contentFields, Map<Filter, Sort> filterSortMapping, WidgetOptions widgetOptions, int limit) {
    Filter filter = GROUP_FILTERS.apply(filterSortMapping.keySet());
    Sort sort = GROUP_SORTS.apply(filterSortMapping.values());
    String contentField = contentFields.get(0);
    List<ChartStatisticsContent> content = widgetContentRepository.casesTrendStatistics(filter, contentField, sort, limit);
    return CollectionUtils.isEmpty(content) ? emptyMap() : calculateStatistics(widgetOptions, content, contentField, sort);
}
Also used : Filter(com.epam.ta.reportportal.commons.querygen.Filter) Sort(org.springframework.data.domain.Sort) ChartStatisticsContent(com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent)

Aggregations

ChartStatisticsContent (com.epam.ta.reportportal.entity.widget.content.ChartStatisticsContent)11 Filter (com.epam.ta.reportportal.commons.querygen.Filter)6 Sort (org.springframework.data.domain.Sort)6 Optional.ofNullable (java.util.Optional.ofNullable)4 java.util (java.util)3 BinaryOperator (java.util.function.BinaryOperator)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 DATE_PATTERN (net.sf.jasperreports.types.date.FixedDate.DATE_PATTERN)3 MapUtils (org.apache.commons.collections.MapUtils)3 DateTime (org.joda.time.DateTime)3 LoadContentStrategy (com.epam.ta.reportportal.core.widget.content.LoadContentStrategy)1 RESULT (com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.RESULT)1 TIMELINE (com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.TIMELINE)1 GROUP_FILTERS (com.epam.ta.reportportal.core.widget.util.WidgetFilterUtil.GROUP_FILTERS)1 GROUP_SORTS (com.epam.ta.reportportal.core.widget.util.WidgetFilterUtil.GROUP_SORTS)1 WidgetOptionUtil (com.epam.ta.reportportal.core.widget.util.WidgetOptionUtil)1 WidgetContentRepository (com.epam.ta.reportportal.dao.WidgetContentRepository)1 WidgetOptions (com.epam.ta.reportportal.entity.widget.WidgetOptions)1 ArrayList (java.util.ArrayList)1