Search in sources :

Example 1 with Trend

use of com.djrapitops.plan.delivery.rendering.json.Trend 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 2 with Trend

use of com.djrapitops.plan.delivery.rendering.json.Trend 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 3 with Trend

use of com.djrapitops.plan.delivery.rendering.json.Trend 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)

Aggregations

Trend (com.djrapitops.plan.delivery.rendering.json.Trend)3 Database (com.djrapitops.plan.storage.database.Database)3 HashMap (java.util.HashMap)3