From adb0285565a4afb93e55d17fb615a60c49b98901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Fri, 22 Nov 2019 12:41:54 +0100 Subject: Add data processing functions for charts and small fixes --- .../pl/edu/mimuw/cloudatlas/client/Attribute.java | 51 ---------------- .../mimuw/cloudatlas/client/AttributeInput.java | 51 ++++++++++++++++ .../mimuw/cloudatlas/client/ClientController.java | 69 ++++++++++++++++++---- .../mimuw/cloudatlas/client/ContactsString.java | 20 ------- .../mimuw/cloudatlas/client/DataStringInput.java | 20 +++++++ 5 files changed, 129 insertions(+), 82 deletions(-) delete mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java delete mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/client/ContactsString.java create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/client/DataStringInput.java (limited to 'src/main/java/pl/edu/mimuw/cloudatlas') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java deleted file mode 100644 index abaa02a..0000000 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java +++ /dev/null @@ -1,51 +0,0 @@ -package pl.edu.mimuw.cloudatlas.client; - -import pl.edu.mimuw.cloudatlas.model.Value; - -public class Attribute { - private String zoneName; - private String attributeName; - private String valueString; - private String attributeType; - private Value value; - - public String getZoneName() { - return zoneName; - } - - public void setZoneName(String zoneName) { - this.zoneName = zoneName; - } - - public String getAttributeName() { - return attributeName; - } - - public void setAttributeName(String attributeName) { - this.attributeName = attributeName; - } - - public String getValueString() { - return valueString; - } - - public void setValueString(String valueString) { - this.valueString = valueString; - } - - public Value getValue() { - return value; - } - - public void setValue(Value value) { - this.value = value; - } - - public String getAttributeType() { - return attributeType; - } - - public void setAttributeType(String attributeType) { - this.attributeType = attributeType; - } -} diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java new file mode 100644 index 0000000..58e1a30 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java @@ -0,0 +1,51 @@ +package pl.edu.mimuw.cloudatlas.client; + +import pl.edu.mimuw.cloudatlas.model.Value; + +public class AttributeInput { + private String zoneName; + private String attributeName; + private String valueString; + private String attributeType; + private Value value; + + public String getZoneName() { + return zoneName; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public String getAttributeName() { + return attributeName; + } + + public void setAttributeName(String attributeName) { + this.attributeName = attributeName; + } + + public String getValueString() { + return valueString; + } + + public void setValueString(String valueString) { + this.valueString = valueString; + } + + public Value getValue() { + return value; + } + + public void setValue(Value value) { + this.value = value; + } + + public String getAttributeType() { + return attributeType; + } + + public void setAttributeType(String attributeType) { + this.attributeType = attributeType; + } +} 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 bb19ac4..58770b6 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -9,7 +9,6 @@ import pl.edu.mimuw.cloudatlas.api.Api; import pl.edu.mimuw.cloudatlas.model.*; import java.net.InetAddress; -import java.net.UnknownHostException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.util.*; @@ -84,11 +83,11 @@ public class ClientController { @GetMapping("/contacts") public String contactPage(Model model) { - model.addAttribute("contactsObject" , new ContactsString()); + model.addAttribute("contactsObject" , new DataStringInput()); return "contactsForm"; } - private Set parseContactsString(ContactsString contactsInput) throws Exception { + private Set parseContactsString(DataStringInput contactsInput) throws Exception { Gson gson = new Gson(); Map contactStrings = gson.fromJson(contactsInput.getString(), Map.class); Set contactObjects = new HashSet(); @@ -110,7 +109,7 @@ public class ClientController { } @PostMapping("/contacts") - public String contactPage(@ModelAttribute ContactsString contactsObject, Model model) { + public String contactPage(@ModelAttribute DataStringInput contactsObject, Model model) { boolean success = true; Set contactObjects; @@ -134,11 +133,11 @@ public class ClientController { @GetMapping("/attribs") public String attribPage(Model model) { - model.addAttribute("attributeObject", new Attribute()); + model.addAttribute("attributeObject", new AttributeInput()); return "attribForm"; } - private Value parseAttributeValue(Attribute attributeObject) throws Exception { + private Value parseAttributeValue(AttributeInput attributeObject) throws Exception { Value attributeValue = null; switch (attributeObject.getAttributeType()) { @@ -163,7 +162,7 @@ public class ClientController { attributeValue = new ValueDuration(attributeObject.getValueString()); break; case "Contact": - ContactsString contactsString = new ContactsString(); + DataStringInput contactsString = new DataStringInput(); contactsString.setString(attributeObject.getValueString()); attributeValue = parseContactsString(contactsString).iterator().next(); break; @@ -179,7 +178,7 @@ public class ClientController { } @PostMapping("/attribs") - public String attribPage(@ModelAttribute Attribute attributeObject, Model model) { + public String attribPage(@ModelAttribute AttributeInput attributeObject, Model model) { boolean success = true; Value attributeValue; @@ -229,7 +228,7 @@ public class ClientController { public String valuesPage(Model model) { model.addAttribute("availableZones", getAvailableZonesString()); model.addAttribute("currentZone", "Current zone: " + this.currentZoneName); - model.addAttribute("zoneName", new ContactsString()); + model.addAttribute("zoneName", new DataStringInput()); return "attribChart"; } @@ -250,18 +249,66 @@ public class ClientController { } Iterator it = this.attributes.keySet().iterator(); - while (it.hasNext() && this.attributes.size() > 1000) { + while (it.hasNext() && this.attributes.size() > 50) { it.next(); it.remove(); } } + private boolean isValueNumerical(Value val) { + Type valType = val.getType(); + + if (TypePrimitive.DOUBLE.isCompatible(valType) || + TypePrimitive.INTEGER.isCompatible(valType) || + TypePrimitive.TIME.isCompatible(valType) || + TypePrimitive.DURATION.isCompatible(valType)) { + return true; + } else { + return false; + } + } + + private String processAttribNumValues() { + String jsonAttributes = ""; + Gson gson = new Gson(); + Value val; + ArrayList> chartValues = new ArrayList<>(); + ArrayList chartValueNames = new ArrayList<>(); + + 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()); + } + } + chartValues.add(chartValueColumn); + } + + chartValues.add(0, chartValueNames); + jsonAttributes = gson.toJson(chartValues); + System.out.println(jsonAttributes); + return jsonAttributes; + } + + @GetMapping("/attribNumValues") + @ResponseBody + public String attribNumValuesApi() { + return processAttribNumValues(); + } + @PostMapping("/values") - public String valuesPage(@ModelAttribute ContactsString zoneName, Model model) { + public String valuesPage(@ModelAttribute DataStringInput zoneName, Model model) { this.currentZoneName = zoneName.getString(); this.attributes.clear(); model.addAttribute("currentZone", "Current zone: " + this.currentZoneName); model.addAttribute("availableZones", getAvailableZonesString()); + model.addAttribute("zoneName", new DataStringInput()); return "attribChart"; } } diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/ContactsString.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/ContactsString.java deleted file mode 100644 index 7cdd82e..0000000 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ContactsString.java +++ /dev/null @@ -1,20 +0,0 @@ -package pl.edu.mimuw.cloudatlas.client; - -public class ContactsString { - private String string; - - public String getString() { - return string; - } - - public void setString(String string) { - this.string = string; - } - - @Override - public String toString() { - return "ContactString{" + - "string='" + string + '\'' + - '}'; - } -} diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/DataStringInput.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/DataStringInput.java new file mode 100644 index 0000000..e1465c7 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/DataStringInput.java @@ -0,0 +1,20 @@ +package pl.edu.mimuw.cloudatlas.client; + +public class DataStringInput { + private String string; + + public String getString() { + return string; + } + + public void setString(String string) { + this.string = string; + } + + @Override + public String toString() { + return "ContactString{" + + "string='" + string + '\'' + + '}'; + } +} -- cgit v1.2.3