use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class ServerOverviewJSONCreator method createWeeksMap.
private Map<String, Object> createWeeksMap(ServerUUID serverUUID) {
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, serverUUID));
Integer uniqueAfter = db.query(PlayerCountQueries.uniquePlayerCount(oneWeekAgo, now, serverUUID));
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, serverUUID));
Integer newAfter = db.query(PlayerCountQueries.newPlayerCount(oneWeekAgo, now, serverUUID));
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(ActivityIndexQueries.fetchRegularPlayerCount(oneWeekAgo, serverUUID, playtimeThreshold));
int regularAfter = db.query(ActivityIndexQueries.fetchRegularPlayerCount(now, serverUUID, 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, serverUUID));
Long playtimeAfter = db.query(SessionQueries.playtime(oneWeekAgo, now, serverUUID));
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, serverUUID));
Long sessionsAfter = db.query(SessionQueries.sessionCount(oneWeekAgo, now, serverUUID));
Trend sessionsTrend = new Trend(sessionsBefore, sessionsAfter, false);
weeks.put("sessions_before", sessionsBefore);
weeks.put("sessions_after", sessionsAfter);
weeks.put("sessions_trend", sessionsTrend);
Long pksBefore = db.query(KillQueries.playerKillCount(twoWeeksAgo, oneWeekAgo, serverUUID));
Long pksAfter = db.query(KillQueries.playerKillCount(oneWeekAgo, now, serverUUID));
Trend pksTrend = new Trend(pksBefore, pksAfter, false);
weeks.put("player_kills_before", pksBefore);
weeks.put("player_kills_after", pksAfter);
weeks.put("player_kills_trend", pksTrend);
Long mkBefore = db.query(KillQueries.mobKillCount(twoWeeksAgo, oneWeekAgo, serverUUID));
Long mkAfter = db.query(KillQueries.mobKillCount(oneWeekAgo, now, serverUUID));
Trend mkTrend = new Trend(mkBefore, mkAfter, false);
weeks.put("mob_kills_before", mkBefore);
weeks.put("mob_kills_after", mkAfter);
weeks.put("mob_kills_trend", mkTrend);
Long deathsBefore = db.query(KillQueries.deathCount(twoWeeksAgo, oneWeekAgo, serverUUID));
Long deathsAfter = db.query(KillQueries.deathCount(oneWeekAgo, now, serverUUID));
Trend deathTrend = new Trend(deathsBefore, deathsAfter, true);
weeks.put("deaths_before", deathsBefore);
weeks.put("deaths_after", deathsAfter);
weeks.put("deaths_trend", deathTrend);
return weeks;
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class GraphJSONCreator method serverCalendarJSON.
public String serverCalendarJSON(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
long twoYearsAgo = now - TimeUnit.DAYS.toMillis(730L);
int timeZoneOffset = config.getTimeZone().getOffset(now);
NavigableMap<Long, Integer> uniquePerDay = db.query(PlayerCountQueries.uniquePlayerCounts(twoYearsAgo, now, timeZoneOffset, serverUUID));
NavigableMap<Long, Integer> newPerDay = db.query(PlayerCountQueries.newPlayerCounts(twoYearsAgo, now, timeZoneOffset, serverUUID));
NavigableMap<Long, Long> playtimePerDay = db.query(SessionQueries.playtimePerDay(twoYearsAgo, now, timeZoneOffset, serverUUID));
NavigableMap<Long, Integer> sessionsPerDay = db.query(SessionQueries.sessionCountPerDay(twoYearsAgo, now, timeZoneOffset, serverUUID));
return "{\"data\":" + graphs.calendar().serverCalendar(uniquePerDay, newPerDay, playtimePerDay, sessionsPerDay).toCalendarSeries() + ",\"firstDay\":" + 1 + '}';
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class GraphJSONCreator method activityGraphsJSONAsMap.
public Map<String, Object> activityGraphsJSONAsMap(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
long date = System.currentTimeMillis();
Long threshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
DateMap<Map<String, Integer>> activityData = new DateMap<>();
for (long time = date; time >= date - TimeAmount.MONTH.toMillis(2L); time -= TimeAmount.WEEK.toMillis(1L)) {
activityData.put(time, db.query(ActivityIndexQueries.fetchActivityIndexGroupingsOn(time, serverUUID, threshold)));
}
return createActivityGraphJSON(activityData);
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class GraphJSONCreator method uniqueAndNewGraphJSON.
public String uniqueAndNewGraphJSON(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
LineGraphFactory lineGraphs = graphs.line();
long now = System.currentTimeMillis();
long halfYearAgo = now - TimeUnit.DAYS.toMillis(180L);
int timeZoneOffset = config.getTimeZone().getOffset(now);
NavigableMap<Long, Integer> uniquePerDay = db.query(PlayerCountQueries.uniquePlayerCounts(halfYearAgo, now, timeZoneOffset, serverUUID));
NavigableMap<Long, Integer> newPerDay = db.query(PlayerCountQueries.newPlayerCounts(halfYearAgo, now, timeZoneOffset, serverUUID));
return createUniqueAndNewJSON(lineGraphs, uniquePerDay, newPerDay, TimeUnit.DAYS.toMillis(1L));
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class GraphJSONCreator method geolocationGraphsJSONAsMap.
public Map<String, Object> geolocationGraphsJSONAsMap(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
Map<String, Integer> geolocationCounts = db.query(GeoInfoQueries.serverGeolocationCounts(serverUUID));
return createGeolocationJSON(geolocationCounts);
}
Aggregations