Search in sources :

Example 46 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class JSONFactory method serverPlayersTableJSON.

public Map<String, Object> serverPlayersTableJSON(ServerUUID serverUUID) {
    Integer xMostRecentPlayers = config.get(DisplaySettings.PLAYERS_PER_SERVER_PAGE);
    Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
    boolean openPlayerLinksInNewTab = config.isTrue(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB);
    Database database = dbSystem.getDatabase();
    return new PlayersTableJSONCreator(database.query(new ServerTablePlayersQuery(serverUUID, System.currentTimeMillis(), playtimeThreshold, xMostRecentPlayers)), database.query(new ExtensionServerTableDataQuery(serverUUID, xMostRecentPlayers)), openPlayerLinksInNewTab, formatters, locale).toJSONMap();
}
Also used : ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) Database(com.djrapitops.plan.storage.database.Database) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery)

Example 47 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class JSONFactory method serversAsJSONMaps.

public Map<String, Object> serversAsJSONMaps() {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
    Formatter<Long> year = formatters.yearLong();
    Formatter<Double> decimals = formatters.decimals();
    Formatter<Long> timeAmount = formatters.timeAmount();
    Map<ServerUUID, Server> serverInformation = db.query(ServerQueries.fetchPlanServerInformation());
    ServerUUID proxyUUID = serverInformation.values().stream().filter(Server::isProxy).findFirst().map(Server::getUuid).orElse(null);
    Map<ServerUUID, List<TPS>> tpsData = db.query(TPSQueries.fetchTPSDataOfAllServersBut(weekAgo, now, proxyUUID));
    Map<ServerUUID, Integer> totalPlayerCounts = db.query(PlayerCountQueries.newPlayerCounts(0, now));
    Map<ServerUUID, Integer> newPlayerCounts = db.query(PlayerCountQueries.newPlayerCounts(weekAgo, now));
    Map<ServerUUID, Integer> uniquePlayerCounts = db.query(PlayerCountQueries.uniquePlayerCounts(weekAgo, now));
    List<Map<String, Object>> servers = new ArrayList<>();
    serverInformation.entrySet().stream().sorted(Comparator.comparing(entry -> entry.getValue().getIdentifiableName().toLowerCase())).filter(entry -> entry.getValue().isNotProxy()).forEach(entry -> {
        ServerUUID serverUUID = entry.getKey();
        Map<String, Object> server = new HashMap<>();
        server.put("name", entry.getValue().getIdentifiableName());
        Optional<DateObj<Integer>> recentPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, now - TimeUnit.DAYS.toMillis(2L)));
        Optional<DateObj<Integer>> allTimePeak = db.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID));
        server.put("last_peak_date", recentPeak.map(DateObj::getDate).map(year).orElse("-"));
        server.put("best_peak_date", allTimePeak.map(DateObj::getDate).map(year).orElse("-"));
        server.put("last_peak_players", recentPeak.map(DateObj::getValue).orElse(0));
        server.put("best_peak_players", allTimePeak.map(DateObj::getValue).orElse(0));
        TPSMutator tpsMonth = new TPSMutator(tpsData.getOrDefault(serverUUID, Collections.emptyList()));
        server.put("playersOnline", tpsMonth.all().stream().map(tps -> new double[] { tps.getDate(), tps.getPlayers() }).toArray(double[][]::new));
        server.put("players", totalPlayerCounts.getOrDefault(serverUUID, 0));
        server.put("new_players", newPlayerCounts.getOrDefault(serverUUID, 0));
        server.put("unique_players", uniquePlayerCounts.getOrDefault(serverUUID, 0));
        TPSMutator tpsWeek = tpsMonth.filterDataBetween(weekAgo, now);
        double averageTPS = tpsWeek.averageTPS();
        server.put("avg_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(HtmlLang.UNIT_NO_DATA).toString());
        server.put("low_tps_spikes", tpsWeek.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
        server.put("downtime", timeAmount.apply(tpsWeek.serverDownTime()));
        server.put("current_uptime", serverUptimeCalculator.getServerUptimeMillis(serverUUID).map(timeAmount).orElse(locale.getString(GenericLang.UNAVAILABLE)));
        Optional<TPS> online = tpsWeek.getLast();
        server.put("online", online.map(point -> point.getDate() >= now - TimeUnit.MINUTES.toMillis(3L) ? point.getPlayers() : "Possibly offline").orElse(locale.get(HtmlLang.UNIT_NO_DATA).toString()));
        servers.add(server);
    });
    return Collections.singletonMap("servers", servers);
}
Also used : HtmlLang(com.djrapitops.plan.settings.locale.lang.HtmlLang) java.util(java.util) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator) Singleton(javax.inject.Singleton) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) Graphs(com.djrapitops.plan.delivery.rendering.json.graphs.Graphs) TimeSettings(com.djrapitops.plan.settings.config.paths.TimeSettings) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) DateObj(com.djrapitops.plan.delivery.domain.DateObj) ServerUptimeCalculator(com.djrapitops.plan.gathering.ServerUptimeCalculator) ServerDto(com.djrapitops.plan.delivery.domain.datatransfer.ServerDto) ExtensionTabData(com.djrapitops.plan.extension.implementation.results.ExtensionTabData) SessionCache(com.djrapitops.plan.gathering.cache.SessionCache) Maps(com.djrapitops.plan.utilities.java.Maps) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) com.djrapitops.plan.gathering.domain(com.djrapitops.plan.gathering.domain) ServerInfo(com.djrapitops.plan.identification.ServerInfo) GenericLang(com.djrapitops.plan.settings.locale.lang.GenericLang) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) PlayerKillMutator(com.djrapitops.plan.delivery.domain.mutators.PlayerKillMutator) Formatters(com.djrapitops.plan.delivery.formatting.Formatters) SessionStartComparator(com.djrapitops.plan.utilities.comparators.SessionStartComparator) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Server(com.djrapitops.plan.identification.Server) Locale(com.djrapitops.plan.settings.locale.Locale) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) DisplaySettings(com.djrapitops.plan.settings.config.paths.DisplaySettings) Formatter(com.djrapitops.plan.delivery.formatting.Formatter) PlayerCountQueries(com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries) Server(com.djrapitops.plan.identification.Server) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) DateObj(com.djrapitops.plan.delivery.domain.DateObj) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 48 with Database

