From 76a54ed93cd8d3cec80e300255ca2d2c62b4fd2a Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sat, 18 May 2019 14:56:07 +0200 Subject: [PATCH 1/3] 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(); + +} From 6d9aa153fb87a7c081b757480aa22dd4ed1d4086 Mon Sep 17 00:00:00 2001 From: joethei Date: Tue, 21 May 2019 14:45:20 +0200 Subject: [PATCH 2/3] ~ small changes to look #SPM-22: add work 20m development --- src/main/webapp/index.jsp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 78725a0..8d34d83 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -77,10 +77,10 @@
--%> -
+
- Top/Flop Artikel + Verkaufszahlen
From 115950bf23ae233def7037685a079f980b0e7d5b Mon Sep 17 00:00:00 2001 From: joethei Date: Thu, 23 May 2019 15:15:30 +0200 Subject: [PATCH 3/3] + readme + sonarqube integration + removed unnecessary stuff --- README.md | 28 ++++++++++++++++ pom.xml | 30 +++++++++++++++++ src/main/webapp/header.jsp | 12 ------- src/main/webapp/index.jsp | 33 ++----------------- .../spm/baudas/analysis/WeekOverviewTest.java | 6 ++-- 5 files changed, 64 insertions(+), 45 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..dff7b07 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +![BauDas Logo](https://services.joethei.xyz/images/bauDas.png) +#Kundenkarten Verwaltung + +[![Build Status](https://teamcity.joethei.xyz/app/rest/builds/buildType:(id:Studium_Programmierung_Softwareprojektmanagement_SpmProd)/statusIcon)](https://tcstatus.joethei.space/dashboard/spm) +[![Quality Gate](https://sonarqube.joethei.xyz/api/project_badges/measure?project=Studium_Programmierung_Softwareprojektmanagement&metric=alert_status) +![Code Coverage](https://sonarqube.joethei.xyz/api/project_badges/measure?project=Studium_Programmierung_Softwareprojektmanagement&metric=coverage)](https://sonarqube.joethei.xyz/dashboard?id=Studium_Programmierung_Softwareprojektmanagement) + +## Requirements + +- Java 8 +- Maven 3 +- Tomcat 9 + +## Development Setup + +- clone this repository +- import it into your preferred editor +- start the server with maven goal ````tomcat7:run```` +- change stuff +- restart the server if needed + + +## TODO: better Name for this +- clone this repository +- run maven goal ````package```` +- war can be found in target folder + +© 2019 Ihni GmbH \ No newline at end of file diff --git a/pom.xml b/pom.xml index b498d69..fc47fbe 100644 --- a/pom.xml +++ b/pom.xml @@ -16,8 +16,10 @@ 1.8 checkstyle.xml UTF-8 + ${project.build.directory}/jacoco.exec + Johannes Theiner @@ -213,6 +215,34 @@ + + + org.jacoco + jacoco-maven-plugin + 0.8.4 + + + default-prepare-agent + + prepare-agent + + + + default-report + prepare-package + + report + + + + default-check + + check + + + + + diff --git a/src/main/webapp/header.jsp b/src/main/webapp/header.jsp index b1b958e..5cd9784 100644 --- a/src/main/webapp/header.jsp +++ b/src/main/webapp/header.jsp @@ -65,18 +65,6 @@
  • -
  • -
    - -
    - -
    -
  • diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 8d34d83..6879491 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -11,12 +11,9 @@
    - Übersicht -
    -
    - Tagesübersicht - Wochenübersicht + Wochenübersicht
    +
    @@ -52,31 +49,7 @@
    - <%-- -
    -
    -
    -
    - Verkaufte Artikel -
    -
    -
    - - -
    -
    -
    - -
    -
    -
    -
    --%> - - +
    diff --git a/src/test/java/de/hsel/spm/baudas/analysis/WeekOverviewTest.java b/src/test/java/de/hsel/spm/baudas/analysis/WeekOverviewTest.java index 0f6f283..2ed832e 100644 --- a/src/test/java/de/hsel/spm/baudas/analysis/WeekOverviewTest.java +++ b/src/test/java/de/hsel/spm/baudas/analysis/WeekOverviewTest.java @@ -30,7 +30,7 @@ class WeekOverviewTest { AtomicReference>> result = new AtomicReference<>(); - assertTimeout(Duration.ofMillis(1), () -> result.set(overview.getResult())); + assertTimeout(Duration.ofMillis(5), () -> result.set(overview.getResult())); assertEquals(2477, result.get().get("Montag").getKey()); @@ -57,7 +57,7 @@ class WeekOverviewTest { AtomicReference>> result = new AtomicReference<>(); - assertTimeout(Duration.ofMillis(3), () -> result.set(overview.getResult())); + assertTimeout(Duration.ofMillis(7), () -> result.set(overview.getResult())); assertEquals(26273, result.get().get("Montag").getKey()); @@ -84,7 +84,7 @@ class WeekOverviewTest { AtomicReference>> result = new AtomicReference<>(); - assertTimeout(Duration.ofMillis(30), () -> result.set(overview.getResult())); + assertTimeout(Duration.ofMillis(60), () -> result.set(overview.getResult())); assertEquals(295688, result.get().get("Montag").getKey());