diff --git a/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java b/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java index 46feb38ed..04d3c69cb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java +++ b/Plan/src/main/java/com/djrapitops/plan/ServerVariableHolder.java @@ -11,7 +11,6 @@ import org.bukkit.Server; */ public class ServerVariableHolder { - private final int maxPlayers; private final String ip; private final boolean usingPaper; @@ -21,7 +20,6 @@ public class ServerVariableHolder { * @param server instance the plugin is running on. */ public ServerVariableHolder(Server server) { - maxPlayers = server.getMaxPlayers(); ip = server.getIp(); String serverName = server.getName(); @@ -29,15 +27,6 @@ public class ServerVariableHolder { || serverName.equals("TacoSpigot"); //Fork of Paper } - /** - * Maximum amount of players defined in server.properties. - * - * @return number. - */ - public int getMaxPlayers() { - return maxPlayers; - } - /** * Ip string in server.properties. * diff --git a/Plan/src/main/java/com/djrapitops/plan/Settings.java b/Plan/src/main/java/com/djrapitops/plan/Settings.java index 2d46ee0fb..2207ab685 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Settings.java +++ b/Plan/src/main/java/com/djrapitops/plan/Settings.java @@ -15,7 +15,6 @@ public enum Settings { ANALYSIS_REFRESH_ON_ENABLE("Settings.Cache.AnalysisCache.RefreshAnalysisCacheOnEnable"), ANALYSIS_LOG_TO_CONSOLE("Settings.Analysis.LogProgressOnConsole"), ANALYSIS_LOG_FINISHED("Settings.Analysis.NotifyWhenFinished"), - ANALYSIS_REMOVE_OUTLIERS("Settings.Analysis.RemoveOutliersFromVisualization"), ANALYSIS_EXPORT("Settings.Analysis.Export.Enabled"), SHOW_ALTERNATIVE_IP("Settings.WebServer.ShowAlternativeServerIP"), USE_ALTERNATIVE_UI("Settings.UseTextUI"), @@ -26,7 +25,6 @@ public enum Settings { DO_NOT_LOG_UNKNOWN_COMMANDS("Customization.Data.DoNotLogUnknownCommands"), COMBINE_COMMAND_ALIASES_TO_MAIN_COMMAND("Customization.Data.CombineCommandAliasesToMainCommand"), SECURITY_IP_UUID("Settings.WebServer.Security.DisplayIPsAndUUIDs"), - GRAPH_PLAYERS_USEMAXPLAYERS_SCALE("Customization.Graphs.PlayersOnlineGraph.UseMaxPlayersAsScale"), PLAYERLIST_SHOW_IMAGES("Customization.SmallHeadImagesOnAnalysisPlayerlist"), // Integer ANALYSIS_MINUTES_FOR_ACTIVE("Settings.Analysis.MinutesPlayedUntilConsidiredActive"), @@ -76,7 +74,6 @@ public enum Settings { HCOLOR_TER("Customization.Colors.HTML.UI.Tertiary"), HCOLOR_TER_DARK("Customization.Colors.HTML.UI.TertiaryDark"), HCOLOR_ACT_ONL("Customization.Colors.HTML.ActivityGraph.OnlinePlayers"), - HCOLOR_ACT_ONL_FILL("Customization.Colors.HTML.ActivityGraph.OnlinePlayersFill"), HCOLOR_ACTP_ACT("Customization.Colors.HTML.ActivityPie.Active"), HCOLOR_ACTP_BAN("Customization.Colors.HTML.ActivityPie.Banned"), HCOLOR_ACTP_INA("Customization.Colors.HTML.ActivityPie.Inactive"), diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/ActivityPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/ActivityPart.java index 537a22889..624c333f6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/ActivityPart.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/ActivityPart.java @@ -12,6 +12,7 @@ import main.java.com.djrapitops.plan.ui.html.graphs.PunchCardGraphCreator; import main.java.com.djrapitops.plan.ui.html.graphs.SessionLengthDistributionGraphCreator; import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.HtmlUtils; +import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; @@ -73,25 +74,17 @@ public class ActivityPart extends RawData { long averageLength = MathUtils.averageLong(lengths); addValue("sessionaverage", FormatUtils.formatTimeAmount(averageLength)); - addValue("punchcardseries", PunchCardGraphCreator.createDataSeries(sessions)); + List sessionsMonth = sessions.stream() + .filter(s -> s.getSessionStart() > MiscUtils.getTime() - TimeAmount.MONTH.ms()) + .collect(Collectors.toList()); + addValue("punchcardseries", PunchCardGraphCreator.createDataSeries(sessionsMonth)); addValue("sessionlengthseries", SessionLengthDistributionGraphCreator.createDataSeries(lengths)); } private void playerActivityGraphs() { List tpsData = tpsPart.getTpsData(); - - String dayScatter = PlayerActivityGraphCreator.buildScatterDataString(tpsData, TimeAmount.DAY.ms()); - String weekScatter = PlayerActivityGraphCreator.buildScatterDataString(tpsData, TimeAmount.WEEK.ms()); - String monthScatter = PlayerActivityGraphCreator.buildScatterDataString(tpsData, TimeAmount.MONTH.ms()); - - addValue("datascatterday", dayScatter); - addValue("datascatterweek", weekScatter); - addValue("datascattermonth", monthScatter); - addValue("playersonlineseries", PlayerActivityGraphCreator.buildSeriesDataString(tpsData)); - addValue("%playersgraphcolor%", Settings.HCOLOR_ACT_ONL + ""); - addValue("%playersgraphfill%", Settings.HCOLOR_ACT_ONL_FILL + ""); } private void activityPiechart() { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/GeolocationPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/GeolocationPart.java index 1f4ea4008..66fce4c83 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/GeolocationPart.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/GeolocationPart.java @@ -19,12 +19,10 @@ import java.util.Map; */ public class GeolocationPart extends RawData { - private final Map geoLocations; private final Map geoCodes; private final Map geoCodeCounts; public GeolocationPart() { - geoLocations = new HashMap<>(); geoCodes = new HashMap<>(); geoCodeCounts = new HashMap<>(); @@ -34,7 +32,6 @@ public class GeolocationPart extends RawData { String country = countries[i]; String countryCode = codes[i]; - geoLocations.put(country, 0); geoCodes.put(country, countryCode); geoCodeCounts.put(countryCode, 0); } @@ -42,21 +39,10 @@ public class GeolocationPart extends RawData { @Override public void analyse() { - choroplethMapValues(); - } - - private void choroplethMapValues() { - String[] choropleth = WorldMapCreator.choroplethMapValues(geoLocations, geoCodes); - addValue("geomapseries", WorldMapCreator.createDataSeries(geoCodeCounts)); - - addValue("geomapz", choropleth[0]); - addValue("geomapcountries", choropleth[1]); - addValue("geomapcodes", choropleth[2]); } - public void addGeoloc(String country) { - geoLocations.computeIfPresent(country, (computedCountry, amount) -> amount + 1); + public void addGeolocation(String country) { String countryCode = geoCodes.get(country); if (countryCode != null) { geoCodeCounts.computeIfPresent(countryCode, (computedCountry, amount) -> amount + 1); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/JoinInfoPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/JoinInfoPart.java index 96eae1576..44edffd00 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/JoinInfoPart.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/JoinInfoPart.java @@ -3,7 +3,6 @@ package main.java.com.djrapitops.plan.data.analysis; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.data.SessionData; -import main.java.com.djrapitops.plan.ui.html.graphs.NewPlayersGraphCreator; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; @@ -87,14 +86,6 @@ public class JoinInfoPart extends RawData { addValue("newperdayday", newPerDayDay); addValue("newperdayweek", newPerDayWeek); addValue("newperdaymonth", newPerDayMonth); - - String scatterDay = NewPlayersGraphCreator.buildScatterDataString(registered, TimeAmount.DAY.ms(), now); - String scatterWeek = NewPlayersGraphCreator.buildScatterDataString(registered, TimeAmount.WEEK.ms(), now); - String scatterMonth = NewPlayersGraphCreator.buildScatterDataString(registered, TimeAmount.MONTH.ms(), now); - - addValue("npdataday", scatterDay); - addValue("npdataweek", scatterWeek); - addValue("npdatamonth", scatterMonth); } public void addToLoginTimes() { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/TPSPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/TPSPart.java index 4c9a70395..268a694e6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/TPSPart.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/TPSPart.java @@ -66,8 +66,8 @@ public class TPSPart extends RawData { addValue("averagetpsweek", FormatUtils.cutDecimals(averageTPSWeek)); addValue("averagetpsday", FormatUtils.cutDecimals(averageTPSDay)); - addValue("averagecpuweek", FormatUtils.cutDecimals(averageCPUWeek)); - addValue("averagecpuday", FormatUtils.cutDecimals(averageCPUDay)); + addValue("averagecpuweek", averageCPUWeek >= 0 ? FormatUtils.cutDecimals(averageCPUWeek) + "%" : "Unavailable"); + addValue("averagecpuday", averageCPUDay >= 0 ? FormatUtils.cutDecimals(averageCPUDay) + "%" : "Unavailable"); addValue("averagememoryweek", FormatUtils.cutDecimals(averageUsedMemoryWeek)); addValue("averagememoryday", FormatUtils.cutDecimals(averageUsedMemoryDay)); diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/CPUGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/CPUGraphCreator.java index 9060c9b5f..b58a8a200 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/CPUGraphCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/CPUGraphCreator.java @@ -1,7 +1,6 @@ package main.java.com.djrapitops.plan.ui.html.graphs; import main.java.com.djrapitops.plan.data.TPS; -import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.Point; import java.util.List; @@ -22,13 +21,4 @@ public class CPUGraphCreator { .collect(Collectors.toList()); return SeriesCreator.seriesGraph(points, true); } - - public static String buildScatterDataString(List tpsData, long scale) { - long now = MiscUtils.getTime(); - List points = tpsData.stream() - .filter(tps -> tps.getDate() >= now - scale) - .map(tps -> new Point(tps.getDate(), tps.getCPUUsage())) - .collect(Collectors.toList()); - return ScatterGraphCreator.scatterGraph(points, true); - } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/NewPlayersGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/NewPlayersGraphCreator.java deleted file mode 100644 index 93f9edd4b..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/NewPlayersGraphCreator.java +++ /dev/null @@ -1,51 +0,0 @@ -package main.java.com.djrapitops.plan.ui.html.graphs; - -import main.java.com.djrapitops.plan.utilities.analysis.Point; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * Class for creating scatter graph data from Registration epoch dates. - * - * @author Rsl1122 - * @since 3.6.0 - */ -public class NewPlayersGraphCreator { - - /** - * Constructor used to hide the public constructor - */ - private NewPlayersGraphCreator() { - throw new IllegalStateException("Utility class"); - } - - /** - * Creates a scatter data string from given data. - * - * @param registered Registration dates of players - * @param scale Scale which the graph should reside within. (Milliseconds) - * @param now Current epoch ms. - * @return Scatter Graph data string for ChartJs - */ - public static String buildScatterDataString(List registered, long scale, long now) { - List filtered = registered.stream() - .filter(date -> date >= now - scale).collect(Collectors.toList()); - List points = filtered.stream() - .distinct() - .map(date -> new Point(date, getCount(filtered, date))) - .collect(Collectors.toList()); - return ScatterGraphCreator.scatterGraph(points, true); - } - - /** - * Counts registration amounts of certain date. - * - * @param filtered Filtered registration list (Filtered to scale) - * @param lookFor Look for this date - * @return How many were on the list. - */ - private static long getCount(List filtered, long lookFor) { - return filtered.stream().filter(date -> lookFor == date).count(); - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PlayerActivityGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PlayerActivityGraphCreator.java index 618ce7b9f..e7f0b8c0b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PlayerActivityGraphCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PlayerActivityGraphCreator.java @@ -2,12 +2,11 @@ package main.java.com.djrapitops.plan.ui.html.graphs; import main.java.com.djrapitops.plan.data.SessionData; import main.java.com.djrapitops.plan.data.TPS; -import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.Point; import java.util.Arrays; +import java.util.Collection; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; /** @@ -29,33 +28,11 @@ public class PlayerActivityGraphCreator { return SeriesCreator.seriesGraph(points, true); } - public static String buildScatterDataString(List tpsData, long scale) { - long now = MiscUtils.getTime(); - List points = tpsData.stream() - .filter(tps -> tps.getDate() >= now - scale) - .map(tps -> new Point(tps.getDate(), tps.getPlayers())) - .collect(Collectors.toList()); - return ScatterGraphCreator.scatterGraph(points, true); - } - - public static String buildScatterDataStringSessions(List sessionData, long scale) { - long now = MiscUtils.getTime(); - long nowMinusScale = now - scale; - List filtered = filterSessions(sessionData, nowMinusScale); - - List points = filtered.stream() + public static String buildSeriesDataStringSessions(Collection sessions) { + List points = sessions.stream() .map(session -> new Point[]{new Point(session.getSessionStart(), 1), new Point(session.getSessionEnd(), 0)}) .flatMap(Arrays::stream) .collect(Collectors.toList()); return ScatterGraphCreator.scatterGraph(points, true, false); } - - private static List filterSessions(List sessions, long nowMinusScale) { - return sessions.parallelStream() - .filter(Objects::nonNull) - .filter(session -> session.isValid() || session.getSessionEnd() == -1) - .filter(session -> session.getSessionStart() >= nowMinusScale || session.getSessionEnd() >= nowMinusScale) - .distinct() - .collect(Collectors.toList()); - } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java index abdd3a644..08d97015b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java @@ -5,20 +5,20 @@ */ package main.java.com.djrapitops.plan.ui.html.graphs; -import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.data.SessionData; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; -import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; /** + * Utility class for creating Punch Card Data Array for the javascripts. + * * @author Rsl1122 + * @since 3.6.0 */ public class PunchCardGraphCreator { @@ -29,7 +29,12 @@ public class PunchCardGraphCreator { throw new IllegalStateException("Utility class"); } - + /** + * Creates a Punchcard series data Array for HighCharts + * + * @param sessions Sessions (Unique/Player) to be placed into the punchcard. + * @return Data array as a string. + */ public static String createDataSeries(Collection sessions) { List sessionStarts = getSessionStarts(sessions); List daysAndHours = AnalysisUtils.getDaysAndHours(sessionStarts); @@ -43,7 +48,11 @@ public class PunchCardGraphCreator { if (value == 0) { continue; } - arrayBuilder.append("{x:").append(j * 3600000).append(", y:").append(i).append(", z:").append(value).append(", marker: { radius:").append(value).append("}}"); + arrayBuilder.append("{x:").append(j * 3600000) + .append(", y:").append(i) + .append(", z:").append(value). + append(", marker: { radius:").append(value) + .append("}}"); if (i != 6 || j != 23) { arrayBuilder.append(","); } @@ -53,38 +62,6 @@ public class PunchCardGraphCreator { return arrayBuilder.toString(); } - /** - * @param data - * @return - */ - public static String generateDataArray(Collection data) { - List sessionStarts = getSessionStarts(data); - List daysAndHours = AnalysisUtils.getDaysAndHours(sessionStarts); - int[][] dataArray = createDataArray(daysAndHours); - int big = findBiggestValue(dataArray); - int[][] scaled = scale(dataArray, big); - StringBuilder arrayBuilder = buildString(scaled); - return arrayBuilder.toString(); - } - - private static StringBuilder buildString(int[][] scaled) { - StringBuilder arrayBuilder = new StringBuilder("["); - for (int i = 0; i < 7; i++) { - for (int j = 0; j < 24; j++) { - int value = scaled[i][j]; - if (value == 0) { - continue; - } - arrayBuilder.append("{x:").append(j).append(", y:").append(i).append(", r:").append(value).append("}"); - if (i != 6 || j != 23) { - arrayBuilder.append(","); - } - } - } - arrayBuilder.append("]"); - return arrayBuilder; - } - private static int[][] createDataArray(List daysAndHours) { int[][] dataArray = createEmptyArray(); for (int[] dAndH : daysAndHours) { @@ -92,47 +69,9 @@ public class PunchCardGraphCreator { int h = dAndH[1]; dataArray[d][h] = dataArray[d][h] + 1; } - - if (Settings.ANALYSIS_REMOVE_OUTLIERS.isTrue()) { - int avg = findAverage(dataArray); - double standardDeviation = getStandardDeviation(dataArray, avg); - if (standardDeviation > 3.5) { - for (int i = 0; i < 7; i++) { - for (int j = 0; j < 24; j++) { - int value = dataArray[i][j]; - if (value - avg > 3 * standardDeviation) { - dataArray[i][j] = avg; - } - } - } - } - } return dataArray; } - private static double getStandardDeviation(int[][] array, int avg) { - int[][] valueMinusAvg = new int[7][24]; - for (int i = 0; i < 7; i++) { - for (int j = 0; j < 24; j++) { - valueMinusAvg[i][j] = (int) Math.pow(Math.abs(array[i][j] - avg), 2); - } - } - - int size = array.length * array[0].length; - double sum = sum(valueMinusAvg); - return Math.sqrt(sum / size); - } - - private static int findAverage(int[][] array) { - int total = sum(array); - int size = array.length * array[0].length; - return (int) MathUtils.average(total, size); - } - - private static int sum(int[][] array) { - return Arrays.stream(array).mapToInt(is -> is.length).sum(); - } - private static List getSessionStarts(Collection data) { long now = MiscUtils.getTime(); return data.stream() diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/RamGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/RamGraphCreator.java index 3786155d3..3bc56fdea 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/RamGraphCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/RamGraphCreator.java @@ -1,7 +1,6 @@ package main.java.com.djrapitops.plan.ui.html.graphs; import main.java.com.djrapitops.plan.data.TPS; -import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.Point; import java.util.List; @@ -23,26 +22,16 @@ public class RamGraphCreator { throw new IllegalStateException("Utility class"); } + /** + * Creates a series data string from given data. + * + * @param tpsData TPS Data collected by TPSCountTimer, one data point for each minute. + * @return Series data for HighCharts + */ public static String buildSeriesDataString(List tpsData) { List points = tpsData.stream() .map(tps -> new Point(tps.getDate(), tps.getUsedMemory())) .collect(Collectors.toList()); return SeriesCreator.seriesGraph(points, true); } - - /** - * Creates a scatter data string from given data. - * - * @param tpsData TPS Data collected by TPSCountTimer, one data point for each minute. - * @param scale Time span this graph resides within. (Milliseconds) - * @return Scatter Graph data string for ChartJs - */ - public static String buildScatterDataString(List tpsData, long scale) { - long now = MiscUtils.getTime(); - List points = tpsData.stream() - .filter(tps -> tps.getDate() >= now - scale) - .map(tps -> new Point(tps.getDate(), tps.getUsedMemory())) - .collect(Collectors.toList()); - return ScatterGraphCreator.scatterGraph(points, true); - } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/SessionLengthDistributionGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/SessionLengthDistributionGraphCreator.java index e647354aa..b5cda83a6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/SessionLengthDistributionGraphCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/SessionLengthDistributionGraphCreator.java @@ -5,10 +5,6 @@ */ package main.java.com.djrapitops.plan.ui.html.graphs; -import main.java.com.djrapitops.plan.data.SessionData; -import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; -import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; - import java.util.*; import java.util.stream.Collectors; @@ -55,63 +51,6 @@ public class SessionLengthDistributionGraphCreator { return arrayBuilder.toString(); } - /** - * @param data - * @return - */ - public static String[] generateDataArraySessions(Collection data) { - List lengths = AnalysisUtils.transformSessionDataToLengths(data); - return generateDataArray(lengths); - } - - /** - * @param lengths - * @return - */ - public static String[] generateDataArray(Collection lengths) { - Map values = getValues(lengths); - StringBuilder arrayBuilder = buildString(values); - StringBuilder labelBuilder = buildLabels(values); - - return new String[]{arrayBuilder.toString(), labelBuilder.toString()}; - } - - private static StringBuilder buildString(Map scaled) { - StringBuilder arrayBuilder = new StringBuilder("["); - - long big = MathUtils.getBiggestLong(scaled.keySet()); - for (long key = 0; key <= big; key++) { - Integer value = scaled.get(key); - if (value == null) { - continue; - } - arrayBuilder.append(value); - if (key != big) { - arrayBuilder.append(", "); - } - } - arrayBuilder.append("]"); - return arrayBuilder; - } - - private static StringBuilder buildLabels(Map scaled) { - StringBuilder arrayBuilder = new StringBuilder("["); - - long big = MathUtils.getBiggestLong(scaled.keySet()); - for (long key = 0; key <= big; key++) { - Integer value = scaled.get(key); - if (value == null) { - continue; - } - arrayBuilder.append("\'").append(key - 5).append(" - ").append(key).append(" min").append("\'"); - if (key != big) { - arrayBuilder.append(", "); - } - } - arrayBuilder.append("]"); - return arrayBuilder; - } - private static Map getValues(Collection lengths) { List unused = new ArrayList<>(lengths); Map values = new HashMap<>(); diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/TPSGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/TPSGraphCreator.java index 7f81b54ae..df6ccc4ae 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/TPSGraphCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/TPSGraphCreator.java @@ -1,7 +1,6 @@ package main.java.com.djrapitops.plan.ui.html.graphs; import main.java.com.djrapitops.plan.data.TPS; -import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.Point; import java.util.List; @@ -29,15 +28,6 @@ public class TPSGraphCreator { } - public static String buildScatterDataStringTPS(List tpsData, long scale) { - long now = MiscUtils.getTime(); - List points = tpsData.stream() - .filter(tps -> tps.getDate() >= now - scale) - .map(tps -> new Point(tps.getDate(), tps.getTps())) - .collect(Collectors.toList()); - return ScatterGraphCreator.scatterGraph(points, true); - } - public static List filterTPS(List tpsData, long nowMinusScale) { return tpsData.stream() .filter(Objects::nonNull) diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldLoadGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldLoadGraphCreator.java index 4810b3b21..69ea4b7e6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldLoadGraphCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldLoadGraphCreator.java @@ -1,7 +1,6 @@ package main.java.com.djrapitops.plan.ui.html.graphs; import main.java.com.djrapitops.plan.data.TPS; -import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.Point; import java.util.List; @@ -16,20 +15,6 @@ import java.util.stream.Collectors; */ public class WorldLoadGraphCreator { - public static String buildSeriesDataStringEntities(List tpsData) { - List points = tpsData.stream() - .map(tps -> new Point(tps.getDate(), tps.getEntityCount())) - .collect(Collectors.toList()); - return SeriesCreator.seriesGraph(points, true); - } - - public static String buildSeriesDataStringChunks(List tpsData) { - List points = tpsData.stream() - .map(tps -> new Point(tps.getDate(), tps.getChunksLoaded())) - .collect(Collectors.toList()); - return SeriesCreator.seriesGraph(points, true); - } - /** * Constructor used to hide the public constructor */ @@ -38,34 +23,28 @@ public class WorldLoadGraphCreator { } /** - * Creates scatter graph data of entity load. + * Creates series graph data of entity load. * * @param tpsData TPS Data collected by TPSCountTimer, one data point for each minute. - * @param scale Time span this graph resides within. (Milliseconds) - * @return Scatter Graph data string for ChartJs + * @return Series data for HighCharts */ - public static String buildScatterDataStringEntities(List tpsData, long scale) { - long now = MiscUtils.getTime(); - List entityPoints = tpsData.stream() - .filter(tps -> tps.getDate() >= now - scale) + public static String buildSeriesDataStringEntities(List tpsData) { + List points = tpsData.stream() .map(tps -> new Point(tps.getDate(), tps.getEntityCount())) .collect(Collectors.toList()); - return ScatterGraphCreator.scatterGraph(entityPoints, true); + return SeriesCreator.seriesGraph(points, true); } /** - * Creates scatter graph data of chunk load. + * Creates series data of chunk load. * * @param tpsData TPS Data collected by TPSCountTimer, one data point for each minute. - * @param scale Time span this graph resides within. (Milliseconds) - * @return Scatter Graph data string for ChartJs + * @return Series data for HighCharts */ - public static String buildScatterDataStringChunks(List tpsData, long scale) { - long now = MiscUtils.getTime(); - List chunkPoints = tpsData.stream() - .filter(tps -> tps.getDate() >= now - scale) + public static String buildSeriesDataStringChunks(List tpsData) { + List points = tpsData.stream() .map(tps -> new Point(tps.getDate(), tps.getChunksLoaded())) .collect(Collectors.toList()); - return ScatterGraphCreator.scatterGraph(chunkPoints, true); + return SeriesCreator.seriesGraph(points, true); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldMapCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldMapCreator.java index 94cf04896..8dcf965ef 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldMapCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldMapCreator.java @@ -38,34 +38,4 @@ public class WorldMapCreator { arrayBuilder.append("]"); return arrayBuilder.toString(); } - - public static String[] choroplethMapValues(Map geoLocations, Map geoCodes) { - StringBuilder locations = new StringBuilder("["); - StringBuilder z = new StringBuilder("["); - StringBuilder text = new StringBuilder("["); - - int i = 0; - int size = geoLocations.size(); - for (Map.Entry entrySet : geoLocations.entrySet()) { - String country = entrySet.getKey(); - String code = geoCodes.getOrDefault(country, "UNK"); - int amount = entrySet.getValue(); - - z.append("\"").append(amount).append("\""); - locations.append("\"").append(country).append("\""); - text.append("\"").append(code).append("\""); - - if (i < size - 1) { - locations.append(","); - z.append(","); - text.append(","); - } - } - - locations.append("]"); - z.append("]"); - text.append("]"); - - return new String[]{z.toString(), locations.toString(), text.toString()}; - } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/PlaceholderUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/PlaceholderUtils.java index c9b38ffe7..ef3268468 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/PlaceholderUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/PlaceholderUtils.java @@ -1,9 +1,9 @@ package main.java.com.djrapitops.plan.utilities; -import com.djrapitops.plugin.api.TimeAmount; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.data.AnalysisData; +import main.java.com.djrapitops.plan.data.SessionData; import main.java.com.djrapitops.plan.data.UserData; import main.java.com.djrapitops.plan.data.analysis.GamemodePart; import main.java.com.djrapitops.plan.ui.html.Html; @@ -14,9 +14,7 @@ import main.java.com.djrapitops.plan.ui.html.tables.KillsTableCreator; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; /** * @author Rsl1122 @@ -42,11 +40,9 @@ public class PlaceholderUtils { replaceMap.putAll(data.getReplaceMap()); replaceMap.put("%plugins%", data.replacePluginsTabLayout()); - replaceMap.put("%currenttime%", MiscUtils.getTime() + ""); replaceMap.put("%refresh%", FormatUtils.formatTimeAmountDifference(data.getRefreshDate(), MiscUtils.getTime())); replaceMap.put("%refreshlong%", data.getRefreshDate() + ""); - replaceMap.put("%graphmaxplayers%", Settings.GRAPH_PLAYERS_USEMAXPLAYERS_SCALE.isTrue() ? Plan.getInstance().getVariable().getMaxPlayers() + "" : "2"); replaceMap.put("%servername%", Settings.SERVER_NAME.toString()); // Html Theme colors @@ -108,17 +104,14 @@ public class PlaceholderUtils { replaceMap.put("%killstable%", KillsTableCreator.createKillsTable(data.getPlayerKills())); Plan plugin = Plan.getInstance(); replaceMap.put("%version%", plugin.getDescription().getVersion()); - replaceMap.put("%planlite%", ""); - replaceMap.put("%graphmaxplayers%", "2"); - String scatterGraphData = PlayerActivityGraphCreator.buildScatterDataStringSessions(data.getSessions(), TimeAmount.WEEK.ms()); - replaceMap.put("%dataweek%", scatterGraphData); replaceMap.put("%playersgraphcolor%", Settings.HCOLOR_ACT_ONL.toString()); - replaceMap.put("%playersgraphfill%", Settings.HCOLOR_ACT_ONL_FILL.toString()); - replaceMap.put("%datapunchcard%", PunchCardGraphCreator.generateDataArray(data.getSessions())); - String[] distribution = SessionLengthDistributionGraphCreator.generateDataArraySessions(data.getSessions()); - replaceMap.put("%datasessiondistribution%", distribution[0]); - replaceMap.put("%labelssessiondistribution%", distribution[1]); - replaceMap.put("%inaccuratedatawarning%", (now - data.getRegistered() < 180000) ? Html.WARN_INACCURATE.parse() : ""); + Set sessions = new HashSet<>(data.getSessions()); + replaceMap.put("%punchcardseries%", PunchCardGraphCreator.createDataSeries(sessions)); + List lengths = AnalysisUtils.transformSessionDataToLengths(sessions); + replaceMap.put("%sessionlengthseries%", SessionLengthDistributionGraphCreator.createDataSeries(lengths)); + + replaceMap.put("%playersonlineseries%", PlayerActivityGraphCreator.buildSeriesDataStringSessions(sessions)); + String[] colors = new String[]{Settings.HCOLOR_MAIN.toString(), Settings.HCOLOR_MAIN_DARK.toString(), Settings.HCOLOR_SEC.toString(), Settings.HCOLOR_TER.toString(), Settings.HCOLOR_TER_DARK.toString()}; String[] defaultCols = new String[]{"348e0f", "267F00", "5cb239", "89c471", "5da341"}; for (int i = 0; i < colors.length; i++) { @@ -126,8 +119,9 @@ public class PlaceholderUtils { replaceMap.put("#" + defaultCols[i], "#" + colors[i]); } } - replaceMap.put("%refreshlong%", String.valueOf(plugin.getInspectCache().getCacheTime(uuid))); - replaceMap.put("%currenttime%", String.valueOf(MiscUtils.getTime())); + long cacheTime = plugin.getInspectCache().getCacheTime(uuid); + replaceMap.put("%refresh%", FormatUtils.formatTimeAmountDifference(cacheTime, now)); + replaceMap.put("%refreshlong%", String.valueOf(cacheTime)); replaceMap.put("%servername%", Settings.SERVER_NAME.toString()); String pluginsTabHtml = plugin.getHookHandler().getPluginsTabLayoutForInspect(); Map additionalReplaceRules = plugin.getHookHandler().getAdditionalInspectReplaceRules(uuid); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index 2959d36f8..7f474fa76 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -277,7 +277,7 @@ public class Analysis { joinInfo.addToLoginTimes(uData.getLoginTimes()); joinInfo.addRegistered(uData.getRegistered()); - geolocPart.addGeoloc(uData.getGeolocation()); + geolocPart.addGeolocation(uData.getGeolocation()); final UUID uuid = uData.getUuid(); if (uData.isOp()) { diff --git a/Plan/src/main/resources/analysis.html b/Plan/src/main/resources/analysis.html index 9aeb2fe58..b5389a0f4 100644 --- a/Plan/src/main/resources/analysis.html +++ b/Plan/src/main/resources/analysis.html @@ -341,7 +341,6 @@ -

Unique Players: %uniquejoinsday% | Unique/Day: %avguniquejoinsday%

@@ -530,14 +529,14 @@

Week:
Average TPS: %averagetpsweek%
- Average CPU: %averagecpuweek%%
+ Average CPU: %averagecpuweek%
Average RAM: %averagememoryweek%Mb
Avg. Entities: %averageentitiesweek%
Average Chunks: %averagechunksweek%

Day:
Average TPS: %averagetpsday%
- Average CPU: %averagecpuday%%
+ Average CPU: %averagecpuday%
Average RAM: %averagememoryday%Mb
Avg. Entities: %averageentitiesday%
Average Chunks: %averagechunksday%

@@ -669,8 +668,6 @@ - - + + + + + + - - - - diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java index f63f20619..7ec73baa8 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java @@ -14,7 +14,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import test.java.utils.TestInit; -import java.io.FileNotFoundException; import java.util.HashMap; import static org.junit.Assert.assertEquals; @@ -76,29 +75,6 @@ public class HtmlUtilsTest { assertEquals(result, exp); } - /** - * @throws FileNotFoundException - */ - @Test - public void testGetServerAnalysisUrl() throws Exception { - TestInit.init(); - String result = HtmlUtils.getServerAnalysisUrlWithProtocol(); - String exp = "http://0.0.0.0:8804/server"; - assertEquals(exp, result); - } - - /** - * - */ - @Test - public void testGetInspectUrl() throws Exception { - TestInit.init(); - String playerName = "Test"; - String expResult = "http://0.0.0.0:8804/player/Test"; - String result = HtmlUtils.getInspectUrlWithProtocol(playerName); - assertEquals(expResult, result); - } - /** * */