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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations