Search in sources :

Example 21 with Database

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

the class ServerUptimeCalculator method tryToGetServerUptimeMillisFromDatabase.

private Optional<Long> tryToGetServerUptimeMillisFromDatabase(ServerUUID serverUUID) {
    long dataGapThreshold = TimeUnit.MINUTES.toMillis(3);
    Database database = dbSystem.getDatabase();
    Optional<Long> latestDataDate = database.query(TPSQueries.fetchLatestTPSEntryForServer(serverUUID)).map(TPS::getDate);
    Optional<Long> dataBlockStartDate = database.query(TPSQueries.fetchLatestServerStartTime(serverUUID, dataGapThreshold));
    if (!latestDataDate.isPresent() || !dataBlockStartDate.isPresent()) {
        return Optional.empty();
    }
    if (System.currentTimeMillis() - latestDataDate.get() > dataGapThreshold) {
        return Optional.empty();
    }
    return Optional.of(System.currentTimeMillis() - dataBlockStartDate.get());
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) Database(com.djrapitops.plan.storage.database.Database)

Example 22 with Database

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

the class DBCleanTask method run.

@Override
public void run() {
    Database database = dbSystem.getDatabase();
    try {
        if (database.getState() != Database.State.CLOSED) {
            database.executeTransaction(new RemoveOldSampledDataTransaction(serverInfo.getServerUUID(), config.get(TimeSettings.DELETE_TPS_DATA_AFTER), config.get(TimeSettings.DELETE_PING_DATA_AFTER)));
            database.executeTransaction(new RemoveDuplicateUserInfoTransaction());
            database.executeTransaction(new RemoveUnsatisfiedConditionalPlayerResultsTransaction());
            database.executeTransaction(new RemoveUnsatisfiedConditionalServerResultsTransaction());
            int removed = cleanOldPlayers(database);
            if (removed > 0) {
                logger.info(locale.getString(PluginLang.DB_NOTIFY_CLEAN, removed));
            }
            Long deleteExtensionDataAfter = config.get(TimeSettings.DELETE_EXTENSION_DATA_AFTER);
            Long databaseCleanPeriod = config.get(TimeSettings.CLEAN_DATABASE_PERIOD);
            if (databaseCleanPeriod > deleteExtensionDataAfter) {
                logger.warn("Data of Disabled Extensions can not be cleaned due to " + TimeSettings.CLEAN_DATABASE_PERIOD.getPath() + " being larger than " + TimeSettings.DELETE_EXTENSION_DATA_AFTER.getPath());
            }
            // for plugins being deleted all the time.
            if (System.currentTimeMillis() - lastReload <= deleteExtensionDataAfter) {
                database.executeTransaction(new RemoveOldExtensionsTransaction(config.getExtensionSettings(), deleteExtensionDataAfter, serverInfo.getServerUUID()));
            }
        }
    } catch (DBOpException e) {
        errorLogger.error(e);
        cancel();
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) RemoveUnsatisfiedConditionalPlayerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction) RemoveOldExtensionsTransaction(com.djrapitops.plan.storage.database.transactions.init.RemoveOldExtensionsTransaction) RemoveOldSampledDataTransaction(com.djrapitops.plan.storage.database.transactions.init.RemoveOldSampledDataTransaction) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) Database(com.djrapitops.plan.storage.database.Database) RemoveDuplicateUserInfoTransaction(com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUserInfoTransaction)

Example 23 with Database

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

the class PvPPvEJSONCreator method createNumbersMap.

