Skip to content

Commit 24adbad

Browse files
committed
Add DOWNTIME datapoint
Deprecated /v1/serverOverview
1 parent 4a8bb70 commit 24adbad

15 files changed

Lines changed: 258 additions & 61 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of Player Analytics (Plan).
3+
*
4+
* Plan is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License v3 as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Plan is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
package com.djrapitops.plan.delivery.domain;
18+
19+
/**
20+
* @author AuroraLS3
21+
*/
22+
public class Segment {
23+
24+
private final long segmentStart;
25+
private final long segmentEnd;
26+
27+
public Segment(long segmentStart, long segmentEnd) {
28+
this.segmentStart = segmentStart;
29+
this.segmentEnd = segmentEnd;
30+
}
31+
32+
public Long getLength() {
33+
return segmentEnd - segmentStart;
34+
}
35+
}

Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/auth/WebPermission.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ public enum WebPermission implements Supplier<String>, Lang {
166166
DATA_NETWORK_PLAYERS_ONLINE_CURRENT("See Players online -datapoint of network"),
167167
DATA_SERVER_UPTIME_CURRENT("See Current uptime -datapoint of servers"),
168168
DATA_NETWORK_UPTIME_CURRENT("See Current uptime -datapoint of network"),
169+
DATA_SERVER_DOWNTIME("See Downtime datapoint of servers"),
170+
DATA_NETWORK_DOWNTIME("See Downtime datapoint of network"),
169171
DATA_PLAYER_MOB_KILLS("See Mob kills -datapoint of players"),
170172
DATA_SERVER_MOB_KILLS("See Mob kills -datapoint of servers"),
171173
DATA_NETWORK_MOB_KILLS("See Mob kills -datapoint of network"),

Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ServerPageExporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public void exportJSON(Path toDirectory, ServerUUID serverUUID) throws IOExcepti
124124
String afterMillis = "&afterMillisAgo=";
125125
String beforeMillis = "&beforeMillisAgo=";
126126
exportJSON(toDirectory,
127-
"serverOverview?server=" + serverUUID,
128127
"onlineOverview?server=" + serverUUID,
129128
"playerVersus?server=" + serverUUID,
130129
"playerbaseOverview?server=" + serverUUID,
@@ -172,6 +171,7 @@ public void exportJSON(Path toDirectory, ServerUUID serverUUID) throws IOExcepti
172171
datapointType + DatapointType.TPS_LOW_SPIKES + afterMillis + TimeUnit.DAYS.toMillis(7) + server,
173172
datapointType + DatapointType.UNIQUE_PLAYERS_AVERAGE + afterMillis + TimeUnit.DAYS.toMillis(7) + server,
174173
datapointType + DatapointType.NEW_PLAYER_RETENTION + afterMillis + TimeUnit.DAYS.toMillis(7) + server,
174+
datapointType + DatapointType.DOWNTIME + afterMillis + TimeUnit.DAYS.toMillis(7) + server,
175175
// Week comparison
176176
datapointType + DatapointType.UNIQUE_PLAYERS_COUNT + afterMillis + TimeUnit.DAYS.toMillis(14) + beforeMillis + TimeUnit.DAYS.toMillis(7L) + server,
177177
datapointType + DatapointType.NEW_PLAYERS + afterMillis + TimeUnit.DAYS.toMillis(14) + beforeMillis + TimeUnit.DAYS.toMillis(7L) + server,

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/ServerOverviewJSONCreator.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import com.djrapitops.plan.settings.config.PlanConfig;
2929
import com.djrapitops.plan.settings.config.paths.DisplaySettings;
3030
import com.djrapitops.plan.settings.config.paths.TimeSettings;
31+
import com.djrapitops.plan.settings.locale.Locale;
3132
import com.djrapitops.plan.settings.locale.lang.GenericLang;
33+
import com.djrapitops.plan.settings.locale.lang.PluginLang;
3234
import com.djrapitops.plan.storage.database.DBSystem;
3335
import com.djrapitops.plan.storage.database.Database;
3436
import com.djrapitops.plan.storage.database.queries.ServerAggregateQueries;
@@ -38,6 +40,7 @@
3840
import com.djrapitops.plan.storage.database.queries.objects.SessionQueries;
3941
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
4042
import com.djrapitops.plan.utilities.analysis.Percentage;
43+
import net.playeranalytics.plugin.server.PluginLogger;
4144

4245
import javax.inject.Inject;
4346
import javax.inject.Singleton;
@@ -50,14 +53,18 @@
5053
* Creates JSON payload for /server-page Server Overview tab.
5154
*
5255
* @author AuroraLS3
56+
* @deprecated Use /v1/datapoint instead (types UNIQUE_PLAYERS, NEW_PLAYERS, REGULAR_PLAYERS, UPTIME_CURRENT, PLAYERS_ONLINE, PLAYTIME, PLAYTIME_PER_PLAYER_AVERAGE, SESSION_LENGTH_AVERAGE, PLAYER_KILLS, MOB_KILLS, DEATHS, DOWNTIME, TPS_AVERAGE, NEW_PLAYER_RETENTION, UNIQUE_PLAYERS_AVERAGE, TPS_LOW_SPIKES).
5357
*/
5458
@Singleton
59+
@Deprecated(since = "2026-04-27 / 5.7 build 3400")
5560
public class ServerOverviewJSONCreator implements ServerTabJSONCreator<Map<String, Object>> {
5661

5762
private final PlanConfig config;
5863
private final DBSystem dbSystem;
5964
private final ServerInfo serverInfo;
6065
private final ServerSensor<?> serverSensor;
66+
private final PluginLogger logger;
67+
private final Locale locale;
6168

6269
private final Formatter<Double> decimals;
6370
private final Formatter<Double> percentage;
@@ -68,21 +75,25 @@ public ServerOverviewJSONCreator(
6875
PlanConfig config,
6976
DBSystem dbSystem,
7077
ServerInfo serverInfo,
71-
ServerSensor<?> serverSensor,
78+
ServerSensor<?> serverSensor, PluginLogger logger, Locale locale,
7279
ServerUptimeCalculator serverUptimeCalculator,
7380
Formatters formatters
7481
) {
7582
this.config = config;
7683
this.dbSystem = dbSystem;
7784
this.serverInfo = serverInfo;
7885
this.serverSensor = serverSensor;
86+
this.logger = logger;
87+
this.locale = locale;
7988
this.serverUptimeCalculator = serverUptimeCalculator;
8089

8190
decimals = formatters.decimals();
8291
percentage = formatters.percentage();
8392
}
8493

8594
public Map<String, Object> createJSONAsMap(ServerUUID serverUUID) {
95+
logger.warn(locale.getString(PluginLang.DEPRECATED_ENDPOINT_CALL, "/v1/serverOverview", "/v1/datapoint"));
96+
8697
Map<String, Object> serverOverview = new HashMap<>();
8798
serverOverview.put("last_7_days", createLast7DaysMap(serverUUID));
8899
serverOverview.put("numbers", createNumbersMap(serverUUID));
@@ -91,6 +102,7 @@ public Map<String, Object> createJSONAsMap(ServerUUID serverUUID) {
91102
}
92103

93104
private Map<String, Object> createLast7DaysMap(ServerUUID serverUUID) {
105+
94106
Database db = dbSystem.getDatabase();
95107
long now = System.currentTimeMillis();
96108
long weekAgo = now - TimeUnit.DAYS.toMillis(7L);

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/datapoint/DatapointType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public enum DatapointType {
5858
CHUNKS_AVERAGE(ChunksAverage.class, DatapointCacheKey.TPS),
5959
UNIQUE_PLAYERS_AVERAGE(UniquePlayersPerDayAverage.class, DatapointCacheKey.SESSION),
6060
NEW_PLAYER_RETENTION(NewPlayerRetention.class, DatapointCacheKey.SESSION),
61-
TPS_LOW_SPIKES(TPSLowSpikes.class, DatapointCacheKey.TPS);
61+
TPS_LOW_SPIKES(TPSLowSpikes.class, DatapointCacheKey.TPS),
62+
DOWNTIME(Downtime.class, DatapointCacheKey.TPS);
6263

6364
private final Class<? extends Datapoint<?>> datapointClass;
6465
private final DatapointCacheKey[] cacheKeys;

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/datapoint/types/DatapointModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,8 @@ public interface DatapointModule {
149149
@Binds
150150
@IntoSet
151151
Datapoint<?> bindTPSLowSpikes(TPSLowSpikes tpsLowSpikes);
152+
153+
@Binds
154+
@IntoSet
155+
Datapoint<?> bindDowntime(Downtime downtime);
152156
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* This file is part of Player Analytics (Plan).
3+
*
4+
* Plan is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License v3 as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Plan is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
package com.djrapitops.plan.delivery.rendering.json.datapoint.types;
18+
19+
import com.djrapitops.plan.delivery.domain.auth.WebPermission;
20+
import com.djrapitops.plan.delivery.domain.datatransfer.GenericFilter;
21+
import com.djrapitops.plan.delivery.rendering.json.datapoint.Datapoint;
22+
import com.djrapitops.plan.delivery.rendering.json.datapoint.DatapointType;
23+
import com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException;
24+
import com.djrapitops.plan.identification.ServerUUID;
25+
import com.djrapitops.plan.storage.database.DBSystem;
26+
import com.djrapitops.plan.storage.database.Database;
27+
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
28+
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
29+
30+
import javax.inject.Inject;
31+
import javax.inject.Singleton;
32+
import java.util.List;
33+
import java.util.Optional;
34+
35+
/**
36+
* Downtime datapoint.
37+
* <p>
38+
* Downtime is calculated by checking gaps between TPS data points,
39+
* if multiple servers are given it is assumed they act as fallback for each other, reducing downtime if one of them is up.
40+
* <p>
41+
* Giving no server parameter gives downtime for network, where same fallback rule applies for multi-proxy setups.
42+
*
43+
* @author AuroraLS3
44+
*/
45+
@Singleton
46+
public class Downtime implements Datapoint<Long> {
47+
48+
private final DBSystem dbSystem;
49+
50+
@Inject
51+
public Downtime(DBSystem dbSystem) {
52+
this.dbSystem = dbSystem;
53+
}
54+
55+
@Override
56+
public Optional<Long> getValue(GenericFilter filter) {
57+
if (filter.getPlayerUUID().isPresent()) {
58+
throw new BadRequestException("DOWNTIME does not support player parameter");
59+
}
60+
61+
Database db = dbSystem.getDatabase();
62+
List<ServerUUID> serverUUIDs = filter.getServerUUIDs();
63+
if (filter.getServerUUIDs().isEmpty()) {
64+
serverUUIDs = db.query(ServerQueries.fetchProxyServerUUIDs());
65+
}
66+
67+
return Optional.of(db.query(TPSQueries.downtime(filter.getAfter(), filter.getBefore(), serverUUIDs)));
68+
}
69+
70+
@Override
71+
public WebPermission getPermission(GenericFilter filter) {
72+
if (filter.getPlayerUUID().isPresent()) {
73+
return WebPermission.DATA_PLAYER;
74+
} else if (!filter.getServerUUIDs().isEmpty()) {
75+
return WebPermission.DATA_SERVER_DOWNTIME;
76+
} else {
77+
return WebPermission.DATA_NETWORK_DOWNTIME;
78+
}
79+
}
80+
81+
@Override
82+
public DatapointType getType() {
83+
return DatapointType.DOWNTIME;
84+
}
85+
86+
@Override
87+
public FormatType getFormatType() {
88+
return FormatType.TIME_AMOUNT;
89+
}
90+
}

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/datapoint/types/ServerOccupied.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import javax.inject.Inject;
2929
import javax.inject.Singleton;
30-
import java.util.Map;
3130
import java.util.Optional;
3231

3332
/**
@@ -47,12 +46,10 @@ public Optional<OutOf> getValue(GenericFilter filter) {
4746
throw new BadRequestException("SERVER_OCCUPIED does not support player parameter");
4847
}
4948

50-
Map<Integer, Long> occupied = dbSystem.getDatabase().query(TPSQueries.occupiedTime(filter.getAfter(), filter.getBefore(), filter.getServerUUIDs()));
51-
Map<Integer, Long> uptime = dbSystem.getDatabase().query(TPSQueries.uptime(filter.getAfter(), filter.getBefore(), filter.getServerUUIDs()));
49+
Long occupied = dbSystem.getDatabase().query(TPSQueries.occupiedTime(filter.getAfter(), filter.getBefore(), filter.getServerUUIDs()));
50+
Long uptime = dbSystem.getDatabase().query(TPSQueries.uptime(filter.getAfter(), filter.getBefore(), filter.getServerUUIDs()));
5251

53-
long occupiedTime = occupied.values().stream().mapToLong(l -> l).sum();
54-
long uptimeTime = uptime.values().stream().mapToLong(l -> l).sum();
55-
return Optional.of(new OutOf(occupiedTime, uptimeTime, FormatType.TIME_AMOUNT));
52+
return Optional.of(new OutOf(occupied, uptime, FormatType.TIME_AMOUNT));
5653
}
5754

5855
@Override

0 commit comments

Comments
 (0)