use of com.djrapitops.plan.storage.database.Database 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 49 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class JSONFactory method serverSessionsAsJSONMap.

public List<Map<String, Object>> serverSessionsAsJSONMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    Integer perPageLimit = config.get(DisplaySettings.SESSIONS_PER_PAGE);
    List<FinishedSession> sessions = db.query(SessionQueries.fetchLatestSessionsOfServer(serverUUID, perPageLimit));
    // Add online sessions
    if (serverUUID.equals(serverInfo.getServerUUID())) {
        addActiveSessions(sessions);
        sessions.sort(new SessionStartComparator());
        while (true) {
            int size = sessions.size();
            if (size <= perPageLimit)
                break;
            // Remove last until it fits.
            sessions.remove(size - 1);
        }
    }
    return new SessionsMutator(sessions).toPlayerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters);
}
Also used : Database(com.djrapitops.plan.storage.database.Database) SessionStartComparator(com.djrapitops.plan.utilities.comparators.SessionStartComparator) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)

Example 50 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class JSONFactory method serverPlayerKillsAsJSONMap.

public List<Map<String, Object>> serverPlayerKillsAsJSONMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    List<PlayerKill> kills = db.query(KillQueries.fetchPlayerKillsOnServer(serverUUID, 100));
    return new PlayerKillMutator(kills).toJSONAsMap(formatters);
}
Also used : Database(com.djrapitops.plan.storage.database.Database) PlayerKillMutator(com.djrapitops.plan.delivery.domain.mutators.PlayerKillMutator)

Aggregations

Database (com.djrapitops.plan.storage.database.Database)90 ServerUUID (com.djrapitops.plan.identification.ServerUUID)18 HashMap (java.util.HashMap)18 StoreIconTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction)12 ProviderInformation (com.djrapitops.plan.extension.implementation.ProviderInformation)11 UUID (java.util.UUID)10 StoreProviderTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction)9 DBSystem (com.djrapitops.plan.storage.database.DBSystem)9 TPSMutator (com.djrapitops.plan.delivery.domain.mutators.TPSMutator)7 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)7 PlayerName (com.djrapitops.plan.delivery.domain.PlayerName)6 ServerName (com.djrapitops.plan.delivery.domain.ServerName)6 Point (com.djrapitops.plan.delivery.rendering.json.graphs.line.Point)6 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)6 ServerInfo (com.djrapitops.plan.identification.ServerInfo)6 InetAddress (java.net.InetAddress)6 Inject (javax.inject.Inject)6 DateObj (com.djrapitops.plan.delivery.domain.DateObj)5 LineGraphFactory (com.djrapitops.plan.delivery.rendering.json.graphs.line.LineGraphFactory)5 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)5