Search in sources :

Example 26 with Database

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;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database)

Example 27 with Database

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 + '}';
}
Also used : Database(com.djrapitops.plan.storage.database.Database) Point(com.djrapitops.plan.delivery.rendering.json.graphs.line.Point)

Example 28 with Database

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);
}
Also used : DateMap(com.djrapitops.plan.delivery.domain.DateMap) Database(com.djrapitops.plan.storage.database.Database) Map(java.util.Map) NavigableMap(java.util.NavigableMap) WorldMap(com.djrapitops.plan.delivery.rendering.json.graphs.special.WorldMap) DateMap(com.djrapitops.plan.delivery.domain.DateMap)

Example 29 with Database

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));
}
Also used : Database(com.djrapitops.plan.storage.database.Database) LineGraphFactory(com.djrapitops.plan.delivery.rendering.json.graphs.line.LineGraphFactory) Point(com.djrapitops.plan.delivery.rendering.json.graphs.line.Point)

Example 30 with Database

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);
}
Also used : 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