From 93db6e464335a361b53fb6fb14d1146fe224c26c Mon Sep 17 00:00:00 2001 From: Darshan Nagesh <darshan.nagesh@tarento.com> Date: Mon, 28 Mar 2022 13:52:56 +0530 Subject: [PATCH] Making the Visualization a cumulative one --- .../handler/LineChartResponseHandler.java | 25 +++++++++++-------- .../resources/schema/SMF_ChartApiConfig.json | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/tarento/analytics/handler/LineChartResponseHandler.java b/src/main/java/com/tarento/analytics/handler/LineChartResponseHandler.java index f4b05bc..271fd24 100644 --- a/src/main/java/com/tarento/analytics/handler/LineChartResponseHandler.java +++ b/src/main/java/com/tarento/analytics/handler/LineChartResponseHandler.java @@ -88,6 +88,7 @@ public class LineChartResponseHandler implements IResponseHandler { double previousVal = !isCumulative ? 0.0 : (totalValues.size() > 0 ? totalValues.get(totalValues.size() - 1) : 0.0); + double value; if (action.equals("Negative Count") && action != null && bucket.findValue(IResponseHandler.NEGATIVE_COUNT) != null) { @@ -95,7 +96,7 @@ public class LineChartResponseHandler implements IResponseHandler { ? bucket.findValue(IResponseHandler.VALUE).asDouble() * -1 : bucket.findValue(IResponseHandler.DOC_COUNT).asDouble()); } else { - if (bucket.findValue(IResponseHandler.CUMULATIVE_VALUE) != null) { + if (isCumulative) { value = previousVal + ((bucket.findValue(IResponseHandler.VALUE) != null) ? bucket.findValue(IResponseHandler.VALUE).asDouble() : bucket.findValue(IResponseHandler.DOC_COUNT).asDouble()); @@ -115,17 +116,21 @@ public class LineChartResponseHandler implements IResponseHandler { .map(e -> new Plot(e.getKey(), e.getValue(), symbol, headerLabel, valueLabel)) .collect(Collectors.toList()); try { - Data data = new Data(headerPath.asText(), (totalValues == null || totalValues.isEmpty()) ? 0.0 - : totalValues.stream().reduce(0.0, Double::sum), symbol); - /* - * Data data; if(!isCumulative) { data = new Data(headerPath.asText(), - * (totalValues==null || totalValues.isEmpty()) ? 0.0 : - * totalValues.stream().reduce(0.0, Double::sum), symbol); } else { data = new - * Data(headerPath.asText(), (totalValues==null || totalValues.isEmpty()) ? 0.0 - * : plots.get(plots.size()-1), symbol); } - */ +// Data data = new Data(headerPath.asText(), (totalValues == null || totalValues.isEmpty()) ? 0.0 +// : totalValues.stream().reduce(0.0, Double::sum), symbol); + + Data data; + + if (!isCumulative) { + data = new Data(headerPath.asText(), (totalValues == null || totalValues.isEmpty()) ? 0.0 + : totalValues.stream().reduce(0.0, Double::sum), symbol); + } else { + data = new Data(headerPath.asText(), + (totalValues == null || totalValues.isEmpty()) ? 0.0 : plots.get(plots.size() - 1), symbol); + } data.setPlots(plots); dataList.add(data); + } catch (Exception e) { logger.error(" Legend/Header " + headerPath.asText() + " exception occurred " + e.getMessage()); } diff --git a/src/main/resources/schema/SMF_ChartApiConfig.json b/src/main/resources/schema/SMF_ChartApiConfig.json index e271caa..3b52769 100644 --- a/src/main/resources/schema/SMF_ChartApiConfig.json +++ b/src/main/resources/schema/SMF_ChartApiConfig.json @@ -157,7 +157,7 @@ } ], "chartType": "line", - "resultType": "doc_count", + "resultType": "value", "valueType": "number", "isDecimal": true, "action": "", -- GitLab