diff --git a/checkstyle.xml b/checkstyle.xml index 1cec088..0c17f24 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -44,7 +44,7 @@ - + @@ -55,13 +55,14 @@ - + + + + value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_DO, LITERAL_IF, LITERAL_ELSE"/> diff --git a/src/main/java/de/hsel/spm/baudas/analysis/Attribute.java b/src/main/java/de/hsel/spm/baudas/analysis/Attribute.java index 375714b..e6d9883 100644 --- a/src/main/java/de/hsel/spm/baudas/analysis/Attribute.java +++ b/src/main/java/de/hsel/spm/baudas/analysis/Attribute.java @@ -1,11 +1,13 @@ package de.hsel.spm.baudas.analysis; /** + * Indexes for all attributes. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 **/ -public class Attribute { +class Attribute { static final int SEX = 0; static final int AGE = 1; diff --git a/src/main/java/de/hsel/spm/baudas/analysis/Cluster.java b/src/main/java/de/hsel/spm/baudas/analysis/Cluster.java index 10e25b1..f98989c 100644 --- a/src/main/java/de/hsel/spm/baudas/analysis/Cluster.java +++ b/src/main/java/de/hsel/spm/baudas/analysis/Cluster.java @@ -1,5 +1,6 @@ package de.hsel.spm.baudas.analysis; +import org.jetbrains.annotations.NotNull; import weka.clusterers.SimpleKMeans; import weka.core.Instances; import weka.filters.Filter; @@ -31,51 +32,51 @@ public class Cluster implements Analysis>> { */ @Override public Map> getResult() { - if(result == null) { - result = new HashMap<>(); - //TODO: anpassen wenn #SPM-17 gemerged ist. - int[] keepIndexes = new int[]{0, 1, 3, 5, 6, 7}; - Remove remove = new Remove(); + if (result != null) { + return result; + } + result = new HashMap<>(); + int[] keepIndexes = new int[]{Attribute.SEX, Attribute.AGE, Attribute.MARITAL_STATUS, Attribute.SHOPPING_DAY, Attribute.SHOPPING_HOUR, Attribute.RESIDENCE}; + Remove remove = new Remove(); - try { - remove.setAttributeIndicesArray(keepIndexes); - remove.setInvertSelection(true); - remove.setInputFormat(instances); - instances = Filter.useFilter(instances, remove); - } catch (Exception e) { - e.printStackTrace(); - } + try { + remove.setAttributeIndicesArray(keepIndexes); + remove.setInvertSelection(true); + remove.setInputFormat(instances); + instances = Filter.useFilter(instances, remove); + } catch (Exception e) { + e.printStackTrace(); + } - //creating a single cluster to get average, weka has no way to get that from a bigger one. - SimpleKMeans fullMeans = new SimpleKMeans(); - Instances fullCentroids = null; - try { - fullMeans.setNumClusters(1); - fullMeans.setPreserveInstancesOrder(true); - fullMeans.buildClusterer(instances); - fullCentroids = fullMeans.getClusterCentroids(); + //creating a single cluster to get average, weka has no way to get that from a bigger one. + SimpleKMeans averageMeans = new SimpleKMeans(); + Instances averageCentroids = null; + try { + averageMeans.setNumClusters(1); + averageMeans.setPreserveInstancesOrder(true); + averageMeans.buildClusterer(instances); + averageCentroids = averageMeans.getClusterCentroids(); - } catch (Exception ex) { - ex.printStackTrace(); - } - assert fullCentroids != null; + } catch (Exception ex) { + ex.printStackTrace(); + } + assert averageCentroids != null; - //creating real cluster - SimpleKMeans kMeans = new SimpleKMeans(); - try { - kMeans.setNumClusters(5); - kMeans.setPreserveInstancesOrder(true); - kMeans.buildClusterer(instances); + //creating real cluster + SimpleKMeans fullMeans = new SimpleKMeans(); + try { + fullMeans.setNumClusters(5); + fullMeans.setPreserveInstancesOrder(true); + fullMeans.buildClusterer(instances); - int count = 0; - count = putIntoMap(fullCentroids, count); + int count = 0; + count = putIntoMap(averageCentroids, count); - Instances centroids = kMeans.getClusterCentroids(); - putIntoMap(centroids, count); + Instances centroids = fullMeans.getClusterCentroids(); + putIntoMap(centroids, count); - } catch (Exception ex) { - ex.printStackTrace(); - } + } catch (Exception ex) { + ex.printStackTrace(); } return result; } @@ -84,10 +85,10 @@ public class Cluster implements Analysis>> { * puts data into map. * * @param centroids cluster analysis result - * @param count current insert count + * @param count current insert count * @return count increment */ - private int putIntoMap(Instances centroids, int count) { + private int putIntoMap(@NotNull Instances centroids, int count) { for (int i = 0; i < centroids.numInstances(); i++) { Map map = new HashMap<>(); for (int j = 0; j < centroids.numAttributes(); j++) { diff --git a/src/main/java/de/hsel/spm/baudas/analysis/DayHour.java b/src/main/java/de/hsel/spm/baudas/analysis/DayHour.java index 52f7793..f2a223d 100644 --- a/src/main/java/de/hsel/spm/baudas/analysis/DayHour.java +++ b/src/main/java/de/hsel/spm/baudas/analysis/DayHour.java @@ -5,6 +5,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; /** + * object to better handle day, hour combinations. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java b/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java index 865517f..4c4a697 100644 --- a/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java +++ b/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java @@ -31,17 +31,19 @@ public class ShoppingTimes implements Analysis> { */ @Override public Map getResult() { - if (result == null) { - result = new HashMap<>(); + if (result != null) { + return result; + } - for(Instance instance : instances) { - DayHour dayHour = new DayHour(instance.stringValue(Attribute.SHOPPING_DAY), instance.stringValue(Attribute.SHOPPING_HOUR)); - int tmp = 1; - if(result.containsKey(dayHour)) - tmp = result.get(dayHour) + 1; + result = new HashMap<>(); - result.put(dayHour, tmp); - } + for (Instance instance : instances) { + DayHour dayHour = new DayHour(instance.stringValue(Attribute.SHOPPING_DAY), instance.stringValue(Attribute.SHOPPING_HOUR)); + int tmp = 1; + if (result.containsKey(dayHour)) + tmp = result.get(dayHour) + 1; + + result.put(dayHour, tmp); } return result; } diff --git a/src/main/java/de/hsel/spm/baudas/analysis/TopFlopArticle.java b/src/main/java/de/hsel/spm/baudas/analysis/TopFlopArticle.java index b8a24dc..995379c 100644 --- a/src/main/java/de/hsel/spm/baudas/analysis/TopFlopArticle.java +++ b/src/main/java/de/hsel/spm/baudas/analysis/TopFlopArticle.java @@ -1,16 +1,18 @@ package de.hsel.spm.baudas.analysis; -import java.io.*; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.HashMap; -import java.util.stream.Collectors; -import java.util.stream.Stream; - import weka.core.Instance; import weka.core.Instances; +import java.io.File; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + /** + * get sum for every article and sort them ascending. + * * @author Karsten Eden * @version 0.1 * @since 0.1 @@ -22,29 +24,34 @@ public class TopFlopArticle implements Analysis> { private Instances instances; private Map results; - public TopFlopArticle(File file){ - results = new HashMap<>(); + public TopFlopArticle(File file) { + instances = load(file); } /** - * get sum for every article and sort them asending + * get result of analysis. + * * @return Map of Name of Products and Sum of Values */ public Map getResult() { + if (results != null) { + return results; + } + results = new HashMap<>(); String name; - Double sum = 0.0; - for(int i=11; i<=25; i++) { + double sum = 0.0; + for (int i = 11; i <= 25; i++) { for (Instance instance : instances) { sum += instance.value(i); } name = instances.attribute(i).name(); - results.put(name, sum.intValue()); + results.put(name, (int) sum); sum = 0.0; } //Sort Map in ascending order Stream> sorted = results.entrySet().stream().sorted(Map.Entry.comparingByValue()); - results = sorted.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), (e1, e2) -> e2, LinkedHashMap::new)); + results = sorted.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new)); return results; } diff --git a/src/main/java/de/hsel/spm/baudas/analysis/WeekOverview.java b/src/main/java/de/hsel/spm/baudas/analysis/WeekOverview.java index 033365a..7c54043 100644 --- a/src/main/java/de/hsel/spm/baudas/analysis/WeekOverview.java +++ b/src/main/java/de/hsel/spm/baudas/analysis/WeekOverview.java @@ -9,7 +9,7 @@ import java.util.HashMap; import java.util.Map; /** - * Week Overview Analysis. + * Week WeekOverviewDiagram Analysis. * * @author Julian Hinxlage * @version 0.1 @@ -21,19 +21,26 @@ public class WeekOverview implements Analysis> result; public WeekOverview(File file) { - result = new HashMap<>(); + instances = load(file); } + /** + * get results for analysis. + * + * @return day, amount, count + */ @Override public Map> getResult() { + if (result != null) { + return result; + } + result = new HashMap<>(); + int dayIndex = Attribute.SHOPPING_DAY; + int amountIndex = Attribute.PURCHASE_AMOUNT; - //TODO: replace values when #SPM-17 is merged - int dayIndex = 5; - int amountIndex = 10; - - int startArticles = 11; - int endArticles = 26; + int startArticles = Attribute.POWER_TOOLS; + int endArticles = Attribute.GARDENING_TOOLS + 1; for (int i = 0; i < instances.numInstances(); i++) { Instance instance = instances.get(i); 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 f90f673..f969b45 100644 --- a/src/main/java/de/hsel/spm/baudas/web/Upload.java +++ b/src/main/java/de/hsel/spm/baudas/web/Upload.java @@ -56,6 +56,6 @@ public class Upload extends HttpServlet { Files.copy(inputStream, path, StandardCopyOption.REPLACE_EXISTING); - resp.sendRedirect("index.jsf"); + resp.sendRedirect(""); } } \ No newline at end of file diff --git a/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java b/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java new file mode 100644 index 0000000..21855c4 --- /dev/null +++ b/src/main/java/de/hsel/spm/baudas/web/WeekOverviewDiagram.java @@ -0,0 +1,89 @@ +package de.hsel.spm.baudas.web; + +import com.google.gson.Gson; +import de.hsel.spm.baudas.analysis.WeekOverview; +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.IOException; +import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; +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 + * + * @author Johannes Theiner + * @version 0.1 + * @since 0.1 + **/ +@WebServlet("/week_overview") +public class WeekOverviewDiagram extends HttpServlet { + + /** + * 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 { + req.setCharacterEncoding(StandardCharsets.UTF_8.name()); + resp.setCharacterEncoding(StandardCharsets.UTF_8.name()); + resp.setContentType("application/json"); + PrintWriter out = resp.getWriter(); + + List definedOrder = Arrays.asList("Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"); + Map> result = new HashMap<>(); + + Gson gson = new Gson(); + + SavedFile file = Data.getFiles().peek(); + if (file == null) { + result.put("labels", definedOrder); + result.put("count", new ArrayList<>()); + result.put("revenue", new ArrayList<>()); + out.print(gson.toJson(result)); + return; + } + assert file.getUuid() != null; + WeekOverview overview = new WeekOverview(Data.get(file.getUuid())); + + List labels = new ArrayList<>(); + + List count = new ArrayList<>(); + List revenue = new ArrayList<>(); + + for (Map.Entry> entry : overview.getResult().entrySet()) { + labels.add(entry.getKey()); + count.add(entry.getValue().getKey().toString()); + revenue.add(entry.getValue().getValue().toString()); + } + + + Comparator comparator = Comparator.comparingInt(definedOrder::indexOf); + labels.sort(comparator); + + for (String label : labels) { + Map.Entry entry = overview.getResult().get(label); + count.add(entry.getKey().toString()); + revenue.add(entry.getValue().toString()); + } + + + result.put("labels", labels); + result.put("count", count); + result.put("revenue", revenue); + + out.print(gson.toJson(result)); + } +} \ No newline at end of file diff --git a/src/main/webapp/preview/data/flop_articles.json b/src/main/webapp/data/flop_articles.json similarity index 100% rename from src/main/webapp/preview/data/flop_articles.json rename to src/main/webapp/data/flop_articles.json diff --git a/src/main/webapp/preview/data/overview.json b/src/main/webapp/data/overview.json similarity index 100% rename from src/main/webapp/preview/data/overview.json rename to src/main/webapp/data/overview.json diff --git a/src/main/webapp/preview/data/shoping_times.json b/src/main/webapp/data/shoping_times.json similarity index 100% rename from src/main/webapp/preview/data/shoping_times.json rename to src/main/webapp/data/shoping_times.json diff --git a/src/main/webapp/preview/data/sold_articles.json b/src/main/webapp/data/sold_articles.json similarity index 100% rename from src/main/webapp/preview/data/sold_articles.json rename to src/main/webapp/data/sold_articles.json diff --git a/src/main/webapp/preview/data/top_articles.json b/src/main/webapp/data/top_articles.json similarity index 100% rename from src/main/webapp/preview/data/top_articles.json rename to src/main/webapp/data/top_articles.json diff --git a/src/main/webapp/footer.jsp b/src/main/webapp/footer.jsp new file mode 100644 index 0000000..b7edde8 --- /dev/null +++ b/src/main/webapp/footer.jsp @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/header.jsp b/src/main/webapp/header.jsp new file mode 100644 index 0000000..f0aa07f --- /dev/null +++ b/src/main/webapp/header.jsp @@ -0,0 +1,95 @@ +<% response.setCharacterEncoding(StandardCharsets.UTF_8.name()); %> +<% request.setCharacterEncoding(StandardCharsets.UTF_8.name()); %> + + + + BauDas + + + + + + + + + + + + + + + + +
+ + +
    +
  • +
    + +
    +
    +
    +
  • +
  • +
  • + +
    + +
  • +
  • + +
    + +
    +
  • +
  • +
  • +
    +
    +
    + File + +
    +
    + +
    +
    + +
  • +
