Search in sources :

Example 46 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class JSONFactory method networkPlayersTableJSON.

public Map<String, Object> networkPlayersTableJSON() {
    Integer xMostRecentPlayers = config.get(DisplaySettings.PLAYERS_PER_PLAYERS_PAGE);
    Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
    boolean openPlayerLinksInNewTab = config.isTrue(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB);
    Database database = dbSystem.getDatabase();
    ServerUUID mainServerUUID = database.query(ServerQueries.fetchProxyServerInformation()).map(Server::getUuid).orElse(serverInfo.getServerUUID());
    Map<UUID, ExtensionTabData> pluginData = database.query(new ExtensionServerTableDataQuery(mainServerUUID, xMostRecentPlayers));
    return new PlayersTableJSONCreator(database.query(new NetworkTablePlayersQuery(System.currentTimeMillis(), playtimeThreshold, xMostRecentPlayers)), pluginData, openPlayerLinksInNewTab, formatters, locale, // players page
    true).toJSONMap();
}
Also used : ExtensionTabData(com.djrapitops.plan.extension.implementation.results.ExtensionTabData) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Database(com.djrapitops.plan.storage.database.Database) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 47 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class PlayerJSONCreator method createJSONAsMap.

public Map<String, Object> createJSONAsMap(UUID playerUUID) {
    Database db = dbSystem.getDatabase();
    Map<ServerUUID, String> serverNames = db.query(ServerQueries.fetchServerNames());
    String[] pieColors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
    PlayerContainer player = db.query(new PlayerContainerQuery(playerUUID));
    SessionsMutator sessionsMutator = SessionsMutator.forContainer(player);
    Map<ServerUUID, WorldTimes> worldTimesPerServer = PerServerMutator.forContainer(player).worldTimesPerServer();
    List<Map<String, Object>> serverAccordion = new ServerAccordion(player, serverNames, graphs, year, timeAmount, locale.getString(GenericLang.UNKNOWN)).asMaps();
    List<PlayerKill> kills = player.getValue(PlayerKeys.PLAYER_KILLS).orElse(Collections.emptyList());
    List<PlayerKill> deaths = player.getValue(PlayerKeys.PLAYER_DEATHS_KILLS).orElse(Collections.emptyList());
    PingMutator.forContainer(player).addPingToSessions(sessionsMutator.all());
    Map<String, Object> data = new HashMap<>();
    data.put("info", createInfoJSONMap(player, serverNames));
    data.put("online_activity", createOnlineActivityJSONMap(sessionsMutator));
    data.put("kill_data", createPvPPvEMap(player));
    data.put("nicknames", player.getValue(PlayerKeys.NICKNAMES).map(nicks -> Nickname.fromDataNicknames(nicks, serverNames, year)).orElse(Collections.emptyList()));
    data.put("connections", player.getValue(PlayerKeys.GEO_INFO).map(geoInfo -> ConnectionInfo.fromGeoInfo(geoInfo, year)).orElse(Collections.emptyList()));
    data.put("player_kills", new PlayerKillMutator(kills).filterNonSelfKills().toJSONAsMap(formatters));
    data.put("player_deaths", new PlayerKillMutator(deaths).toJSONAsMap(formatters));
    data.put("sessions", sessionsMutator.sort(new DateHolderRecentComparator()).toServerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters));
    data.put("sessions_per_page", config.get(DisplaySettings.SESSIONS_PER_PAGE));
    data.put("servers", serverAccordion);
    data.put("punchcard_series", graphs.special().punchCard(sessionsMutator).getDots());
    WorldPie worldPie = graphs.pie().worldPie(player.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes()));
    data.put("world_pie_series", worldPie.getSlices());
    data.put("gm_series", worldPie.toHighChartsDrillDownMaps());
    data.put("calendar_series", graphs.calendar().playerCalendar(player).getEntries());
    data.put("server_pie_series", graphs.pie().serverPreferencePie(serverNames, worldTimesPerServer).getSlices());
    data.put("server_pie_colors", pieColors);
    // Monday
    data.put("first_day", 1);
    return data;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PlayerContainerQuery(com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) Database(com.djrapitops.plan.storage.database.Database) DateHolderRecentComparator(com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator) WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie)

Example 48 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class OnlineActivityOverviewJSONCreator method createInsightsMap.

