use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class PlayerBaseOverviewJSONCreator method createTrendsMap.
private Map<String, Object> createTrendsMap(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
long twoMonthsAgo = now - TimeUnit.DAYS.toMillis(60L);
Long playThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
Map<String, Object> trends = new HashMap<>();
Integer playersBefore = db.query(PlayerCountQueries.newPlayerCount(0L, monthAgo, serverUUID));
Integer playersAfter = db.query(PlayerCountQueries.newPlayerCount(0L, now, serverUUID));
trends.put("total_players_then", playersBefore);
trends.put("total_players_now", playersAfter);
trends.put("total_players_trend", new Trend(playersBefore, playersAfter, false));
Integer regularBefore = db.query(ActivityIndexQueries.fetchRegularPlayerCount(monthAgo, serverUUID, playThreshold));
Integer regularAfter = db.query(ActivityIndexQueries.fetchRegularPlayerCount(now, serverUUID, playThreshold));
trends.put("regular_players_then", regularBefore);
trends.put("regular_players_now", regularAfter);
trends.put("regular_players_trend", new Trend(regularBefore, regularAfter, false));
Long avgPlaytimeBefore = db.query(SessionQueries.averagePlaytimePerPlayer(twoMonthsAgo, monthAgo, serverUUID));
Long avgPlaytimeAfter = db.query(SessionQueries.averagePlaytimePerPlayer(monthAgo, now, serverUUID));
trends.put("playtime_avg_then", timeAmount.apply(avgPlaytimeBefore));
trends.put("playtime_avg_now", timeAmount.apply(avgPlaytimeAfter));
trends.put("playtime_avg_trend", new Trend(avgPlaytimeBefore, avgPlaytimeAfter, false, timeAmount));
Long avgAfkBefore = db.query(SessionQueries.averageAfkPerPlayer(twoMonthsAgo, monthAgo, serverUUID));
Long avgAfkAfter = db.query(SessionQueries.averageAfkPerPlayer(monthAgo, now, serverUUID));
double afkPercentageBefore = Percentage.calculate(avgAfkBefore, avgPlaytimeBefore);
double afkPercentageAfter = Percentage.calculate(avgAfkAfter, avgPlaytimeAfter);
trends.put("afk_then", percentage.apply(afkPercentageBefore));
trends.put("afk_now", percentage.apply(afkPercentageAfter));
trends.put("afk_trend", new Trend(afkPercentageBefore, afkPercentageAfter, Trend.REVERSED, percentage));
Long avgRegularPlaytimeBefore = db.query(ActivityIndexQueries.averagePlaytimePerRegularPlayer(twoMonthsAgo, monthAgo, serverUUID, playThreshold));
Long avgRegularPlaytimeAfter = db.query(ActivityIndexQueries.averagePlaytimePerRegularPlayer(monthAgo, now, serverUUID, playThreshold));
trends.put("regular_playtime_avg_then", timeAmount.apply(avgRegularPlaytimeBefore));
trends.put("regular_playtime_avg_now", timeAmount.apply(avgRegularPlaytimeAfter));
trends.put("regular_playtime_avg_trend", new Trend(avgRegularPlaytimeBefore, avgRegularPlaytimeAfter, false, timeAmount));
Long avgRegularSessionLengthBefore = db.query(ActivityIndexQueries.averageSessionLengthPerRegularPlayer(twoMonthsAgo, monthAgo, serverUUID, playThreshold));
Long avgRegularSessionLengthAfter = db.query(ActivityIndexQueries.averageSessionLengthPerRegularPlayer(monthAgo, now, serverUUID, playThreshold));
trends.put("regular_session_avg_then", timeAmount.apply(avgRegularSessionLengthBefore));
trends.put("regular_session_avg_now", timeAmount.apply(avgRegularSessionLengthAfter));
trends.put("regular_session_avg_trend", new Trend(avgRegularSessionLengthBefore, avgRegularSessionLengthAfter, false, timeAmount));
Long avgRegularAfkBefore = db.query(ActivityIndexQueries.averageAFKPerRegularPlayer(twoMonthsAgo, monthAgo, serverUUID, playThreshold));
Long avgRegularAfkAfter = db.query(ActivityIndexQueries.averageAFKPerRegularPlayer(monthAgo, now, serverUUID, playThreshold));
double afkRegularPercentageBefore = Percentage.calculate(avgRegularAfkBefore, avgRegularPlaytimeBefore);
double afkRegularPercentageAfter = Percentage.calculate(avgRegularAfkAfter, avgRegularPlaytimeAfter);
trends.put("regular_afk_avg_then", percentage.apply(afkRegularPercentageBefore));
trends.put("regular_afk_avg_now", percentage.apply(afkRegularPercentageAfter));
trends.put("regular_afk_avg_trend", new Trend(afkRegularPercentageBefore, afkRegularPercentageAfter, Trend.REVERSED, percentage));
return trends;
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class PlayerOnlineListener method actOnJoinEvent.
private void actOnJoinEvent(ServerPlayerEntity player) {
UUID playerUUID = player.getUuid();
ServerUUID serverUUID = serverInfo.getServerUUID();
long time = System.currentTimeMillis();
FabricAFKListener.afkTracker.performedAction(playerUUID, time);
String world = player.getServerWorld().getRegistryKey().getValue().toString();
String gm = player.interactionManager.getGameMode().name();
Database database = dbSystem.getDatabase();
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
InetSocketAddress socketAddress = (InetSocketAddress) player.networkHandler.connection.getAddress();
InetAddress address = InetAddresses.forString(socketAddress.getAddress().toString().replace("/", ""));
Supplier<String> getHostName = () -> getHostname(player);
String playerName = player.getEntityName();
String displayName = player.getDisplayName().asString();
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
}
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, System::currentTimeMillis, playerName, serverUUID, getHostName));
database.executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, server.getPlayerManager().getOpList().isOp(player.getGameProfile())));
ActiveSession session = new ActiveSession(playerUUID, serverUUID, time, world, gm);
session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
session.getExtraData().put(ServerName.class, new ServerName(serverInfo.getServer().getIdentifiableName()));
sessionCache.cacheSession(playerUUID, session).ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));
database.executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname(displayName, time, serverUUID), (uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class DataValueGatherer method storeBoolean.
private void storeBoolean(Parameters parameters, Conditions conditions, BooleanDataValue data) {
ProviderInformation information = data.getInformation();
Boolean value = getValue(conditions, data, information);
if (value == null)
return;
if (value) {
conditions.conditionFulfilled(information.getProvidedCondition());
} else {
conditions.conditionFulfilled("not_" + information.getProvidedCondition());
}
Database db = dbSystem.getDatabase();
db.executeTransaction(new StoreIconTransaction(information.getIcon()));
db.executeTransaction(new StoreProviderTransaction(information, parameters));
db.executeTransaction(new StoreServerBooleanResultTransaction(information, parameters, value));
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class DataValueGatherer method storePlayerGroups.
private void storePlayerGroups(Parameters parameters, Conditions conditions, GroupsDataValue data) {
ProviderInformation information = data.getInformation();
String[] 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 StorePlayerGroupsResultTransaction(information, parameters, value));
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class DataValueGatherer method storePlayerBoolean.
private void storePlayerBoolean(Parameters parameters, Conditions conditions, BooleanDataValue data) {
ProviderInformation information = data.getInformation();
Boolean value = getValue(conditions, data, information);
if (value == null)
return;
if (value) {
conditions.conditionFulfilled(information.getProvidedCondition());
} else {
conditions.conditionFulfilled("not_" + information.getProvidedCondition());
}
Database db = dbSystem.getDatabase();
db.executeTransaction(new StoreIconTransaction(information.getIcon()));
db.executeTransaction(new StoreProviderTransaction(information, parameters));
db.executeTransaction(new StorePlayerBooleanResultTransaction(information, parameters, value));
}
Aggregations