Search in sources :

Example 11 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer in project Plan by plan-player-analytics.

the class PlayersMutator method compareAndFindThoseLikelyToBeRetained.

/**
 * Compares players in the mutator to other players in terms of player retention.
 *
 * @param compareTo           Players to compare to.
 * @param dateLimit           Epoch ms back limit, if the player registered after this their value is not used.
 * @param onlineResolver      Thing that figures out how many players were online at different dates.
 * @param activityMsThreshold Threshold for activity index calculation.
 * @return Mutator containing the players that are considered to be retained.
 * @throws IllegalStateException If all players are rejected due to dateLimit.
 */
public PlayersMutator compareAndFindThoseLikelyToBeRetained(Iterable<PlayerContainer> compareTo, long dateLimit, PlayersOnlineResolver onlineResolver, long activityMsThreshold) {
    Collection<PlayerContainer> retainedAfterMonth = new ArrayList<>();
    Collection<PlayerContainer> notRetainedAfterMonth = new ArrayList<>();
    for (PlayerContainer player : players) {
        long registered = player.getValue(PlayerKeys.REGISTERED).orElse(System.currentTimeMillis());
        // Discard uncertain data
        if (registered > dateLimit) {
            continue;
        }
        long monthAfterRegister = registered + TimeAmount.MONTH.toMillis(1L);
        long half = registered + (TimeAmount.MONTH.toMillis(1L) / 2L);
        if (player.playedBetween(registered, half) && player.playedBetween(half, monthAfterRegister)) {
            retainedAfterMonth.add(player);
        } else {
            notRetainedAfterMonth.add(player);
        }
    }
    if (retainedAfterMonth.isEmpty() || notRetainedAfterMonth.isEmpty()) {
        throw new IllegalStateException("No players to compare to after rejecting with dateLimit");
    }
    Function<PlayerContainer, RetentionData> mapper = player -> new RetentionData(player, onlineResolver, activityMsThreshold);
    List<RetentionData> retained = Lists.map(retainedAfterMonth, mapper);
    List<RetentionData> notRetained = Lists.map(notRetainedAfterMonth, mapper);
    RetentionData avgRetained = RetentionData.average(retained);
    RetentionData avgNotRetained = RetentionData.average(notRetained);
    List<PlayerContainer> toBeRetained = new ArrayList<>();
    for (PlayerContainer player : compareTo) {
        RetentionData retentionData = new RetentionData(player, onlineResolver, activityMsThreshold);
        if (retentionData.distance(avgRetained) < retentionData.distance(avgNotRetained)) {
            toBeRetained.add(player);
        }
    }
    return new PlayersMutator(toBeRetained);
}
Also used : java.util(java.util) ServerKeys(com.djrapitops.plan.delivery.domain.keys.ServerKeys) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Predicate(java.util.function.Predicate) ServerUUID(com.djrapitops.plan.identification.ServerUUID) TimeAmount(net.playeranalytics.plugin.scheduling.TimeAmount) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) DataContainer(com.djrapitops.plan.delivery.domain.container.DataContainer) DateObj(com.djrapitops.plan.delivery.domain.DateObj) Lists(com.djrapitops.plan.utilities.java.Lists) PlayerKeys(com.djrapitops.plan.delivery.domain.keys.PlayerKeys) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) Ping(com.djrapitops.plan.gathering.domain.Ping) Maps(com.djrapitops.plan.utilities.java.Maps) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer)

Example 12 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer in project Plan by plan-player-analytics.

the class DBPatchMySQLRegressionTest method mysqlPatchesAreApplied.

@Test
void mysqlPatchesAreApplied() {
    Patch[] patches = underTest.patches();
    for (Patch patch : patches) {
        underTest.executeTransaction(patch);
    }
    assertPatchesHaveBeenApplied(patches);
    // Make sure that a fetch works.
    PlayerContainer player = underTest.query(ContainerFetchQueries.fetchPlayerContainer(TestConstants.PLAYER_ONE_UUID));
    OptionalAssert.equals(1, player.getValue(PlayerKeys.PLAYER_KILL_COUNT));
    // Make sure no foreign key checks fail on removal
    underTest.executeTransaction(new RemoveEverythingTransaction());
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) Patch(com.djrapitops.plan.storage.database.transactions.patches.Patch) KillsOptimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.KillsOptimizationPatch)

Example 13 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer in project Plan by plan-player-analytics.

the class DBPatchSQLiteRegressionTest method sqlitePatchesAreApplied.

