From 150c4825fd8994a42e5a5f08164211f897985507 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 28 Aug 2017 21:31:00 +0300 Subject: [PATCH] Inspect Page Parsing. (Fixes Inspect command) --- .../plan/command/commands/InspectCommand.java | 15 +- .../plan/systems/info/InformationManager.java | 18 +- .../info/parsing/InspectPageParser.java | 172 ++++++++++++++++++ .../utilities/analysis/AnalysisUtils.java | 11 +- .../comparators/ActionComparator.java | 19 ++ .../comparators/SessionLengthComparator.java | 16 ++ ...rator.java => SessionStartComparator.java} | 2 +- .../djrapitops/plan/utilities/html/Html.java | 2 +- .../plan/utilities/html/HtmlStructure.java | 148 +++++++++++++++ .../html/tables/ActionsTableCreator.java | 49 +++++ .../html/tables/KillsTableCreator.java | 2 +- Plan/src/main/resources/main.css | 2 +- .../utilities/html/HtmlStructureTest.java | 60 ++++++ .../utilities/comparators/ComparatorTest.java | 2 +- 14 files changed, 506 insertions(+), 12 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/utilities/comparators/ActionComparator.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionLengthComparator.java rename Plan/src/main/java/com/djrapitops/plan/utilities/comparators/{SessionDataComparator.java => SessionStartComparator.java} (82%) create mode 100644 Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/ActionsTableCreator.java create mode 100644 Plan/test/main/java/com/djrapitops/plan/utilities/html/HtmlStructureTest.java diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java index 17a858cc7..a7210254d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java @@ -13,6 +13,9 @@ import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.command.ConditionUtils; import main.java.com.djrapitops.plan.locale.Locale; import main.java.com.djrapitops.plan.locale.Msg; +import main.java.com.djrapitops.plan.systems.processing.Processor; +import main.java.com.djrapitops.plan.systems.webserver.PageCache; +import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse; import main.java.com.djrapitops.plan.utilities.Check; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; @@ -87,8 +90,14 @@ public class InspectCommand extends SubCommand { sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register "); } } - //TODO Inspect Request. - runMessageSenderTask(uuid, sender, playerName); + + plugin.addToProcessQueue(new Processor(uuid) { + @Override + public void process() { + PageCache.loadPage("inspectPage: " + uuid, () -> new InspectPageResponse(plugin.getInfoManager(), uuid)); + sendInspectMsg(sender, playerName); + } + }); } catch (SQLException ex) { Log.toLog(this.getClass().getName(), ex); } finally { @@ -116,7 +125,7 @@ public class InspectCommand extends SubCommand { }).runTaskTimer(TimeAmount.SECOND.ticks(), 5 * TimeAmount.SECOND.ticks()); } - private void sendInspectMsg(ISender sender, String playerName, UUID uuid) { + private void sendInspectMsg(ISender sender, String playerName) { sender.sendMessage(Locale.get(Msg.CMD_HEADER_INSPECT) + " " + playerName); // Link String url = HtmlUtils.getInspectUrlWithProtocol(playerName); diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java index 1e9029378..09d59a1d0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java @@ -5,6 +5,7 @@ package main.java.com.djrapitops.plan.systems.info; import com.djrapitops.plugin.command.ISender; +import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.bungee.PlanBungee; import main.java.com.djrapitops.plan.command.commands.AnalyzeCommand; @@ -12,10 +13,14 @@ import main.java.com.djrapitops.plan.data.AnalysisData; import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.systems.cache.DataCache; import main.java.com.djrapitops.plan.systems.cache.SessionCache; +import main.java.com.djrapitops.plan.systems.info.parsing.InspectPageParser; import main.java.com.djrapitops.plan.systems.info.parsing.UrlParser; +import main.java.com.djrapitops.plan.systems.webserver.PageCache; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.Analysis; +import java.io.FileNotFoundException; +import java.sql.SQLException; import java.util.HashSet; import java.util.Optional; import java.util.Set; @@ -92,12 +97,19 @@ public class InformationManager { } public boolean isCached(UUID uuid) { - // TODO - return false; + if (usingBungeeWebServer) { + // TODO bungee part + } + return PageCache.isCached("inspectPage: " + uuid); } public String getPlayerHtml(UUID uuid) { - // TODO + // TODO Bungee part. + try { + return new InspectPageParser(uuid, plugin).parse(); + } catch (SQLException | FileNotFoundException e) { + Log.toLog(this.getClass().getName(), e); + } return ""; } 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 new file mode 100644 index 000000000..cdf1fb826 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java @@ -0,0 +1,172 @@ +/* + * Licence is provided in the jar as license.yml also here: + * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml + */ +package main.java.com.djrapitops.plan.systems.info.parsing; + +import com.djrapitops.plugin.api.TimeAmount; +import main.java.com.djrapitops.plan.Log; +import main.java.com.djrapitops.plan.Settings; +import main.java.com.djrapitops.plan.api.IPlan; +import main.java.com.djrapitops.plan.data.Action; +import main.java.com.djrapitops.plan.data.PlayerKill; +import main.java.com.djrapitops.plan.data.Session; +import main.java.com.djrapitops.plan.data.UserInfo; +import main.java.com.djrapitops.plan.database.Database; +import main.java.com.djrapitops.plan.database.tables.SessionsTable; +import main.java.com.djrapitops.plan.utilities.Benchmark; +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.comparators.SessionLengthComparator; +import main.java.com.djrapitops.plan.utilities.comparators.SessionStartComparator; +import main.java.com.djrapitops.plan.utilities.file.FileUtil; +import main.java.com.djrapitops.plan.utilities.html.HtmlStructure; +import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; +import main.java.com.djrapitops.plan.utilities.html.graphs.PunchCardGraphCreator; +import main.java.com.djrapitops.plan.utilities.html.tables.ActionsTableCreator; + +import java.io.FileNotFoundException; +import java.io.Serializable; +import java.sql.SQLException; +import java.util.*; +import java.util.stream.Collectors; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public class InspectPageParser { + + private final UUID uuid; + private final IPlan plugin; + + private final Map placeHolders; + + public InspectPageParser(UUID uuid, IPlan plugin) { + this.uuid = uuid; + this.plugin = plugin; + placeHolders = new HashMap<>(); + } + + public String parse() throws SQLException, FileNotFoundException { + Log.debug("Database", "Inspect Parse Fetch"); + Benchmark.start("Inspect Parse, Fetch"); + Database db = plugin.getDB(); + UserInfo userInfo = db.getUserInfoTable().getUserInfo(uuid); + int timesKicked = db.getUsersTable().getTimesKicked(uuid); + + addValue("version", MiscUtils.getPlanVersion()); + addValue("serverName", Settings.SERVER_NAME.toString()); + + addValue("playerName", userInfo.getName()); + addValue("registered", FormatUtils.formatTimeStampYear(userInfo.getRegistered())); + long lastSeen = userInfo.getLastSeen(); + addValue("lastSeen", FormatUtils.formatTimeStampYear(lastSeen)); + addValue("kickCount", timesKicked); + + SessionsTable sessionsTable = db.getSessionsTable(); + Map playtimeByServer = sessionsTable.getPlaytimeByServer(uuid); + + List geolocations = db.getIpsTable().getGeolocations(uuid); + List nicknames = db.getNicknamesTable().getNicknames(uuid).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()) + .collect(Collectors.toList()); + + addValue("contentSessions", HtmlStructure.createSessionsTabContent(sessions, allSessions)); + addValue("contentServerOverview", HtmlStructure.createServerOverviewColumn(sessions)); + + long now = MiscUtils.getTime(); + long dayAgo = now - TimeAmount.DAY.ms(); + long weekAgo = now - TimeAmount.WEEK.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()); + + int sessionCountDay = sessionsDay.size(); + int sessionCountWeek = sessionsDay.size(); + long playtimeDay = AnalysisUtils.getTotalPlaytime(sessionsDay); + long playtimeWeek = AnalysisUtils.getTotalPlaytime(sessionsWeek); + + addValue("sessionCountDay", sessionCountDay); + addValue("sessionCountWeek", sessionCountWeek); + addValue("playtimeDay", FormatUtils.formatTimeAmount(playtimeDay)); + addValue("playtimeWeek", FormatUtils.formatTimeAmount(playtimeWeek)); + + 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("tableBodyActions", ActionsTableCreator.createTableContent(actions)); + + Benchmark.stop("Inspect Parse, Fetch"); + + long playTime = AnalysisUtils.getTotalPlaytime(allSessions); + int sessionCount = allSessions.size(); + + addValue("sessionCount", sessionCount); + addValue("playtimeTotal", FormatUtils.formatTimeAmount(playTime)); + addValue("lastSeen", FormatUtils.formatTimeAmount(playTime)); + + String puchCardData = PunchCardGraphCreator.createDataSeries(allSessions); + List sessionsInLengthOrder = allSessions.stream().sorted(new SessionLengthComparator()).collect(Collectors.toList()); + if (sessionsInLengthOrder.isEmpty()) { + addValue("sessionLengthMedian", "No Sessions"); + addValue("sessionLengthLongest", "No Sessions"); + } else { + Session medianSession = sessionsInLengthOrder.get(sessionsInLengthOrder.size() / 2); + addValue("sessionLengthMedian", FormatUtils.formatTimeAmount(medianSession.getLength())); + addValue("sessionLengthLongest", FormatUtils.formatTimeAmount(sessionsInLengthOrder.get(0).getLength())); + } + + long playerKillCount = allSessions.stream().map(Session::getPlayerKills).mapToLong(Collection::size).sum(); + long mobKillCount = allSessions.stream().mapToLong(Session::getMobKills).sum(); + long deathCount = allSessions.stream().mapToLong(Session::getDeaths).sum(); + + addValue("playerKillCount", playerKillCount); + addValue("mobKillCount", mobKillCount); + addValue("deathCount", deathCount); + + + playerClassification(userInfo, lastSeen, playTime, sessionCount); + + return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("player.html"), placeHolders); + } + + private void playerClassification(UserInfo userInfo, long lastPlayed, long playTime, int loginTimes) { + boolean isBanned = userInfo.isBanned(); + boolean isOP = userInfo.isOpped(); + boolean isActive = AnalysisUtils.isActive(MiscUtils.getTime(), lastPlayed, playTime, loginTimes); + + String active = isActive ? "Active" : "Inactive"; + String banned = isBanned ? "Banned" : ""; + String op = isOP ? "Operator (OP)" : ""; + + addValue("playerclassification", HtmlStructure.separateWithDots(active, banned, op)); + } + + private void addValue(String placeholder, Serializable value) { + placeHolders.put(placeholder, value); + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java index 7b6f7488c..94915b05a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java @@ -6,6 +6,7 @@ import main.java.com.djrapitops.plan.data.additional.AnalysisType; import main.java.com.djrapitops.plan.data.additional.PluginData; import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils; +import main.java.com.djrapitops.plan.utilities.comparators.SessionLengthComparator; import java.io.Serializable; import java.util.*; @@ -32,7 +33,6 @@ public class AnalysisUtils { * @return */ public static boolean isActive(long now, long lastPlayed, long playTime, int loginTimes) { - int timeToActive = 10; long twoWeeks = 1209600000; return now - lastPlayed < twoWeeks @@ -318,4 +318,13 @@ public class AnalysisUtils { day.setTimeInMillis(date); return day.get(Calendar.DAY_OF_YEAR); } + + public static long getTotalPlaytime(List sessions) { + return sessions.stream().mapToLong(Session::getLength).sum(); + } + + public static long getLongestSessionLength(List sessions) { + Optional longest = sessions.stream().sorted(new SessionLengthComparator()).findFirst(); + return longest.map(Session::getLength).orElse(0L); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/ActionComparator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/ActionComparator.java new file mode 100644 index 000000000..028baef9b --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/ActionComparator.java @@ -0,0 +1,19 @@ +package main.java.com.djrapitops.plan.utilities.comparators; + +import main.java.com.djrapitops.plan.data.Action; + +import java.util.Comparator; + +/** + * Comparator for comparing Actions so that latest is the first component. + * + * @author Rsl1122 + */ +public class ActionComparator implements Comparator { + + @Override + public int compare(Action o1, Action o2) { + return -Long.compare(o1.getDate(), o2.getDate()); + } + +} diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionLengthComparator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionLengthComparator.java new file mode 100644 index 000000000..3855c2828 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionLengthComparator.java @@ -0,0 +1,16 @@ +package main.java.com.djrapitops.plan.utilities.comparators; + +import main.java.com.djrapitops.plan.data.Session; + +import java.util.Comparator; + +/** + * @author Rsl1122 + */ +public class SessionLengthComparator implements Comparator { + + @Override + public int compare(Session s1, Session s2) { + return Long.compare(s1.getLength(), s2.getLength()); + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionDataComparator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionStartComparator.java similarity index 82% rename from Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionDataComparator.java rename to Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionStartComparator.java index 8ec31de9c..6d9f90d7d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionDataComparator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionStartComparator.java @@ -7,7 +7,7 @@ import java.util.Comparator; /** * @author Rsl1122 */ -public class SessionDataComparator implements Comparator { +public class SessionStartComparator implements Comparator { @Override public int compare(Session s1, Session s2) { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java index 8b15742bc..711dba7a7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java @@ -42,7 +42,7 @@ public enum Html { TABLE_START_3(""), TABLE_START_4("
${0}${1}${2}
"), TABLE_SESSIONS_START(TABLE_START_3.parse("Session Started", "Session Ended", "Session Length")), - TABLE_KILLS_START(TABLE_START_3.parse("Date", "Killed", "With")), + TABLE_KILLS_START(TABLE_START_3.parse(FONT_AWESOME_ICON.parse("clock-o") + " Time", "Killed", "With")), TABLE_FACTIONS_START(TABLE_START_4.parse(FONT_AWESOME_ICON.parse("flag") + " Faction", FONT_AWESOME_ICON.parse("bolt") + " Power", FONT_AWESOME_ICON.parse("map-o") + " Land", FONT_AWESOME_ICON.parse("user") + " Leader")), TABLE_TOWNS_START(TABLE_START_4.parse(FONT_AWESOME_ICON.parse("bank") + " Town", FONT_AWESOME_ICON.parse("users") + " Residents", FONT_AWESOME_ICON.parse("map-o") + " Land", FONT_AWESOME_ICON.parse("user") + " Mayor")), TABLELINE_2(""), 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 31766e869..ff6b3948d 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 @@ -4,10 +4,158 @@ */ package main.java.com.djrapitops.plan.utilities.html; +import main.java.com.djrapitops.plan.data.Session; +import main.java.com.djrapitops.plan.utilities.FormatUtils; +import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; +import main.java.com.djrapitops.plan.utilities.html.tables.KillsTableCreator; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * Class for parsing layout components of the websites. * * @author Rsl1122 */ public class HtmlStructure { + + public static String separateWithDots(String... elements) { + if (elements.length == 0) { + return ""; + } + StringBuilder builder = new StringBuilder(elements[0]); + for (int i = 1; i < elements.length; i++) { + String element = elements[i]; + if (element.isEmpty()) { + continue; + } + builder.append(" • "); + builder.append(element); + } + return builder.toString(); + } + + public static String createDotList(String... elements) { + if (elements.length == 0) { + return ""; + } + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < elements.length; i++) { + String element = elements[i]; + if (element.isEmpty()) { + continue; + } + builder.append("• "); + builder.append(element); + if (i < elements.length - 1) { + builder.append("
"); + } + } + return builder.toString(); + } + + public static String createServerOverviewColumn(Map> sessions) { + StringBuilder builder = new StringBuilder("
"); + for (Map.Entry> entry : sessions.entrySet()) { + String serverName = entry.getKey(); + List serverSessions = entry.getValue(); + + // Header + builder.append("

").append(serverName).append("

"); + + // White box + builder.append("
"); + + // Content + builder.append("

Sessions: ").append(serverSessions.size()).append("
"); + long playTime = AnalysisUtils.getTotalPlaytime(serverSessions); + builder.append("Playtime: ").append(FormatUtils.formatTimeAmount(playTime)).append("
"); + builder.append("
"); + long longestSessionLength = AnalysisUtils.getLongestSessionLength(serverSessions); + builder.append("Longest Session: " + FormatUtils.formatTimeAmount(longestSessionLength)); + + // Content and box end + builder.append("

"); + + } + // Column ends + builder.append("
"); + return builder.toString(); + } + + public static String createSessionsTabContent(Map> sessions, List allSessions) { + Map serverNameIDRelationMap = new HashMap<>(); + + for (Map.Entry> entry : sessions.entrySet()) { + String serverName = entry.getKey(); + List serverSessions = entry.getValue(); + for (Session session : serverSessions) { + serverNameIDRelationMap.put(session.getSessionID(), serverName); + } + } + + StringBuilder builder = new StringBuilder(); + int i = 0; + for (Session session : allSessions) { + if (i >= 50) { + break; + } + + String sessionStart = FormatUtils.formatTimeStampYear(session.getSessionStart()); + String sessionLength = FormatUtils.formatTimeAmount(session.getLength()); + String sessionEnd = FormatUtils.formatTimeStampYear(session.getSessionEnd()); + + String dotSeparated = separateWithDots(sessionStart, sessionLength); + + // Session-column starts & header. + builder.append("
") + .append("
") + .append("
") + .append("

").append(dotSeparated).append("

") + .append("

Click to Expand

") + .append("
") + .append("
"); + + String serverName = serverNameIDRelationMap.get(session.getSessionID()); + + // Left side of Session box + builder.append("
") + .append("
") // + .append("
"); + + // Left side header + builder.append("
") + .append("

") + .append(sessionStart) + .append("

") + .append("
"); + + // Left side content + builder.append("
") + .append("

Session Length: ").append(sessionLength).append("
") + .append("Session Ended: ").append(sessionEnd).append("
") + .append("Server: ").append(serverName).append("

") + .append("Mob Kills: ").append(session.getMobKills()).append("
") + .append("Deaths: ").append(session.getDeaths()).append("

"); + + builder.append(KillsTableCreator.createTable(session.getPlayerKills())) + .append("
"); // Left Side content ends + + // Left side ends & Right side starts + builder.append("
") + .append("
"); + + // TODO WorldTimes Pie + + // Session-col, Row, Session-Content, Session-column ends. + builder.append("
") + .append("
") + .append("
") + .append("
"); + + i++; + } + return builder.toString(); + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/ActionsTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/ActionsTableCreator.java new file mode 100644 index 000000000..69a346f0d --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/ActionsTableCreator.java @@ -0,0 +1,49 @@ +/* + * Licence is provided in the jar as license.yml also here: + * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml + */ +package main.java.com.djrapitops.plan.utilities.html.tables; + +import main.java.com.djrapitops.plan.data.Action; +import main.java.com.djrapitops.plan.utilities.FormatUtils; +import main.java.com.djrapitops.plan.utilities.html.Html; + +import java.util.List; + +/** + * Utility Class for creating Actions Table for inspect page. + * + * @author Rsl1122 + */ +public class ActionsTableCreator { + + + public ActionsTableCreator() { + throw new IllegalStateException("Utility class"); + } + + public static String createTableContent(List actions) { + StringBuilder html = new StringBuilder(); + if (actions.isEmpty()) { + html.append(Html.TABLELINE_3.parse("", "", "")); + } else { + int i = 0; + for (Action action : actions) { + if (i >= 100) { + break; + } + + long date = action.getDate(); + + html.append(Html.TABLELINE_3_CUSTOMKEY_1.parse( + String.valueOf(date), FormatUtils.formatTimeStamp(date), + action.getDoneAction().toString(), + action.getAdditionalInfo() + )); + + i++; + } + } + return html.toString(); + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/KillsTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/KillsTableCreator.java index 72c4ac8ca..7bbd19231 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/KillsTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/KillsTableCreator.java @@ -29,7 +29,7 @@ public class KillsTableCreator { * @param playerKills The list of the {@link PlayerKill} Objects from which the kill table should be created * @return The created kills table */ - public static String createKillsTable(List playerKills) { + public static String createTable(List playerKills) { StringBuilder html = new StringBuilder(Html.TABLE_KILLS_START.parse()); if (playerKills.isEmpty()) { diff --git a/Plan/src/main/resources/main.css b/Plan/src/main/resources/main.css index 5562a49eb..0eec2fb2d 100644 --- a/Plan/src/main/resources/main.css +++ b/Plan/src/main/resources/main.css @@ -217,7 +217,7 @@ tr:nth-child(odd) {background: #eee} transform: translate3d(0, 0, 0); opacity: 0; transition: 1.5s; - width: 100%; + width: 500%; display: flex; flex-direction: row; } diff --git a/Plan/test/main/java/com/djrapitops/plan/utilities/html/HtmlStructureTest.java b/Plan/test/main/java/com/djrapitops/plan/utilities/html/HtmlStructureTest.java new file mode 100644 index 000000000..0586dd227 --- /dev/null +++ b/Plan/test/main/java/com/djrapitops/plan/utilities/html/HtmlStructureTest.java @@ -0,0 +1,60 @@ +package main.java.com.djrapitops.plan.utilities.html; + +import main.java.com.djrapitops.plan.data.Session; +import org.apache.commons.lang.StringUtils; +import org.bukkit.plugin.java.JavaPlugin; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import test.java.utils.TestInit; + +import java.util.*; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest(JavaPlugin.class) +public class HtmlStructureTest { + + private Map> sessions; + + @Before + public void setUp() throws Exception { + TestInit t = TestInit.init(); + sessions = new HashMap<>(); + sessions.put("World 1", new ArrayList<>()); + sessions.get("World 1").add(new Session(1, 12345L, 23455L, 1, 2)); + sessions.get("World 1").add(new Session(2, 23455L, 23457L, 1, 2)); + sessions.put("World 2", new ArrayList<>()); + sessions.get("World 2").add(new Session(3, 23455L, 23457L, 1, 2)); + } + + @Test + public void createServerOverviewColumn() throws Exception { + String serverOverviewColumn = HtmlStructure.createServerOverviewColumn(sessions); + int opened = StringUtils.countMatches(serverOverviewColumn, " allSessions = sessions.values().stream().flatMap(Collection::stream).collect(Collectors.toList()); + String sessionsTab = HtmlStructure.createSessionsTabContent(sessions, allSessions); + int opened = StringUtils.countMatches(sessionsTab, " test = RandomData.randomSessions(); List longValues = test.stream().map(Session::getSessionStart).collect(Collectors.toList()); longValues.sort(Long::compare); - test.sort(new SessionDataComparator()); + test.sort(new SessionStartComparator()); List afterSort = test.stream().map(Session::getSessionStart).collect(Collectors.toList()); assertEquals(longValues, afterSort); }
${0}${1}${2}${3}
${0}${1}