+ documentation
~ cleanup Signed-off-by: Johannes Theiner <j.theiner@live.de> #SPM-18: add work 1h documentation
This commit is contained in:
parent
303fad71d8
commit
66305b51d1
2
pom.xml
2
pom.xml
@ -277,7 +277,7 @@
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<scope>compile</scope>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
|
@ -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 {
|
||||
|
@ -16,7 +16,7 @@ import java.util.UUID;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class SavedFile {
|
||||
class SavedFile {
|
||||
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
|
@ -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<DayHour, Integer> map = shoppingTimes.getResult();
|
||||
|
@ -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 {
|
||||
|
@ -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<String> comparator = Comparator.comparingInt(definedOrder::indexOf);
|
||||
labels.sort(comparator);
|
||||
System.out.println(labels);
|
||||
|
||||
for (String label : labels) {
|
||||
Map.Entry<Double, Integer> entry = overview.getResult().get(label);
|
||||
|
@ -9,7 +9,7 @@
|
||||
<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 src="js/overview.js"></script>
|
||||
<script src="js/week_overview.js"></script>
|
||||
<script src="js/shopping_times.js"></script>
|
||||
<%--<script src="js/sold_articles.js"></script>
|
||||
<script src="js/top_articles.js"></script>
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
<!--Einkaufszeiten-->
|
||||
<div class="col s12 m6">
|
||||
<div id="shoping_times" class="card white">
|
||||
<div id="shopping_times" class="card white">
|
||||
<div class="card-content">
|
||||
<div class="center">
|
||||
<span class="card-title">Einkaufszeiten</span>
|
||||
@ -46,7 +46,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<canvas id="shoping_times_chart" width="1000" height="400"></canvas>
|
||||
<canvas id="shopping_times_chart" width="1000" height="400"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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
|
||||
}]
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
@ -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
|
||||
}
|
65
src/main/webapp/js/week_overview.js
Normal file
65
src/main/webapp/js/week_overview.js
Normal file
@ -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();
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user