Search in sources :

Example 1 with PlayerContainer

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

the class PageFactory method playerPage.

public PlayerPage playerPage(UUID playerUUID) throws IOException {
    Database db = dbSystem.get().getDatabase();
    PlayerContainer player = db.query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
    return new PlayerPage(getResource("player.html"), player, versionChecker.get(), config.get(), this, theme.get(), locale.get(), formatters.get(), serverInfo.get());
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) Database(com.djrapitops.plan.storage.database.Database)

Example 2 with PlayerContainer

use of com.djrapitops.plan.delivery.domain.container.PlayerContainer 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 PlayerContainer

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

the class PlayersMutator method getPingPerCountry.

public Map<String, List<Ping>> getPingPerCountry(ServerUUID serverUUID) {
    Map<String, List<Ping>> pingPerCountry = new HashMap<>();
    for (PlayerContainer player : players) {
        Optional<GeoInfo> mostRecent = GeoInfoMutator.forContainer(player).mostRecent();
        if (!mostRecent.isPresent()) {
            continue;
        }
        List<Ping> pings = player.getValue(PlayerKeys.PING).orElse(new ArrayList<>());
        String country = mostRecent.get().getGeolocation();
        List<Ping> countryPings = pingPerCountry.computeIfAbsent(country, Lists::create);
        countryPings.addAll(new PingMutator(pings).filterByServer(serverUUID).all());
    }
    return pingPerCountry;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) Lists(com.djrapitops.plan.utilities.java.Lists) Ping(com.djrapitops.plan.gathering.domain.Ping) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo)

Example 4 with PlayerContainer

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

the class PlayersMutator method toActivityDataMap.

public TreeMap<Long, Map<String, Set<UUID>>> toActivityDataMap(long date, long msThreshold) {
    TreeMap<Long, Map<String, Set<UUID>>> activityData = new TreeMap<>();
    for (long time = date; time >= date - TimeAmount.MONTH.toMillis(2L); time -= TimeAmount.WEEK.toMillis(1L)) {
        Map<String, Set<UUID>> map = activityData.computeIfAbsent(time, Maps::create);
        if (!players.isEmpty()) {
            for (PlayerContainer player : players) {
                if (player.getValue(PlayerKeys.REGISTERED).orElse(0L) > time) {
                    continue;
                }
                ActivityIndex activityIndex = player.getActivityIndex(time, msThreshold);
                String activityGroup = activityIndex.getGroup();
                Set<UUID> uuids = map.computeIfAbsent(activityGroup, Maps::createSet);
                uuids.add(player.getUnsafe(PlayerKeys.UUID));
            }
        }
    }
    return activityData;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) Maps(com.djrapitops.plan.utilities.java.Maps) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 5 with PlayerContainer

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

the class PlayersMutator method getGeolocations.

public List<String> getGeolocations() {
    List<String> geolocations = new ArrayList<>();
    for (PlayerContainer player : players) {
        Optional<GeoInfo> mostRecent = GeoInfoMutator.forContainer(player).mostRecent();
        geolocations.add(mostRecent.map(GeoInfo::getGeolocation).orElse("Unknown"));
    }
    return geolocations;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo)

Aggregations

PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)15 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)5 ServerUUID (com.djrapitops.plan.identification.ServerUUID)5 GeoInfo (com.djrapitops.plan.gathering.domain.GeoInfo)4 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)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 Collectors (java.util.stream.Collectors)2 Test (org.junit.jupiter.api.Test)2