\ No newline at end of file diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..9fbc781 --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,197 @@ +<%@ page import="java.nio.charset.StandardCharsets" %> +<%@ page contentType="text/html;charset=UTF-8" %> +<%@include file="header.jsp"%> +<% response.setCharacterEncoding(StandardCharsets.UTF_8.name()); %> +<% request.setCharacterEncoding(StandardCharsets.UTF_8.name()); %> + + + +
+ +
+
+
+ Übersicht +
+ +
+
+ +
+
+
+
+ + +
+
+
+
+ Einkaufszeiten +
+
+
+ + +
+
+
+ +
+
+
+
+ + +
+
+
+
+ Verkaufte Artikel +
+
+
+ + +
+
+
+ +
+
+
+
+ + +
+
+
+ Top Artikel +
+ +
+
+ +
+
+
+
+ +
+
+
+ Flop Artikel +
+ +
+
+ +
+
+
+
+ + +
+
+
+
+ Warenkorbanalyse +
+
+

Coming Soon

+
+
+
+
+ + +
+
+
+
+ Gruppenübersicht +
+
+

Coming Soon

+
+
+
+
+
+ + +
+ +
+
+
+
+ Marketingmaßnahme 1 +
+
+

Coming Soon

+
+
+
+
+
+
+
+
+ Marketingmaßnahme 2 +
+
+

