+ table for clusters (gui)
This commit is contained in:
parent
160808e10f
commit
c087ed7706
47
src/main/java/de/hsel/spm/baudas/web/ClusterDiagram.java
Normal file
47
src/main/java/de/hsel/spm/baudas/web/ClusterDiagram.java
Normal file
@ -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<Integer, Map<String, String>> 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));
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
<script src="js/week_overview.js"></script>
|
||||
<script src="js/shopping_times.js"></script>
|
||||
<script src="js/top_flop.js"></script>
|
||||
<script src="js/clusters.js"></script>
|
||||
|
||||
<%--<script src="js/sold_articles.js"></script>--%>
|
||||
|
||||
|
@ -85,7 +85,8 @@
|
||||
<span class="card-title center">Gruppenübersicht</span>
|
||||
</div>
|
||||
<div>
|
||||
<p>Coming Soon</p>
|
||||
<tabel id="cluster_table" width="1000" height="400">
|
||||
</tabel>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -38,6 +38,7 @@ function updateAll(uuid) {
|
||||
updateWeekOverviewChart(uuid);
|
||||
updateShoppingTimesChart(uuid);
|
||||
updateTopFlopChart(uuid);
|
||||
updateClusters(uuid)
|
||||
//add new charts here.
|
||||
}
|
||||
|
||||
|
39
src/main/webapp/js/clusters.js
Normal file
39
src/main/webapp/js/clusters.js
Normal file
@ -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 = $("<thead>");
|
||||
row.append("<tr>");
|
||||
row.append("<td>Alter</td>");
|
||||
row.append("<td>Wohnort</td>");
|
||||
row.append("<td>Einkaufstag</td>");
|
||||
row.append("<td>Geschlecht</td>");
|
||||
row.append("<td>Familienstand</td>");
|
||||
row.append("<td>Einkaufsuhrzeit</td>");
|
||||
row.append("</tr>");
|
||||
row.append("</thead>");
|
||||
row.append("</tbody>");
|
||||
for(x in cluster_result){
|
||||
row.append($("<tr>"));
|
||||
row.append($("<td>" + cluster_result[x].Alter +"</td>"));
|
||||
row.append($("<td>" + cluster_result[x].Wohnort +"</td>"));
|
||||
row.append($("<td>" + cluster_result[x].Einkaufstag +"</td>"));
|
||||
row.append($("<td>" + cluster_result[x].Geschlecht +"</td>"));
|
||||
row.append($("<td>" + cluster_result[x].Familienstand +"</td>"));
|
||||
row.append($("<td>" + cluster_result[x].Einkaufsuhrzeit +"</td>"));
|
||||
row.append($("</tr>"));
|
||||
}
|
||||
row.append("</tbody>");
|
||||
$("#cluster_table").append(row);
|
||||
}
|
Loading…
Reference in New Issue
Block a user