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;
}
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;
}
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;
}
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;
}
}
}
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);
}
Aggregations