Change player ping graph data format

HighCharts error 12 was occurring due to too many data points

This commit changes player ping graph data to be served in format expected by turbo-mode so that it renders.

Affects issues:
- Fixed #3498
This commit is contained in:
Aurora Lahtela 2024-03-05 20:10:20 +02:00
parent e1b4e34e77
commit 70e3f394ba
6 changed files with 17 additions and 12 deletions

View File

@ -28,15 +28,15 @@ import java.util.Objects;
*/ */
public class ServerSpecificLineGraph { public class ServerSpecificLineGraph {
private final List<Double[]> points; private final List<Number[]> points;
private final ServerDto server; private final ServerDto server;
public ServerSpecificLineGraph(List<Double[]> points, ServerDto server) { public ServerSpecificLineGraph(List<Number[]> points, ServerDto server) {
this.points = points; this.points = points;
this.server = server; this.server = server;
} }
public List<Double[]> getPoints() { public List<Number[]> getPoints() {
return points; return points;
} }

View File

@ -154,9 +154,9 @@ public class PlayerJSONCreator {
private Map<String, Object> createPingGraphJson(PlayerContainer player) { private Map<String, Object> createPingGraphJson(PlayerContainer player) {
PingGraph pingGraph = graphs.line().pingGraph(player.getUnsafe(PlayerKeys.PING)); PingGraph pingGraph = graphs.line().pingGraph(player.getUnsafe(PlayerKeys.PING));
return Maps.builder(String.class, Object.class) return Maps.builder(String.class, Object.class)
.put("min_ping_series", pingGraph.getMinGraph().getPoints()) .put("min_ping_series", pingGraph.getMinGraph().getPointArrays())
.put("avg_ping_series", pingGraph.getAvgGraph().getPoints()) .put("avg_ping_series", pingGraph.getAvgGraph().getPointArrays())
.put("max_ping_series", pingGraph.getMaxGraph().getPoints()) .put("max_ping_series", pingGraph.getMaxGraph().getPointArrays())
.put("colors", Maps.builder(String.class, String.class) .put("colors", Maps.builder(String.class, String.class)
.put("min", theme.getValue(ThemeVal.GRAPH_MIN_PING)) .put("min", theme.getValue(ThemeVal.GRAPH_MIN_PING))
.put("avg", theme.getValue(ThemeVal.GRAPH_AVG_PING)) .put("avg", theme.getValue(ThemeVal.GRAPH_AVG_PING))

View File

@ -537,7 +537,7 @@ public class GraphJSONCreator {
List<ServerSpecificLineGraph> proxyGraphs = new ArrayList<>(); List<ServerSpecificLineGraph> proxyGraphs = new ArrayList<>();
for (Server proxy : db.query(ServerQueries.fetchProxyServers())) { for (Server proxy : db.query(ServerQueries.fetchProxyServers())) {
ServerUUID proxyUUID = proxy.getUuid(); ServerUUID proxyUUID = proxy.getUuid();
List<Double[]> points = Lists.map( List<Number[]> points = Lists.map(
db.query(TPSQueries.fetchPlayersOnlineOfServer(halfYearAgo, now, proxyUUID)), db.query(TPSQueries.fetchPlayersOnlineOfServer(halfYearAgo, now, proxyUUID)),
point -> Point.fromDateObj(point).toArray() point -> Point.fromDateObj(point).toArray()
); );

View File

@ -21,6 +21,7 @@ import com.djrapitops.plan.delivery.rendering.json.graphs.HighChart;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/** /**
* This is a LineGraph for any set of Points, thus it is Abstract. * This is a LineGraph for any set of Points, thus it is Abstract.
@ -80,6 +81,10 @@ public class LineGraph implements HighChart {
return points; return points;
} }
public List<Number[]> getPointArrays() {
return getPoints().stream().map(Point::toArray).collect(Collectors.toList());
}
private void addMissingPoints(StringBuilder arrayBuilder, Long lastX, long date) { private void addMissingPoints(StringBuilder arrayBuilder, Long lastX, long date) {
long iterate = lastX + gapStrategy.diffToFirstGapPointMs; long iterate = lastX + gapStrategy.diffToFirstGapPointMs;
while (iterate < date) { while (iterate < date) {

View File

@ -75,7 +75,7 @@ public class Point {
"y=" + y + '}'; "y=" + y + '}';
} }
public Double[] toArray() { public Number[] toArray() {
return new Double[]{x, y}; return new Number[]{x, y};
} }
} }

View File

@ -114,7 +114,7 @@ public class FiltersJSONResolver implements Resolver {
)).build(); )).build();
} }
private List<Double[]> fetchViewGraphPoints() { private List<Number[]> fetchViewGraphPoints() {
List<DateObj<Integer>> data = dbSystem.getDatabase().query(TPSQueries.fetchViewPreviewGraphData(serverInfo.getServerUUID())); List<DateObj<Integer>> data = dbSystem.getDatabase().query(TPSQueries.fetchViewPreviewGraphData(serverInfo.getServerUUID()));
Long earliestStart = dbSystem.getDatabase().query(SessionQueries.earliestSessionStart()); Long earliestStart = dbSystem.getDatabase().query(SessionQueries.earliestSessionStart());
data.add(0, new DateObj<>(earliestStart, 1)); data.add(0, new DateObj<>(earliestStart, 1));
@ -136,9 +136,9 @@ public class FiltersJSONResolver implements Resolver {
class FilterResponseDto { class FilterResponseDto {
final List<FilterDto> filters; final List<FilterDto> filters;
final ViewDto view; final ViewDto view;
final List<Double[]> viewPoints; final List<Number[]> viewPoints;
public FilterResponseDto(Map<String, Filter> filtersByKind, ViewDto view, List<Double[]> viewPoints) { public FilterResponseDto(Map<String, Filter> filtersByKind, ViewDto view, List<Number[]> viewPoints) {
this.viewPoints = viewPoints; this.viewPoints = viewPoints;
this.filters = new ArrayList<>(); this.filters = new ArrayList<>();
for (Map.Entry<String, Filter> entry : filtersByKind.entrySet()) { for (Map.Entry<String, Filter> entry : filtersByKind.entrySet()) {