Search in sources :

Example 91 with Database

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

the class GraphJSONCreator method hourlyUniqueAndNewGraphJSON.

public String hourlyUniqueAndNewGraphJSON(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    LineGraphFactory lineGraphs = graphs.line();
    long now = System.currentTimeMillis();
    long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
    int timeZoneOffset = config.getTimeZone().getOffset(now);
    NavigableMap<Long, Integer> uniquePerDay = db.query(PlayerCountQueries.hourlyUniquePlayerCounts(weekAgo, now, timeZoneOffset, serverUUID));
    NavigableMap<Long, Integer> newPerDay = db.query(PlayerCountQueries.newPlayerCounts(weekAgo, now, timeZoneOffset, serverUUID));
    return createUniqueAndNewJSON(lineGraphs, uniquePerDay, newPerDay, TimeUnit.HOURS.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 92 with Database

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

the class GraphJSONCreator method serverWorldPieJSONAsMap.

public Map<String, Object> serverWorldPieJSONAsMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    WorldTimes worldTimes = db.query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID));
    WorldPie worldPie = graphs.pie().worldPie(worldTimes);
    return Maps.builder(String.class, Object.class).put("world_series", worldPie.getSlices()).put("gm_series", worldPie.toHighChartsDrillDownMaps()).build();
}
Also used : Database(com.djrapitops.plan.storage.database.Database) WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes)

Example 93 with Database

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

the class GraphJSONCreator method hourlyUniqueAndNewGraphJSON.

public String hourlyUniqueAndNewGraphJSON() {
    Database db = dbSystem.getDatabase();
    LineGraphFactory lineGraphs = graphs.line();
    long now = System.currentTimeMillis();
    long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
    int timeZoneOffset = config.getTimeZone().getOffset(now);
    NavigableMap<Long, Integer> uniquePerDay = db.query(PlayerCountQueries.hourlyUniquePlayerCounts(weekAgo, now, timeZoneOffset));
    NavigableMap<Long, Integer> newPerDay = db.query(PlayerCountQueries.hourlyNewPlayerCounts(weekAgo, now, timeZoneOffset));
    return createUniqueAndNewJSON(lineGraphs, uniquePerDay, newPerDay, TimeUnit.HOURS.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 94 with Database

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

the class NetworkOverviewJSONCreator method createNumbersMap.

private Map<String, Object> createNumbersMap() {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long twoDaysAgo = now - TimeUnit.DAYS.toMillis(2L);
    Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
    Map<String, Object> numbers = new HashMap<>();
    Integer userCount = db.query(PlayerCountQueries.newPlayerCount(0L, now));
    numbers.put("total_players", userCount);
    numbers.put("regular_players", db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(now, playtimeThreshold)));
    numbers.put("online_players", serverSensor.getOnlinePlayerCount());
    ServerUUID serverUUID = serverInfo.getServerUUID();
    Optional<DateObj<Integer>> lastPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, twoDaysAgo));
    Optional<DateObj<Integer>> allTimePeak = db.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID));
    numbers.put("last_peak_date", lastPeak.map(year).orElse("-"));
    numbers.put("last_peak_players", lastPeak.map(dateObj -> dateObj.getValue().toString()).orElse("-"));
    numbers.put("best_peak_date", allTimePeak.map(year).orElse("-"));
    numbers.put("best_peak_players", allTimePeak.map(dateObj -> dateObj.getValue().toString()).orElse("-"));
    Long totalPlaytime = db.query(SessionQueries.playtime(0L, now));
    numbers.put("playtime", timeAmount.apply(totalPlaytime));
    numbers.put("player_playtime", userCount != 0 ? timeAmount.apply(totalPlaytime / userCount) : "-");
    Long sessionCount = db.query(SessionQueries.sessionCount(0L, now));
    numbers.put("sessions", sessionCount);
    numbers.put("session_length_avg", sessionCount != 0 ? timeAmount.apply(totalPlaytime / sessionCount) : "-");
    numbers.put("current_uptime", serverUptimeCalculator.getServerUptimeMillis(serverUUID).map(timeAmount).orElse(locale.getString(GenericLang.UNAVAILABLE)));
    return numbers;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) DateObj(com.djrapitops.plan.delivery.domain.DateObj) Database(com.djrapitops.plan.storage.database.Database)

Example 95 with Database

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

the class PluginBooleanGroupFilter method getMatchingUUIDs.

@Override
public Set<UUID> getMatchingUUIDs(InputFilterDto query) {
    Map<PluginBooleanOption, SelectedBoolean> selectedBooleanOptions = new HashMap<>();
    for (String selected : getSelected(query)) {
        String[] optionAndBoolean = StringUtils.split(selected, ":", 2);
        PluginBooleanOption pluginBooleanOption = PluginBooleanOption.parse(optionAndBoolean[0].trim());
        String selectedBoolean = optionAndBoolean[1].trim().toUpperCase();
        selectedBooleanOptions.computeIfPresent(pluginBooleanOption, (key, existing) -> SelectedBoolean.BOTH);
        selectedBooleanOptions.computeIfAbsent(pluginBooleanOption, key -> SelectedBoolean.valueOf(selectedBoolean));
    }
    Database db = dbSystem.getDatabase();
    Map<String, ServerUUID> namesToUUIDs = db.query(ServerQueries.fetchServerNamesToUUIDs());
    return db.query(playersInGroups(selectedBooleanOptions, namesToUUIDs));
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Database(com.djrapitops.plan.storage.database.Database)

Aggregations

Database (com.djrapitops.plan.storage.database.Database)95 ServerUUID (com.djrapitops.plan.identification.ServerUUID)20 HashMap (java.util.HashMap)18 StoreIconTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction)12 ProviderInformation (com.djrapitops.plan.extension.implementation.ProviderInformation)11 StoreProviderTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction)9 DBSystem (com.djrapitops.plan.storage.database.DBSystem)9 UUID (java.util.UUID)9 TPSMutator (com.djrapitops.plan.delivery.domain.mutators.TPSMutator)7 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)7 DateMap (com.djrapitops.plan.delivery.domain.DateMap)6 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 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