private Map<String, Object> createNumbersMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    Map<String, Object> numbers = new HashMap<>();
    Long pks = db.query(KillQueries.playerKillCount(0L, now, serverUUID));
    Long pks7d = db.query(KillQueries.playerKillCount(weekAgo, now, serverUUID));
    Long pks30d = db.query(KillQueries.playerKillCount(monthAgo, now, serverUUID));
    numbers.put("player_kills_total", pks);
    numbers.put("player_kills_30d", pks30d);
    numbers.put("player_kills_7d", pks7d);
    numbers.put("player_kdr_avg", decimals.apply(db.query(KillQueries.averageKDR(0L, now, serverUUID))));
    numbers.put("player_kdr_avg_30d", decimals.apply(db.query(KillQueries.averageKDR(monthAgo, now, serverUUID))));
    numbers.put("player_kdr_avg_7d", decimals.apply(db.query(KillQueries.averageKDR(weekAgo, now, serverUUID))));
    Long mobKills = db.query(KillQueries.mobKillCount(0L, now, serverUUID));
    Long mobKills30d = db.query(KillQueries.mobKillCount(monthAgo, now, serverUUID));
    Long mobKills7d = db.query(KillQueries.mobKillCount(weekAgo, now, serverUUID));
    numbers.put("mob_kills_total", mobKills);
    numbers.put("mob_kills_30d", mobKills30d);
    numbers.put("mob_kills_7d", mobKills7d);
    Long deaths = db.query(KillQueries.deathCount(0L, now, serverUUID));
    Long deaths30d = db.query(KillQueries.deathCount(monthAgo, now, serverUUID));
    Long deaths7d = db.query(KillQueries.deathCount(weekAgo, now, serverUUID));
    numbers.put("deaths_total", deaths);
    numbers.put("deaths_30d", deaths30d);
    numbers.put("deaths_7d", deaths7d);
    long mobDeaths = deaths - pks;
    long mobDeaths30d = deaths30d - pks30d;
    long mobDeaths7d = deaths7d - pks7d;
    numbers.put("mob_deaths_total", mobDeaths);
    numbers.put("mob_deaths_30d", mobDeaths30d);
    numbers.put("mob_deaths_7d", mobDeaths7d);
    double mobKdr = mobDeaths != 0 ? (double) mobKills / mobDeaths : mobKills;
    double mobKdr30d = mobDeaths30d != 0 ? (double) mobKills30d / mobDeaths30d : mobKills30d;
    double mobKdr7d = mobDeaths7d != 0 ? (double) mobKills7d / mobDeaths7d : mobKills7d;
    numbers.put("mob_kdr_total", decimals.apply(mobKdr));
    numbers.put("mob_kdr_30d", decimals.apply(mobKdr30d));
    numbers.put("mob_kdr_7d", decimals.apply(mobKdr7d));
    return numbers;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database)

Example 24 with Database

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

the class PvPPvEJSONCreator method createInsightsMap.

private Map<String, Object> createInsightsMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    Map<String, Object> insights = new HashMap<>();
    List<String> top3Weapons = db.query(KillQueries.topWeaponsOfServer(monthAgo, now, serverUUID, 3));
    insights.put("weapon_1st", getWeapon(top3Weapons, 0).orElse("-"));
    insights.put("weapon_2nd", getWeapon(top3Weapons, 1).orElse("-"));
    insights.put("weapon_3rd", getWeapon(top3Weapons, 2).orElse("-"));
    return insights;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database)

Example 25 with Database

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

the class ServerOverviewJSONCreator method createLast7DaysMap.

private Map<String, Object> createLast7DaysMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
    Map<String, Object> sevenDays = new HashMap<>();
    sevenDays.put("unique_players", db.query(PlayerCountQueries.uniquePlayerCount(weekAgo, now, serverUUID)));
    sevenDays.put("unique_players_day", db.query(PlayerCountQueries.averageUniquePlayerCount(weekAgo, now, config.getTimeZone().getOffset(now), serverUUID)));
    int new7d = db.query(PlayerCountQueries.newPlayerCount(weekAgo, now, serverUUID));
    int retained7d = db.query(PlayerCountQueries.retainedPlayerCount(weekAgo, now, serverUUID));
    double retentionPercentage7d = Percentage.calculate(retained7d, new7d, -1);
    sevenDays.put("new_players", new7d);
    sevenDays.put("new_players_retention", retained7d);
    sevenDays.put("new_players_retention_perc", percentage.apply(retentionPercentage7d));
    TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(weekAgo, now, serverUUID)));
    double averageTPS = tpsMutator.averageTPS();
    sevenDays.put("average_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(GenericLang.UNAVAILABLE).toString());
    sevenDays.put("low_tps_spikes", tpsMutator.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
    sevenDays.put("downtime", timeAmount.apply(tpsMutator.serverDownTime()));
    return sevenDays;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

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