Skip to content

Commit 319e03d

Browse files
committed
Add CURRENT_UPTIME datapoint
1 parent 985ebfb commit 319e03d

18 files changed

Lines changed: 192 additions & 58 deletions

File tree

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
@@ -160,6 +160,8 @@ public enum WebPermission implements Supplier<String>, Lang {
160160
DATA_NETWORK_PLAYERS_ONLINE_PEAK("See Player online peak -datapoint of network"),
161161
DATA_SERVER_PLAYERS_ONLINE("See Players online -datapoint of servers"),
162162
DATA_NETWORK_PLAYERS_ONLINE("See Players online -datapoint of network"),
163+
DATA_SERVER_CURRENT_UPTIME("See Current uptime -datapoint of servers"),
164+
DATA_NETWORK_CURRENT_UPTIME("See Current uptime -datapoint of network"),
163165
DATA_PLAYER_MOB_KILLS("See Mob kills datapoint of players"),
164166
DATA_SERVER_MOB_KILLS("See Mob kills datapoint of servers"),
165167
DATA_NETWORK_MOB_KILLS("See Mob kills datapoint of network"),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public void exportJSON(Path toDirectory, ServerUUID serverUUID) throws IOExcepti
160160
datapointType + DatapointType.PLAYER_KILLS,
161161
datapointType + DatapointType.MOB_KILLS,
162162
datapointType + DatapointType.DEATHS,
163+
datapointType + DatapointType.CURRENT_UPTIME,
163164
// Week comparison
164165
datapointType + DatapointType.UNIQUE_PLAYERS + afterMillis + TimeUnit.DAYS.toMillis(14) + beforeMillis + TimeUnit.DAYS.toMillis(7L),
165166
datapointType + DatapointType.NEW_PLAYERS + afterMillis + TimeUnit.DAYS.toMillis(14) + beforeMillis + TimeUnit.DAYS.toMillis(7L),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public void exportJSON(Path toDirectory, ServerUUID serverUUID) throws IOExcepti
167167
datapointType + DatapointType.PLAYER_KILLS + server,
168168
datapointType + DatapointType.MOB_KILLS + server,
169169
datapointType + DatapointType.DEATHS + server,
170+
datapointType + DatapointType.CURRENT_UPTIME + server,
170171
// Week comparison
171172
datapointType + DatapointType.UNIQUE_PLAYERS + afterMillis + TimeUnit.DAYS.toMillis(14) + beforeMillis + TimeUnit.DAYS.toMillis(7L) + server,
172173
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/datapoint/DatapointType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public enum DatapointType {
4545
PLAYTIME_PER_PLAYER_AVERAGE(PlaytimePerPlayerAverage.class, DatapointCacheKey.SESSION),
4646
PLAYERS_ONLINE_PEAK(PlayersOnlinePeak.class, DatapointCacheKey.TPS),
4747
PLAYERS_ONLINE(PlayersOnline.class, DatapointCacheKey.TPS),
48+
CURRENT_UPTIME(CurrentUptime.class),
4849
MOB_KILLS(MobKills.class, DatapointCacheKey.SESSION),
4950
PLAYER_KILLS(PlayerKills.class, DatapointCacheKey.SESSION),
5051
DEATHS(Deaths.class, DatapointCacheKey.SESSION);
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.gathering.ServerUptimeCalculator;
25+
import com.djrapitops.plan.identification.ServerInfo;
26+
import com.djrapitops.plan.identification.ServerUUID;
27+
28+
import javax.inject.Inject;
29+
import javax.inject.Singleton;
30+
import java.util.List;
31+
import java.util.Optional;
32+
33+
/**
34+
* Datapoint for looking up current uptime of the servers.
35+
*
36+
* @author AuroraLS3
37+
*/
38+
@Singleton
39+
public class CurrentUptime implements Datapoint<Long> {
40+
41+
private final ServerInfo serverInfo;
42+
private final ServerUptimeCalculator serverUptimeCalculator;
43+
44+
@Inject
45+
public CurrentUptime(ServerInfo serverInfo, ServerUptimeCalculator serverUptimeCalculator) {
46+
this.serverInfo = serverInfo;
47+
this.serverUptimeCalculator = serverUptimeCalculator;
48+
}
49+
50+
@Override
51+
public Optional<Long> getValue(GenericFilter filter) {
52+
if (filter.getPlayerUUID().isPresent()) {
53+
throw new BadRequestException("CURRENT_UPTIME does not support player parameter");
54+
}
55+
56+
List<ServerUUID> serverUUIDs = filter.getServerUUIDs();
57+
ServerUUID serverUUID = serverUUIDs.size() == 1 ? serverUUIDs.get(0) : serverInfo.getServerUUID();
58+
59+
return serverUptimeCalculator.getServerUptimeMillis(serverUUID);
60+
}
61+
62+
@Override
63+
public WebPermission getPermission(GenericFilter filter) {
64+
if (filter.getPlayerUUID().isPresent()) {
65+
return WebPermission.DATA_PLAYER;
66+
} else if (!filter.getServerUUIDs().isEmpty()) {
67+
return WebPermission.DATA_SERVER_CURRENT_UPTIME;
68+
} else {
69+
return WebPermission.DATA_NETWORK_CURRENT_UPTIME;
70+
}
71+
}
72+
73+
@Override
74+
public DatapointType getType() {
75+
return DatapointType.CURRENT_UPTIME;
76+
}
77+
78+
@Override
79+
public FormatType getFormatType() {
80+
return FormatType.TIME_AMOUNT;
81+
}
82+
}

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
@@ -96,6 +96,10 @@ public interface DatapointModule {
9696
@IntoSet
9797
Datapoint<?> bindPlayersOnline(PlayersOnline playersOnline);
9898

99+
@Binds
100+
@IntoSet
101+
Datapoint<?> bindCurrentUptime(CurrentUptime currentUptime);
102+
99103
@Binds
100104
@IntoSet
101105
Datapoint<?> bindMobKills(MobKills mobKills);

Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/AccessControlTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ static Stream<Arguments> testCases() {
222222
Arguments.of("/v1/datapoint?type=PLAYERS_ONLINE", WebPermission.DATA_NETWORK_PLAYERS_ONLINE, 200, 403),
223223
Arguments.of("/v1/datapoint?type=PLAYERS_ONLINE&server=" + TestConstants.SERVER_UUID_STRING, WebPermission.DATA_SERVER_PLAYERS_ONLINE, 200, 403),
224224
Arguments.of("/v1/datapoint?type=PLAYERS_ONLINE&player=" + TestConstants.PLAYER_ONE_UUID_STRING, WebPermission.DATA_PLAYER, 400, 403),
225+
Arguments.of("/v1/datapoint?type=CURRENT_UPTIME", WebPermission.DATA_NETWORK_CURRENT_UPTIME, 200, 403),
226+
Arguments.of("/v1/datapoint?type=CURRENT_UPTIME&server=" + TestConstants.SERVER_UUID_STRING, WebPermission.DATA_SERVER_CURRENT_UPTIME, 200, 403),
227+
Arguments.of("/v1/datapoint?type=CURRENT_UPTIME&player=" + TestConstants.PLAYER_ONE_UUID_STRING, WebPermission.DATA_PLAYER, 400, 403),
225228
Arguments.of("/v1/datapoint?type=REGULAR_PLAYERS", WebPermission.DATA_NETWORK_REGULAR_PLAYERS, 200, 403),
226229
Arguments.of("/v1/datapoint?type=REGULAR_PLAYERS&server=" + TestConstants.SERVER_UUID_STRING, WebPermission.DATA_SERVER_REGULAR_PLAYERS, 200, 403),
227230
Arguments.of("/v1/datapoint?type=REGULAR_PLAYERS&player=" + TestConstants.PLAYER_ONE_UUID_STRING, WebPermission.DATA_PLAYER, 400, 403),

Plan/react/dashboard/src/components/cards/network/QuickViewDataCard.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from "@fortawesome/free-solid-svg-icons";
1212
import {useTranslation} from "react-i18next";
1313
import Datapoint from "../../datapoint/Datapoint.tsx";
14-
import CurrentUptime from "../../datapoint/CurrentUptime";
14+
import CurrentUptime from "../../datapoint/CurrentUptime.tsx";
1515
import FormattedDate from "../../text/FormattedDate.tsx";
1616
import FormattedTime from "../../text/FormattedTime.jsx";
1717

Plan/react/dashboard/src/components/cards/server/insights/SessionInsightsCard.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ const SessionInsightsCard = ({identifier}) => {
4444
icon={faClock} color="playtime-afk"
4545
dataType={DatapointType.AFK_TIME}
4646
filter={filter}
47-
valueLabel={<QueryDatapointValue dataType={DatapointType.AFK_TIME_PERCENTAGE}
48-
filter={filter}
49-
permission={"afk.time"}/>}
47+
valueLabel={<>(<QueryDatapointValue dataType={DatapointType.AFK_TIME_PERCENTAGE}
48+
filter={filter}
49+
permission={"afk.time"}/>)</>}
5050
/>
5151
</InsightsFor30DaysCard>
5252
)

Plan/react/dashboard/src/components/cards/server/values/ServerAsNumbersCard.jsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import React from "react";
77
import {CardLoader} from "../../../navigation/Loader.tsx";
88
import ExtendableCardBody from "../../../layout/extension/ExtendableCardBody.tsx";
99
import {useMetadata} from "../../../../hooks/metadataHook.tsx";
10-
import CurrentUptime from "../../../datapoint/CurrentUptime";
10+
import CurrentUptime from "../../../datapoint/CurrentUptime.tsx";
1111
import {GenericFilterContextProvider} from "../../../../dataHooks/genericFilterContextHook.tsx";
1212
import {useParams} from "react-router";
1313
import {QueryDatapoint} from "../../../datapoint/QueryDatapoint.tsx";
1414
import {DatapointType} from "../../../../dataHooks/model/datapoint/Datapoint.ts";
1515
import {MS_24H} from "../../../../util/format/useDateFormatter.js";
1616

17-
const ServerAsNumbersCard = ({data}) => {
17+
const ServerAsNumbersCard = () => {
1818
const {t} = useTranslation();
1919
const {networkMetadata} = useMetadata();
2020
const {identifier} = useParams();
2121

22-
if (!data || !networkMetadata) return <CardLoader/>;
22+
if (!networkMetadata) return <CardLoader/>;
2323

2424
const isGameServer = !!identifier;
2525

@@ -33,8 +33,8 @@ const ServerAsNumbersCard = ({data}) => {
3333
</h6>
3434
</Card.Header>
3535
<ExtendableCardBody
36-
id={data.player_kills === undefined ? 'card-body-network-as-numbers' : 'card-body-server-as-numbers'}>
37-
<CurrentUptime uptime={data.current_uptime}/>
36+
id={isGameServer ? 'card-body-server-as-numbers' : 'card-body-network-as-numbers'}>
37+
<CurrentUptime filter={filter}/>
3838
<hr/>
3939
<QueryDatapoint name={t('html.label.totalPlayers')}
4040
color={'players-count'} icon={faUsers}
@@ -81,17 +81,14 @@ const ServerAsNumbersCard = ({data}) => {
8181
<hr/>
8282
<QueryDatapoint name={t('html.label.playerKills')}
8383
color={'player-kills'} icon={faCrosshairs}
84-
value={data.player_kills}
8584
dataType={DatapointType.PLAYER_KILLS}
8685
filter={filter}/>
8786
<QueryDatapoint name={t('html.label.mobKills')}
8887
color={'mob-kills'} icon={faCrosshairs}
89-
value={data.mob_kills}
9088
dataType={DatapointType.MOB_KILLS}
9189
filter={filter}/>
9290
<QueryDatapoint name={t('html.label.deaths')}
9391
color={'deaths'} icon={faSkull}
94-
value={data.deaths}
9592
dataType={DatapointType.DEATHS}
9693
filter={filter}/>
9794
</ExtendableCardBody>

0 commit comments

Comments
 (0)