use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class PerServerMutator method worldTimesPerServer.
public Map<ServerUUID, WorldTimes> worldTimesPerServer() {
Map<ServerUUID, WorldTimes> timesMap = new HashMap<>();
for (Map.Entry<ServerUUID, DataContainer> entry : data.entrySet()) {
DataContainer container = entry.getValue();
timesMap.put(entry.getKey(), container.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes()));
}
return timesMap;
}
use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class ServerAccordion method asMaps.
public List<Map<String, Object>> asMaps() {
List<Map<String, Object>> servers = new ArrayList<>();
for (Map.Entry<ServerUUID, DataContainer> entry : perServer.entrySet()) {
ServerUUID serverUUID = entry.getKey();
DataContainer ofServer = entry.getValue();
Map<String, Object> server = new HashMap<>();
String serverName = serverNames.getOrDefault(serverUUID, unknown);
WorldTimes worldTimes = ofServer.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes());
SessionsMutator sessionsMutator = SessionsMutator.forContainer(ofServer);
server.put("server_name", serverName);
server.put("banned", ofServer.getValue(PerServerKeys.BANNED).orElse(false));
server.put("operator", ofServer.getValue(PerServerKeys.OPERATOR).orElse(false));
server.put("registered", year.apply(ofServer.getValue(PerServerKeys.REGISTERED).orElse(0L)));
server.put("last_seen", year.apply(sessionsMutator.toLastSeen()));
server.put("join_address", ofServer.getValue(PerServerKeys.JOIN_ADDRESS).orElse("-"));
server.put("session_count", sessionsMutator.count());
server.put("playtime", timeAmount.apply(sessionsMutator.toPlaytime()));
server.put("afk_time", timeAmount.apply(sessionsMutator.toAfkTime()));
server.put("session_median", timeAmount.apply(sessionsMutator.toMedianSessionLength()));
server.put("longest_session_length", timeAmount.apply(sessionsMutator.toLongestSessionLength()));
server.put("mob_kills", sessionsMutator.toMobKillCount());
server.put("player_kills", sessionsMutator.toPlayerKillCount());
server.put("deaths", sessionsMutator.toDeathCount());
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
server.put("world_pie_series", worldPie.getSlices());
server.put("gm_series", worldPie.toHighChartsDrillDownMaps());
servers.add(server);
}
return servers;
}
use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class WorldTimesQueries method fetchServerTotalWorldTimes.
/**
* Sum total playtime per world on a server.
*
* @param serverUUID Server UUID of the Plan server.
* @return WorldTimes with world name - playtime ms information.
*/
public static Query<WorldTimes> fetchServerTotalWorldTimes(ServerUUID serverUUID) {
String sql = SELECT_WORLD_TIMES_STATEMENT_START + SELECT_WORLD_TIMES_JOIN_WORLD_NAME + WHERE + WorldTimesTable.TABLE_NAME + '.' + WorldTimesTable.SERVER_UUID + "=?" + GROUP_BY + WORLD_COLUMN;
return new QueryStatement<WorldTimes>(sql, 1000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
}
@Override
public WorldTimes processResults(ResultSet set) throws SQLException {
String[] gms = GMTimes.getGMKeyArray();
WorldTimes worldTimes = new WorldTimes();
while (set.next()) {
String worldName = set.getString(WORLD_COLUMN);
GMTimes gmTimes = extractGMTimes(set, gms);
worldTimes.setGMTimesForWorld(worldName, gmTimes);
}
return worldTimes;
}
};
}
use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class WorldTimesTable method addSessionWorldTimesToBatch.
public static void addSessionWorldTimesToBatch(PreparedStatement statement, FinishedSession session, String[] gms) throws SQLException {
UUID uuid = session.getPlayerUUID();
ServerUUID serverUUID = session.getServerUUID();
Optional<WorldTimes> worldTimes = session.getExtraData().get(WorldTimes.class);
if (!worldTimes.isPresent())
return;
for (Map.Entry<String, GMTimes> worldTimesEntry : worldTimes.get().getWorldTimes().entrySet()) {
String worldName = worldTimesEntry.getKey();
GMTimes gmTimes = worldTimesEntry.getValue();
// Session ID select statement
statement.setString(1, uuid.toString());
statement.setString(2, serverUUID.toString());
statement.setLong(3, session.getStart());
statement.setLong(4, session.getEnd());
// World ID select statement
statement.setString(5, worldName);
statement.setString(6, serverUUID.toString());
statement.setString(7, uuid.toString());
statement.setString(8, serverUUID.toString());
statement.setLong(9, gmTimes.getTime(gms[0]));
statement.setLong(10, gmTimes.getTime(gms[1]));
statement.setLong(11, gmTimes.getTime(gms[2]));
statement.setLong(12, gmTimes.getTime(gms[3]));
statement.addBatch();
}
}
use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class PlayerJSONCreator method createJSONAsMap.
public Map<String, Object> createJSONAsMap(UUID playerUUID) {
Database db = dbSystem.getDatabase();
Map<ServerUUID, String> serverNames = db.query(ServerQueries.fetchServerNames());
String[] pieColors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
PlayerContainer player = db.query(new PlayerContainerQuery(playerUUID));
SessionsMutator sessionsMutator = SessionsMutator.forContainer(player);
Map<ServerUUID, WorldTimes> worldTimesPerServer = PerServerMutator.forContainer(player).worldTimesPerServer();
List<Map<String, Object>> serverAccordion = new ServerAccordion(player, serverNames, graphs, year, timeAmount, locale.getString(GenericLang.UNKNOWN)).asMaps();
List<PlayerKill> kills = player.getValue(PlayerKeys.PLAYER_KILLS).orElse(Collections.emptyList());
List<PlayerKill> deaths = player.getValue(PlayerKeys.PLAYER_DEATHS_KILLS).orElse(Collections.emptyList());
PingMutator.forContainer(player).addPingToSessions(sessionsMutator.all());
Map<String, Object> data = new HashMap<>();
data.put("info", createInfoJSONMap(player, serverNames));
data.put("online_activity", createOnlineActivityJSONMap(sessionsMutator));
data.put("kill_data", createPvPPvEMap(player));
data.put("nicknames", player.getValue(PlayerKeys.NICKNAMES).map(nicks -> Nickname.fromDataNicknames(nicks, serverNames, year)).orElse(Collections.emptyList()));
data.put("connections", player.getValue(PlayerKeys.GEO_INFO).map(geoInfo -> ConnectionInfo.fromGeoInfo(geoInfo, year)).orElse(Collections.emptyList()));
data.put("player_kills", new PlayerKillMutator(kills).filterNonSelfKills().toJSONAsMap(formatters));
data.put("player_deaths", new PlayerKillMutator(deaths).toJSONAsMap(formatters));
data.put("sessions", sessionsMutator.sort(new DateHolderRecentComparator()).toServerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters));
data.put("sessions_per_page", config.get(DisplaySettings.SESSIONS_PER_PAGE));
data.put("servers", serverAccordion);
data.put("punchcard_series", graphs.special().punchCard(sessionsMutator).getDots());
WorldPie worldPie = graphs.pie().worldPie(player.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes()));
data.put("world_pie_series", worldPie.getSlices());
data.put("gm_series", worldPie.toHighChartsDrillDownMaps());
data.put("calendar_series", graphs.calendar().playerCalendar(player).getEntries());
data.put("server_pie_series", graphs.pie().serverPreferencePie(serverNames, worldTimesPerServer).getSlices());
data.put("server_pie_colors", pieColors);
// Monday
data.put("first_day", 1);
return data;
}
Aggregations