Search in sources :

Example 1 with ServerTablePlayersQuery

use of com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery 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 ServerTablePlayersQuery

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

the class DatabaseTest method serverTablePlayersQueryQueriesAtLeastOnePlayer.

@Test
default void serverTablePlayersQueryQueriesAtLeastOnePlayer() {
    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 ServerTablePlayersQuery(serverUUID(), System.currentTimeMillis(), 10L, 1));
    assertEquals(1, result.size(), () -> "Incorrect query result: " + result);
    assertNotEquals(Collections.emptyList(), result);
}
Also used : ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) Test(org.junit.jupiter.api.Test)

Example 3 with ServerTablePlayersQuery

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

the class JSONFactory method serverPlayersTableJSON.

public Map<String, Object> serverPlayersTableJSON(ServerUUID serverUUID) {
    Integer xMostRecentPlayers = config.get(DisplaySettings.PLAYERS_PER_SERVER_PAGE);
    Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
    boolean openPlayerLinksInNewTab = config.isTrue(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB);
    Database database = dbSystem.getDatabase();
    return new PlayersTableJSONCreator(database.query(new ServerTablePlayersQuery(serverUUID, System.currentTimeMillis(), playtimeThreshold, xMostRecentPlayers)), database.query(new ExtensionServerTableDataQuery(serverUUID, xMostRecentPlayers)), openPlayerLinksInNewTab, formatters, locale).toJSONMap();
}
Also used : ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) Database(com.djrapitops.plan.storage.database.Database) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery)

Example 4 with ServerTablePlayersQuery

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

the class ActivityIndexQueriesTest method activityIndexCalculationsMatchWithMissingData.

@RepeatedTest(value = 3, name = "Activity Index calculations match with missing data {currentRepetition}/{totalRepetitions}")
default void activityIndexCalculationsMatchWithMissingData() {
    long keepAfter = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7L);
    storeSessions(session -> session.getDate() >= keepAfter && session.getEnd() >= keepAfter);
    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 ServerTablePlayersQuery(serverUUID(), 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(SessionQueries.activePlaytime(weekAgo, date, serverUUID()));
        Long dbW2 = db().query(SessionQueries.activePlaytime(twoWeeksAgo, weekAgo, serverUUID()));
        Long dbW3 = db().query(SessionQueries.activePlaytime(threeWeeksAgo, twoWeeksAgo, serverUUID()));
        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) ActivityIndex(com.djrapitops.plan.delivery.domain.mutators.ActivityIndex) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 5 with ServerTablePlayersQuery

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

the class ActivityIndexQueriesTest method activityIndexCalculationsMatch.

// @Test
// default void activityIndexCoalesceSanityCheck() {
// storeSessions();
// Map<String, Integer> groupings = db().query(
// ActivityIndexQueries.fetchActivityIndexGroupingsOn(System.currentTimeMillis(), serverUUID(), TimeUnit.HOURS.toMillis(2L))
// );
// Map<String, Integer> expected = Collections.singletonMap(ActivityIndex.getDefaultGroups()[4], 1); // Inactive
// assertEquals(expected, groupings);
// }
@RepeatedTest(value = 3, name = "Activity Index calculations match {currentRepetition}/{totalRepetitions}")
default void activityIndexCalculationsMatch() {
    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 ServerTablePlayersQuery(serverUUID(), 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(SessionQueries.activePlaytime(weekAgo, date, serverUUID()));
        Long dbW2 = db().query(SessionQueries.activePlaytime(twoWeeksAgo, weekAgo, serverUUID()));
        Long dbW3 = db().query(SessionQueries.activePlaytime(threeWeeksAgo, twoWeeksAgo, serverUUID()));
        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) ActivityIndex(com.djrapitops.plan.delivery.domain.mutators.ActivityIndex) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Aggregations

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