diff --git a/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java b/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java index 0449b8eae..34de9c505 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java @@ -156,7 +156,7 @@ public class PlayerProfile implements OfflinePlayer { if (longestSession.isPresent()) { return longestSession.getAsLong(); } - return 0L; + return -1; } public long getSessionMedian() { diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java index eff1b49fa..daca67c64 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java @@ -11,17 +11,14 @@ import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.api.IPlan; import main.java.com.djrapitops.plan.api.exceptions.ParseException; import main.java.com.djrapitops.plan.data.Action; -import main.java.com.djrapitops.plan.data.PlayerKill; +import main.java.com.djrapitops.plan.data.PlayerProfile; import main.java.com.djrapitops.plan.data.Session; -import main.java.com.djrapitops.plan.data.UserInfo; import main.java.com.djrapitops.plan.data.time.WorldTimes; import main.java.com.djrapitops.plan.database.Database; -import main.java.com.djrapitops.plan.database.tables.SessionsTable; -import main.java.com.djrapitops.plan.database.tables.UsersTable; import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; -import main.java.com.djrapitops.plan.utilities.comparators.ActionComparator; +import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; import main.java.com.djrapitops.plan.utilities.comparators.SessionLengthComparator; import main.java.com.djrapitops.plan.utilities.comparators.SessionStartComparator; import main.java.com.djrapitops.plan.utilities.file.FileUtil; @@ -32,7 +29,10 @@ import main.java.com.djrapitops.plan.utilities.html.graphs.ServerPreferencePieCr import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator; import main.java.com.djrapitops.plan.utilities.html.tables.ActionsTableCreator; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; /** @@ -56,103 +56,121 @@ public class InspectPageParser extends PageParser { Log.logDebug("Database", "Inspect Parse Fetch"); Benchmark.start("Inspect Parse, Fetch"); Database db = plugin.getDB(); - SessionsTable sessionsTable = db.getSessionsTable(); - UserInfo userInfo = db.getUserInfoTable().getUserInfo(uuid); - UsersTable usersTable = db.getUsersTable(); - String playerName = usersTable.getPlayerName(uuid); - Optional registerDate = usersTable.getRegisterDate(uuid); - if (registerDate.isPresent()) { - addValue("registered", FormatUtils.formatTimeStampYear(registerDate.get())); - } else { - addValue("registered", "-"); - } - - addValue("playerName", playerName); - int timesKicked = usersTable.getTimesKicked(uuid); + long now = MiscUtils.getTime(); + addValue("refresh", FormatUtils.formatTimeStamp(now)); addValue("version", MiscUtils.getPlanVersion()); addValue("timeZone", MiscUtils.getTimeZoneOffsetHours()); - long lastSeen = sessionsTable.getLastSeen(uuid); + PlayerProfile profile = db.getPlayerProfile(uuid); + + Benchmark.stop("Inspect Parse, Fetch"); + + String playerName = profile.getName(); + long registered = profile.getRegistered(); + int timesKicked = profile.getTimesKicked(); + long lastSeen = profile.getLastSeen(); + + addValue("registered", FormatUtils.formatTimeStampYear(registered)); + addValue("playerName", playerName); + addValue("kickCount", timesKicked); if (lastSeen != 0) { addValue("lastSeen", FormatUtils.formatTimeStampYear(lastSeen)); } else { addValue("lastSeen", "-"); } - addValue("kickCount", timesKicked); - Map playtimeByServer = sessionsTable.getPlaytimeByServer(uuid); - addValue("serverPieSeries", ServerPreferencePieCreator.createSeriesData(playtimeByServer)); + Map serverNames = db.getServerTable().getServerNames(); + Map worldTimesPerServer = profile.getWorldTimesPerServer(); + addValue("serverPieSeries", ServerPreferencePieCreator.createSeriesData(serverNames, worldTimesPerServer)); addValue("worldPieColors", Settings.THEME_GRAPH_WORLD_PIE.toString()); addValue("gmPieColors", Settings.THEME_GRAPH_GM_PIE.toString()); addValue("serverPieColors", Settings.THEME_GRAPH_SERVER_PREF_PIE.toString()); + // TODO IP Timestamp table // List geolocations = db.getIpsTable().getGeolocations(uuid); - List nicknames = db.getNicknamesTable().getNicknames(uuid).stream() + List nicknames = profile.getNicknames().stream() .map(HtmlUtils::swapColorsToSpan) .collect(Collectors.toList()); addValue("nicknames", HtmlStructure.createDotList(nicknames.toArray(new String[nicknames.size()]))); // addValue("geolocations", HtmlStructure.createDotList(geolocations.toArray(new String[geolocations.size()]))); - Map> sessions = sessionsTable.getSessions(uuid); - List allSessions = sessions.values().stream() - .flatMap(Collection::stream) - .sorted(new SessionStartComparator()) // Sorted Newest first. + Map> sessions = profile.getSessions(); + Map> sessionsByServerName = sessions.entrySet().stream() + .collect(Collectors.toMap(entry -> serverNames.get(entry.getKey()), Map.Entry::getValue)); + + List allSessions = profile.getAllSessions() + .sorted(new SessionStartComparator()) .collect(Collectors.toList()); -// String[] sessionsTabContent = HtmlStructure.createSessionsTabContentInspectPage(sessions, allSessions, uuid); -// addValue("contentSessions", sessionsTabContent[0]); -// addValue("sessionTabGraphViewFunctions", sessionsTabContent[1]); -// addValue("contentServerOverview", HtmlStructure.createServerOverviewColumn(sessions)); - - long now = MiscUtils.getTime(); - - addValue("refresh", FormatUtils.formatTimeStamp(now)); + String[] sessionsTabContent = HtmlStructure.createSessionsTabContentInspectPage(sessionsByServerName, allSessions, uuid); + addValue("contentSessions", sessionsTabContent[0]); + addValue("sessionTabGraphViewFunctions", sessionsTabContent[1]); + addValue("contentServerOverview", HtmlStructure.createServerOverviewColumn(sessionsByServerName)); long dayAgo = now - TimeAmount.DAY.ms(); long weekAgo = now - TimeAmount.WEEK.ms(); + long monthAgo = now - TimeAmount.MONTH.ms(); - List sessionsDay = allSessions.stream() - .filter(s -> s.getSessionStart() > dayAgo) - .sorted(new SessionLengthComparator()) - .collect(Collectors.toList()); - List sessionsWeek = allSessions.stream() - .filter(s -> s.getSessionStart() > weekAgo) - .sorted(new SessionLengthComparator()) - .collect(Collectors.toList()); + List sessionsDay = profile.getSessions(dayAgo, now).collect(Collectors.toList()); + List sessionsWeek = profile.getSessions(weekAgo, now).collect(Collectors.toList()); + List sessionsMonth = profile.getSessions(monthAgo, now).collect(Collectors.toList()); + 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 longestSession = PlayerProfile.getLongestSession(allSessions.stream()); + long longestSessionDay = PlayerProfile.getLongestSession(sessionsDay.stream()); + long longestSessionWeek = PlayerProfile.getLongestSession(sessionsWeek.stream()); + long longestSessionMonth = PlayerProfile.getLongestSession(sessionsMonth.stream()); + + long sessionMedian = PlayerProfile.getSessionMedian(allSessions.stream()); + long sessionMedianDay = PlayerProfile.getSessionMedian(sessionsDay.stream()); + long sessionMedianWeek = PlayerProfile.getSessionMedian(sessionsWeek.stream()); + long sessionMedianMonth = PlayerProfile.getSessionMedian(sessionsMonth.stream()); + + int sessionCount = allSessions.size(); int sessionCountDay = sessionsDay.size(); int sessionCountWeek = sessionsWeek.size(); - long playtimeDay = AnalysisUtils.getTotalPlaytime(sessionsDay); - long playtimeWeek = AnalysisUtils.getTotalPlaytime(sessionsWeek); + int sessionCountMonth = sessionsMonth.size(); - addValue("sessionLengthLongestDay", !sessionsDay.isEmpty() ? FormatUtils.formatTimeAmount(sessionsDay.get(0).getLength()) : "-"); - addValue("sessionLengthLongestWeek", !sessionsWeek.isEmpty() ? FormatUtils.formatTimeAmount(sessionsWeek.get(0).getLength()) : "-"); + long sessionAverage = MathUtils.averageLong(playtime, sessionCount); + long sessionAverageDay = MathUtils.averageLong(playtimeDay, sessionCountDay); + long sessionAverageWeek = MathUtils.averageLong(playtimeWeek, sessionCountWeek); + long sessionAverageMonth = MathUtils.averageLong(playtimeMonth, sessionCountMonth); - addValue("sessionCountDay", sessionCountDay); - addValue("sessionCountWeek", sessionCountWeek); - addValue("playtimeDay", FormatUtils.formatTimeAmount(playtimeDay)); - addValue("playtimeWeek", FormatUtils.formatTimeAmount(playtimeWeek)); + addValue("playtimeTotal", playtime > 0L ? FormatUtils.formatTimeAmount(playtime) : "-"); + addValue("playtimeDay", playtimeDay > 0L ? FormatUtils.formatTimeAmount(playtimeDay) : "-"); + addValue("playtimeWeek", playtimeWeek > 0L ? FormatUtils.formatTimeAmount(playtimeWeek) : "-"); + addValue("playtimeMonth", playtimeMonth > 0L ? FormatUtils.formatTimeAmount(playtimeMonth) : "-"); - List actions = db.getActionsTable().getActions(uuid); - actions.addAll(allSessions.stream() - .map(Session::getPlayerKills) - .flatMap(Collection::stream) - .map(PlayerKill::convertToAction) - .collect(Collectors.toList())); - actions.sort(new ActionComparator()); + addValue("sessionLengthLongest", longestSession > 0L ? FormatUtils.formatTimeAmount(longestSession) : "-"); + addValue("sessionLongestDay", longestSessionDay > 0L ? FormatUtils.formatTimeAmount(longestSessionDay) : "-"); + addValue("sessionLongestWeek", longestSessionWeek > 0L ? FormatUtils.formatTimeAmount(longestSessionWeek) : "-"); + addValue("sessionLongestMonth", longestSessionMonth > 0L ? FormatUtils.formatTimeAmount(longestSessionMonth) : "-"); - addValue("tableBodyActions", ActionsTableCreator.createTable(actions)); + addValue("sessionLengthMedian", sessionMedian > 0L ? FormatUtils.formatTimeAmount(sessionMedian) : "-"); + addValue("sessionMedianDay", sessionMedianDay > 0L ? FormatUtils.formatTimeAmount(sessionMedianDay) : "-"); + addValue("sessionMedianWeek", sessionMedianWeek > 0L ? FormatUtils.formatTimeAmount(sessionMedianWeek) : "-"); + addValue("sessionMedianMonth", sessionMedianMonth > 0L ? FormatUtils.formatTimeAmount(sessionMedianMonth) : "-"); - Benchmark.stop("Inspect Parse, Fetch"); + addValue("sessionAverage", sessionAverage > 0L ? FormatUtils.formatTimeAmount(sessionAverage) : "-"); + addValue("sessionAverageDay", sessionAverageDay > 0L ? FormatUtils.formatTimeAmount(sessionAverageDay) : "-"); + addValue("sessionAverageWeek", sessionAverageWeek > 0L ? FormatUtils.formatTimeAmount(sessionAverageWeek) : "-"); + addValue("sessionAverageMonth", sessionAverageMonth > 0L ? FormatUtils.formatTimeAmount(sessionAverageMonth) : "-"); - long playTime = AnalysisUtils.getTotalPlaytime(allSessions); - int sessionCount = allSessions.size(); addValue("sessionCount", sessionCount); - addValue("playtimeTotal", FormatUtils.formatTimeAmount(playTime)); + addValue("sessionCountDay", sessionCountDay); + addValue("sessionCountWeek", sessionCountWeek); + addValue("sessionCountMonth", sessionCountMonth); + + List actions = profile.getAllActions(); + addValue("tableBodyActions", ActionsTableCreator.createTable(actions)); String punchCardData = PunchCardGraphCreator.createDataSeries(allSessions); WorldTimes worldTimes = db.getWorldTimesTable().getWorldTimesOfUser(uuid); @@ -185,13 +203,9 @@ public class InspectPageParser extends PageParser { addValue("mobKillCount", mobKillCount); addValue("deathCount", deathCount); - boolean isActive = AnalysisUtils.isActive(MiscUtils.getTime(), lastSeen, playTime, sessionCount); + boolean isActive = AnalysisUtils.isActive(MiscUtils.getTime(), lastSeen, playtime, sessionCount); String active = isActive ? "Active" : "Inactive"; - if (userInfo != null) { - playerClassification(userInfo, active); - } else { - addValue("playerClassification", active); - } + playerClassification(profile, active); if (!plugin.getInfoManager().isUsingAnotherWebServer()) { addValue("networkName", Settings.SERVER_NAME.toString()); @@ -204,14 +218,13 @@ public class InspectPageParser extends PageParser { } } - private void playerClassification(UserInfo userInfo, String active) { - boolean isBanned = userInfo.isBanned(); - boolean isOP = userInfo.isOpped(); + private void playerClassification(PlayerProfile profile, String active) { + boolean isBanned = profile.isBanned(); + boolean isOP = profile.isOp(); String banned = isBanned ? "Banned" : ""; String op = isOP ? "Operator (OP)" : ""; addValue("playerClassification", HtmlStructure.separateWithDots(active, banned, op)); } - } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java index cfc76848e..0f1e9ef74 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java @@ -95,6 +95,9 @@ public class MathUtils { * @see #average(int, int) */ public static long averageLong(long total, long size) { + if (size == 0) { + return -1L; + } return total / size; } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java index e259f73b3..31d23e711 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java @@ -58,6 +58,7 @@ public class HtmlStructure { return builder.toString(); } + @Deprecated public static String createServerOverviewColumn(Map> sessions) { StringBuilder builder = new StringBuilder("
"); if (Verify.isEmpty(sessions)) { @@ -91,6 +92,7 @@ public class HtmlStructure { return builder.toString(); } + @Deprecated public static String[] createSessionsTabContentInspectPage(Map> sessions, List allSessions, UUID uuid) { Map>> map = new HashMap<>(); map.put(uuid, sessions); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/ServerPreferencePieCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/ServerPreferencePieCreator.java index bcb2ed498..b74b0e752 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/ServerPreferencePieCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/ServerPreferencePieCreator.java @@ -1,6 +1,9 @@ package main.java.com.djrapitops.plan.utilities.html.graphs; +import main.java.com.djrapitops.plan.data.time.WorldTimes; + import java.util.Map; +import java.util.UUID; public class ServerPreferencePieCreator { @@ -8,14 +11,14 @@ public class ServerPreferencePieCreator { throw new IllegalStateException("Utility Class"); } - public static String createSeriesData(Map serverPlaytimes) { + public static String createSeriesData(Map serverNames, Map serverWorldTimes) { StringBuilder seriesBuilder = new StringBuilder("["); int i = 0; - int size = serverPlaytimes.size(); - for (Map.Entry server : serverPlaytimes.entrySet()) { - String serverName = server.getKey(); + int size = serverWorldTimes.size(); + for (Map.Entry server : serverWorldTimes.entrySet()) { + String serverName = serverNames.getOrDefault(server.getKey(), "Unknown"); seriesBuilder.append("{name:'").append(serverName) - .append("',y:").append(server.getValue()); + .append("',y:").append(server.getValue().getTotal()); seriesBuilder.append("}"); if (i < size - 1) {