Search in sources :

Example 71 with ServerUUID

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

the class PerServerContainer method putSession.

private void putSession(FinishedSession session) {
    if (session == null) {
        return;
    }
    ServerUUID serverUUID = session.getServerUUID();
    DataContainer container = getOrDefault(serverUUID, new DynamicDataContainer());
    if (!container.supports(PerServerKeys.SESSIONS)) {
        container.putRawData(PerServerKeys.SESSIONS, new ArrayList<>());
    }
    container.getUnsafe(PerServerKeys.SESSIONS).add(session);
    put(serverUUID, container);
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 72 with ServerUUID

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

the class ServerPage method toHtml.

@Override
public String toHtml() {
    PlaceholderReplacer placeholders = new PlaceholderReplacer();
    ServerUUID serverUUID = server.getUuid();
    placeholders.put("serverUUID", serverUUID.toString());
    placeholders.put("serverName", server.getIdentifiableName());
    placeholders.put("serverDisplayName", server.getName());
    placeholders.put("refreshBarrier", config.get(WebserverSettings.REDUCED_REFRESH_BARRIER));
    placeholders.put("timeZone", config.getTimeZoneOffsetHours());
    placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE));
    placeholders.put("contributors", Contributors.generateContributorHtml());
    placeholders.put("versionButton", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton()));
    placeholders.put("version", versionChecker.getCurrentVersion());
    placeholders.put("updateModal", versionChecker.getUpdateModal());
    CachingSupplier<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
        List<ExtensionData> extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID));
        return new ServerPluginTabs(extensionData, formatters);
    });
    long after = System.currentTimeMillis() - config.get(WebserverSettings.REDUCED_REFRESH_BARRIER);
    String navIdentifier = DataID.EXTENSION_NAV.of(serverUUID);
    String tabIdentifier = DataID.EXTENSION_TABS.of(serverUUID);
    String nav = jsonStorage.fetchJsonMadeAfter(navIdentifier, after).orElseGet(() -> {
        jsonStorage.invalidateOlder(navIdentifier, after);
        return jsonStorage.storeJson(navIdentifier, pluginTabs.get().getNav());
    }).json;
    String tabs = jsonStorage.fetchJsonMadeAfter(tabIdentifier, after).orElseGet(() -> {
        jsonStorage.invalidateOlder(tabIdentifier, after);
        return jsonStorage.storeJson(tabIdentifier, pluginTabs.get().getTabs());
    }).json;
    PlaceholderReplacer pluginPlaceholders = new PlaceholderReplacer();
    pluginPlaceholders.put("serverUUID", serverUUID.toString());
    pluginPlaceholders.put("serverName", server.getIdentifiableName());
    pluginPlaceholders.put("serverDisplayName", server.getName());
    pluginPlaceholders.put("backButton", serverInfo.getServer().isProxy() ? Html.BACK_BUTTON_NETWORK.create() : "");
    pluginPlaceholders.put("navPluginsTabs", nav);
    pluginPlaceholders.put("tabsPlugins", tabs);
    return UnaryChain.of(templateHtml).chain(theme::replaceThemeColors).chain(placeholders::apply).chain(pluginPlaceholders::apply).chain(locale::replaceLanguageInHtml).apply();
}
Also used : ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlaceholderReplacer(com.djrapitops.plan.delivery.formatting.PlaceholderReplacer) CachingSupplier(com.djrapitops.plan.delivery.domain.container.CachingSupplier) ExtensionData(com.djrapitops.plan.extension.implementation.results.ExtensionData)

Example 73 with ServerUUID

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

the class NetworkOverviewJSONCreator method createNumbersMap.

private Map<String, Object> createNumbersMap() {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long twoDaysAgo = now - TimeUnit.DAYS.toMillis(2L);
    Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
    Map<String, Object> numbers = new HashMap<>();
    Integer userCount = db.query(PlayerCountQueries.newPlayerCount(0L, now));
    numbers.put("total_players", userCount);
    numbers.put("regular_players", db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(now, playtimeThreshold)));
    numbers.put("online_players", serverSensor.getOnlinePlayerCount());
    ServerUUID serverUUID = serverInfo.getServerUUID();
    Optional<DateObj<Integer>> lastPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, twoDaysAgo));
    Optional<DateObj<Integer>> allTimePeak = db.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID));
    numbers.put("last_peak_date", lastPeak.map(year).orElse("-"));
    numbers.put("last_peak_players", lastPeak.map(dateObj -> dateObj.getValue().toString()).orElse("-"));
    numbers.put("best_peak_date", allTimePeak.map(year).orElse("-"));
    numbers.put("best_peak_players", allTimePeak.map(dateObj -> dateObj.getValue().toString()).orElse("-"));
    Long totalPlaytime = db.query(SessionQueries.playtime(0L, now));
    numbers.put("playtime", timeAmount.apply(totalPlaytime));
    numbers.put("player_playtime", userCount != 0 ? timeAmount.apply(totalPlaytime / userCount) : "-");
    Long sessionCount = db.query(SessionQueries.sessionCount(0L, now));
    numbers.put("sessions", sessionCount);
    numbers.put("session_length_avg", sessionCount != 0 ? timeAmount.apply(totalPlaytime / sessionCount) : "-");
    numbers.put("current_uptime", serverUptimeCalculator.getServerUptimeMillis(serverUUID).map(timeAmount).orElse(locale.getString(GenericLang.UNAVAILABLE)));
    return numbers;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) DateObj(com.djrapitops.plan.delivery.domain.DateObj) Database(com.djrapitops.plan.storage.database.Database)

