use of com.djrapitops.plan.delivery.domain.DateObj in project Plan by plan-player-analytics.
the class GeolocationQueriesTest method pingIsGroupedByGeolocationAppropriately.
@Test
default void pingIsGroupedByGeolocationAppropriately() {
UUID[] uuids = storeSpecificGeolocations();
Database db = db();
long time = System.currentTimeMillis();
List<DateObj<Integer>> ping = Collections.singletonList(new DateObj<>(time, 5));
for (UUID uuid : uuids) {
db.executeTransaction(new PingStoreTransaction(uuid, serverUUID(), ping));
}
Map<String, Ping> got = db.query(PingQueries.fetchPingDataOfServerByGeolocation(serverUUID()));
Map<String, Ping> expected = new HashMap<>();
// first user has a more recent connection from Finland so their country should be counted as Finland.
Ping expectedPing = new Ping(time, serverUUID(), 5, 5, 5);
expected.put("Finland", expectedPing);
expected.put("Sweden", expectedPing);
expected.put("Not Known", expectedPing);
expected.put("Local Machine", expectedPing);
expected.put("Denmark", expectedPing);
assertEquals(expected, got);
}
use of com.djrapitops.plan.delivery.domain.DateObj in project Plan by plan-player-analytics.
the class ServerOverviewJSONCreator method createNumbersMap.
private Map<String, Object> createNumbersMap(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
long twoDaysAgo = now - TimeUnit.DAYS.toMillis(2L);
Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
Map<String, Object> numbers = new HashMap<>();
Integer userCount = db.query(ServerAggregateQueries.serverUserCount(serverUUID));
numbers.put("total_players", userCount);
numbers.put("regular_players", db.query(ActivityIndexQueries.fetchRegularPlayerCount(now, serverUUID, playtimeThreshold)));
numbers.put("online_players", getOnlinePlayers(serverUUID, db));
Optional<DateObj<Integer>> lastPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, twoDaysAgo));
Optional<DateObj<Integer>> allTimePeak = db.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID));
numbers.put("last_peak_date", lastPeak.map(year).orElse("-"));
numbers.put("last_peak_players", lastPeak.map(dateObj -> dateObj.getValue().toString()).orElse("-"));
numbers.put("best_peak_date", allTimePeak.map(year).orElse("-"));
numbers.put("best_peak_players", allTimePeak.map(dateObj -> dateObj.getValue().toString()).orElse("-"));
Long totalPlaytime = db.query(SessionQueries.playtime(0L, now, serverUUID));
numbers.put("playtime", timeAmount.apply(totalPlaytime));
numbers.put("player_playtime", userCount != 0 ? timeAmount.apply(totalPlaytime / userCount) : "-");
numbers.put("sessions", db.query(SessionQueries.sessionCount(0L, now, serverUUID)));
numbers.put("player_kills", db.query(KillQueries.playerKillCount(0L, now, serverUUID)));
numbers.put("mob_kills", db.query(KillQueries.mobKillCount(0L, now, serverUUID)));
numbers.put("deaths", db.query(KillQueries.deathCount(0L, now, serverUUID)));
numbers.put("current_uptime", serverUptimeCalculator.getServerUptimeMillis(serverUUID).map(timeAmount).orElse(locale.getString(GenericLang.UNAVAILABLE)));
return numbers;
}
use of com.djrapitops.plan.delivery.domain.DateObj in project Plan by plan-player-analytics.
the class NetworkOverviewJSONCreator method createNumbersMap.
private Map<String, Object> createNumbersMap() {
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
long twoDaysAgo = now - TimeUnit.DAYS.toMillis(2L);
Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
Map<String, Object> numbers = new HashMap<>();
Integer userCount = db.query(PlayerCountQueries.newPlayerCount(0L, now));
numbers.put("total_players", userCount);
numbers.put("regular_players", db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(now, playtimeThreshold)));
numbers.put("online_players", serverSensor.getOnlinePlayerCount());
ServerUUID serverUUID = serverInfo.getServerUUID();
Optional<DateObj<Integer>> lastPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, twoDaysAgo));
Optional<DateObj<Integer>> allTimePeak = db.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID));
numbers.put("last_peak_date", lastPeak.map(year).orElse("-"));
numbers.put("last_peak_players", lastPeak.map(dateObj -> dateObj.getValue().toString()).orElse("-"));
numbers.put("best_peak_date", allTimePeak.map(year).orElse("-"));
numbers.put("best_peak_players", allTimePeak.map(dateObj -> dateObj.getValue().toString()).orElse("-"));
Long totalPlaytime = db.query(SessionQueries.playtime(0L, now));
numbers.put("playtime", timeAmount.apply(totalPlaytime));
numbers.put("player_playtime", userCount != 0 ? timeAmount.apply(totalPlaytime / userCount) : "-");
Long sessionCount = db.query(SessionQueries.sessionCount(0L, now));
numbers.put("sessions", sessionCount);
numbers.put("session_length_avg", sessionCount != 0 ? timeAmount.apply(totalPlaytime / sessionCount) : "-");
numbers.put("current_uptime", serverUptimeCalculator.getServerUptimeMillis(serverUUID).map(timeAmount).orElse(locale.getString(GenericLang.UNAVAILABLE)));
return numbers;
}
Aggregations