Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Works #211

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Works #211

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public interface DashBoardConfig {
final static String NAME = "name";
final static String ID = "id";
final static String TITLE = "title";

final static String CUSTOM_FILTER_COMPONENT = "filter";
final static String CUSTOM_FILTER_CONFIGURATION = "filterConfig";
}
public interface MDMSKeys {
final static String CODE = "code";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public interface IResponseHandler {
public final String DOC_COUNT = "doc_count";

public static final String POST_AGGREGATION_THEORY = "postAggregationTheory";

public static final String COMPARE_TWO_INDICES = "compareTwoIndices";

public static final String CHART_SPECIFIC = "chartSpecificProperty";

Expand Down Expand Up @@ -207,4 +209,17 @@ default void appendMissingPlot(Set<String> plotKeys, Data data, String symbol, b
data.setPlots(sortedMap.values().stream().collect(Collectors.toList()));
}

default Double compareTwoIndices(List<List<String>> bucketList){
List<String> listA = bucketList.get(0);
List<String> listB = bucketList.get(1);

Double count = 0.0;
for (String str : listA) {
if (!listB.contains(str)) {
count++;
}
}
return count;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,25 @@ public AggregateDto translate(AggregateRequestDto request, ObjectNode aggregatio
List<Double> percentageList = new ArrayList<>();
ArrayNode aggrsPaths = (ArrayNode) chartNode.get(AGGS_PATH);

boolean extractBuckets = chartNode.get(POST_AGGREGATION_THEORY).asText().equals(COMPARE_TWO_INDICES);
List<List<String>> bucketList = new ArrayList<>();
/*
* Sums all value of all aggrsPaths i.e all aggregations
* */
boolean isRoundOff = (chartNode.get(IS_ROUND_OFF)!=null && chartNode.get(IS_ROUND_OFF).asBoolean()) ? true : false;
Plot latestDateplot = new Plot("todaysDate", Double.valueOf(0), "number");;
Plot lastUpdatedTime = new Plot("lastUpdatedTime", Double.valueOf(0), "number");
Plot latestCount = new Plot("count",Double.valueOf(0),"number");
Boolean isTodaysCollection = (chartNode.get("TodaysCollection") == null ? Boolean.FALSE : chartNode.get("TodaysCollection").asBoolean());
Boolean isLatestCount = (chartNode.get("metricCount") == null ? Boolean.FALSE : chartNode.get("metricCount").asBoolean());
for( JsonNode headerPath : aggrsPaths) {
List<JsonNode> values = aggregationNode.findValues(headerPath.asText());
int valueIndex = 0;
Double headerPathValue = new Double(0);
for (JsonNode value : values) {
if(extractBuckets){
bucketList.add(value.findValuesAsText("key"));
}
if (isRoundOff) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = value.get("value");
Expand Down Expand Up @@ -172,6 +179,12 @@ public AggregateDto translate(AggregateRequestDto request, ObjectNode aggregatio
}

}
if (isLatestCount == Boolean.TRUE){
JsonNode countNode = aggregationNode.findValue("Count");
if(countNode != null && countNode.has(IResponseHandler.VALUE)){
latestCount.setValue(countNode.findValue(IResponseHandler.VALUE).asDouble());
}
}
valueIndex++;
}
// Why is aggrsPaths.size()==2 required? Is there validation if action =
Expand All @@ -185,7 +198,11 @@ public AggregateDto translate(AggregateRequestDto request, ObjectNode aggregatio
}

String symbol = chartNode.get(IResponseHandler.VALUE_TYPE).asText();

if (extractBuckets && bucketList.size() ==2){
Double count = compareTwoIndices(bucketList);
totalValues.clear();
totalValues.add(count);
}
try{
Data data = new Data(chartName, action.equals(PERCENTAGE) && aggrsPaths.size()==2? percentageValue(percentageList, isRoundOff) : (totalValues==null || totalValues.isEmpty())? 0.0 :totalValues.stream().reduce(0.0, Double::sum), symbol);
//Logic to perform DIVISION action
Expand All @@ -199,7 +216,7 @@ public AggregateDto translate(AggregateRequestDto request, ObjectNode aggregatio
else
throw new CustomException("INVALID_NUMBER_OF_OPERANDS", "Division operation can be performed only with 2 operands.");
}
data.setPlots( Arrays.asList(latestDateplot,lastUpdatedTime));
data.setPlots( Arrays.asList(latestDateplot,lastUpdatedTime,latestCount));
request.getResponseRecorder().put(visualizationCode, request.getModuleLevel(), data);
dataList.add(data);
if(chartNode.get(POST_AGGREGATION_THEORY) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public void add(Data data, List<String> fields, String newField,JsonNode chartNo

double total = 0.0;
for (String field: fields){
dataType = plotMap.get(field).getSymbol();
total = total+ plotMap.get(field).getValue();
if(plotMap.containsKey(field)) {
dataType = plotMap.get(field).getSymbol();
total = total + plotMap.get(field).getValue();
}
}
if(postAggrTheoryName != null && !postAggrTheoryName.isEmpty()) {
ComputeHelper computeHelper = computeHelperFactory.getInstance(postAggrTheoryName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public ArrayNode getDashboardConfiguration(String dashboardId, String catagory,
visArray.add(visual);
});
}
// Check if filter component exists in config then add into response config
if (dbNode.has(Constants.DashBoardConfig.CUSTOM_FILTER_COMPONENT))
copyDashboard.set(Constants.DashBoardConfig.CUSTOM_FILTER_COMPONENT, dbNode.get(Constants.DashBoardConfig.CUSTOM_FILTER_COMPONENT));
// Check if FILTER CONFIGURATION exists in config then add into response config
if (dbNode.has(Constants.DashBoardConfig.CUSTOM_FILTER_CONFIGURATION))
copyDashboard.set(Constants.DashBoardConfig.CUSTOM_FILTER_CONFIGURATION, dbNode.get(Constants.DashBoardConfig.CUSTOM_FILTER_CONFIGURATION));
}
copyDashboard.set(Constants.DashBoardConfig.NAME, name);
copyDashboard.set(Constants.DashBoardConfig.ID, id);
Expand Down