Search in sources :

Example 1 with SessionsMutator

use of com.djrapitops.plan.delivery.domain.mutators.SessionsMutator in project Plan by plan-player-analytics.

the class SessionQueriesTest method serverPreferencePieValuesAreCorrect.

@Test
default void serverPreferencePieValuesAreCorrect() {
    prepareForSessionSave();
    List<FinishedSession> server1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
    server1Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    ServerUUID serverTwoUuid = TestConstants.SERVER_TWO_UUID;
    executeTransactions(new StoreServerInformationTransaction(new Server(serverTwoUuid, TestConstants.SERVER_TWO_NAME, "")));
    db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[0]));
    db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[1]));
    List<FinishedSession> server2Sessions = RandomData.randomSessions(serverTwoUuid, worlds, playerUUID, player2UUID);
    server2Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    Map<String, Long> expected = Maps.builder(String.class, Long.class).put(TestConstants.SERVER_NAME, new SessionsMutator(server1Sessions).toPlaytime()).put(TestConstants.SERVER_TWO_NAME, new SessionsMutator(server2Sessions).toPlaytime()).build();
    Map<String, Long> results = db().query(SessionQueries.playtimePerServer(Long.MIN_VALUE, Long.MAX_VALUE));
    assertEquals(expected, results);
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 2 with SessionsMutator

use of com.djrapitops.plan.delivery.domain.mutators.SessionsMutator 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 3 with SessionsMutator

use of com.djrapitops.plan.delivery.domain.mutators.SessionsMutator in project Plan by plan-player-analytics.

the class ServerAccordion method asMaps.

public List<Map<String, Object>> asMaps() {
    List<Map<String, Object>> servers = new ArrayList<>();
    for (Map.Entry<ServerUUID, DataContainer> entry : perServer.entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        DataContainer ofServer = entry.getValue();
        Map<String, Object> server = new HashMap<>();
        String serverName = serverNames.getOrDefault(serverUUID, unknown);
        WorldTimes worldTimes = ofServer.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes());
        SessionsMutator sessionsMutator = SessionsMutator.forContainer(ofServer);
        server.put("server_name", serverName);
        server.put("banned", ofServer.getValue(PerServerKeys.BANNED).orElse(false));
        server.put("operator", ofServer.getValue(PerServerKeys.OPERATOR).orElse(false));
        server.put("registered", year.apply(ofServer.getValue(PerServerKeys.REGISTERED).orElse(0L)));
        server.put("last_seen", year.apply(sessionsMutator.toLastSeen()));
        server.put("join_address", ofServer.getValue(PerServerKeys.JOIN_ADDRESS).orElse("-"));
        server.put("session_count", sessionsMutator.count());
        server.put("playtime", timeAmount.apply(sessionsMutator.toPlaytime()));
        server.put("afk_time", timeAmount.apply(sessionsMutator.toAfkTime()));
        server.put("session_median", timeAmount.apply(sessionsMutator.toMedianSessionLength()));
        server.put("longest_session_length", timeAmount.apply(sessionsMutator.toLongestSessionLength()));
        server.put("mob_kills", sessionsMutator.toMobKillCount());
        server.put("player_kills", sessionsMutator.toPlayerKillCount());
        server.put("deaths", sessionsMutator.toDeathCount());
        WorldPie worldPie = graphs.pie().worldPie(worldTimes);
        server.put("world_pie_series", worldPie.getSlices());
        server.put("gm_series", worldPie.toHighChartsDrillDownMaps());
        servers.add(server);
    }
    return servers;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) DataContainer(com.djrapitops.plan.delivery.domain.container.DataContainer) WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie) HashMap(java.util.HashMap) Map(java.util.Map) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)

Example 4 with SessionsMutator

use of com.djrapitops.plan.delivery.domain.mutators.SessionsMutator in project Plan by plan-player-analytics.

the class JSONFactory method networkSessionsAsJSONMap.

public List<Map<String, Object>> networkSessionsAsJSONMap() {
    Database db = dbSystem.getDatabase();
    Integer perPageLimit = config.get(DisplaySettings.SESSIONS_PER_PAGE);
    List<FinishedSession> sessions = db.query(SessionQueries.fetchLatestSessions(perPageLimit));
    // Add online sessions
    if (serverInfo.getServer().isProxy()) {
        addActiveSessions(sessions);
        sessions.sort(new SessionStartComparator());
        while (true) {
            int size = sessions.size();
            if (size <= perPageLimit)
                break;
            // Remove last until it fits.
            sessions.remove(size - 1);
        }
    }
    List<Map<String, Object>> sessionMaps = new SessionsMutator(sessions).toPlayerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters);
    // Add network_server property so that sessions have a server page link
    sessionMaps.forEach(map -> map.put("network_server", map.get("server_name")));
    return sessionMaps;
}
Also used : Database(com.djrapitops.plan.storage.database.Database) SessionStartComparator(com.djrapitops.plan.utilities.comparators.SessionStartComparator) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)

Example 5 with SessionsMutator

use of com.djrapitops.plan.delivery.domain.mutators.SessionsMutator in project Plan by plan-player-analytics.

the class JSONFactory method serverSessionsAsJSONMap.

public List<Map<String, Object>> serverSessionsAsJSONMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    Integer perPageLimit = config.get(DisplaySettings.SESSIONS_PER_PAGE);
    List<FinishedSession> sessions = db.query(SessionQueries.fetchLatestSessionsOfServer(serverUUID, perPageLimit));
    // Add online sessions
    if (serverUUID.equals(serverInfo.getServerUUID())) {
        addActiveSessions(sessions);
        sessions.sort(new SessionStartComparator());
        while (true) {
            int size = sessions.size();
            if (size <= perPageLimit)
                break;
            // Remove last until it fits.
            sessions.remove(size - 1);
        }
    }
    return new SessionsMutator(sessions).toPlayerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters);
}
Also used : Database(com.djrapitops.plan.storage.database.Database) SessionStartComparator(com.djrapitops.plan.utilities.comparators.SessionStartComparator) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)

Aggregations

SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)11 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)6 RepeatedTest (org.junit.jupiter.api.RepeatedTest)6 Test (org.junit.jupiter.api.Test)5 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)4 ActivityIndex (com.djrapitops.plan.delivery.domain.mutators.ActivityIndex)4 ServerUUID (com.djrapitops.plan.identification.ServerUUID)4 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)4 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)4 Database (com.djrapitops.plan.storage.database.Database)3 DatabaseTestPreparer (com.djrapitops.plan.storage.database.DatabaseTestPreparer)3 ActivityIndexQueries (com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueries)3 SessionQueries (com.djrapitops.plan.storage.database.queries.objects.SessionQueries)3 NetworkTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery)3 Sql (com.djrapitops.plan.storage.database.sql.building.Sql)3 SessionsTable (com.djrapitops.plan.storage.database.sql.tables.SessionsTable)3 UsersTable (com.djrapitops.plan.storage.database.sql.tables.UsersTable)3 PlayerServerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3