From c087ed77068825a05d5615a95ecc9d3ccb60b608 Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Mon, 27 May 2019 09:06:04 +0200 Subject: [PATCH] + table for clusters (gui) --- .../hsel/spm/baudas/web/ClusterDiagram.java | 47 +++++++++++++++++++ src/main/webapp/footer.jsp | 1 + src/main/webapp/index.jsp | 3 +- src/main/webapp/js/cache.js | 1 + src/main/webapp/js/clusters.js | 39 +++++++++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/hsel/spm/baudas/web/ClusterDiagram.java create mode 100644 src/main/webapp/js/clusters.js diff --git a/src/main/java/de/hsel/spm/baudas/web/ClusterDiagram.java b/src/main/java/de/hsel/spm/baudas/web/ClusterDiagram.java new file mode 100644 index 0000000..4da9a7f --- /dev/null +++ b/src/main/java/de/hsel/spm/baudas/web/ClusterDiagram.java @@ -0,0 +1,47 @@ +package de.hsel.spm.baudas.web; + +import com.google.gson.Gson; +import de.hsel.spm.baudas.analysis.Cluster; +import org.jetbrains.annotations.NotNull; + +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; +import java.util.*; + +/** + * changes data from cluster analysis into a readable format + * + * @author Julian Hinxlage + * @version 0.1 + * @since 0.1 + **/ +@WebServlet("/clusters") +public class ClusterDiagram extends HttpServlet { + @Override + protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException { + req.setCharacterEncoding(StandardCharsets.UTF_8.name()); + resp.setCharacterEncoding(StandardCharsets.UTF_8.name()); + resp.setContentType("application/json"); + PrintWriter out = resp.getWriter(); + + Map> result = new HashMap<>(); + Gson gson = new Gson(); + + if (req.getParameter("id") == null) { + out.print(gson.toJson(result)); + return; + } + UUID uuid = UUID.fromString(req.getParameter("id")); + File file = Data.get(uuid); + + Cluster cluster = new Cluster(file); + result = cluster.getResult(); + out.print(gson.toJson(result)); + } +} diff --git a/src/main/webapp/footer.jsp b/src/main/webapp/footer.jsp index 5e91340..b496efb 100644 --- a/src/main/webapp/footer.jsp +++ b/src/main/webapp/footer.jsp @@ -16,6 +16,7 @@ + <%----%> diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 6879491..6d0cb93 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -85,7 +85,8 @@ Gruppenübersicht
-

Coming Soon

+ +
diff --git a/src/main/webapp/js/cache.js b/src/main/webapp/js/cache.js index 8876e59..e712e2b 100644 --- a/src/main/webapp/js/cache.js +++ b/src/main/webapp/js/cache.js @@ -38,6 +38,7 @@ function updateAll(uuid) { updateWeekOverviewChart(uuid); updateShoppingTimesChart(uuid); updateTopFlopChart(uuid); + updateClusters(uuid) //add new charts here. } diff --git a/src/main/webapp/js/clusters.js b/src/main/webapp/js/clusters.js new file mode 100644 index 0000000..cb04091 --- /dev/null +++ b/src/main/webapp/js/clusters.js @@ -0,0 +1,39 @@ +let cluster_result; + +function updateClusters(id) { + if(typeof id !== 'undefined') { + request('clusters', id).then(function (data) { + cluster_result = data; + drawClusterTable(); + }); + }else request('clusters').then(function(data) { + cluster_result = data; + drawClusterTable(); + }); +} + +function drawClusterTable(){ + let row = $(""); + row.append(""); + row.append("Alter"); + row.append("Wohnort"); + row.append("Einkaufstag"); + row.append("Geschlecht"); + row.append("Familienstand"); + row.append("Einkaufsuhrzeit"); + row.append(""); + row.append(""); + row.append(""); + for(x in cluster_result){ + row.append($("")); + row.append($("" + cluster_result[x].Alter +"")); + row.append($("" + cluster_result[x].Wohnort +"")); + row.append($("" + cluster_result[x].Einkaufstag +"")); + row.append($("" + cluster_result[x].Geschlecht +"")); + row.append($("" + cluster_result[x].Familienstand +"")); + row.append($("" + cluster_result[x].Einkaufsuhrzeit +"")); + row.append($("")); + } + row.append(""); + $("#cluster_table").append(row); +}