From 2ae058e3465b2ba2495c294b82c65de5d48eb7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Fri, 22 Nov 2019 17:09:31 +0100 Subject: Add proper data processing for attribute chart --- .../mimuw/cloudatlas/client/ClientController.java | 71 +++++++++++++++++----- 1 file changed, 56 insertions(+), 15 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/client') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java index 58770b6..a4a9097 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -8,9 +8,11 @@ import org.springframework.stereotype.Controller; import pl.edu.mimuw.cloudatlas.api.Api; import pl.edu.mimuw.cloudatlas.model.*; +import java.lang.reflect.Array; import java.net.InetAddress; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; +import java.time.format.DateTimeFormatter; import java.util.*; /* @@ -255,6 +257,27 @@ public class ClientController { } } + private ArrayList getNumericalValues(AttributesMap attribs) { + Value val; + Type valType; + ArrayList valuesList = new ArrayList<>(); + + for (Map.Entry entry : attribs) { + val = entry.getValue(); + valType = val.getType(); + if (TypePrimitive.DOUBLE.isCompatible(valType)) { + valuesList.add(Double.parseDouble(val.toString())); + } else if (TypePrimitive.INTEGER.isCompatible(valType)) { + valuesList.add(Long.parseLong(val.toString())); + } else if (TypePrimitive.TIME.isCompatible(valType)) { + valuesList.add(Long.parseLong(val.toString())); + } else if (TypePrimitive.DURATION.isCompatible(valType)) { + valuesList.add(Long.parseLong(val.convertTo(TypePrimitive.INTEGER).toString())); + } + } + return valuesList; + } + private boolean isValueNumerical(Value val) { Type valType = val.getType(); @@ -268,29 +291,47 @@ public class ClientController { } } - private String processAttribNumValues() { - String jsonAttributes = ""; - Gson gson = new Gson(); - Value val; - ArrayList> chartValues = new ArrayList<>(); + private AttributesMap getLastAttributesMap() { + ArrayList> attribsMap = new ArrayList<>(this.attributes.entrySet()); + return attribsMap.get(attribsMap.size() - 1).getValue(); + } + + private ArrayList getChartColumnNames() { ArrayList chartValueNames = new ArrayList<>(); + AttributesMap lastAttribMap = getLastAttributesMap(); + + for (Map.Entry e : lastAttribMap) { + if (isValueNumerical(e.getValue())) { + chartValueNames.add(e.getKey().getName()); + } + } + chartValueNames.add(0, "Timestamp"); + return chartValueNames; + } + + private ArrayList getNumericalValuesTable() { + ArrayList chartValues = new ArrayList<>(); + ArrayList chartValueNames = getChartColumnNames(); + ArrayList chartValueColumn; System.out.println(this.attributes); - for (AttributesMap m : this.attributes.values()) { - ArrayList chartValueColumn = new ArrayList<>(); - chartValueNames.clear(); - for (Map.Entry e : m) { - val = e.getValue(); - System.out.println(val); - if (isValueNumerical(val)) { - chartValueNames.add(e.getKey().getName()); - chartValueColumn.add(val.toString()); - } + for (Map.Entry attribsMap : this.attributes.entrySet()) { + chartValueColumn = getNumericalValues(attribsMap.getValue()); + chartValueColumn.add(0, attribsMap.getKey().toString().substring(11, 19)); + while (chartValueColumn.size() < chartValueNames.size()) { + chartValueColumn.add(null); } chartValues.add(chartValueColumn); } chartValues.add(0, chartValueNames); + return chartValues; + } + + private String processAttribNumValues() { + String jsonAttributes = ""; + Gson gson = new Gson(); + ArrayList chartValues = getNumericalValuesTable(); jsonAttributes = gson.toJson(chartValues); System.out.println(jsonAttributes); return jsonAttributes; -- cgit v1.2.3