use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class ServerSettingsManager method updateConfigInDB.
private void updateConfigInDB(File file) {
if (!file.exists()) {
return;
}
Database database = dbSystem.getDatabase();
Optional<ServerUUID> serverUUID = serverInfo.getServerUUIDSafe();
if (!serverUUID.isPresent()) {
return;
}
try (ConfigReader reader = new ConfigReader(file.toPath())) {
Config read = reader.read();
database.executeTransaction(new StoreConfigTransaction(serverUUID.get(), read, file.lastModified()));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class NetworkOverviewJSONCreator method createWeeksMap.
private Map<String, Object> createWeeksMap() {
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));
Integer uniqueAfter = db.query(PlayerCountQueries.uniquePlayerCount(oneWeekAgo, now));
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));
Integer newAfter = db.query(PlayerCountQueries.newPlayerCount(oneWeekAgo, now));
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(NetworkActivityIndexQueries.fetchRegularPlayerCount(oneWeekAgo, playtimeThreshold));
int regularAfter = db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(now, 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));
Long playtimeAfter = db.query(SessionQueries.playtime(oneWeekAgo, now));
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));
Long sessionsAfter = db.query(SessionQueries.sessionCount(oneWeekAgo, now));
Trend sessionsTrend = new Trend(sessionsBefore, sessionsAfter, false);
weeks.put("sessions_before", sessionsBefore);
weeks.put("sessions_after", sessionsAfter);
weeks.put("sessions_trend", sessionsTrend);
long avgSessionLengthBefore = sessionsBefore != 0 ? playtimeBefore / sessionsBefore : 0;
long avgSessionLengthAfter = sessionsAfter != 0 ? playtimeAfter / sessionsAfter : 0;
Trend avgSessionLengthTrend = new Trend(avgSessionLengthBefore, avgSessionLengthAfter, false, timeAmount);
weeks.put("session_length_average_before", timeAmount.apply(avgSessionLengthBefore));
weeks.put("session_length_average_after", timeAmount.apply(avgSessionLengthAfter));
weeks.put("session_length_average_trend", avgSessionLengthTrend);
return weeks;
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class NetworkOverviewJSONCreator method createPlayersMap.
private Map<String, Object> createPlayersMap() {
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
long dayAgo = now - TimeUnit.DAYS.toMillis(1L);
long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
Map<String, Object> sevenDays = new HashMap<>();
sevenDays.put("unique_players_1d", db.query(PlayerCountQueries.uniquePlayerCount(dayAgo, now)));
sevenDays.put("unique_players_7d", db.query(PlayerCountQueries.uniquePlayerCount(weekAgo, now)));
sevenDays.put("unique_players_30d", db.query(PlayerCountQueries.uniquePlayerCount(monthAgo, now)));
sevenDays.put("new_players_1d", db.query(PlayerCountQueries.newPlayerCount(dayAgo, now)));
sevenDays.put("new_players_7d", db.query(PlayerCountQueries.newPlayerCount(weekAgo, now)));
sevenDays.put("new_players_30d", db.query(PlayerCountQueries.newPlayerCount(monthAgo, now)));
return sevenDays;
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class NetworkSessionsOverviewJSONCreator method createInsightsMap.
private Map<String, Object> createInsightsMap() {
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
Map<String, Object> insights = new HashMap<>();
Long playtime = db.query(SessionQueries.playtime(monthAgo, now));
Long afkTime = db.query(SessionQueries.afkTime(monthAgo, now));
insights.put("total_playtime", timeAmount.apply(playtime));
insights.put("afk_time", timeAmount.apply(afkTime));
insights.put("afk_time_perc", percentage.apply(Percentage.calculate(afkTime, playtime, -1)));
return insights;
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class PageFactory method inspectPluginTabs.
public PlayerPluginTab inspectPluginTabs(UUID playerUUID) {
Database database = dbSystem.get().getDatabase();
Map<ServerUUID, List<ExtensionData>> extensionPlayerData = database.query(new ExtensionPlayerDataQuery(playerUUID));
if (extensionPlayerData.isEmpty()) {
return new PlayerPluginTab("", Collections.emptyList(), formatters.get());
}
List<PlayerPluginTab> playerPluginTabs = new ArrayList<>();
for (Map.Entry<ServerUUID, Server> entry : database.query(ServerQueries.fetchPlanServerInformation()).entrySet()) {
ServerUUID serverUUID = entry.getKey();
String serverName = entry.getValue().getIdentifiableName();
List<ExtensionData> ofServer = extensionPlayerData.get(serverUUID);
if (ofServer == null) {
continue;
}
playerPluginTabs.add(new PlayerPluginTab(serverName, ofServer, formatters.get()));
}
StringBuilder navs = new StringBuilder();
StringBuilder tabs = new StringBuilder();
playerPluginTabs.stream().sorted().forEach(tab -> {
navs.append(tab.getNav());
tabs.append(tab.getTab());
});
return new PlayerPluginTab(navs.toString(), tabs.toString());
}
Aggregations