use of com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie in project Plan by plan-player-analytics.
the class SessionsMutator method toJSONMaps.
private List<Map<String, Object>> toJSONMaps(Graphs graphs, WorldAliasSettings worldAliasSettings, Formatters formatters, Function<Map<String, Object>, Object> nameFunction) {
return Lists.map(sessions, session -> {
Map<String, Object> sessionMap = new HashMap<>();
String playerUUID = session.getPlayerUUID().toString();
String serverUUID = session.getServerUUID().toString();
String playerName = session.getExtraData(PlayerName.class).map(PlayerName::get).orElse(playerUUID);
String serverName = session.getExtraData(ServerName.class).map(ServerName::get).orElse(serverUUID);
sessionMap.put("player_name", playerName);
sessionMap.put("player_url_name", Html.encodeToURL(playerName));
sessionMap.put("player_uuid", playerUUID);
sessionMap.put("server_name", serverName);
sessionMap.put("server_url_name", Html.encodeToURL(serverName));
sessionMap.put("server_uuid", serverUUID);
sessionMap.put("name", nameFunction.apply(sessionMap));
sessionMap.put("start", formatters.yearLong().apply(session.getStart()) + (session.getExtraData(ActiveSession.class).isPresent() ? " (Online)" : ""));
sessionMap.put("end", formatters.yearLong().apply(session.getEnd()));
sessionMap.put("most_used_world", worldAliasSettings.getLongestWorldPlayed(session));
sessionMap.put("length", formatters.timeAmount().apply(session.getLength()));
sessionMap.put("afk_time", formatters.timeAmount().apply(session.getAfkTime()));
sessionMap.put("mob_kills", session.getMobKillCount());
sessionMap.put("deaths", session.getDeathCount());
sessionMap.put("player_kills", session.getExtraData(PlayerKills.class).map(PlayerKills::asMutator).map(killsMutator -> killsMutator.toJSONAsMap(formatters)).orElseGet(ArrayList::new));
sessionMap.put("first_session", session.isFirstSession());
WorldPie worldPie = graphs.pie().worldPie(session.getExtraData(WorldTimes.class).orElseGet(WorldTimes::new));
sessionMap.put("world_series", worldPie.getSlices());
sessionMap.put("gm_series", worldPie.toHighChartsDrillDownMaps());
session.getExtraData(AveragePing.class).ifPresent(averagePing -> sessionMap.put("avg_ping", formatters.decimals().apply(averagePing.getValue()) + " ms"));
return sessionMap;
});
}
use of com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie 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.delivery.rendering.json.graphs.pie.WorldPie 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;
}
use of com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie in project Plan by plan-player-analytics.
the class GraphJSONCreator method serverWorldPieJSONAsMap.
public Map<String, Object> serverWorldPieJSONAsMap(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
WorldTimes worldTimes = db.query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID));
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
return Maps.builder(String.class, Object.class).put("world_series", worldPie.getSlices()).put("gm_series", worldPie.toHighChartsDrillDownMaps()).build();
}
Aggregations