Merge remote-tracking branch 'origin/SPM-28' into SPM-22

This commit is contained in:
Johannes Theiner 2019-05-18 12:37:44 +02:00
commit fb607592a6
12 changed files with 139 additions and 55 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
.project .project
.vscode .vscode
target target
*.csv

View File

@ -9,6 +9,7 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
@ -36,7 +37,7 @@ public class Data {
//cleanup old files //cleanup old files
if (files.isEmpty()) { if (files.isEmpty()) {
try { try {
Files.list(Paths.get("target/")).forEach(path -> { Files.list(Paths.get("")).forEach(path -> {
if (path.toFile().getName().endsWith(".csv")) { if (path.toFile().getName().endsWith(".csv")) {
try { try {
Files.delete(path); Files.delete(path);
@ -60,11 +61,11 @@ public class Data {
System.out.println("failed to delete file..."); System.out.println("failed to delete file...");
} }
path = Paths.get(getFileName(uuid)); path = Paths.get(getFileName(uuid));
files.offer(new SavedFile(uuid, name)); files.offer(new SavedFile(uuid, name, LocalDateTime.now()));
} else { } else {
files.add(new SavedFile(uuid, name)); files.add(new SavedFile(uuid, name, LocalDateTime.now()));
path = Paths.get(getFileName(uuid)); path = Paths.get(getFileName(uuid));
} }
return path; return path;
@ -91,6 +92,6 @@ public class Data {
@Contract(pure = true) @Contract(pure = true)
@NotNull @NotNull
private static String getFileName(@NotNull UUID uuid) { private static String getFileName(@NotNull UUID uuid) {
return "target/" + uuid + ".csv"; return uuid + ".csv";
} }
} }

View File

@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.ToString; import lombok.ToString;
import java.time.LocalDateTime;
import java.util.UUID; import java.util.UUID;
/** /**
@ -20,4 +21,5 @@ class SavedFile {
private UUID uuid; private UUID uuid;
private String name; private String name;
private LocalDateTime date;
} }

View File

@ -9,6 +9,7 @@ import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -21,6 +22,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.UUID;
/** /**
* changes data from shopping times diagram into a readable format for chart.js * changes data from shopping times diagram into a readable format for chart.js
@ -48,15 +50,16 @@ public class ShoppingTimesDiagram extends HttpServlet {
Gson gson = new Gson(); Gson gson = new Gson();
SavedFile file = Data.getFiles().peek();
if (file == null) { if (req.getParameter("id") == null) {
result.put("labels", definedOrder); result.put("labels", definedOrder);
out.print(gson.toJson(result)); out.print(gson.toJson(result));
return; return;
} }
UUID uuid = UUID.fromString(req.getParameter("id"));
File file = Data.get(uuid);
assert file.getUuid() != null; ShoppingTimes shoppingTimes = new ShoppingTimes(file);
ShoppingTimes shoppingTimes = new ShoppingTimes(Data.get(file.getUuid()));
Map<DayHour, Integer> map = shoppingTimes.getResult(); Map<DayHour, Integer> map = shoppingTimes.getResult();
Set<String> days = new TreeSet<>(); Set<String> days = new TreeSet<>();

View File

@ -8,6 +8,7 @@ import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -17,6 +18,7 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
/** /**
* changes data from week overview into readable format for chart.js * changes data from week overview into readable format for chart.js
@ -43,16 +45,19 @@ public class WeekOverviewDiagram extends HttpServlet {
Gson gson = new Gson(); Gson gson = new Gson();
SavedFile file = Data.getFiles().peek();
if (file == null) { if (req.getParameter("id") == null) {
result.put("labels", definedOrder); result.put("labels", definedOrder);
result.put("count", new ArrayList<>()); result.put("count", new ArrayList<>());
result.put("revenue", new ArrayList<>()); result.put("revenue", new ArrayList<>());
out.print(gson.toJson(result)); out.print(gson.toJson(result));
return; return;
} }
assert file.getUuid() != null;
WeekOverview overview = new WeekOverview(Data.get(file.getUuid())); UUID uuid = UUID.fromString(req.getParameter("id"));
File file = Data.get(uuid);
WeekOverview overview = new WeekOverview(file);
List<String> count = new ArrayList<>(); List<String> count = new ArrayList<>();
List<String> revenue = new ArrayList<>(); List<String> revenue = new ArrayList<>();

View File

@ -7,7 +7,11 @@
<!--Script für Materlialize--> <!--Script für Materlialize-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script> <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script type="text/javascript" src="js/materialize_components.js"></script> <script>
M.AutoInit();
</script>
<script src="js/cache.js"></script>
<script src="js/week_overview.js"></script> <script src="js/week_overview.js"></script>
<script src="js/shopping_times.js"></script> <script src="js/shopping_times.js"></script>

View File

@ -23,11 +23,11 @@
<body class="blue-grey lighten-5"> <body class="blue-grey lighten-5">
<!--Navbar--> <!--Navbar-->
<div class="navbar-fixed"> <div class="navbar-fixed">
<nav class="nav-extended blue-grey lighten-3 white-text row"> <nav class="nav-extended blue-grey darken-3 white-text row">
<a href="#" class="brand-logo hide-on-small-and-down center">BauDas</a> <a href="#" class="brand-logo hide-on-small-and-down center">BauDas</a>
<!--Navbar Tabs--> <!--Navbar Tabs-->
<div class="nav-content col 12 "> <div class="nav-content col 12 ">
<ul class="tabs tabs-transparent blue-grey lighten-3 white-text"> <ul class="tabs tabs-transparent blue-grey darken-3 white-text">
<li class="tab"><a class="active" href="#analysis"><i class="material-icons left">poll</i>Analyse</a> <li class="tab"><a class="active" href="#analysis"><i class="material-icons left">poll</i>Analyse</a>
</li> </li>
<li class="tab"><a href="#marketing"><i class="material-icons left">public</i>Marketing</a></li> <li class="tab"><a href="#marketing"><i class="material-icons left">public</i>Marketing</a></li>
@ -79,15 +79,9 @@
</li> </li>
<li> <li>
<div class="input-field container"> <div class="input-field container">
<label>Datensatzauswahl</label> <label for="dataset">Datensatzauswahl</label>
<br> <br>
<select> <select id="dataset" onChange="updateCache()">
<option value="0">aktuell</option>
<option value="1">Datensatz 1</option>
<option value="2">Datensatz 2</option>
<option value="3">Datensatz 3</option>
<option value="4">Datensatz 4</option>
<option value="5">Datensatz 5</option>
</select> </select>
<br> <br>
</div> </div>

View File

@ -34,7 +34,7 @@
</div> </div>
<div class="center"> <div class="center">
<div class="input-field col s12"> <div class="input-field col s12">
<select id="day" onchange="updateDays()"> <select id="day" onchange="changeDay()">
<option value="0">Montag</option> <option value="0">Montag</option>
<option value="1">Dienstag</option> <option value="1">Dienstag</option>
<option value="2">Mittwoch</option> <option value="2">Mittwoch</option>

View File

@ -0,0 +1,74 @@
$(document).ready(function () {
let dataset = $('#dataset');
request('files').then(results => {
dataset.empty();
for (const result of results) {
dataset.append($("<option></option>")
.attr("value", result.uuid)
.text(result.name + " (" + result.date.date.day + "." + result.date.date.month + " "
+ result.date.time.hour + ":" + result.date.time.minute + ")"));
}
dataset.formSelect();
});
updateCache();
});
/**
* update all charts with correct values for dataset
*/
function updateCache() {
let dataset = $('#dataset');
let selected = $('#dataset :selected');
if (typeof selected !== 'undefined' && selected.index() !== -1) {
updateWeekOverviewChart(selected.val());
updateShoppingTimesChart(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);
dataset.formSelect();
});
}
}
/**
* request json data
* @param url base url
* @param id dataset id
* @returns {Promise<result>}
*/
function request(url, id) {
return new Promise(((resolve) => {
if (typeof id !== 'undefined') {
requestInternal(url + '?id=' + id).then(function (data) {
resolve(data);
});
} else {
requestInternal(url).then(function (data) {
resolve(data);
});
}
}));
}
/**
* only for use inside this file, javascript has no better way
* @param url url
* @returns {Promise<result>}
*/
function requestInternal(url) {
return new Promise(((resolve) => {
$.ajax({
url: url,
dataType: 'json'
}).done(function (results) {
resolve(results);
});
}));
}

View File

@ -1,14 +0,0 @@
$(".dropdown-trigger").dropdown();
$('.tabs').tabs();
$(document).ready(function(){
$('.sidenav').sidenav();
});
$(document).ready(function(){
$('select').formSelect();
});
$(document).ready(function(){
$('.collapsible').collapsible();
});
$(document).ready(function() {
M.updateTextFields();
});

View File

@ -52,15 +52,19 @@ let shopping_chart = new Chart(document.getElementById("shopping_times_chart"),
} }
}); });
$.ajax({ function updateShoppingTimesChart(id) {
url: 'shopping_times', if(typeof id !== 'undefined') {
dataType: 'json' request('shopping_times', id).then(function (data) {
}).done(function (results) { shopping_result = data;
shopping_result = results; changeDay();
updateDays(); });
}); }else request('shopping_times').then(function(data) {
shopping_result = data;
changeDay();
});
}
function updateDays() { function changeDay() {
if(typeof shopping_result["Montag"] !== 'undefined') { if(typeof shopping_result["Montag"] !== 'undefined') {
let e = document.getElementById("day"); let e = document.getElementById("day");
let value = e.options[e.selectedIndex].text; let value = e.options[e.selectedIndex].text;

View File

@ -1,4 +1,6 @@
let week_overview = new Chart(document.getElementById("overview_chart"), { let week_result;
let week_overview = new Chart($("#overview_chart"), {
type: 'line', type: 'line',
data: { data: {
labels: [0, 0, 0, 0, 0], labels: [0, 0, 0, 0, 0],
@ -52,14 +54,22 @@ let week_overview = new Chart(document.getElementById("overview_chart"), {
} }
}); });
$.ajax({ function updateWeekOverviewChart(id) {
url: 'week_overview', if (typeof id !== 'undefined') {
dataType: 'json' request('week_overview', id).then(function (data) {
}).done(function (results) { week_result = data;
week_overview.data.labels = results.labels; updateWeekOverview();
week_overview.data.datasets[0].data = results.count; });
week_overview.data.datasets[1].data = results.revenue; } else request('week_overview').then(function (data) {
week_result = data;
updateWeekOverview();
});
}
function updateWeekOverview() {
week_overview.data.labels = week_result.labels;
week_overview.data.datasets[0].data = week_result.count;
week_overview.data.datasets[1].data = week_result.revenue;
week_overview.update(); week_overview.update();
}); }