@Test
void sqlitePatchesAreApplied() {
    Patch[] patches = underTest.patches();
    for (Patch patch : patches) {
        underTest.executeTransaction(patch);
    }
    assertPatchesHaveBeenApplied(patches);
    // Make sure that a fetch works.
    PlayerContainer player = underTest.query(ContainerFetchQueries.fetchPlayerContainer(TestConstants.PLAYER_ONE_UUID));
    OptionalAssert.equals(1, player.getValue(PlayerKeys.PLAYER_KILL_COUNT));
    // Make sure no foreign key checks fail on removal
    underTest.executeTransaction(new RemoveEverythingTransaction());
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) Patch(com.djrapitops.plan.storage.database.transactions.patches.Patch) Test(org.junit.jupiter.api.Test)

Example 14 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer in project Plan by plan-player-analytics.

the class DatabaseTest method playerContainerSupportsAllPlayerKeys.

@Test
default void playerContainerSupportsAllPlayerKeys() throws IllegalAccessException {
    saveUserOne();
    saveUserTwo();
    saveTwoWorlds();
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    db().executeTransaction(new StoreSessionTransaction(session));
    db().executeTransaction(new NicknameStoreTransaction(playerUUID, RandomData.randomNickname(serverUUID()), (uuid, name) -> false));
    saveGeoInfo(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime()));
    assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
    db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(), RandomData.randomIntDateObjects()));
    PlayerContainer playerContainer = db().query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
    // Active sessions are added after fetching
    playerContainer.putRawData(PlayerKeys.ACTIVE_SESSION, RandomData.randomUnfinishedSession(serverUUID(), worlds, playerUUID));
    List<String> unsupported = new ArrayList<>();
    List<Key> keys = FieldFetcher.getPublicStaticFields(PlayerKeys.class, Key.class);
    for (Key<?> key : keys) {
        if (!playerContainer.supports(key)) {
            unsupported.add(key.getKeyName());
        }
    }
    assertTrue(unsupported.isEmpty(), () -> "Some keys are not supported by PlayerContainer: PlayerKeys." + unsupported.toString());
}
Also used : java.util(java.util) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) UserInfoTable(com.djrapitops.plan.storage.database.sql.tables.UserInfoTable) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Query(com.djrapitops.plan.storage.database.queries.Query) LocalDateTime(java.time.LocalDateTime) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) FieldFetcher(utilities.FieldFetcher) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) SQLException(java.sql.SQLException) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) ResultSet(java.sql.ResultSet) BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) PlayerKeys(com.djrapitops.plan.delivery.domain.keys.PlayerKeys) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ServerAggregateQueries(com.djrapitops.plan.storage.database.queries.ServerAggregateQueries) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) ZoneOffset(java.time.ZoneOffset) UsersTable(com.djrapitops.plan.storage.database.sql.tables.UsersTable) TestConstants(utilities.TestConstants) FormatSettings(com.djrapitops.plan.settings.config.paths.FormatSettings) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) ContainerFetchQueries(com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) PlayerFetchQueries(com.djrapitops.plan.storage.database.queries.PlayerFetchQueries) QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) QuerySvc(com.djrapitops.plan.query.QuerySvc) Sql(com.djrapitops.plan.storage.database.sql.building.Sql) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Key(com.djrapitops.plan.delivery.domain.keys.Key) DBCleanTask(com.djrapitops.plan.storage.upkeep.DBCleanTask) Locale(com.djrapitops.plan.settings.locale.Locale) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) Assertions(org.junit.jupiter.api.Assertions) RandomData(utilities.RandomData) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) TestPluginLogger(utilities.TestPluginLogger) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) CreateIndexTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction) RegisterDateMinimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Config(com.djrapitops.plan.settings.config.Config) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Key(com.djrapitops.plan.delivery.domain.keys.Key) Test(org.junit.jupiter.api.Test)

Example 15 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer 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 -> db().executeTransaction(new StoreSessionTransaction(session)));
    player2Sessions.forEach(session -> db().executeTransaction(new StoreSessionTransaction(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) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Aggregations

PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)16 ServerUUID (com.djrapitops.plan.identification.ServerUUID)5 GeoInfo (com.djrapitops.plan.gathering.domain.GeoInfo)4 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)3 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)3 PlayerContainerQuery (com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery)3 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)3 PerServerContainer (com.djrapitops.plan.delivery.domain.container.PerServerContainer)2 Key (com.djrapitops.plan.delivery.domain.keys.Key)2 PlayerKeys (com.djrapitops.plan.delivery.domain.keys.PlayerKeys)2 PerServerMutator (com.djrapitops.plan.delivery.domain.mutators.PerServerMutator)2 BaseUser (com.djrapitops.plan.gathering.domain.BaseUser)2 Ping (com.djrapitops.plan.gathering.domain.Ping)2 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)2 Database (com.djrapitops.plan.storage.database.Database)2 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)2 Patch (com.djrapitops.plan.storage.database.transactions.patches.Patch)2 java.util (java.util)2 Test (org.junit.jupiter.api.Test)2 Arguments (com.djrapitops.plan.commands.use.Arguments)1