private Map<String, Object> createInsightsMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long halfMonthAgo = now - TimeUnit.DAYS.toMillis(15L);
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    Map<String, Object> insights = new HashMap<>();
    SessionsMutator sessions = new SessionsMutator(db.query(SessionQueries.fetchServerSessionsWithoutKillOrWorldData(monthAgo, now, serverUUID)));
    List<TPS> tpsData = db.query(TPSQueries.fetchTPSDataOfServer(monthAgo, now, serverUUID));
    Map<UUID, Long> registerDates = db.query(UserInfoQueries.fetchRegisterDates(monthAgo, now, serverUUID));
    PlayersOnlineResolver playersOnlineResolver = new PlayersOnlineResolver(new TPSMutator(tpsData));
    SessionsMutator firstSessions = sessions.filterBy(session -> {
        long registered = registerDates.getOrDefault(session.getPlayerUUID(), -501L);
        long start = session.getDate();
        return Math.abs(registered - start) < 500L;
    });
    SessionsMutator firstSessionsBefore = firstSessions.filterSessionsBetween(monthAgo, halfMonthAgo);
    SessionsMutator firstSessionsAfter = firstSessions.filterSessionsBetween(halfMonthAgo, now);
    long avgFirstSessionLength = firstSessions.toAverageSessionLength();
    long avgFirstSessionLengthBefore = firstSessionsBefore.toAverageSessionLength();
    long avgFirstSessionLengthAfter = firstSessionsAfter.toAverageSessionLength();
    insights.put("first_session_length_avg", timeAmountFormatter.apply(avgFirstSessionLength));
    insights.put("first_session_length_trend", new Trend(avgFirstSessionLengthBefore, avgFirstSessionLengthAfter, false, timeAmountFormatter));
    long medianFirstSessionLength = firstSessions.toMedianSessionLength();
    long medianFirstSessionLengthBefore = firstSessionsBefore.toMedianSessionLength();
    long medianFirstSessionLengthAfter = firstSessionsAfter.toMedianSessionLength();
    insights.put("first_session_length_median", timeAmountFormatter.apply(medianFirstSessionLength));
    insights.put("first_session_length_median_trend", new Trend(medianFirstSessionLengthBefore, medianFirstSessionLengthAfter, false, timeAmountFormatter));
    int lonelyJoins = playersOnlineResolver.findLonelyJoins(sessions.toSessionStarts());
    int loneJoinsBefore = playersOnlineResolver.findLonelyJoins(sessions.filterSessionsBetween(monthAgo, halfMonthAgo).toSessionStarts());
    int loneJoinsAfter = playersOnlineResolver.findLonelyJoins(sessions.filterSessionsBetween(halfMonthAgo, now).toSessionStarts());
    insights.put("lone_joins", lonelyJoins);
    insights.put("lone_joins_trend", new Trend(loneJoinsBefore, loneJoinsAfter, true));
    int newLonelyJoins = playersOnlineResolver.findLonelyJoins(firstSessions.toSessionStarts());
    int newLoneJoinsBefore = playersOnlineResolver.findLonelyJoins(firstSessionsBefore.toSessionStarts());
    int newLoneJoinsAfter = playersOnlineResolver.findLonelyJoins(firstSessionsAfter.toSessionStarts());
    insights.put("lone_new_joins", newLonelyJoins);
    insights.put("lone_new_joins_trend", new Trend(newLoneJoinsBefore, newLoneJoinsAfter, true));
    double playersOnlineOnRegister = firstSessions.toAveragePlayersOnline(playersOnlineResolver);
    double playersOnlineOnRegisterBefore = firstSessionsBefore.toAveragePlayersOnline(playersOnlineResolver);
    double playersOnlineOnRegisterAfter = firstSessionsAfter.toAveragePlayersOnline(playersOnlineResolver);
    insights.put("players_first_join_avg", decimalFormatter.apply(playersOnlineOnRegister));
    insights.put("players_first_join_trend", new Trend(playersOnlineOnRegisterBefore, playersOnlineOnRegisterAfter, false, decimalFormatter));
    return insights;
}
Also used : HashMap(java.util.HashMap) PlayersOnlineResolver(com.djrapitops.plan.delivery.domain.mutators.PlayersOnlineResolver) TPS(com.djrapitops.plan.gathering.domain.TPS) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 49 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class SessionsMutator method sortByServersToMaps.

public static Map<ServerUUID, TreeMap<Long, FinishedSession>> sortByServersToMaps(List<FinishedSession> sessions) {
    Map<ServerUUID, TreeMap<Long, FinishedSession>> sorted = new HashMap<>();
    for (FinishedSession session : sessions) {
        ServerUUID serverUUID = session.getServerUUID();
        TreeMap<Long, FinishedSession> serverSessions = sorted.getOrDefault(serverUUID, new TreeMap<>());
        serverSessions.put(session.getDate(), session);
        sorted.put(serverUUID, serverSessions);
    }
    return sorted;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 50 with ServerUUID

use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.

the class SessionsMutator method sortByServers.

public static Map<ServerUUID, List<FinishedSession>> sortByServers(List<FinishedSession> sessions) {
    Map<ServerUUID, List<FinishedSession>> sorted = new HashMap<>();
    for (FinishedSession session : sessions) {
        ServerUUID serverUUID = session.getServerUUID();
        List<FinishedSession> serverSessions = sorted.computeIfAbsent(serverUUID, Lists::create);
        serverSessions.add(session);
    }
    return sorted;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Lists(com.djrapitops.plan.utilities.java.Lists)

Aggregations

ServerUUID (com.djrapitops.plan.identification.ServerUUID)105 UUID (java.util.UUID)26 ResultSet (java.sql.ResultSet)23 PreparedStatement (java.sql.PreparedStatement)21 Database (com.djrapitops.plan.storage.database.Database)17 Test (org.junit.jupiter.api.Test)17 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)14 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)12 Nickname (com.djrapitops.plan.delivery.domain.Nickname)11 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)11 Server (com.djrapitops.plan.identification.Server)11 HashMap (java.util.HashMap)11 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)9 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)9 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)9 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)9 Lists (com.djrapitops.plan.utilities.java.Lists)9 CallEvents (com.djrapitops.plan.extension.CallEvents)8 List (java.util.List)8 Map (java.util.Map)8