Search in sources :

Example 1 with Database

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

the class ServerSettingsManager method updateConfigInDB.

private void updateConfigInDB(File file) {
    if (!file.exists()) {
        return;
    }
    Database database = dbSystem.getDatabase();
    Optional<ServerUUID> serverUUID = serverInfo.getServerUUIDSafe();
    if (!serverUUID.isPresent()) {
        return;
    }
    try (ConfigReader reader = new ConfigReader(file.toPath())) {
        Config read = reader.read();
        database.executeTransaction(new StoreConfigTransaction(serverUUID.get(), read, file.lastModified()));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Config(com.djrapitops.plan.settings.config.Config) ConfigReader(com.djrapitops.plan.settings.config.ConfigReader) Database(com.djrapitops.plan.storage.database.Database) UncheckedIOException(java.io.UncheckedIOException) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 2 with Database

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

the class NetworkOverviewJSONCreator method createWeeksMap.

private Map<String, Object> createWeeksMap() {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long oneWeekAgo = now - TimeUnit.DAYS.toMillis(7L);
    long twoWeeksAgo = now - TimeUnit.DAYS.toMillis(14L);
    Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
    Map<String, Object> weeks = new HashMap<>();
    weeks.put("start", day.apply(twoWeeksAgo));
    weeks.put("midpoint", day.apply(oneWeekAgo));
    weeks.put("end", day.apply(now));
    Integer uniqueBefore = db.query(PlayerCountQueries.uniquePlayerCount(twoWeeksAgo, oneWeekAgo));
    Integer uniqueAfter = db.query(PlayerCountQueries.uniquePlayerCount(oneWeekAgo, now));
    Trend uniqueTrend = new Trend(uniqueBefore, uniqueAfter, false);
    weeks.put("unique_before", uniqueBefore);
    weeks.put("unique_after", uniqueAfter);
    weeks.put("unique_trend", uniqueTrend);
    Integer newBefore = db.query(PlayerCountQueries.newPlayerCount(twoWeeksAgo, oneWeekAgo));
    Integer newAfter = db.query(PlayerCountQueries.newPlayerCount(oneWeekAgo, now));
    Trend newTrend = new Trend(newBefore, newAfter, false);
    weeks.put("new_before", newBefore);
    weeks.put("new_after", newAfter);
    weeks.put("new_trend", newTrend);
    int regularBefore = db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(oneWeekAgo, playtimeThreshold));
    int regularAfter = db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(now, playtimeThreshold));
    weeks.put("regular_before", regularBefore);
    weeks.put("regular_after", regularAfter);
    weeks.put("regular_trend", new Trend(regularBefore, regularAfter, false));
    Long playtimeBefore = db.query(SessionQueries.playtime(twoWeeksAgo, oneWeekAgo));
    Long playtimeAfter = db.query(SessionQueries.playtime(oneWeekAgo, now));
    long avgPlaytimeBefore = uniqueBefore != 0 ? playtimeBefore / uniqueBefore : 0L;
    long avgPlaytimeAfter = uniqueAfter != 0 ? playtimeAfter / uniqueAfter : 0L;
    Trend avgPlaytimeTrend = new Trend(avgPlaytimeBefore, avgPlaytimeAfter, false, timeAmount);
    weeks.put("average_playtime_before", timeAmount.apply(avgPlaytimeBefore));
    weeks.put("average_playtime_after", timeAmount.apply(avgPlaytimeAfter));
    weeks.put("average_playtime_trend", avgPlaytimeTrend);
    Long sessionsBefore = db.query(SessionQueries.sessionCount(twoWeeksAgo, oneWeekAgo));
    Long sessionsAfter = db.query(SessionQueries.sessionCount(oneWeekAgo, now));
    Trend sessionsTrend = new Trend(sessionsBefore, sessionsAfter, false);
    weeks.put("sessions_before", sessionsBefore);
    weeks.put("sessions_after", sessionsAfter);
    weeks.put("sessions_trend", sessionsTrend);
    long avgSessionLengthBefore = sessionsBefore != 0 ? playtimeBefore / sessionsBefore : 0;
    long avgSessionLengthAfter = sessionsAfter != 0 ? playtimeAfter / sessionsAfter : 0;
    Trend avgSessionLengthTrend = new Trend(avgSessionLengthBefore, avgSessionLengthAfter, false, timeAmount);
    weeks.put("session_length_average_before", timeAmount.apply(avgSessionLengthBefore));
    weeks.put("session_length_average_after", timeAmount.apply(avgSessionLengthAfter));
    weeks.put("session_length_average_trend", avgSessionLengthTrend);
    return weeks;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database) Trend(com.djrapitops.plan.delivery.rendering.json.Trend)