Example 74 with ServerUUID

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

the class NetworkPage method toHtml.

@Override
public String toHtml() {
    PlaceholderReplacer placeholders = new PlaceholderReplacer();
    ServerUUID serverUUID = serverInfo.getServerUUID();
    placeholders.put("networkDisplayName", config.get(ProxySettings.NETWORK_NAME));
    placeholders.put("serverName", config.get(ProxySettings.NETWORK_NAME));
    placeholders.put("serverUUID", serverUUID.toString());
    placeholders.put("refreshBarrier", config.get(WebserverSettings.REDUCED_REFRESH_BARRIER));
    placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE));
    placeholders.put("playersGraphColor", theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
    placeholders.put("worldMapColLow", theme.getValue(ThemeVal.WORLD_MAP_LOW));
    placeholders.put("worldMapColHigh", theme.getValue(ThemeVal.WORLD_MAP_HIGH));
    placeholders.put("maxPingColor", theme.getValue(ThemeVal.GRAPH_MAX_PING));
    placeholders.put("minPingColor", theme.getValue(ThemeVal.GRAPH_MIN_PING));
    placeholders.put("avgPingColor", theme.getValue(ThemeVal.GRAPH_AVG_PING));
    placeholders.put("timeZone", config.getTimeZoneOffsetHours());
    placeholders.put("versionButton", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton()));
    placeholders.put("version", versionChecker.getCurrentVersion());
    placeholders.put("updateModal", versionChecker.getUpdateModal());
    placeholders.put("contributors", Contributors.generateContributorHtml());
    CachingSupplier<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
        List<ExtensionData> extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID));
        return new ServerPluginTabs(extensionData, formatters);
    });
    long after = System.currentTimeMillis() - config.get(WebserverSettings.REDUCED_REFRESH_BARRIER);
    String navIdentifier = DataID.EXTENSION_NAV.of(serverUUID);
    String tabIdentifier = DataID.EXTENSION_TABS.of(serverUUID);
    String nav = jsonStorage.fetchJsonMadeAfter(navIdentifier, after).orElseGet(() -> {
        jsonStorage.invalidateOlder(navIdentifier, after);
        return jsonStorage.storeJson(navIdentifier, pluginTabs.get().getNav());
    }).json;
    String tabs = jsonStorage.fetchJsonMadeAfter(tabIdentifier, after).orElseGet(() -> {
        jsonStorage.invalidateOlder(tabIdentifier, after);
        return jsonStorage.storeJson(tabIdentifier, pluginTabs.get().getTabs());
    }).json;
    PlaceholderReplacer pluginPlaceholders = new PlaceholderReplacer();
    pluginPlaceholders.put("networkDisplayName", config.get(ProxySettings.NETWORK_NAME));
    pluginPlaceholders.put("serverName", config.get(ProxySettings.NETWORK_NAME));
    pluginPlaceholders.put("serverUUID", serverUUID.toString());
    pluginPlaceholders.put("navPluginsTabs", nav);
    pluginPlaceholders.put("tabsPlugins", StringUtils.remove(tabs, "${backButton}"));
    return UnaryChain.of(templateHtml).chain(theme::replaceThemeColors).chain(placeholders::apply).chain(pluginPlaceholders::apply).chain(locale::replaceLanguageInHtml).apply();
}
Also used : ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlaceholderReplacer(com.djrapitops.plan.delivery.formatting.PlaceholderReplacer) CachingSupplier(com.djrapitops.plan.delivery.domain.container.CachingSupplier) ExtensionData(com.djrapitops.plan.extension.implementation.results.ExtensionData)

Example 75 with ServerUUID

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

the class ExtensionPlayerDataQuery method flatMapByServerUUID.

private Map<ServerUUID, List<ExtensionData>> flatMapByServerUUID(Map<ServerUUID, List<ExtensionInformation>> extensionsByServerUUID, Map<Integer, ExtensionData.Builder> extensionDataByPluginID) {
    Map<ServerUUID, List<ExtensionData>> extensionDataByServerUUID = new HashMap<>();
    for (Map.Entry<ServerUUID, List<ExtensionInformation>> entry : extensionsByServerUUID.entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        for (ExtensionInformation extensionInformation : entry.getValue()) {
            ExtensionData.Builder data = extensionDataByPluginID.get(extensionInformation.getId());
            if (data == null) {
                continue;
            }
            List<ExtensionData> list = extensionDataByServerUUID.computeIfAbsent(serverUUID, Lists::create);
            list.add(data.setInformation(extensionInformation).build());
        }
    }
    return extensionDataByServerUUID;
}
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