diff --git a/pom.xml b/pom.xml index b7c613d..b498d69 100644 --- a/pom.xml +++ b/pom.xml @@ -277,7 +277,7 @@ org.projectlombok lombok 1.18.4 - compile + provided org.jetbrains diff --git a/src/main/java/de/hsel/spm/baudas/web/Files.java b/src/main/java/de/hsel/spm/baudas/web/Files.java index defc588..9688f07 100644 --- a/src/main/java/de/hsel/spm/baudas/web/Files.java +++ b/src/main/java/de/hsel/spm/baudas/web/Files.java @@ -24,12 +24,6 @@ public class Files extends HttpServlet { private static final long serialVersionUID = 148451844848L; - /** - * do get. - * @param req request - * @param resp response - * @throws IOException writer could not be retrieved - */ @Override protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException { diff --git a/src/main/java/de/hsel/spm/baudas/web/SavedFile.java b/src/main/java/de/hsel/spm/baudas/web/SavedFile.java index a292925..f568faf 100644 --- a/src/main/java/de/hsel/spm/baudas/web/SavedFile.java +++ b/src/main/java/de/hsel/spm/baudas/web/SavedFile.java @@ -16,7 +16,7 @@ import java.util.UUID; @Getter @AllArgsConstructor @ToString -public class SavedFile { +class SavedFile { private UUID uuid; private String name; diff --git a/src/main/java/de/hsel/spm/baudas/web/ShoppingTimesDiagram.java b/src/main/java/de/hsel/spm/baudas/web/ShoppingTimesDiagram.java index a728d98..41a491e 100644 --- a/src/main/java/de/hsel/spm/baudas/web/ShoppingTimesDiagram.java +++ b/src/main/java/de/hsel/spm/baudas/web/ShoppingTimesDiagram.java @@ -12,17 +12,28 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; /** + * changes data from shopping times diagram into a readable format for chart.js + * * @author Johannes Theiner * @version 0.1 * @since 0.1 **/ - @WebServlet("/shopping_times") public class ShoppingTimesDiagram extends HttpServlet { + private static final long serialVersionUID = 6567531484L; + @Override protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException { req.setCharacterEncoding(StandardCharsets.UTF_8.name()); @@ -39,9 +50,11 @@ public class ShoppingTimesDiagram extends HttpServlet { SavedFile file = Data.getFiles().peek(); if (file == null) { + result.put("labels", definedOrder); out.print(gson.toJson(result)); return; } + assert file.getUuid() != null; ShoppingTimes shoppingTimes = new ShoppingTimes(Data.get(file.getUuid())); Map map = shoppingTimes.getResult(); diff --git a/src/main/java/de/hsel/spm/baudas/web/Upload.java b/src/main/java/de/hsel/spm/baudas/web/Upload.java index f969b45..28f7c9d 100644 --- a/src/main/java/de/hsel/spm/baudas/web/Upload.java +++ b/src/main/java/de/hsel/spm/baudas/web/Upload.java @@ -31,14 +31,7 @@ public class Upload extends HttpServlet { private static final long serialVersionUID = 14144111845151L; - /** - * doPost. - * - * @param req request - * @param resp response - * @throws ServletException could not get file part - * @throws IOException writer could not be retrieved - */ + @Override protected void doPost(@NotNull HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { diff --git a/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java b/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java index 8d56b02..7478e73 100644 --- a/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java +++ b/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java @@ -11,7 +11,12 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * changes data from week overview into readable format for chart.js @@ -23,13 +28,9 @@ import java.util.*; @WebServlet("/week_overview") public class WeekOverviewDiagram extends HttpServlet { - /** - * do get. - * - * @param req request - * @param resp response - * @throws IOException writer could not be retrieved - */ + private static final long serialVersionUID = 8484151844118L; + + @Override protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException { req.setCharacterEncoding(StandardCharsets.UTF_8.name()); @@ -61,7 +62,6 @@ public class WeekOverviewDiagram extends HttpServlet { Comparator comparator = Comparator.comparingInt(definedOrder::indexOf); labels.sort(comparator); - System.out.println(labels); for (String label : labels) { Map.Entry entry = overview.getResult().get(label); diff --git a/src/main/webapp/footer.jsp b/src/main/webapp/footer.jsp index a358f08..e74138a 100644 --- a/src/main/webapp/footer.jsp +++ b/src/main/webapp/footer.jsp @@ -9,7 +9,7 @@ - + <%-- diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 06451ba..c0ccd3c 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -27,7 +27,7 @@
-
+
Einkaufszeiten @@ -46,7 +46,7 @@
- +
diff --git a/src/main/webapp/js/overview.js b/src/main/webapp/js/overview.js deleted file mode 100644 index 9b048d4..0000000 --- a/src/main/webapp/js/overview.js +++ /dev/null @@ -1,58 +0,0 @@ -$.ajax({ - url: 'week_overview', - dataType: 'json' -}).done(function (results) { - new Chart(document.getElementById("overview_chart"), { - type: 'line', - data: { - labels: results.labels, - datasets: [{ - label: "Warenanzahl", - data: results.count, - fill: true, - backgroundColor: 'rgba(113, 114, 231, 0.7)', - lineTension: 0 - }, { - label: "Einnahmen in €", - data: results.revenue, - fill: true, - backgroundColor: 'rgba(104, 216, 154, 0.8)', - lineTension: 0 - }] - }, - options: { - responsive: true, - title: { - display: false, - text: 'Übersicht' - }, - legend: { - display: false - }, - tooltips: { - mode: 'index', - intersect: false - }, - hover: { - mode: 'nearest', - intersect: true - }, - elements: { - point: { - radius: 0 - } - }, - scales: { - xAxes: [{ - display: true, - gridLines: { - display: false - } - }], - yAxes: [{ - display: true - }] - } - } - }); -}); \ No newline at end of file diff --git a/src/main/webapp/js/shopping_times.js b/src/main/webapp/js/shopping_times.js index 97655fd..6a745b1 100644 --- a/src/main/webapp/js/shopping_times.js +++ b/src/main/webapp/js/shopping_times.js @@ -1,6 +1,6 @@ let shopping_result; -let shopping_chart = new Chart(document.getElementById("shoping_times_chart"), { +let shopping_chart = new Chart(document.getElementById("shopping_times_chart"), { type: 'bar', data: { labels: [1, 2, 3, 4, 5], @@ -61,45 +61,29 @@ $.ajax({ }); function updateDays() { - let e = document.getElementById("day"); - let value = e.options[e.selectedIndex].text; - shopping_chart.data.labels = shopping_result.labels; - shopping_chart.data.datasets[0].data = shopping_result[value]; + if(typeof shopping_result["Montag"] !== 'undefined') { + let e = document.getElementById("day"); + let value = e.options[e.selectedIndex].text; + shopping_chart.data.labels = shopping_result.labels; + shopping_chart.data.datasets[0].data = shopping_result[value]; - let color = shopping_result[value].map(x => 'rgba(143, 170, 220, 0.9)'); + let max = Math.max.apply(null, shopping_result[value]); + let min = Math.min.apply(null, shopping_result[value]); + let array = []; + shopping_result[value].map(function (value) { + if(value == max) + value = 'rgba(129, 199, 132, 1)'; + else if(value == min) { + value = 'rgba(239, 154, 154, 1)'; + } + else { + value = 'rgba(143, 170, 220, 0.9)'; + } + array.push(value); + }); + shopping_chart.data.datasets[0].backgroundColor = array; - console.log("max"); - argMax(shopping_result[value]).slice().forEach(function (item) { - console.log(item); - color[item] = 'green'; - }); - /*console.log("min"); - argMin(shopping_result[value]).forEach(function(item) { - console.log(item); - color[item] = 'red'; - });*/ + shopping_chart.update(); + } - shopping_chart.data.datasets[0].backgroundColor = color; - - shopping_chart.update(); -} - -function argMax(array) { - let result = []; - console.log(Math.max.apply(null, array)); - array.forEach(function(item) { - console.log(item); - if(item == Math.max.apply(null, array)) { - console.log(true); - result.push(array.indexOf(item)); - } - }); - console.log(result); - return result; -} - -function argMin(array) { - let arr = array.slice().sort(); - console.log(arr[0]); - return arr } \ No newline at end of file diff --git a/src/main/webapp/js/week_overview.js b/src/main/webapp/js/week_overview.js new file mode 100644 index 0000000..1cb0046 --- /dev/null +++ b/src/main/webapp/js/week_overview.js @@ -0,0 +1,65 @@ +let week_overview = new Chart(document.getElementById("overview_chart"), { + type: 'line', + data: { + labels: [0, 0, 0, 0, 0], + datasets: [{ + label: "Warenanzahl", + data: [0, 0, 0, 0, 0], + fill: true, + backgroundColor: 'rgba(113, 114, 231, 0.7)', + lineTension: 0 + }, { + label: "Einnahmen in €", + data: [0, 0, 0, 0, 0], + fill: true, + backgroundColor: 'rgba(104, 216, 154, 0.8)', + lineTension: 0 + }] + }, + options: { + responsive: true, + title: { + display: false, + text: 'Übersicht' + }, + legend: { + display: false + }, + tooltips: { + mode: 'index', + intersect: false + }, + hover: { + mode: 'nearest', + intersect: true + }, + elements: { + point: { + radius: 0 + } + }, + scales: { + xAxes: [{ + display: true, + gridLines: { + display: false + } + }], + yAxes: [{ + display: true + }] + } + } +}); + +$.ajax({ + url: 'week_overview', + dataType: 'json' +}).done(function (results) { + week_overview.data.labels = results.labels; + week_overview.data.datasets[0].data = results.count; + week_overview.data.datasets[1].data = results.revenue; + + week_overview.update(); + +}); \ No newline at end of file