Coming Soon

+
+
+
+
+
+
+
+
+ Marketingmaßnahme 3 +
+
+

Coming Soon

+
+
+
+
+
+
+
+
+ Marketingmaßnahme 4 +
+
+

Coming Soon

+
+
+
+
+
+ +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/src/main/webapp/preview/js/flop_articles.js b/src/main/webapp/js/flop_articles.js similarity index 100% rename from src/main/webapp/preview/js/flop_articles.js rename to src/main/webapp/js/flop_articles.js diff --git a/src/main/webapp/preview/js/materialize_components.js b/src/main/webapp/js/materialize_components.js similarity index 100% rename from src/main/webapp/preview/js/materialize_components.js rename to src/main/webapp/js/materialize_components.js diff --git a/src/main/webapp/preview/js/overview.js b/src/main/webapp/js/overview.js similarity index 84% rename from src/main/webapp/preview/js/overview.js rename to src/main/webapp/js/overview.js index 9f2c58a..9b048d4 100644 --- a/src/main/webapp/preview/js/overview.js +++ b/src/main/webapp/js/overview.js @@ -1,5 +1,5 @@ $.ajax({ - url: 'data/overview.json', + url: 'week_overview', dataType: 'json' }).done(function (results) { new Chart(document.getElementById("overview_chart"), { @@ -8,16 +8,16 @@ $.ajax({ labels: results.labels, datasets: [{ label: "Warenanzahl", - data: results.data1, + data: results.count, fill: true, backgroundColor: 'rgba(113, 114, 231, 0.7)', - lineTension: 0, + lineTension: 0 }, { label: "Einnahmen in €", - data: results.data2, + data: results.revenue, fill: true, backgroundColor: 'rgba(104, 216, 154, 0.8)', - lineTension: 0, + lineTension: 0 }] }, options: { @@ -31,7 +31,7 @@ $.ajax({ }, tooltips: { mode: 'index', - intersect: false, + intersect: false }, hover: { mode: 'nearest', @@ -50,7 +50,7 @@ $.ajax({ } }], yAxes: [{ - display: true, + display: true }] } } diff --git a/src/main/webapp/preview/js/shoping_times.js b/src/main/webapp/js/shoping_times.js similarity index 100% rename from src/main/webapp/preview/js/shoping_times.js rename to src/main/webapp/js/shoping_times.js diff --git a/src/main/webapp/preview/js/sold_articles.js b/src/main/webapp/js/sold_articles.js similarity index 100% rename from src/main/webapp/preview/js/sold_articles.js rename to src/main/webapp/js/sold_articles.js diff --git a/src/main/webapp/preview/js/top_articles.js b/src/main/webapp/js/top_articles.js similarity index 97% rename from src/main/webapp/preview/js/top_articles.js rename to src/main/webapp/js/top_articles.js index 7c0a587..d61e496 100644 --- a/src/main/webapp/preview/js/top_articles.js +++ b/src/main/webapp/js/top_articles.js @@ -3,7 +3,7 @@ $.ajax({ dataType: 'json' }).done(function (results) { new Chart(document.getElementById("top_articles_chart"), { - type: 'phorizontalBarie', + type: 'horizontalBar', data: { labels: results.labels, datasets: [{ diff --git a/src/main/webapp/preview/logoOrginal.gif b/src/main/webapp/logoOrginal.gif similarity index 100% rename from src/main/webapp/preview/logoOrginal.gif rename to src/main/webapp/logoOrginal.gif diff --git a/src/main/webapp/preview/index.html b/src/main/webapp/preview/index.html index 1095225..31a72e1 100644 --- a/src/main/webapp/preview/index.html +++ b/src/main/webapp/preview/index.html @@ -44,7 +44,7 @@
  • - +


    diff --git a/src/main/webapp/preview/login.html b/src/main/webapp/preview/login.html index 67dd914..8538999 100644 --- a/src/main/webapp/preview/login.html +++ b/src/main/webapp/preview/login.html @@ -18,7 +18,7 @@
    - +
    diff --git a/src/main/webapp/preview/registration.html b/src/main/webapp/preview/registration.html index 0dbe2f8..a8705ba 100644 --- a/src/main/webapp/preview/registration.html +++ b/src/main/webapp/preview/registration.html @@ -21,7 +21,7 @@
    - +
    diff --git a/src/main/webapp/upload-test.html b/src/main/webapp/upload-test.html deleted file mode 100644 index b57a823..0000000 --- a/src/main/webapp/upload-test.html +++ /dev/null @@ -1,11 +0,0 @@ - - - -
    - - -
    - - \ No newline at end of file diff --git a/src/test/java/de/hsel/spm/baudas/analysis/ClusterTest.java b/src/test/java/de/hsel/spm/baudas/analysis/ClusterTest.java index 8eddd85..df3438d 100644 --- a/src/test/java/de/hsel/spm/baudas/analysis/ClusterTest.java +++ b/src/test/java/de/hsel/spm/baudas/analysis/ClusterTest.java @@ -29,7 +29,7 @@ class ClusterTest { AtomicReference>> results = new AtomicReference<>(); - assertTimeout(Duration.ofMillis(2000), () -> results.set(cluster.getResult())); + assertTimeout(Duration.ofMillis(10000), () -> results.set(cluster.getResult())); assertEquals("m", results.get().get(0).get("Geschlecht")); } 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 7a02cf7..0f6f283 100644 --- a/src/test/java/de/hsel/spm/baudas/analysis/WeekOverviewTest.java +++ b/src/test/java/de/hsel/spm/baudas/analysis/WeekOverviewTest.java @@ -13,7 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertTimeout; /** - * Week Overview Analysis Test. + * Week WeekOverviewDiagram Analysis Test. * * @author Johannes Theiner * @version 0.1 @@ -84,7 +84,7 @@ class WeekOverviewTest { AtomicReference>> result = new AtomicReference<>(); - assertTimeout(Duration.ofMillis(15), () -> result.set(overview.getResult())); + assertTimeout(Duration.ofMillis(30), () -> result.set(overview.getResult())); assertEquals(295688, result.get().get("Montag").getKey());