Search in sources :

Example 1 with NetworkTablePlayersQuery

use of com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery in project Plan by plan-player-analytics.

the class DatabaseTest method networkTablePlayersQueryQueriesAtLeastOnePlayer.

@Test
default void networkTablePlayersQueryQueriesAtLeastOnePlayer() {
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    db().executeTransaction(new SessionEndTransaction(RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID)));
    List<TablePlayer> result = db().query(new NetworkTablePlayersQuery(System.currentTimeMillis(), 10L, 1));
    assertEquals(1, result.size(), () -> "Incorrect query result: " + result);
}
Also used : NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) Test(org.junit.jupiter.api.Test)

Example 2 with NetworkTablePlayersQuery

use of com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery in project Plan by plan-player-analytics.

the class JSONFactory method networkPlayersTableJSON.

public Map<String, Object> networkPlayersTableJSON() {
    Integer xMostRecentPlayers = config.get(DisplaySettings.PLAYERS_PER_PLAYERS_PAGE);
    Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
    boolean openPlayerLinksInNewTab = config.isTrue(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB);
    Database database = dbSystem.getDatabase();
    ServerUUID mainServerUUID = database.query(ServerQueries.fetchProxyServerInformation()).map(Server::getUuid).orElse(serverInfo.getServerUUID());
    Map<UUID, ExtensionTabData> pluginData = database.query(new ExtensionServerTableDataQuery(mainServerUUID, xMostRecentPlayers));
    return new PlayersTableJSONCreator(database.query(new NetworkTablePlayersQuery(System.currentTimeMillis(), playtimeThreshold, xMostRecentPlayers)), pluginData, openPlayerLinksInNewTab, formatters, locale, // players page
    true).toJSONMap();
}
Also used : ExtensionTabData(com.djrapitops.plan.extension.implementation.results.ExtensionTabData) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Database(com.djrapitops.plan.storage.database.Database) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 3 with NetworkTablePlayersQuery

use of com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery in project Plan by plan-player-analytics.

the class ActivityIndexQueriesTest method networkActivityIndexCalculationsMatch.

@RepeatedTest(value = 3, name = "Network Activity Index calculations match {currentRepetition}/{totalRepetitions}")
default void networkActivityIndexCalculationsMatch() {
    storeSessions(session -> true);
    long date = System.currentTimeMillis();
    long playtimeThreshold = TimeUnit.HOURS.toMillis(5L);
    List<FinishedSession> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)).values().stream().flatMap(Collection::stream).collect(Collectors.toList());
    ActivityIndex javaCalculation = new ActivityIndex(sessions, date, playtimeThreshold);
    List<TablePlayer> players = db().query(new NetworkTablePlayersQuery(date, playtimeThreshold, 5));
    Optional<TablePlayer> found = players.stream().filter(tp -> playerUUID.equals(tp.getPlayerUUID())).findFirst();
    assertTrue(found.isPresent());
    Optional<ActivityIndex> currentActivityIndex = found.get().getCurrentActivityIndex();
    assertTrue(currentActivityIndex.isPresent());
    assertEquals(javaCalculation.getValue(), currentActivityIndex.get().getValue(), 0.001, () -> {
        StringBuilder errorMsg = new StringBuilder("Activity indexes did not match\n");
        long week = TimeUnit.DAYS.toMillis(7L);
        long weekAgo = date - week;
        long twoWeeksAgo = date - 2L * week;
        long threeWeeksAgo = date - 3L * week;
        SessionsMutator mutator = new SessionsMutator(sessions);
        SessionsMutator w1 = mutator.filterSessionsBetween(weekAgo, date);
        SessionsMutator w2 = mutator.filterSessionsBetween(twoWeeksAgo, weekAgo);
        SessionsMutator w3 = mutator.filterSessionsBetween(threeWeeksAgo, twoWeeksAgo);
        Long dbW1 = db().query(activePlaytime(weekAgo, date));
        Long dbW2 = db().query(activePlaytime(twoWeeksAgo, weekAgo));
        Long dbW3 = db().query(activePlaytime(threeWeeksAgo, twoWeeksAgo));
        errorMsg.append("Java calculation playtimes: ").append(w1.toActivePlaytime()).append("ms,").append(w2.toActivePlaytime()).append("ms,").append(w3.toActivePlaytime()).append("ms\n").append("DB calculation playtimes: ").append(dbW1).append("ms,").append(dbW2).append("ms,").append(dbW3).append("ms");
        return errorMsg.toString();
    });
}
Also used : RepeatedTest(org.junit.jupiter.api.RepeatedTest) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) SessionsTable(com.djrapitops.plan.storage.database.sql.tables.SessionsTable) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) PlayerServerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction) SQLException(java.sql.SQLException) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) ResultSet(java.sql.ResultSet) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) UsersTable(com.djrapitops.plan.storage.database.sql.tables.UsersTable) TestConstants(utilities.TestConstants) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) ActivityIndexQueries(com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueries) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Predicate(java.util.function.Predicate) Collection(java.util.Collection) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) Sql(com.djrapitops.plan.storage.database.sql.building.Sql) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ActivityIndex(com.djrapitops.plan.delivery.domain.mutators.ActivityIndex) Assertions(org.junit.jupiter.api.Assertions) RandomData(utilities.RandomData) Optional(java.util.Optional) SessionQueries(com.djrapitops.plan.storage.database.queries.objects.SessionQueries) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) ActivityIndex(com.djrapitops.plan.delivery.domain.mutators.ActivityIndex) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Aggregations

NetworkTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery)3 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)2 Test (org.junit.jupiter.api.Test)2 ActivityIndex (com.djrapitops.plan.delivery.domain.mutators.ActivityIndex)1 SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)1 ExtensionTabData (com.djrapitops.plan.extension.implementation.results.ExtensionTabData)1 ExtensionServerTableDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery)1 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)1 ServerUUID (com.djrapitops.plan.identification.ServerUUID)1 Database (com.djrapitops.plan.storage.database.Database)1 DatabaseTestPreparer (com.djrapitops.plan.storage.database.DatabaseTestPreparer)1 ActivityIndexQueries (com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueries)1 SessionQueries (com.djrapitops.plan.storage.database.queries.objects.SessionQueries)1 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)1 Sql (com.djrapitops.plan.storage.database.sql.building.Sql)1 SessionsTable (com.djrapitops.plan.storage.database.sql.tables.SessionsTable)1 UsersTable (com.djrapitops.plan.storage.database.sql.tables.UsersTable)1 PlayerServerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction)1 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)1 PreparedStatement (java.sql.PreparedStatement)1