Search in sources :

Example 6 with Database

use of com.djrapitops.plan.storage.database.Database 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());
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) Database(com.djrapitops.plan.storage.database.Database)

Example 7 with Database

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

the class NetworkPlayerBaseOverviewJSONCreator method createTrendsMap.

private Map<String, Object> createTrendsMap() {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    long twoMonthsAgo = now - TimeUnit.DAYS.toMillis(60L);
    Long playThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
    Map<String, Object> trends = new HashMap<>();
    int playersBefore = db.query(PlayerCountQueries.newPlayerCount(0L, monthAgo));
    int playersAfter = db.query(PlayerCountQueries.newPlayerCount(0L, now));
    trends.put("total_players_then", playersBefore);
    trends.put("total_players_now", playersAfter);
    trends.put("total_players_trend", new Trend(playersBefore, playersAfter, false));
    int regularBefore = db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(monthAgo, playThreshold));
    int regularAfter = db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(now, playThreshold));
    trends.put("regular_players_then", regularBefore);
    trends.put("regular_players_now", regularAfter);
    trends.put("regular_players_trend", new Trend(regularBefore, regularAfter, false));
    long avgPlaytimeBefore = db.query(SessionQueries.averagePlaytimePerPlayer(twoMonthsAgo, monthAgo));
    long avgPlaytimeAfter = db.query(SessionQueries.averagePlaytimePerPlayer(monthAgo, now));
    trends.put("playtime_avg_then", timeAmount.apply(avgPlaytimeBefore));
    trends.put("playtime_avg_now", timeAmount.apply(avgPlaytimeAfter));
    trends.put("playtime_avg_trend", new Trend(avgPlaytimeBefore, avgPlaytimeAfter, false, timeAmount));
    long avgAfkBefore = db.query(SessionQueries.averageAfkPerPlayer(twoMonthsAgo, monthAgo));
    long avgAfkAfter = db.query(SessionQueries.averageAfkPerPlayer(monthAgo, now));
    double afkPercentageBefore = Percentage.calculate(avgAfkBefore, avgPlaytimeBefore);
    double afkPercentageAfter = Percentage.calculate(avgAfkAfter, avgPlaytimeAfter);
    trends.put("afk_then", percentage.apply(afkPercentageBefore));
    trends.put("afk_now", percentage.apply(afkPercentageAfter));
    trends.put("afk_trend", new Trend(afkPercentageBefore, afkPercentageAfter, Trend.REVERSED, percentage));
    long avgRegularPlaytimeBefore = db.query(NetworkActivityIndexQueries.averagePlaytimePerRegularPlayer(twoMonthsAgo, monthAgo, playThreshold));
    long avgRegularPlaytimeAfter = db.query(NetworkActivityIndexQueries.averagePlaytimePerRegularPlayer(monthAgo, now, playThreshold));
    trends.put("regular_playtime_avg_then", timeAmount.apply(avgRegularPlaytimeBefore));
    trends.put("regular_playtime_avg_now", timeAmount.apply(avgRegularPlaytimeAfter));
    trends.put("regular_playtime_avg_trend", new Trend(avgRegularPlaytimeBefore, avgRegularPlaytimeAfter, false, timeAmount));
    long avgRegularSessionLengthBefore = db.query(NetworkActivityIndexQueries.averageSessionLengthPerRegularPlayer(twoMonthsAgo, monthAgo, playThreshold));
    long avgRegularSessionLengthAfter = db.query(NetworkActivityIndexQueries.averageSessionLengthPerRegularPlayer(monthAgo, now, playThreshold));
    trends.put("regular_session_avg_then", timeAmount.apply(avgRegularSessionLengthBefore));
    trends.put("regular_session_avg_now", timeAmount.apply(avgRegularSessionLengthAfter));
    trends.put("regular_session_avg_trend", new Trend(avgRegularSessionLengthBefore, avgRegularSessionLengthAfter, false, timeAmount));
    long avgRegularAfkBefore = db.query(NetworkActivityIndexQueries.averageAFKPerRegularPlayer(twoMonthsAgo, monthAgo, playThreshold));
    long avgRegularAfkAfter = db.query(NetworkActivityIndexQueries.averageAFKPerRegularPlayer(monthAgo, now, playThreshold));
    double afkRegularPercentageBefore = Percentage.calculate(avgRegularAfkBefore, avgRegularPlaytimeBefore);
    double afkRegularPercentageAfter = Percentage.calculate(avgRegularAfkAfter, avgRegularPlaytimeAfter);
    trends.put("regular_afk_avg_then", percentage.apply(afkRegularPercentageBefore));
    trends.put("regular_afk_avg_now", percentage.apply(afkRegularPercentageAfter));
    trends.put("regular_afk_avg_trend", new Trend(afkRegularPercentageBefore, afkRegularPercentageAfter, Trend.REVERSED, percentage));
    return trends;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database) Trend(com.djrapitops.plan.delivery.rendering.json.Trend)

