Search in sources :

Example 61 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() {
    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));
    NavigableMap<Long, Integer> newPerDay = db.query(PlayerCountQueries.newPlayerCounts(halfYearAgo, now, timeZoneOffset));
    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 62 with Database

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

the class OnlineActivityOverviewJSONCreator method createInsightsMap.

private Map<String, Object> createInsightsMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long halfMonthAgo = now - TimeUnit.DAYS.toMillis(15L);
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    Map<String, Object> insights = new HashMap<>();
    SessionsMutator sessions = new SessionsMutator(db.query(SessionQueries.fetchServerSessionsWithoutKillOrWorldData(monthAgo, now, serverUUID)));
    List<TPS> tpsData = db.query(TPSQueries.fetchTPSDataOfServer(monthAgo, now, serverUUID));
    Map<UUID, Long> registerDates = db.query(UserInfoQueries.fetchRegisterDates(monthAgo, now, serverUUID));
    PlayersOnlineResolver playersOnlineResolver = new PlayersOnlineResolver(new TPSMutator(tpsData));
    SessionsMutator firstSessions = sessions.filterBy(session -> {
        long registered = registerDates.getOrDefault(session.getPlayerUUID(), -501L);
        long start = session.getDate();
        return Math.abs(registered - start) < 500L;
    });
    SessionsMutator firstSessionsBefore = firstSessions.filterSessionsBetween(monthAgo, halfMonthAgo);
    SessionsMutator firstSessionsAfter = firstSessions.filterSessionsBetween(halfMonthAgo, now);
    long avgFirstSessionLength = firstSessions.toAverageSessionLength();
    long avgFirstSessionLengthBefore = firstSessionsBefore.toAverageSessionLength();
    long avgFirstSessionLengthAfter = firstSessionsAfter.toAverageSessionLength();
    insights.put("first_session_length_avg", timeAmountFormatter.apply(avgFirstSessionLength));
    insights.put("first_session_length_trend", new Trend(avgFirstSessionLengthBefore, avgFirstSessionLengthAfter, false, timeAmountFormatter));
    long medianFirstSessionLength = firstSessions.toMedianSessionLength();
    long medianFirstSessionLengthBefore = firstSessionsBefore.toMedianSessionLength();
    long medianFirstSessionLengthAfter = firstSessionsAfter.toMedianSessionLength();
    insights.put("first_session_length_median", timeAmountFormatter.apply(medianFirstSessionLength));
    insights.put("first_session_length_median_trend", new Trend(medianFirstSessionLengthBefore, medianFirstSessionLengthAfter, false, timeAmountFormatter));
    int lonelyJoins = playersOnlineResolver.findLonelyJoins(sessions.toSessionStarts());
    int loneJoinsBefore = playersOnlineResolver.findLonelyJoins(sessions.filterSessionsBetween(monthAgo, halfMonthAgo).toSessionStarts());
    int loneJoinsAfter = playersOnlineResolver.findLonelyJoins(sessions.filterSessionsBetween(halfMonthAgo, now).toSessionStarts());
    insights.put("lone_joins", lonelyJoins);
    insights.put("lone_joins_trend", new Trend(loneJoinsBefore, loneJoinsAfter, true));
    int newLonelyJoins = playersOnlineResolver.findLonelyJoins(firstSessions.toSessionStarts());
    int newLoneJoinsBefore = playersOnlineResolver.findLonelyJoins(firstSessionsBefore.toSessionStarts());
    int newLoneJoinsAfter = playersOnlineResolver.findLonelyJoins(firstSessionsAfter.toSessionStarts());
    insights.put("lone_new_joins", newLonelyJoins);
    insights.put("lone_new_joins_trend", new Trend(newLoneJoinsBefore, newLoneJoinsAfter, true));
    double playersOnlineOnRegister = firstSessions.toAveragePlayersOnline(playersOnlineResolver);
    double playersOnlineOnRegisterBefore = firstSessionsBefore.toAveragePlayersOnline(playersOnlineResolver);
    double playersOnlineOnRegisterAfter = firstSessionsAfter.toAveragePlayersOnline(playersOnlineResolver);
    insights.put("players_first_join_avg", decimalFormatter.apply(playersOnlineOnRegister));
    insights.put("players_first_join_trend", new Trend(playersOnlineOnRegisterBefore, playersOnlineOnRegisterAfter, false, decimalFormatter));
    return insights;
}
Also used : HashMap(java.util.HashMap) PlayersOnlineResolver(com.djrapitops.plan.delivery.domain.mutators.PlayersOnlineResolver) TPS(com.djrapitops.plan.gathering.domain.TPS) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 63 with Database

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

the class PlayerBaseOverviewJSONCreator method createInsightsMap.

private Map<String, Object> createInsightsMap(ServerUUID serverUUID) {
    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(ActivityIndexQueries.countNewPlayersTurnedRegular(monthAgo, now, serverUUID, playThreshold));
    Integer newToRegularBefore = db.query(ActivityIndexQueries.countNewPlayersTurnedRegular(monthAgo, halfMonthAgo, serverUUID, playThreshold));
    Integer newToRegularAfter = db.query(ActivityIndexQueries.countNewPlayersTurnedRegular(halfMonthAgo, now, serverUUID, playThreshold));
    insights.put("new_to_regular", newToRegular);
    insights.put("new_to_regular_trend", new Trend(newToRegularBefore, newToRegularAfter, false));
    Integer regularToInactive = db.query(ActivityIndexQueries.countRegularPlayersTurnedInactive(monthAgo, now, serverUUID, playThreshold));
    Integer regularToInactiveBefore = db.query(ActivityIndexQueries.countRegularPlayersTurnedInactive(monthAgo, halfMonthAgo, serverUUID, playThreshold));
    Integer regularToInactiveAfter = db.query(ActivityIndexQueries.countRegularPlayersTurnedInactive(halfMonthAgo, now, serverUUID, 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)

Example 64 with Database

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

the class DataValueGatherer method storeTable.

private void storeTable(Parameters parameters, Conditions conditions, TableDataValue data) {
    ProviderInformation information = data.getInformation();
    Table value = getValue(conditions, data, information);
    if (value == null)
        return;
    Database db = dbSystem.getDatabase();
    for (Icon icon : value.getIcons()) {
        if (icon != null)
            db.executeTransaction(new StoreIconTransaction(icon));
    }
    db.executeTransaction(new StoreTableProviderTransaction(information, parameters, value));
    db.executeTransaction(new StoreServerTableResultTransaction(information, parameters, value));
}
Also used : StoreIconTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction) Table(com.djrapitops.plan.extension.table.Table) Database(com.djrapitops.plan.storage.database.Database) Icon(com.djrapitops.plan.extension.icon.Icon) ProviderInformation(com.djrapitops.plan.extension.implementation.ProviderInformation) StoreTableProviderTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreTableProviderTransaction)

Example 65 with Database

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

the class DataValueGatherer method storeDouble.

private void storeDouble(Parameters parameters, Conditions conditions, DoubleDataValue data) {
    ProviderInformation information = data.getInformation();
    Double value = getValue(conditions, data, information);
    if (value == null)
        return;
    Database db = dbSystem.getDatabase();
    db.executeTransaction(new StoreIconTransaction(information.getIcon()));
    db.executeTransaction(new StoreProviderTransaction(information, parameters));
    db.executeTransaction(new StoreServerDoubleResultTransaction(information, parameters, value));
}
Also used : StoreIconTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction) StoreProviderTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction) Database(com.djrapitops.plan.storage.database.Database) ProviderInformation(com.djrapitops.plan.extension.implementation.ProviderInformation)

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