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