Example 8 with Database

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

the class NetworkPlayerBaseOverviewJSONCreator method createInsightsMap.

private Map<String, Object> createInsightsMap() {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long halfMonthAgo = now - TimeUnit.DAYS.toMillis(15L);
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    Long playThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
    Map<String, Object> insights = new HashMap<>();
    int newToRegular = db.query(NetworkActivityIndexQueries.countNewPlayersTurnedRegular(monthAgo, now, playThreshold));
    Integer newToRegularBefore = db.query(NetworkActivityIndexQueries.countNewPlayersTurnedRegular(monthAgo, halfMonthAgo, playThreshold));
    Integer newToRegularAfter = db.query(NetworkActivityIndexQueries.countNewPlayersTurnedRegular(halfMonthAgo, now, playThreshold));
    insights.put("new_to_regular", newToRegular);
    insights.put("new_to_regular_trend", new Trend(newToRegularBefore, newToRegularAfter, false));
    Integer regularToInactive = db.query(NetworkActivityIndexQueries.countRegularPlayersTurnedInactive(monthAgo, now, playThreshold));
    Integer regularToInactiveBefore = db.query(NetworkActivityIndexQueries.countRegularPlayersTurnedInactive(monthAgo, halfMonthAgo, playThreshold));
    Integer regularToInactiveAfter = db.query(NetworkActivityIndexQueries.countRegularPlayersTurnedInactive(halfMonthAgo, now, playThreshold));
    insights.put("regular_to_inactive", regularToInactive);
    insights.put("regular_to_inactive_trend", new Trend(regularToInactiveBefore, regularToInactiveAfter, Trend.REVERSED));
    return insights;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database) Trend(com.djrapitops.plan.delivery.rendering.json.Trend)

Example 9 with Database

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

the class QueryJSONResolver method getActivityGraphData.

private Map<String, Object> getActivityGraphData(Set<UUID> playerUUIDs, List<ServerUUID> serverUUIDs, long after, long before) {
    Database database = dbSystem.getDatabase();
    Long threshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
    long twoMonthsBeforeLastDate = before - TimeAmount.MONTH.toMillis(2L);
    long stopDate = Math.max(twoMonthsBeforeLastDate, after);
    DateMap<Map<String, Integer>> activityData = new DateMap<>();
    for (long time = before; time >= stopDate; time -= TimeAmount.WEEK.toMillis(1L)) {
        activityData.put(time, database.query(NetworkActivityIndexQueries.fetchActivityIndexGroupingsOn(time, threshold, playerUUIDs, serverUUIDs)));
    }
    return graphJSONCreator.createActivityGraphJSON(activityData);
}
Also used : DateMap(com.djrapitops.plan.delivery.domain.DateMap) Database(com.djrapitops.plan.storage.database.Database) DateMap(com.djrapitops.plan.delivery.domain.DateMap)

Example 10 with Database

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

the class QueryJSONResolver method getSessionSummaryData.

private Map<String, String> getSessionSummaryData(Set<UUID> playerUUIDs, List<ServerUUID> serverUUIDs, long after, long before) {
    Database database = dbSystem.getDatabase();
    Map<String, Long> summary = database.query(SessionQueries.summaryOfPlayers(playerUUIDs, serverUUIDs, after, before));
    Map<String, String> formattedSummary = new HashMap<>();
    Formatter<Long> timeAmount = formatters.timeAmount();
    for (Map.Entry<String, Long> entry : summary.entrySet()) {
        formattedSummary.put(entry.getKey(), timeAmount.apply(entry.getValue()));
    }
    formattedSummary.put("total_sessions", Long.toString(summary.get("total_sessions")));
    formattedSummary.put("average_sessions", Long.toString(summary.get("average_sessions")));
    return formattedSummary;
}
Also used : Database(com.djrapitops.plan.storage.database.Database) DateMap(com.djrapitops.plan.delivery.domain.DateMap)

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