+ documentation

~ cleanup

Signed-off-by: Johannes Theiner <j.theiner@live.de>

#SPM-18: add work 1h documentation
This commit is contained in:
Johannes Theiner 2019-05-10 20:32:03 +02:00
parent 303fad71d8
commit 66305b51d1
11 changed files with 118 additions and 127 deletions

View File

@ -277,7 +277,7 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.4</version> <version>1.18.4</version>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jetbrains</groupId> <groupId>org.jetbrains</groupId>

View File

@ -24,12 +24,6 @@ public class Files extends HttpServlet {
private static final long serialVersionUID = 148451844848L; private static final long serialVersionUID = 148451844848L;
/**
* do get.
* @param req request
* @param resp response
* @throws IOException writer could not be retrieved
*/
@Override @Override
protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp)
throws IOException { throws IOException {

View File

@ -16,7 +16,7 @@ import java.util.UUID;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
@ToString @ToString
public class SavedFile { class SavedFile {
private UUID uuid; private UUID uuid;
private String name; private String name;

View File

@ -12,17 +12,28 @@ import javax.servlet.http.HttpServletResponse;
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;
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 * @author Johannes Theiner
* @version 0.1 * @version 0.1
* @since 0.1 * @since 0.1
**/ **/
@WebServlet("/shopping_times") @WebServlet("/shopping_times")
public class ShoppingTimesDiagram extends HttpServlet { public class ShoppingTimesDiagram extends HttpServlet {
private static final long serialVersionUID = 6567531484L;
@Override @Override
protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException { protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException {
req.setCharacterEncoding(StandardCharsets.UTF_8.name()); req.setCharacterEncoding(StandardCharsets.UTF_8.name());
@ -39,9 +50,11 @@ public class ShoppingTimesDiagram extends HttpServlet {
SavedFile file = Data.getFiles().peek(); SavedFile file = Data.getFiles().peek();
if (file == null) { if (file == null) {
result.put("labels", definedOrder);
out.print(gson.toJson(result)); out.print(gson.toJson(result));
return; return;
} }
assert file.getUuid() != null; assert file.getUuid() != null;
ShoppingTimes shoppingTimes = new ShoppingTimes(Data.get(file.getUuid())); ShoppingTimes shoppingTimes = new ShoppingTimes(Data.get(file.getUuid()));
Map<DayHour, Integer> map = shoppingTimes.getResult(); Map<DayHour, Integer> map = shoppingTimes.getResult();

View File

@ -31,14 +31,7 @@ public class Upload extends HttpServlet {
private static final long serialVersionUID = 14144111845151L; 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 @Override
protected void doPost(@NotNull HttpServletRequest req, HttpServletResponse resp) protected void doPost(@NotNull HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException { throws ServletException, IOException {

View File

@ -11,7 +11,12 @@ import javax.servlet.http.HttpServletResponse;
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;
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 * changes data from week overview into readable format for chart.js
@ -23,13 +28,9 @@ import java.util.*;
@WebServlet("/week_overview") @WebServlet("/week_overview")
public class WeekOverviewDiagram extends HttpServlet { public class WeekOverviewDiagram extends HttpServlet {
/** private static final long serialVersionUID = 8484151844118L;
* do get.
*
* @param req request
* @param resp response
* @throws IOException writer could not be retrieved
*/
@Override @Override
protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException { protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException {
req.setCharacterEncoding(StandardCharsets.UTF_8.name()); req.setCharacterEncoding(StandardCharsets.UTF_8.name());
@ -61,7 +62,6 @@ public class WeekOverviewDiagram extends HttpServlet {
Comparator<String> comparator = Comparator.comparingInt(definedOrder::indexOf); Comparator<String> comparator = Comparator.comparingInt(definedOrder::indexOf);
labels.sort(comparator); labels.sort(comparator);
System.out.println(labels);
for (String label : labels) { for (String label : labels) {
Map.Entry<Double, Integer> entry = overview.getResult().get(label); Map.Entry<Double, Integer> entry = overview.getResult().get(label);

View File

@ -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="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 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/shopping_times.js"></script>
<%--<script src="js/sold_articles.js"></script> <%--<script src="js/sold_articles.js"></script>
<script src="js/top_articles.js"></script> <script src="js/top_articles.js"></script>

View File

@ -27,7 +27,7 @@
<!--Einkaufszeiten--> <!--Einkaufszeiten-->
<div class="col s12 m6"> <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="card-content">
<div class="center"> <div class="center">
<span class="card-title">Einkaufszeiten</span> <span class="card-title">Einkaufszeiten</span>
@ -46,7 +46,7 @@
</div> </div>
</div> </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> </div>
</div> </div>

View File

@ -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
}]
}
}
});
});

View File

@ -1,6 +1,6 @@
let shopping_result; 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', type: 'bar',
data: { data: {
labels: [1, 2, 3, 4, 5], labels: [1, 2, 3, 4, 5],
@ -61,45 +61,29 @@ $.ajax({
}); });
function updateDays() { function updateDays() {
let e = document.getElementById("day"); if(typeof shopping_result["Montag"] !== 'undefined') {
let value = e.options[e.selectedIndex].text; let e = document.getElementById("day");
shopping_chart.data.labels = shopping_result.labels; let value = e.options[e.selectedIndex].text;
shopping_chart.data.datasets[0].data = shopping_result[value]; 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"); shopping_chart.update();
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.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
} }

View 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();
});