Chart logic fixed and improved
This commit is contained in:
parent
9ccdd15adb
commit
c90a4029e8
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,6 +12,7 @@ target/
|
|||||||
*.iws
|
*.iws
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
|
src/main/resources/scripts/.venv/
|
||||||
lib/
|
lib/
|
||||||
logs/
|
logs/
|
||||||
data/
|
data/
|
||||||
|
|||||||
Binary file not shown.
@ -4,6 +4,7 @@ import vassistent.model.AppState;
|
|||||||
import vassistent.model.RatioPoint;
|
import vassistent.model.RatioPoint;
|
||||||
import vassistent.service.StatisticsService;
|
import vassistent.service.StatisticsService;
|
||||||
import vassistent.ui.DashboardView;
|
import vassistent.ui.DashboardView;
|
||||||
|
import vassistent.util.Logger;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -28,17 +29,19 @@ public class DashboardController {
|
|||||||
private void onStateChanged(AppState state) {
|
private void onStateChanged(AppState state) {
|
||||||
|
|
||||||
List<RatioPoint> points =
|
List<RatioPoint> points =
|
||||||
statisticsService.getLastNAverages(20);
|
statisticsService.getLastNAverages(120);
|
||||||
|
|
||||||
if (points.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
double ratio = points.get(points.size() - 1).getRatio();
|
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
|
||||||
|
Logger.info("STATISTICS",
|
||||||
|
"Entries loaded: " + points.size());
|
||||||
|
|
||||||
dashboardView.updateChart(points);
|
dashboardView.updateChart(points);
|
||||||
|
|
||||||
|
if (!points.isEmpty()) {
|
||||||
|
double ratio = points.get(points.size() - 1).getRatio();
|
||||||
dashboardView.updateProblemLevel(ratio);
|
dashboardView.updateProblemLevel(ratio);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public class AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void notifyListeners() {
|
private void notifyListeners() {
|
||||||
listeners.forEach(l -> l.accept(this));
|
new ArrayList<>(listeners).forEach(l -> l.accept(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProblemLevel getProblemLevel() {
|
public ProblemLevel getProblemLevel() {
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public class BinaryEventService {
|
|||||||
|
|
||||||
if (lastId != null && lastId == id) {
|
if (lastId != null && lastId == id) {
|
||||||
Logger.warn("EVENT", "Payload ID bereits verarbeitet: " + id);
|
Logger.warn("EVENT", "Payload ID bereits verarbeitet: " + id);
|
||||||
return;
|
//return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastId = id;
|
lastId = id;
|
||||||
|
|||||||
@ -41,29 +41,37 @@ public class StatisticsService {
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RatioPoint> getLastNAverages(int lastN) {
|
public List<RatioPoint> getLastNAverages(int windowSize) {
|
||||||
|
|
||||||
List<DatabaseEntry> entries = persistenceService.getLastEntries(30);
|
List<DatabaseEntry> entries = persistenceService.getLastEntries(windowSize + 1);
|
||||||
|
|
||||||
List<RatioPoint> result = new ArrayList<>();
|
List<RatioPoint> result = new ArrayList<>();
|
||||||
|
|
||||||
if (entries.isEmpty())
|
if (entries.isEmpty())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
for (int i = 10; i < entries.size(); i++) {
|
for (int i = 0; i < entries.size(); i++) {
|
||||||
|
int start = Math.max(0, i - windowSize);
|
||||||
|
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
for (int j = i - 10; j < i; j++) {
|
for (int j = start; j < i; j++) {
|
||||||
sum += entries.get(j).getValue();
|
sum += entries.get(j).getValue();
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
double avg = sum / 10.0;
|
double avg = count == 0 ? 0 : sum / count;
|
||||||
|
|
||||||
LocalDateTime timestamp = entries.get(i).getTimestamp();
|
result.add(new RatioPoint(
|
||||||
|
entries.get(i).getTimestamp(),
|
||||||
result.add(new RatioPoint(timestamp, avg));
|
avg
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.info("STATISTICS",
|
||||||
|
"Computed averages: " + result.size());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,13 @@ package vassistent.ui;
|
|||||||
import org.jfree.chart.ChartFactory;
|
import org.jfree.chart.ChartFactory;
|
||||||
import org.jfree.chart.ChartPanel;
|
import org.jfree.chart.ChartPanel;
|
||||||
import org.jfree.chart.JFreeChart;
|
import org.jfree.chart.JFreeChart;
|
||||||
|
import org.jfree.chart.axis.DateAxis;
|
||||||
import org.jfree.chart.axis.NumberAxis;
|
import org.jfree.chart.axis.NumberAxis;
|
||||||
import org.jfree.chart.axis.NumberTickUnit;
|
import org.jfree.chart.axis.NumberTickUnit;
|
||||||
import org.jfree.chart.plot.ValueMarker;
|
import org.jfree.chart.plot.ValueMarker;
|
||||||
import org.jfree.chart.plot.XYPlot;
|
import org.jfree.chart.plot.XYPlot;
|
||||||
|
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
||||||
|
import org.jfree.chart.ui.Layer;
|
||||||
import org.jfree.chart.ui.RectangleAnchor;
|
import org.jfree.chart.ui.RectangleAnchor;
|
||||||
import org.jfree.chart.ui.TextAnchor;
|
import org.jfree.chart.ui.TextAnchor;
|
||||||
import org.jfree.data.category.DefaultCategoryDataset;
|
import org.jfree.data.category.DefaultCategoryDataset;
|
||||||
@ -75,6 +78,24 @@ public class DashboardView extends JPanel {
|
|||||||
|
|
||||||
XYPlot plot = chart.getXYPlot();
|
XYPlot plot = chart.getXYPlot();
|
||||||
|
|
||||||
|
long tenMinutes = 10 * 60 * 1000L;
|
||||||
|
|
||||||
|
DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
|
||||||
|
|
||||||
|
domainAxis.setFixedAutoRange(tenMinutes);
|
||||||
|
domainAxis.setAutoRange(true);
|
||||||
|
|
||||||
|
XYLineAndShapeRenderer renderer =
|
||||||
|
(XYLineAndShapeRenderer) plot.getRenderer();
|
||||||
|
|
||||||
|
renderer.setDefaultShapesVisible(false);
|
||||||
|
renderer.setSeriesStroke(0,
|
||||||
|
new BasicStroke(
|
||||||
|
2.5f,
|
||||||
|
BasicStroke.CAP_ROUND,
|
||||||
|
BasicStroke.JOIN_ROUND
|
||||||
|
));
|
||||||
|
|
||||||
// Threshold Lines
|
// Threshold Lines
|
||||||
addThresholdLine(plot, 0.5, "Warning");
|
addThresholdLine(plot, 0.5, "Warning");
|
||||||
addThresholdLine(plot, 0.8, "High");
|
addThresholdLine(plot, 0.8, "High");
|
||||||
@ -85,6 +106,7 @@ public class DashboardView extends JPanel {
|
|||||||
rangeAxis.setTickUnit(new NumberTickUnit(0.1));
|
rangeAxis.setTickUnit(new NumberTickUnit(0.1));
|
||||||
|
|
||||||
chart.setAntiAlias(true);
|
chart.setAntiAlias(true);
|
||||||
|
chart.setTextAntiAlias(true);
|
||||||
chart.getPlot().setBackgroundPaint(new Color(245,245,245));
|
chart.getPlot().setBackgroundPaint(new Color(245,245,245));
|
||||||
chart.getPlot().setOutlineVisible(false);
|
chart.getPlot().setOutlineVisible(false);
|
||||||
|
|
||||||
@ -121,6 +143,9 @@ public class DashboardView extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateChart(List<RatioPoint> points) {
|
public void updateChart(List<RatioPoint> points) {
|
||||||
|
if (points == null || points.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
series.clear();
|
series.clear();
|
||||||
|
|
||||||
for (RatioPoint point : points) {
|
for (RatioPoint point : points) {
|
||||||
@ -154,13 +179,25 @@ public class DashboardView extends JPanel {
|
|||||||
|
|
||||||
ValueMarker marker = new ValueMarker(value);
|
ValueMarker marker = new ValueMarker(value);
|
||||||
|
|
||||||
marker.setPaint(Color.RED);
|
marker.setPaint(new Color(150,150,150,150));
|
||||||
marker.setStroke(new BasicStroke(1.5f));
|
|
||||||
|
float[] dash = {6.0f, 6.0f};
|
||||||
|
marker.setStroke(new BasicStroke(
|
||||||
|
1f,
|
||||||
|
BasicStroke.CAP_BUTT,
|
||||||
|
BasicStroke.JOIN_MITER,
|
||||||
|
10.0f,
|
||||||
|
dash,
|
||||||
|
0.0f
|
||||||
|
));
|
||||||
|
|
||||||
marker.setLabel(label);
|
marker.setLabel(label);
|
||||||
marker.setLabelFont(new Font("Segoe UI", Font.PLAIN, 11));
|
marker.setLabelFont(new Font("Segoe UI", Font.PLAIN, 11));
|
||||||
marker.setLabelAnchor(RectangleAnchor.LEFT);
|
marker.setLabelPaint(new Color(160,160,160));
|
||||||
marker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
|
|
||||||
|
|
||||||
plot.addRangeMarker(marker);
|
marker.setLabelAnchor(RectangleAnchor.RIGHT);
|
||||||
|
marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
|
||||||
|
|
||||||
|
plot.addRangeMarker(marker, Layer.BACKGROUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,13 +7,13 @@ import time
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
# ===== KONFIGURATION =====
|
# ===== KONFIGURATION =====
|
||||||
BROKER = "127.0.0.1"
|
BROKER = "141.75.223.13"
|
||||||
PORT = 1883
|
PORT = 1883
|
||||||
TOPIC = "PREDICTION"
|
TOPIC = "PREDICTION"
|
||||||
USERNAME = None
|
USERNAME = None
|
||||||
PASSWORD = None
|
PASSWORD = None
|
||||||
QOS = 0
|
QOS = 0
|
||||||
INTERVAL_SECONDS = 10
|
INTERVAL_SECONDS = 5
|
||||||
# ==========================
|
# ==========================
|
||||||
|
|
||||||
# Logging konfigurieren (Console + Datei)
|
# Logging konfigurieren (Console + Datei)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user