Search in sources :

Example 1 with PlayerContainerQuery

use of com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery in project Plan by plan-player-analytics.

the class SessionQueriesTest method playersTableAndPlayerPageActivityIndexMatches.

@RepeatedTest(value = 3, name = "Players table and player page Activity Index calculations match {currentRepetition}/{totalRepetitions}")
default void playersTableAndPlayerPageActivityIndexMatches() {
    prepareForSessionSave();
    List<FinishedSession> player1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
    List<FinishedSession> player2Sessions = RandomData.randomSessions(serverUUID(), worlds, player2UUID, playerUUID);
    player1Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    player2Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    long time = System.currentTimeMillis();
    long playtimeThreshold = RandomData.randomLong(TimeUnit.HOURS.toMillis(1L), TimeUnit.DAYS.toMillis(2L));
    PlayerContainer playerContainer = db().query(new PlayerContainerQuery(playerUUID));
    TablePlayer tablePlayer = db().query(new ServerTablePlayersQuery(serverUUID(), time, playtimeThreshold, 5)).stream().filter(player -> playerUUID.equals(player.getPlayerUUID())).findAny().orElseThrow(AssertionError::new);
    SessionsMutator sessionsMutator = SessionsMutator.forContainer(playerContainer);
    long week = TimeAmount.WEEK.toMillis(1L);
    long weekAgo = time - week;
    long twoWeeksAgo = time - 2L * week;
    long threeWeeksAgo = time - 3L * week;
    SessionsMutator weekOne = sessionsMutator.filterSessionsBetween(weekAgo, time);
    SessionsMutator weekTwo = sessionsMutator.filterSessionsBetween(twoWeeksAgo, weekAgo);
    SessionsMutator weekThree = sessionsMutator.filterSessionsBetween(threeWeeksAgo, twoWeeksAgo);
    long playtime1 = weekOne.toActivePlaytime();
    long playtime2 = weekTwo.toActivePlaytime();
    long playtime3 = weekThree.toActivePlaytime();
    double expected = playerContainer.getActivityIndex(time, playtimeThreshold).getValue();
    double got = tablePlayer.getCurrentActivityIndex().orElseThrow(AssertionError::new).getValue();
    assertEquals(expected, got, 0.001, () -> "Activity Indexes between queries differed, expected: <" + expected + "> but was: <" + got + ">" + ". Playtime for reference container: <w1:" + playtime1 + ", w2:" + playtime2 + ", w3:" + playtime3 + ">");
}
Also used : ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PlayerContainerQuery(com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 2 with PlayerContainerQuery

use of com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery in project Plan by plan-player-analytics.

the class PlayerJSONCreator method createJSONAsMap.

public Map<String, Object> createJSONAsMap(UUID playerUUID) {
    Database db = dbSystem.getDatabase();
    Map<ServerUUID, String> serverNames = db.query(ServerQueries.fetchServerNames());
    String[] pieColors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
    PlayerContainer player = db.query(new PlayerContainerQuery(playerUUID));
    SessionsMutator sessionsMutator = SessionsMutator.forContainer(player);
    Map<ServerUUID, WorldTimes> worldTimesPerServer = PerServerMutator.forContainer(player).worldTimesPerServer();
    List<Map<String, Object>> serverAccordion = new ServerAccordion(player, serverNames, graphs, year, timeAmount, locale.getString(GenericLang.UNKNOWN)).asMaps();
    List<PlayerKill> kills = player.getValue(PlayerKeys.PLAYER_KILLS).orElse(Collections.emptyList());
    List<PlayerKill> deaths = player.getValue(PlayerKeys.PLAYER_DEATHS_KILLS).orElse(Collections.emptyList());
    PingMutator.forContainer(player).addPingToSessions(sessionsMutator.all());
    Map<String, Object> data = new HashMap<>();
    data.put("info", createInfoJSONMap(player, serverNames));
    data.put("online_activity", createOnlineActivityJSONMap(sessionsMutator));
    data.put("kill_data", createPvPPvEMap(player));
    data.put("nicknames", player.getValue(PlayerKeys.NICKNAMES).map(nicks -> Nickname.fromDataNicknames(nicks, serverNames, year)).orElse(Collections.emptyList()));
    data.put("connections", player.getValue(PlayerKeys.GEO_INFO).map(geoInfo -> ConnectionInfo.fromGeoInfo(geoInfo, year)).orElse(Collections.emptyList()));
    data.put("player_kills", new PlayerKillMutator(kills).filterNonSelfKills().toJSONAsMap(formatters));
    data.put("player_deaths", new PlayerKillMutator(deaths).toJSONAsMap(formatters));
    data.put("sessions", sessionsMutator.sort(new DateHolderRecentComparator()).toServerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters));
    data.put("sessions_per_page", config.get(DisplaySettings.SESSIONS_PER_PAGE));
    data.put("servers", serverAccordion);
    data.put("punchcard_series", graphs.special().punchCard(sessionsMutator).getDots());
    WorldPie worldPie = graphs.pie().worldPie(player.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes()));
    data.put("world_pie_series", worldPie.getSlices());
    data.put("gm_series", worldPie.toHighChartsDrillDownMaps());
    data.put("calendar_series", graphs.calendar().playerCalendar(player).getEntries());
    data.put("server_pie_series", graphs.pie().serverPreferencePie(serverNames, worldTimesPerServer).getSlices());
    data.put("server_pie_colors", pieColors);
    // Monday
    data.put("first_day", 1);
    return data;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PlayerContainerQuery(com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) Database(com.djrapitops.plan.storage.database.Database) DateHolderRecentComparator(com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator) WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie)

Example 3 with PlayerContainerQuery

use of com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery in project Plan by plan-player-analytics.

the class SessionQueriesTest method playersTableAndPlayerPagePlaytimeMatches.

@RepeatedTest(value = 3, name = "Players table and Player page playtimes match {currentRepetition}/{totalRepetitions}")
default void playersTableAndPlayerPagePlaytimeMatches() {
    prepareForSessionSave();
    List<FinishedSession> player1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
    List<FinishedSession> player2Sessions = RandomData.randomSessions(serverUUID(), worlds, player2UUID, playerUUID);
    player1Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    player2Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    long playtimeThreshold = RandomData.randomLong(TimeUnit.HOURS.toMillis(1L), TimeUnit.DAYS.toMillis(2L));
    PlayerContainer playerContainer = db().query(new PlayerContainerQuery(playerUUID));
    TablePlayer tablePlayer = db().query(new ServerTablePlayersQuery(serverUUID(), System.currentTimeMillis(), playtimeThreshold, 5)).stream().filter(player -> playerUUID.equals(player.getPlayerUUID())).findAny().orElseThrow(AssertionError::new);
    long expected = SessionsMutator.forContainer(playerContainer).toActivePlaytime();
    long got = tablePlayer.getActivePlaytime().orElseThrow(AssertionError::new);
    assertEquals(expected, got);
}
Also used : ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PlayerContainerQuery(com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Aggregations

PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)3 PlayerContainerQuery (com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery)3 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)2 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)2 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)1 WorldPie (com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie)1 PlayerKill (com.djrapitops.plan.gathering.domain.PlayerKill)1 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)1 ServerUUID (com.djrapitops.plan.identification.ServerUUID)1 Database (com.djrapitops.plan.storage.database.Database)1 DateHolderRecentComparator (com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator)1