m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-11-22 12:41:54 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-11-22 12:41:54 +0100
commitadb0285565a4afb93e55d17fb615a60c49b98901 (patch)
tree425615f7b0d89bd0d9570faf8421887f8c546443 /src/main
parent7f776e3dfba1db479a208e274f6b191f22a5c6b8 (diff)
Add data processing functions for charts and small fixes
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java (renamed from src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java)2
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java69
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/DataStringInput.java (renamed from src/main/java/pl/edu/mimuw/cloudatlas/client/ContactsString.java)2
-rw-r--r--src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribChart.html4
4 files changed, 62 insertions, 15 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java
index abaa02a..58e1a30 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java
@@ -2,7 +2,7 @@ package pl.edu.mimuw.cloudatlas.client;
import pl.edu.mimuw.cloudatlas.model.Value;
-public class Attribute {
+public class AttributeInput {
private String zoneName;
private String attributeName;
private String valueString;
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<ValueContact> parseContactsString(ContactsString contactsInput) throws Exception {
+ private Set<ValueContact> parseContactsString(DataStringInput contactsInput) throws Exception {
Gson gson = new Gson();
Map<String, ArrayList> contactStrings = gson.fromJson(contactsInput.getString(), Map.class);
Set<ValueContact> contactObjects = new HashSet<ValueContact>();
@@ -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<ValueContact> 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<ValueTime> 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<ArrayList<String>> chartValues = new ArrayList<>();
+ ArrayList<String> chartValueNames = new ArrayList<>();
+
+ System.out.println(this.attributes);
+ for (AttributesMap m : this.attributes.values()) {
+ ArrayList<String> chartValueColumn = new ArrayList<>();
+ chartValueNames.clear();
+ for (Map.Entry<Attribute, Value> 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/DataStringInput.java
index 7cdd82e..e1465c7 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ContactsString.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/DataStringInput.java
@@ -1,6 +1,6 @@
package pl.edu.mimuw.cloudatlas.client;
-public class ContactsString {
+public class DataStringInput {
private String string;
public String getString() {
diff --git a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribChart.html b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribChart.html
index 2a9e1e0..a476301 100644
--- a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribChart.html
+++ b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribChart.html
@@ -6,6 +6,8 @@
<title>Attributes chart</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
@@ -48,8 +50,6 @@
</div>
<div id="chart_div" style="width: 100%; height: 500px;"></div>
-<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
-<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>