Search in sources :

Example 11 with DateObj

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);
}
Also used : DateObj(com.djrapitops.plan.delivery.domain.DateObj) Ping(com.djrapitops.plan.gathering.domain.Ping) Database(com.djrapitops.plan.storage.database.Database) PingStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction) Test(org.junit.jupiter.api.Test)

Example 12 with DateObj

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;
}
Also used : HashMap(java.util.HashMap) DateObj(com.djrapitops.plan.delivery.domain.DateObj) Database(com.djrapitops.plan.storage.database.Database)

Example 13 with DateObj

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;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) DateObj(com.djrapitops.plan.delivery.domain.DateObj) Database(com.djrapitops.plan.storage.database.Database)

Aggregations

DateObj (com.djrapitops.plan.delivery.domain.DateObj)13 PingStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction)7 Database (com.djrapitops.plan.storage.database.Database)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 ServerUUID (com.djrapitops.plan.identification.ServerUUID)3 com.djrapitops.plan.storage.database.queries.objects (com.djrapitops.plan.storage.database.queries.objects)3 Formatter (com.djrapitops.plan.delivery.formatting.Formatter)2 Formatters (com.djrapitops.plan.delivery.formatting.Formatters)2 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)2 Server (com.djrapitops.plan.identification.Server)2 ServerInfo (com.djrapitops.plan.identification.ServerInfo)2 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)2 DBSystem (com.djrapitops.plan.storage.database.DBSystem)2 PlayerCountQueries (com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries)2 HashMap (java.util.HashMap)2 TimeUnit (java.util.concurrent.TimeUnit)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 Player (cn.nukkit.Player)1 Arguments (com.djrapitops.plan.commands.use.Arguments)1