Updated Player page parsing to use PlayerContainer, visible to user:

- Added ban, op status to Server accordion
- Added server specific register dates to Server accordion
- Nickname table supports last seen (Not added yet)
- Actions table is being removed
This commit is contained in:
Rsl1122 2018-06-05 11:26:29 +03:00
parent 7805c2e372
commit ff143af328
4 changed files with 111 additions and 80 deletions

View File

@ -5,10 +5,15 @@
package com.djrapitops.plan.system.webserver.pages.parsing;
import com.djrapitops.plan.api.exceptions.ParseException;
import com.djrapitops.plan.data.PlayerProfile;
import com.djrapitops.plan.data.Actions;
import com.djrapitops.plan.data.calculation.ActivityIndex;
import com.djrapitops.plan.data.container.Action;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.containers.PerServerData;
import com.djrapitops.plan.data.store.containers.PlayerContainer;
import com.djrapitops.plan.data.store.keys.PlayerKeys;
import com.djrapitops.plan.data.store.mutators.PerServerDataMutator;
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.database.databases.Database;
@ -19,7 +24,6 @@ import com.djrapitops.plan.system.settings.theme.Theme;
import com.djrapitops.plan.system.settings.theme.ThemeVal;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.analysis.MathUtils;
import com.djrapitops.plan.utilities.comparators.SessionLengthComparator;
import com.djrapitops.plan.utilities.comparators.SessionStartComparator;
import com.djrapitops.plan.utilities.file.FileUtil;
@ -61,22 +65,22 @@ public class InspectPage extends Page {
}
Benchmark.start("Inspect Parse, Fetch");
Database db = Database.getActive();
PlayerProfile profile = db.fetch().getPlayerProfile(uuid);
if (profile == null) {
throw new IllegalStateException("Player profile was null!");
PlayerContainer container = db.fetch().getPlayerContainer(uuid);
if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) {
throw new IllegalStateException("Player is not registered");
}
UUID serverUUID = ServerInfo.getServerUUID();
Map<UUID, String> serverNames = db.fetch().getServerNames();
Benchmark.stop("Inspect Parse, Fetch");
return parse(profile, serverUUID, serverNames);
return parse(container, serverUUID, serverNames);
} catch (Exception e) {
throw new ParseException(e);
}
}
public String parse(PlayerProfile profile, UUID serverUUID, Map<UUID, String> serverNames) throws IOException {
public String parse(PlayerContainer container, UUID serverUUID, Map<UUID, String> serverNames) throws IOException {
long now = System.currentTimeMillis();
addValue("refresh", FormatUtils.formatTimeStampClock(now));
@ -88,44 +92,49 @@ public class InspectPage extends Page {
if (activeSession.isPresent()) {
Session session = activeSession.get();
session.setSessionID(Integer.MAX_VALUE);
profile.addActiveSession(session);
online = serverNames.get(serverUUID);
container.putRawData(PlayerKeys.ACTIVE_SESSION, session);
}
String playerName = profile.getName();
long registered = profile.getRegistered();
int timesKicked = profile.getTimesKicked();
long lastSeen = profile.getLastSeen();
String playerName = container.getValue(PlayerKeys.NAME).orElse("Unknown");
long registered = container.getValue(PlayerKeys.REGISTERED).orElse(-1L);
int timesKicked = container.getValue(PlayerKeys.KICK_COUNT).orElse(0);
long lastSeen = container.getValue(PlayerKeys.LAST_SEEN).orElse(-1L);
addValue("registered", FormatUtils.formatTimeStampYear(registered));
addValue("playerName", playerName);
addValue("kickCount", timesKicked);
addValue("lastSeen", lastSeen != 0 ? FormatUtils.formatTimeStampYear(lastSeen) : "-");
addValue("toLastSeen", lastSeen != 0 ? FormatUtils.formatTimeStampYear(lastSeen) : "-");
Map<UUID, WorldTimes> worldTimesPerServer = profile.getWorldTimesPerServer();
PerServerData perServerData = container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerData());
PerServerDataMutator perServerDataMutator = new PerServerDataMutator(perServerData);
Map<UUID, WorldTimes> worldTimesPerServer = perServerDataMutator.worldTimesPerServer();
addValue("serverPieSeries", new ServerPreferencePie(serverNames, worldTimesPerServer).toHighChartsSeries());
addValue("worldPieColors", Theme.getValue(ThemeVal.GRAPH_WORLD_PIE));
addValue("gmPieColors", Theme.getValue(ThemeVal.GRAPH_GM_PIE));
addValue("serverPieColors", Theme.getValue(ThemeVal.GRAPH_SERVER_PREF_PIE));
String favoriteServer = serverNames.get(profile.getFavoriteServer());
addValue("favoriteServer", favoriteServer != null ? favoriteServer : "Unknown");
String favoriteServer = serverNames.getOrDefault(perServerDataMutator.favoriteServer(), "Unknown");
addValue("favoriteServer", favoriteServer);
addValue("tableBodyNicknames", new NicknameTable(profile.getNicknames(), serverNames).parseBody());
addValue("tableBodyIPs", new GeoInfoTable(profile.getGeoInformation()).parseBody());
addValue("tableBodyNicknames", new NicknameTable(
container.getValue(PlayerKeys.NICKNAMES).orElse(new ArrayList<>()), serverNames)
.parseBody());
addValue("tableBodyIPs", new GeoInfoTable(container.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>())).parseBody());
Map<UUID, List<Session>> sessions = profile.getSessions();
Map<UUID, List<Session>> sessions = perServerDataMutator.sessionsPerServer();
Map<String, List<Session>> sessionsByServerName = sessions.entrySet().stream()
.collect(Collectors.toMap(entry -> serverNames.get(entry.getKey()), Map.Entry::getValue));
List<Session> allSessions = profile.getAllSessions()
.sorted(new SessionStartComparator())
.collect(Collectors.toList());
List<Session> allSessions = container.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>());
SessionsMutator allSessionsMutator = new SessionsMutator(allSessions);
allSessions.sort(new SessionStartComparator());
String[] sessionsAccordion = HtmlStructure.createSessionsTabContentInspectPage(sessionsByServerName, allSessions, uuid);
ServerAccordion serverAccordion = new ServerAccordion(profile, serverNames);
ServerAccordion serverAccordion = new ServerAccordion(container, worldTimesPerServer, serverNames);
PlayerCalendar playerCalendar = new PlayerCalendar(allSessions, registered);
@ -140,41 +149,41 @@ public class InspectPage extends Page {
long weekAgo = now - TimeAmount.WEEK.ms();
long monthAgo = now - TimeAmount.MONTH.ms();
List<Session> sessionsDay = profile.getSessions(dayAgo, now).collect(Collectors.toList());
List<Session> sessionsWeek = profile.getSessions(weekAgo, now).collect(Collectors.toList());
List<Session> sessionsMonth = profile.getSessions(monthAgo, now).collect(Collectors.toList());
SessionsMutator daySessionsMutator = new SessionsMutator(allSessions).filterSessionsBetween(dayAgo, now);
SessionsMutator weekSessionsMutator = new SessionsMutator(allSessions).filterSessionsBetween(weekAgo, now);
SessionsMutator monthSessionsMutator = new SessionsMutator(allSessions).filterSessionsBetween(monthAgo, now);
long playtime = PlayerProfile.getPlaytime(allSessions.stream());
long playtimeDay = PlayerProfile.getPlaytime(sessionsDay.stream());
long playtimeWeek = PlayerProfile.getPlaytime(sessionsWeek.stream());
long playtimeMonth = PlayerProfile.getPlaytime(sessionsMonth.stream());
long playtime = allSessionsMutator.toPlaytime();
long playtimeDay = daySessionsMutator.toPlaytime();
long playtimeWeek = weekSessionsMutator.toPlaytime();
long playtimeMonth = monthSessionsMutator.toPlaytime();
long afk = PlayerProfile.getAFKTime(allSessions.stream());
long afkDay = PlayerProfile.getAFKTime(sessionsDay.stream());
long afkWeek = PlayerProfile.getAFKTime(sessionsWeek.stream());
long afkMonth = PlayerProfile.getAFKTime(sessionsMonth.stream());
long afk = allSessionsMutator.toAfkTime();
long afkDay = daySessionsMutator.toAfkTime();
long afkWeek = weekSessionsMutator.toAfkTime();
long afkMonth = monthSessionsMutator.toAfkTime();
long activeTotal = playtime - afk;
long longestSession = PlayerProfile.getLongestSession(allSessions.stream());
long longestSessionDay = PlayerProfile.getLongestSession(sessionsDay.stream());
long longestSessionWeek = PlayerProfile.getLongestSession(sessionsWeek.stream());
long longestSessionMonth = PlayerProfile.getLongestSession(sessionsMonth.stream());
long longestSession = allSessionsMutator.toLongestSessionLength();
long longestSessionDay = daySessionsMutator.toLongestSessionLength();
long longestSessionWeek = weekSessionsMutator.toLongestSessionLength();
long longestSessionMonth = monthSessionsMutator.toLongestSessionLength();
long sessionMedian = PlayerProfile.getSessionMedian(allSessions.stream());
long sessionMedianDay = PlayerProfile.getSessionMedian(sessionsDay.stream());
long sessionMedianWeek = PlayerProfile.getSessionMedian(sessionsWeek.stream());
long sessionMedianMonth = PlayerProfile.getSessionMedian(sessionsMonth.stream());
long sessionMedian = allSessionsMutator.toMedianSessionLength();
long sessionMedianDay = daySessionsMutator.toMedianSessionLength();
long sessionMedianWeek = weekSessionsMutator.toMedianSessionLength();
long sessionMedianMonth = monthSessionsMutator.toMedianSessionLength();
int sessionCount = allSessions.size();
int sessionCountDay = sessionsDay.size();
int sessionCountWeek = sessionsWeek.size();
int sessionCountMonth = sessionsMonth.size();
int sessionCount = allSessionsMutator.count();
int sessionCountDay = daySessionsMutator.count();
int sessionCountWeek = weekSessionsMutator.count();
int sessionCountMonth = monthSessionsMutator.count();
long sessionAverage = MathUtils.averageLong(playtime, sessionCount);
long sessionAverageDay = MathUtils.averageLong(playtimeDay, sessionCountDay);
long sessionAverageWeek = MathUtils.averageLong(playtimeWeek, sessionCountWeek);
long sessionAverageMonth = MathUtils.averageLong(playtimeMonth, sessionCountMonth);
long sessionAverage = allSessionsMutator.toAverageSessionLength();
long sessionAverageDay = daySessionsMutator.toAverageSessionLength();
long sessionAverageWeek = weekSessionsMutator.toAverageSessionLength();
long sessionAverageMonth = monthSessionsMutator.toAverageSessionLength();
addValue("playtimeTotal", playtime > 0L ? FormatUtils.formatTimeAmount(playtime) : "-");
addValue("playtimeDay", playtimeDay > 0L ? FormatUtils.formatTimeAmount(playtimeDay) : "-");
@ -208,11 +217,10 @@ public class InspectPage extends Page {
addValue("sessionCountWeek", sessionCountWeek);
addValue("sessionCountMonth", sessionCountMonth);
List<Action> actions = profile.getAllActions();
addValue("tableBodyActions", new ActionsTable(actions).parseBody());
addValue("tableBodyActions", new ActionsTable(Collections.singletonList(new Action(0, Actions.UNKNOWN, "Deprecated"))).parseBody());
String punchCardData = new PunchCardGraph(allSessions).toHighChartsSeries();
WorldTimes worldTimes = profile.getWorldTimes();
WorldTimes worldTimes = container.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
WorldPie worldPie = new WorldPie(worldTimes);
@ -241,13 +249,15 @@ public class InspectPage extends Page {
addValue("mobKillCount", mobKillCount);
addValue("deathCount", deathCount);
ActivityIndex activityIndex = profile.getActivityIndex(now);
ActivityIndex activityIndex = new ActivityIndex(container, now);
addValue("activityIndexNumber", activityIndex.getFormattedValue());
addValue("activityIndexColor", activityIndex.getColor());
addValue("activityIndex", activityIndex.getGroup());
addValue("playerStatus", HtmlStructure.playerStatus(online, profile.getBannedOnServers(), profile.isOp()));
addValue("playerStatus", HtmlStructure.playerStatus(online,
container.getValue(PlayerKeys.BANNED).orElse(false),
container.getValue(PlayerKeys.OPERATOR).orElse(false)));
if (!InfoSystem.getInstance().getConnectionSystem().isServerAvailable()) {
addValue("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));

View File

@ -179,7 +179,7 @@ public class HtmlStructure {
"})</script>";
}
public static String playerStatus(String online, Set<UUID> banned, boolean op) {
public static String playerStatus(String online, boolean banned, boolean op) {
boolean offline = "offline".equalsIgnoreCase(online);
StringBuilder html = new StringBuilder("<p>");
@ -192,9 +192,8 @@ public class HtmlStructure {
if (op) {
html.append("<p>").append(Html.FA_COLORED_ICON.parse("blue", "superpowers")).append(" Operator</p>");
}
int bannedOn = banned.size();
if (bannedOn != 0) {
html.append("<p>").append(Html.FA_COLORED_ICON.parse("red", "gavel")).append(" Banned (").append(bannedOn).append(")");
if (banned) {
html.append("<p>").append(Html.FA_COLORED_ICON.parse("red", "gavel")).append(" Banned");
}
return html.toString();
}

View File

@ -6,6 +6,10 @@ package com.djrapitops.plan.utilities.html.structure;
import com.djrapitops.plan.data.PlayerProfile;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.containers.DataContainer;
import com.djrapitops.plan.data.store.containers.PerServerData;
import com.djrapitops.plan.data.store.containers.PlayerContainer;
import com.djrapitops.plan.data.store.keys.PlayerKeys;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.system.settings.theme.Theme;
import com.djrapitops.plan.system.settings.theme.ThemeVal;
@ -14,9 +18,7 @@ import com.djrapitops.plan.utilities.analysis.MathUtils;
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
import com.djrapitops.plugin.utilities.Format;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
/**
* HTML utility class for creating a Server Accordion.
@ -27,31 +29,43 @@ public class ServerAccordion extends AbstractAccordion {
private final StringBuilder viewScript;
public ServerAccordion(PlayerProfile profile, Map<UUID, String> serverNames) {
private final Map<UUID, String> serverNames;
private PerServerData perServer;
public ServerAccordion(PlayerContainer container, Map<UUID, WorldTimes> worldTimesPerServer, Map<UUID, String> serverNames) {
super("server_accordion");
viewScript = new StringBuilder();
Map<UUID, WorldTimes> worldTimesPerServer = profile.getWorldTimesPerServer();
if (worldTimesPerServer.isEmpty()) {
this.serverNames = serverNames;
Optional<PerServerData> perServerData = container.getValue(PlayerKeys.PER_SERVER);
if (perServerData.isPresent()) {
perServer = perServerData.get();
} else {
return;
}
addElements(profile, serverNames, worldTimesPerServer);
addElements();
}
public String toViewScript() {
return viewScript.toString();
}
private void addElements(PlayerProfile profile, Map<UUID, String> serverNames, Map<UUID, WorldTimes> worldTimesPerServer) {
private void addElements() {
int i = 0;
for (Map.Entry<UUID, WorldTimes> entry : worldTimesPerServer.entrySet()) {
for (Map.Entry<UUID, DataContainer> entry : perServer.entrySet()) {
UUID serverUUID = entry.getKey();
DataContainer container = entry.getValue();
String serverName = serverNames.getOrDefault(serverUUID, "Unknown");
WorldTimes worldTimes = entry.getValue();
WorldTimes worldTimes = container.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
List<Session> sessions = container.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>());
boolean banned = container.getValue(PlayerKeys.BANNED).orElse(false);
boolean opeator = container.getValue(PlayerKeys.OPERATOR).orElse(false);
long registered = container.getValue(PlayerKeys.REGISTERED).orElse(0L);
List<Session> sessions = profile.getSessions(serverUUID);
long playtime = PlayerProfile.getPlaytime(sessions.stream());
long afkTime = PlayerProfile.getAFKTime(sessions.stream());
int sessionCount = sessions.size();
@ -81,6 +95,11 @@ public class ServerAccordion extends AbstractAccordion {
String title = serverName + "<span class=\"pull-right\">" + play + "</span>";
String leftSide = new AccordionElementContentBuilder()
.addRowBold("blue", "superpowers", "Operator", opeator ? "Yes" : "No")
.addRowBold("red", "gavel", "Banned", banned ? "Yes" : "No")
.addRowBold("light-green", "user-plus", "Registered",
registered != 0 ? FormatUtils.formatTimeStampDay(registered) : "Not registered")
.addBreak()
.addRowBold("teal", "calendar-check-o", "Sessions", sessionCount)
.addRowBold("green", "clock-o", "Server Playtime", play)
.addRowBold("grey", "clock-o", "Time AFK", afk)

View File

@ -5,6 +5,8 @@
package com.djrapitops.plan.utilities.html.tables;
import com.djrapitops.plan.data.element.TableContainer;
import com.djrapitops.plan.data.store.objects.Nickname;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.html.HtmlUtils;
import java.util.List;
@ -18,7 +20,7 @@ import java.util.UUID;
*/
public class NicknameTable extends TableContainer {
public NicknameTable(Map<UUID, List<String>> nicknames, Map<UUID, String> serverNames) {
public NicknameTable(List<Nickname> nicknames, Map<UUID, String> serverNames) {
super("Nickname", "Server");
if (nicknames.isEmpty()) {
@ -28,15 +30,16 @@ public class NicknameTable extends TableContainer {
}
}
private void addValues(Map<UUID, List<String>> nicknames, Map<UUID, String> serverNames) {
for (Map.Entry<UUID, List<String>> entry : nicknames.entrySet()) {
String serverName = serverNames.getOrDefault(entry.getKey(), "Unknown");
for (String nick : entry.getValue()) {
addRow(
HtmlUtils.swapColorsToSpan(HtmlUtils.removeXSS(nick)),
serverName
);
}
private void addValues(List<Nickname> nicknames, Map<UUID, String> serverNames) {
for (Nickname nickname : nicknames) {
UUID serverUUID = nickname.getServerUUID();
String serverName = serverNames.getOrDefault(serverUUID, "Unknown");
long lastUsed = nickname.getLastUsed();
addRow(
HtmlUtils.swapColorsToSpan(HtmlUtils.removeXSS(nickname.getName())),
serverName,
lastUsed != 0 ? FormatUtils.formatTimeStampDay(lastUsed) : "-"
);
}
}
}