From 76a54ed93cd8d3cec80e300255ca2d2c62b4fd2a Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sat, 18 May 2019 14:56:07 +0200 Subject: [PATCH] Working article ranking Signed-off-by: Johannes Theiner #SPM-22: add work 4h development --- .../spm/baudas/web/TopFlopArticleDiagram.java | 58 +++++++++++++++++++ src/main/webapp/data/flop_articles.json | 26 --------- src/main/webapp/data/shoping_times.json | 18 ------ src/main/webapp/data/sold_articles.json | 12 ---- src/main/webapp/data/top_articles.json | 30 ---------- src/main/webapp/footer.jsp | 9 +-- src/main/webapp/header.jsp | 1 - src/main/webapp/index.jsp | 31 ++-------- src/main/webapp/js/cache.js | 13 +++-- src/main/webapp/js/flop_articles.js | 47 --------------- src/main/webapp/js/sold_articles.js | 38 ------------ src/main/webapp/js/top_articles.js | 47 --------------- src/main/webapp/js/top_flop.js | 56 ++++++++++++++++++ 13 files changed, 133 insertions(+), 253 deletions(-) create mode 100644 src/main/java/de/hsel/spm/baudas/web/TopFlopArticleDiagram.java delete mode 100644 src/main/webapp/data/flop_articles.json delete mode 100644 src/main/webapp/data/shoping_times.json delete mode 100644 src/main/webapp/data/sold_articles.json delete mode 100644 src/main/webapp/data/top_articles.json delete mode 100644 src/main/webapp/js/flop_articles.js delete mode 100644 src/main/webapp/js/sold_articles.js delete mode 100644 src/main/webapp/js/top_articles.js create mode 100644 src/main/webapp/js/top_flop.js diff --git a/src/main/java/de/hsel/spm/baudas/web/TopFlopArticleDiagram.java b/src/main/java/de/hsel/spm/baudas/web/TopFlopArticleDiagram.java new file mode 100644 index 0000000..2d6692f --- /dev/null +++ b/src/main/java/de/hsel/spm/baudas/web/TopFlopArticleDiagram.java @@ -0,0 +1,58 @@ +package de.hsel.spm.baudas.web; + +import com.google.gson.Gson; +import de.hsel.spm.baudas.analysis.TopFlopArticle; +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.*; + +/** + * @author Johannes Theiner + * @version 0.1 + * @since 0.1 + **/ + +@WebServlet("/top_flop") +public class TopFlopArticleDiagram extends HttpServlet { + + private static final long serialVersionUID = 6567531464214L; + + @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(); + + Gson gson = new Gson(); + + UUID uuid = UUID.fromString(req.getParameter("id")); + File file = Data.get(uuid); + + TopFlopArticle articles = new TopFlopArticle(file); + Map map = articles.getResult(); + + Map> result = new HashMap<>(); + + List labels = new ArrayList<>(); + List data = new ArrayList<>(); + + for(Map.Entry entry : map.entrySet()) { + labels.add(entry.getKey()); + data.add(entry.getValue().toString()); + } + + result.put("labels", labels); + result.put("data", data); + + out.print(gson.toJson(result)); + } +} \ No newline at end of file diff --git a/src/main/webapp/data/flop_articles.json b/src/main/webapp/data/flop_articles.json deleted file mode 100644 index b0aeaf9..0000000 --- a/src/main/webapp/data/flop_articles.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "labels": [ - "Insgesamt", - "Gruppe 1", - "Gruppe 2", - "Gruppe 3" - ], - "data1": [ - 50, - 10, - 20, - 30 - ], - "data2": [ - 30, - 5, - 20, - 5 - ], - "data3": [ - 80, - 20, - 30, - 30 - ] -} \ No newline at end of file diff --git a/src/main/webapp/data/shoping_times.json b/src/main/webapp/data/shoping_times.json deleted file mode 100644 index 4b072f3..0000000 --- a/src/main/webapp/data/shoping_times.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "labels": [ - "8-9", - "9-10", - "10-11", - "11-12", - "12-13", - "13-14" - ], - "data1": [ - 12, - 19, - 3, - 5, - 2, - 3 - ] -} \ No newline at end of file diff --git a/src/main/webapp/data/sold_articles.json b/src/main/webapp/data/sold_articles.json deleted file mode 100644 index d283062..0000000 --- a/src/main/webapp/data/sold_articles.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "labels": [ - "Gruppe 1", - "Gruppe 2", - "Gruppe 3" - ], - "data1": [ - 2055, - 816, - 953 - ] -} \ No newline at end of file diff --git a/src/main/webapp/data/top_articles.json b/src/main/webapp/data/top_articles.json deleted file mode 100644 index 78c9e67..0000000 --- a/src/main/webapp/data/top_articles.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "labels": [ - "Insgesamt", - "Gruppe 1", - "Gruppe 2", - "Gruppe 3" - ], - "label1": "Gartengeräte", - "data1": [ - 150, - 50, - 50, - 50 - ], - "label2": "Eisenwaren", - "data2": [ - 120, - 10, - 80, - 30 - ], - "label3": "Baumaterialien", - "data3": [ - 200, - 102, - 53, - 45 - ] - -} \ No newline at end of file diff --git a/src/main/webapp/footer.jsp b/src/main/webapp/footer.jsp index e6dd7bc..5e91340 100644 --- a/src/main/webapp/footer.jsp +++ b/src/main/webapp/footer.jsp @@ -7,17 +7,18 @@ + - -<%-- - ---%> + + +<%----%> + diff --git a/src/main/webapp/header.jsp b/src/main/webapp/header.jsp index 77aceae..b1b958e 100644 --- a/src/main/webapp/header.jsp +++ b/src/main/webapp/header.jsp @@ -106,7 +106,6 @@
- \ No newline at end of file diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 8cf6ee5..78725a0 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -52,7 +52,7 @@ - + <%--
@@ -74,38 +74,17 @@
- + --%> - +
- Top Artikel -
-
- Umsatz - Stückzahl + Top/Flop Artikel
- -
-
-
-
- -
-
-
- Flop Artikel -
- -
-
- +
diff --git a/src/main/webapp/js/cache.js b/src/main/webapp/js/cache.js index a50e666..8876e59 100644 --- a/src/main/webapp/js/cache.js +++ b/src/main/webapp/js/cache.js @@ -20,20 +20,25 @@ function updateCache() { let dataset = $('#dataset'); let selected = $('#dataset :selected'); if (typeof selected !== 'undefined' && selected.index() !== -1) { - updateWeekOverviewChart(selected.val()); - updateShoppingTimesChart(selected.val()); + updateAll(selected.val()); } else { //requesting files, getting values from html does not work... //if no selection is provided, select newest file request('files').then(results => { let uuid = results[results.length - 1].uuid; dataset.val(uuid); - updateWeekOverviewChart(uuid); - updateShoppingTimesChart(uuid); + updateAll(uuid); dataset.formSelect(); }); } +} + +function updateAll(uuid) { + updateWeekOverviewChart(uuid); + updateShoppingTimesChart(uuid); + updateTopFlopChart(uuid); + //add new charts here. } /** diff --git a/src/main/webapp/js/flop_articles.js b/src/main/webapp/js/flop_articles.js deleted file mode 100644 index b9bc712..0000000 --- a/src/main/webapp/js/flop_articles.js +++ /dev/null @@ -1,47 +0,0 @@ -$.ajax({ - url: 'data/flop_articles.json', - dataType: 'json' -}).done(function (results) { - new Chart(document.getElementById("flop_articles_chart"), { - type: 'horizontalBar', - data: { - labels: results.labels, - datasets: [{ - label: 'Holz', - backgroundColor: 'rgba(244, 177, 131, 1)', - stack: 'Stack 0', - data: results.data1 - }, { - label: 'Eisenwaren', - backgroundColor: 'rgba(255, 217, 102, 1)', - stack: 'Stack 1', - data: results.data2 - }, { - label: 'Baumaterialien', - backgroundColor: 'rgba(196, 209, 142, 1)', - stack: 'Stack 2', - data: results.data3 - }] - }, - options: { - responsive: true, - title: { - display: false, - text: 'Flop Artikel' - }, - legend: { - position: 'bottom', - }, - scales: { - yAxes: [{ - gridLines: { - display: false - }, - ticks: { - beginAtZero: true - } - }] - } - } - }); -}); \ No newline at end of file diff --git a/src/main/webapp/js/sold_articles.js b/src/main/webapp/js/sold_articles.js deleted file mode 100644 index 4b6f30b..0000000 --- a/src/main/webapp/js/sold_articles.js +++ /dev/null @@ -1,38 +0,0 @@ -$.ajax({ - url: 'data/sold_articles.json', - dataType: 'json' -}).done(function (results) { - new Chart(document.getElementById("sold_articles_cake"), { - type: 'pie', - data: { - datasets: [{ - data: results.data1, - backgroundColor: [ - 'rgba(237, 125, 49, 0.9)', - 'rgba(255, 192, 0, 0.9)', - 'rgba(112, 173, 71, 0.9)', - ], - label: 'Dataset 1' - }], - labels: results.labels - }, - options: { - responsive: true, - title: { - display: false, - text: 'Verkaufte Artikel', - }, - tooltips: { - mode: 'index', - intersect: false, - }, - hover: { - mode: 'nearest', - intersect: true - }, - legend: { - position: 'bottom' - } - } - }); -}); \ No newline at end of file diff --git a/src/main/webapp/js/top_articles.js b/src/main/webapp/js/top_articles.js deleted file mode 100644 index d61e496..0000000 --- a/src/main/webapp/js/top_articles.js +++ /dev/null @@ -1,47 +0,0 @@ -$.ajax({ - url: 'data/top_articles.json', - dataType: 'json' -}).done(function (results) { - new Chart(document.getElementById("top_articles_chart"), { - type: 'horizontalBar', - data: { - labels: results.labels, - datasets: [{ - label: results.label1, - backgroundColor: 'rgba(244, 177, 131, 1)', - stack: 'Stack 0', - data: results.data1 - }, { - label: results.label2, - backgroundColor: 'rgba(255, 217, 102, 1)', - stack: 'Stack 1', - data: results.data2 - }, { - label: results.label3, - backgroundColor: 'rgba(196, 209, 142, 1)', - stack: 'Stack 2', - data: results.data3 - }] - }, - options: { - responsive: true, - title: { - display: false, - text: 'Top Artikel' - }, - legend: { - position: 'bottom', - }, - scales: { - yAxes: [{ - gridLines: { - display: false - }, - ticks: { - beginAtZero: true - } - }] - } - } - }); -}); \ No newline at end of file diff --git a/src/main/webapp/js/top_flop.js b/src/main/webapp/js/top_flop.js new file mode 100644 index 0000000..74b51e1 --- /dev/null +++ b/src/main/webapp/js/top_flop.js @@ -0,0 +1,56 @@ +let top_flop_result; + + +let top_flop = new Chart($("#top_flop_chart"), { + type: 'horizontalBar', + data: { + labels: [], + datasets: [{ + data: [], + backgroundColor: [], + }] + }, + options: { + responsive: true, + title: { + display: false, + text: 'Top Flop Artikel' + }, + legend: { + display: false + }, + scales: { + yAxes: [{ + gridLines: { + display: false + }, + ticks: { + beginAtZero: true + } + }] + } + } +}); + +function updateTopFlopChart(id) { + if (typeof id !== 'undefined') { + request('top_flop', id).then(function (data) { + top_flop_result = data; + updateTopFlop(); + }); + } else request('top_flop').then(function (data) { + top_flop_result = data; + updateTopFlop(); + }); +} + +function updateTopFlop() { + top_flop.data.labels = top_flop_result.labels; + top_flop.data.datasets[0].data = top_flop_result.data; + let seq = palette('mpn65', 15); + for (let i = 0; i < 15; i++) { + top_flop.data.datasets[0].backgroundColor[i] = "#" + seq[i]; + } + top_flop.update(); + +}