Example 3 with Database

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

the class NetworkOverviewJSONCreator method createPlayersMap.

private Map<String, Object> createPlayersMap() {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long dayAgo = now - TimeUnit.DAYS.toMillis(1L);
    long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    Map<String, Object> sevenDays = new HashMap<>();
    sevenDays.put("unique_players_1d", db.query(PlayerCountQueries.uniquePlayerCount(dayAgo, now)));
    sevenDays.put("unique_players_7d", db.query(PlayerCountQueries.uniquePlayerCount(weekAgo, now)));
    sevenDays.put("unique_players_30d", db.query(PlayerCountQueries.uniquePlayerCount(monthAgo, now)));
    sevenDays.put("new_players_1d", db.query(PlayerCountQueries.newPlayerCount(dayAgo, now)));
    sevenDays.put("new_players_7d", db.query(PlayerCountQueries.newPlayerCount(weekAgo, now)));
    sevenDays.put("new_players_30d", db.query(PlayerCountQueries.newPlayerCount(monthAgo, now)));
    return sevenDays;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database)

Example 4 with Database

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

the class NetworkSessionsOverviewJSONCreator method createInsightsMap.

private Map<String, Object> createInsightsMap() {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    Map<String, Object> insights = new HashMap<>();
    Long playtime = db.query(SessionQueries.playtime(monthAgo, now));
    Long afkTime = db.query(SessionQueries.afkTime(monthAgo, now));
    insights.put("total_playtime", timeAmount.apply(playtime));
    insights.put("afk_time", timeAmount.apply(afkTime));
    insights.put("afk_time_perc", percentage.apply(Percentage.calculate(afkTime, playtime, -1)));
    return insights;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database)

Example 5 with Database

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

the class PageFactory method inspectPluginTabs.

public PlayerPluginTab inspectPluginTabs(UUID playerUUID) {
    Database database = dbSystem.get().getDatabase();
    Map<ServerUUID, List<ExtensionData>> extensionPlayerData = database.query(new ExtensionPlayerDataQuery(playerUUID));
    if (extensionPlayerData.isEmpty()) {
        return new PlayerPluginTab("", Collections.emptyList(), formatters.get());
    }
    List<PlayerPluginTab> playerPluginTabs = new ArrayList<>();
    for (Map.Entry<ServerUUID, Server> entry : database.query(ServerQueries.fetchPlanServerInformation()).entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        String serverName = entry.getValue().getIdentifiableName();
        List<ExtensionData> ofServer = extensionPlayerData.get(serverUUID);
        if (ofServer == null) {
            continue;
        }
        playerPluginTabs.add(new PlayerPluginTab(serverName, ofServer, formatters.get()));
    }
    StringBuilder navs = new StringBuilder();
    StringBuilder tabs = new StringBuilder();
    playerPluginTabs.stream().sorted().forEach(tab -> {
        navs.append(tab.getNav());
        tabs.append(tab.getTab());
    });
    return new PlayerPluginTab(navs.toString(), tabs.toString());
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) ExtensionData(com.djrapitops.plan.extension.implementation.results.ExtensionData) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Database(com.djrapitops.plan.storage.database.Database)

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