diff --git a/Plan/src/main/java/com/djrapitops/plan/data/AnalysisData.java b/Plan/src/main/java/com/djrapitops/plan/data/AnalysisData.java index e54a0fc3a..8fb0ffeb1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/AnalysisData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/AnalysisData.java @@ -1,15 +1,27 @@ package main.java.com.djrapitops.plan.data; -import com.djrapitops.plugin.api.Benchmark; -import com.djrapitops.plugin.api.utility.log.Log; -import main.java.com.djrapitops.plan.data.analysis.*; +import com.djrapitops.plugin.api.TimeAmount; +import main.java.com.djrapitops.plan.Settings; +import main.java.com.djrapitops.plan.data.time.WorldTimes; +import main.java.com.djrapitops.plan.systems.webserver.theme.Colors; +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.analysis.MathUtils; +import main.java.com.djrapitops.plan.utilities.comparators.SessionStartComparator; +import main.java.com.djrapitops.plan.utilities.html.Html; import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; +import main.java.com.djrapitops.plan.utilities.html.graphs.*; +import main.java.com.djrapitops.plan.utilities.html.structure.SessionTabStructureCreator; +import main.java.com.djrapitops.plan.utilities.html.tables.CommandUseTableCreator; +import main.java.com.djrapitops.plan.utilities.html.tables.SessionsTableCreator; import java.io.Serializable; -import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; /** * Big container object for Data. @@ -27,72 +39,13 @@ import java.util.Map; */ public class AnalysisData extends RawData { - private final ActivityPart activityPart; - private final CommandUsagePart commandUsagePart; - private final GeolocationPart geolocationPart; - private final JoinInfoPart joinInfoPart; - private final KillPart killPart; - private final PlayerCountPart playerCountPart; - private final PlaytimePart playtimePart; - private final TPSPart tpsPart; - private final WorldPart worldPart; private long refreshDate; private String pluginsTabLayout; private Map additionalDataReplaceMap; + @Deprecated private String playersTable; public AnalysisData() { - commandUsagePart = new CommandUsagePart(); - geolocationPart = new GeolocationPart(); - joinInfoPart = new JoinInfoPart(); - playerCountPart = new PlayerCountPart(); - playtimePart = new PlaytimePart(); - killPart = new KillPart(joinInfoPart); - tpsPart = new TPSPart(); - activityPart = new ActivityPart(playerCountPart, joinInfoPart, tpsPart); - worldPart = new WorldPart(); - } - - public ActivityPart getActivityPart() { - return activityPart; - } - - public CommandUsagePart getCommandUsagePart() { - return commandUsagePart; - } - - public GeolocationPart getGeolocationPart() { - return geolocationPart; - } - - public JoinInfoPart getJoinInfoPart() { - return joinInfoPart; - } - - public KillPart getKillPart() { - return killPart; - } - - public PlayerCountPart getPlayerCountPart() { - return playerCountPart; - } - - public PlaytimePart getPlaytimePart() { - return playtimePart; - } - - public TPSPart getTpsPart() { - return tpsPart; - } - - public WorldPart getWorldPart() { - return worldPart; - } - - public List getAllParts() { - return Arrays.asList(activityPart, commandUsagePart, geolocationPart, - joinInfoPart, killPart, playerCountPart, playtimePart, tpsPart, - worldPart); } public void setPluginsTabLayout(String pluginsTabLayout) { @@ -107,32 +60,24 @@ public class AnalysisData extends RawData { this.playersTable = playersTable; } - @Override - protected void analyse() { - if (playersTable == null) { - playersTable = ""; - } - if (pluginsTabLayout == null) { - pluginsTabLayout = ""; - } - - addValue("tableBodyPlayerList", playersTable); + private void addConstants() { addValue("version", MiscUtils.getIPlan().getVersion()); + addValue("worldPieColors", Settings.THEME_GRAPH_WORLD_PIE.toString()); + addValue("gmPieColors", Settings.THEME_GRAPH_GM_PIE.toString()); + addValue("serverName", Settings.SERVER_NAME.toString()); + addValue("timeZone", MiscUtils.getTimeZoneOffsetHours()); + addValue("refresh", FormatUtils.formatTimeStamp(refreshDate)); - final List parts = getAllParts(); - parts.forEach(part -> { - try { - Benchmark.start(part.getClass().getSimpleName()); - part.analyseData(); - Benchmark.stop("Analysis", part.getClass().getSimpleName()); - if (part.isAnalysed()) { - addValues(part.getReplaceMap()); - } - } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); - } - }); - refreshDate = MiscUtils.getTime(); + addValue("activityPieColors", Settings.THEME_GRAPH_ACTIVITY_PIE.toString()); + addValue("playersGraphColor", Colors.PLAYERS_ONLINE.getColor()); + addValue("tpsHighColor", Colors.TPS_HIGH.getColor()); + addValue("tpsMediumColor", Colors.TPS_MED.getColor()); + addValue("tpsLowColor", Colors.TPS_LOW.getColor()); + addValue("tpsMedium", Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber()); + addValue("tpsHigh", Settings.THEME_GRAPH_TPS_THRESHOLD_HIGH.getNumber()); + + addValue("playersMax", ServerProfile.getPlayersMax()); + addValue("playersOnline", ServerProfile.getPlayersOnline()); } public String replacePluginsTabLayout() { @@ -142,4 +87,192 @@ public class AnalysisData extends RawData { public long getRefreshDate() { return refreshDate; } + + public void analyze(ServerProfile profile) { + addConstants(); + long now = MiscUtils.getTime(); + refreshDate = now; + long dayAgo = now - TimeAmount.DAY.ms(); + long weekAgo = now - TimeAmount.WEEK.ms(); + long monthAgo = now - TimeAmount.MONTH.ms(); + + Map> sessions = profile.getSessions(); + List allSessions = profile.getAllSessions(); + allSessions.sort(new SessionStartComparator()); + + List players = profile.getPlayers(); + List ops = profile.getOps().collect(Collectors.toList()); + int playersTotal = players.size(); + + List tpsData = profile.getTPSData(0, now).collect(Collectors.toList()); + List tpsDataDay = profile.getTPSData(dayAgo, now).collect(Collectors.toList()); + List tpsDataWeek = profile.getTPSData(weekAgo, now).collect(Collectors.toList()); + List tpsDataMonth = profile.getTPSData(monthAgo, now).collect(Collectors.toList()); + + List geoLocations = profile.getGeoLocations(); + Map commandUsage = profile.getCommandUsage(); + + directProfileVariables(profile); + performanceTab(tpsData, tpsDataDay, tpsDataWeek, tpsDataMonth); + sessionData(monthAgo, sessions, allSessions); + onlineActivityNumbers(profile, sessions, players); + geolocationsTab(geoLocations); + + addValue("ops", ops.size()); + addValue("playersTotal", playersTotal); + + // TODO Rewrite Activity Pie + addValue("playersActive", 0); + addValue("active", 0); + addValue("inactive", 0); + addValue("joinLeaver", 0); + addValue("banned", 0); + + commandUsage(commandUsage); + + addValue("playtimeTotal", FormatUtils.formatTimeAmount(profile.getTotalPlaytime())); + addValue("playtimeAverage", FormatUtils.formatTimeAmount(profile.getAveragePlayTime())); + } + + private void commandUsage(Map commandUsage) { + addValue("commandUniqueCount", String.valueOf(commandUsage.size())); + addValue("commandCount", MathUtils.sumInt(commandUsage.values().stream().map(i -> (int) i))); + addValue("tableBodyCommands", HtmlUtils.removeXSS(CommandUseTableCreator.createTable(commandUsage))); + } + + private void geolocationsTab(List geoLocations) { + Map geoCodes = new HashMap<>(); + Map geoCodeCounts = new HashMap<>(); + String[] countries = new String[]{"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas, The", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burma", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo, Democratic Republic of the", "Congo, Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Curacao", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Islas Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Polynesia", "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guernsey", "Guinea-Bissau", "Guinea", "Guyana", "Haiti", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia, Federated States of", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Namibia", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Nigeria", "Niger", "Niue", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Sint Maarten", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands", "West Bank", "Yemen", "Zambia", "Zimbabwe"}; + String[] codes = new String[]{"AFG", "ALB", "DZA", "ASM", "AND", "AGO", "AIA", "ATG", "ARG", "ARM", "ABW", "AUS", "AUT", "AZE", "BHM", "BHR", "BGD", "BRB", "BLR", "BEL", "BLZ", "BEN", "BMU", "BTN", "BOL", "BIH", "BWA", "BRA", "VGB", "BRN", "BGR", "BFA", "MMR", "BDI", "CPV", "KHM", "CMR", "CAN", "CYM", "CAF", "TCD", "CHL", "CHN", "COL", "COM", "COD", "COG", "COK", "CRI", "CIV", "HRV", "CUB", "CUW", "CYP", "CZE", "DNK", "DJI", "DMA", "DOM", "ECU", "EGY", "SLV", "GNQ", "ERI", "EST", "ETH", "FLK", "FRO", "FJI", "FIN", "FRA", "PYF", "GAB", "GMB", "GEO", "DEU", "GHA", "GIB", "GRC", "GRL", "GRD", "GUM", "GTM", "GGY", "GNB", "GIN", "GUY", "HTI", "HND", "HKG", "HUN", "ISL", "IND", "IDN", "IRN", "IRQ", "IRL", "IMN", "ISR", "ITA", "JAM", "JPN", "JEY", "JOR", "KAZ", "KEN", "KIR", "KOR", "PRK", "KSV", "KWT", "KGZ", "LAO", "LVA", "LBN", "LSO", "LBR", "LBY", "LIE", "LTU", "LUX", "MAC", "MKD", "MDG", "MWI", "MYS", "MDV", "MLI", "MLT", "MHL", "MRT", "MUS", "MEX", "FSM", "MDA", "MCO", "MNG", "MNE", "MAR", "MOZ", "NAM", "NPL", "NLD", "NCL", "NZL", "NIC", "NGA", "NER", "NIU", "MNP", "NOR", "OMN", "PAK", "PLW", "PAN", "PNG", "PRY", "PER", "PHL", "POL", "PRT", "PRI", "QAT", "ROU", "RUS", "RWA", "KNA", "LCA", "MAF", "SPM", "VCT", "WSM", "SMR", "STP", "SAU", "SEN", "SRB", "SYC", "SLE", "SGP", "SXM", "SVK", "SVN", "SLB", "SOM", "ZAF", "SSD", "ESP", "LKA", "SDN", "SUR", "SWZ", "SWE", "CHE", "SYR", "TWN", "TJK", "TZA", "THA", "TLS", "TGO", "TON", "TTO", "TUN", "TUR", "TKM", "TUV", "UGA", "UKR", "ARE", "GBR", "USA", "URY", "UZB", "VUT", "VEN", "VNM", "VGB", "WBG", "YEM", "ZMB", "ZWE"}; + for (int i = 0; i < countries.length; i++) { + String country = countries[i]; + String countryCode = codes[i]; + + geoCodes.put(country, countryCode); + geoCodeCounts.put(countryCode, 0); + } + for (String geoLocation : geoLocations) { + String countryCode = geoCodes.get(geoLocation); + if (countryCode != null) { + geoCodeCounts.computeIfPresent(countryCode, (computedCountry, amount) -> amount + 1); + } + } + addValue("geoMapSeries", WorldMapCreator.createDataSeries(geoCodeCounts)); + } + + private void onlineActivityNumbers(ServerProfile profile, Map> sessions, List players) { + long now = MiscUtils.getTime(); + long dayAgo = now - TimeAmount.DAY.ms(); + long weekAgo = now - TimeAmount.WEEK.ms(); + long monthAgo = now - TimeAmount.MONTH.ms(); + + List newDay = profile.getPlayersWhoRegistered(dayAgo, now).collect(Collectors.toList()); + List newWeek = profile.getPlayersWhoRegistered(weekAgo, now).collect(Collectors.toList()); + List newMonth = profile.getPlayersWhoRegistered(monthAgo, now).collect(Collectors.toList()); + List uniqueDay = profile.getPlayersWhoPlayedBetween(dayAgo, now).collect(Collectors.toList()); + List uniqueWeek = profile.getPlayersWhoPlayedBetween(weekAgo, now).collect(Collectors.toList()); + List uniqueMonth = profile.getPlayersWhoPlayedBetween(monthAgo, now).collect(Collectors.toList()); + + int uniqD = uniqueDay.size(); + int uniqW = uniqueWeek.size(); + int uniqM = uniqueMonth.size(); + int newD = newDay.size(); + int newW = newWeek.size(); + int newM = newMonth.size(); + int playersTotal = players.size(); + + addValue("playersDay", uniqD); + addValue("playersWeek", uniqW); + addValue("playersMonth", uniqM); + addValue("playersNewDay", newD); + addValue("playersNewWeek", newW); + addValue("playersNewMonth", newM); + + addValue("playersAverage", AnalysisUtils.getUniqueJoinsPerDay(sessions, -1)); + addValue("playersAverageDay", AnalysisUtils.getUniqueJoinsPerDay(sessions, dayAgo)); + addValue("playersAverageWeek", AnalysisUtils.getUniqueJoinsPerDay(sessions, weekAgo)); + addValue("playersAverageMonth", AnalysisUtils.getUniqueJoinsPerDay(sessions, monthAgo)); + addValue("playersNewAverage", AnalysisUtils.getNewUsersPerDay(toRegistered(players), -1, playersTotal)); + addValue("playersNewAverageDay", AnalysisUtils.getNewUsersPerDay(toRegistered(newDay), -1, newD)); + addValue("playersNewAverageWeek", AnalysisUtils.getNewUsersPerDay(toRegistered(newWeek), -1, newW)); + addValue("playersNewAverageMonth", AnalysisUtils.getNewUsersPerDay(toRegistered(newMonth), -1, newM)); + } + + private List toRegistered(List players) { + return players.stream().map(PlayerProfile::getRegistered).collect(Collectors.toList()); + } + + private void sessionData(long monthAgo, Map> sessions, List allSessions) { + List sessionsMonth = allSessions.stream() + .filter(s -> s.getSessionStart() >= monthAgo) + .collect(Collectors.toList()); + String[] tables = SessionsTableCreator.createTable(sessions, allSessions); + String[] sessionContent = SessionTabStructureCreator.creteStructure(sessions, allSessions); + + addValue("sessionCount", allSessions.size()); + addValue("accordionSessions", sessionContent[0]); + addValue("sessionTabGraphViewFunctions", sessionContent[1]); + addValue("tableBodySessions", tables[0]); + addValue("listRecentLogins", tables[1]); + addValue("sessionAverage", FormatUtils.formatTimeAmount(MathUtils.averageLong(allSessions.stream().map(Session::getLength)))); + addValue("punchCardSeries", PunchCardGraphCreator.createDataSeries(sessionsMonth)); + + addValue("deathCount", ServerProfile.getDeathCount(allSessions)); + addValue("mobKillCount", ServerProfile.getMobKillCount(allSessions)); + addValue("killCount", ServerProfile.getPlayerKills(allSessions).size()); + } + + private void directProfileVariables(ServerProfile profile) { + WorldTimes worldTimes = profile.getServerWorldtimes(); + long allTimePeak = profile.getAllTimePeak(); + long lastPeak = profile.getLastPeakDate(); + + addValue("tablePlayerlist", Html.TABLE_PLAYERS.parse(profile.createPlayersTableBody())); + addValue("worldTotal", FormatUtils.formatTimeAmount(worldTimes.getTotal())); + String[] seriesData = WorldPieCreator.createSeriesData(worldTimes); + addValue("worldSeries", seriesData[0]); + addValue("gmSeries", seriesData[1]); + addValue("lastPeakTime", lastPeak != -1 ? FormatUtils.formatTimeStampYear(lastPeak) : "No Data"); + addValue("playersLastPeak", lastPeak != -1 ? profile.getLastPeakPlayers() : "-"); + addValue("bestPeakTime", allTimePeak != -1 ? FormatUtils.formatTimeStampYear(allTimePeak) : "No Data"); + addValue("playersBestPeak", allTimePeak != -1 ? profile.getAllTimePeakPlayers() : "-"); + } + + private void performanceTab(List tpsData, List tpsDataDay, List tpsDataWeek, List tpsDataMonth) { + addValue("tpsSpikeMonth", ServerProfile.getLowSpikeCount(tpsDataMonth)); + addValue("tpsSpikeWeek", ServerProfile.getLowSpikeCount(tpsDataWeek)); + addValue("tpsSpikeDay", ServerProfile.getLowSpikeCount(tpsDataDay)); + + addValue("playersOnlineSeries", PlayerActivityGraphCreator.buildSeriesDataString(tpsData)); + addValue("tpsSeries", TPSGraphCreator.buildSeriesDataString(tpsData)); + addValue("cpuSeries", CPUGraphCreator.buildSeriesDataString(tpsData)); + addValue("ramSeries", RamGraphCreator.buildSeriesDataString(tpsData)); + addValue("entitySeries", WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsData)); + addValue("chunkSeries", WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsData)); + + double averageCPUMonth = MathUtils.averageDouble(tpsDataMonth.stream().map(TPS::getCPUUsage).filter(i -> i != 0)); + double averageCPUWeek = MathUtils.averageDouble(tpsDataWeek.stream().map(TPS::getCPUUsage).filter(i -> i != 0)); + double averageCPUDay = MathUtils.averageDouble(tpsDataDay.stream().map(TPS::getCPUUsage).filter(i -> i != 0)); + + addValue("tpsAverageMonth", FormatUtils.cutDecimals(MathUtils.averageDouble(tpsDataMonth.stream().map(TPS::getTicksPerSecond)))); + addValue("tpsAverageWeek", FormatUtils.cutDecimals(MathUtils.averageDouble(tpsDataWeek.stream().map(TPS::getTicksPerSecond)))); + addValue("tpsAverageDay", FormatUtils.cutDecimals(MathUtils.averageDouble(tpsDataDay.stream().map(TPS::getTicksPerSecond)))); + + addValue("cpuAverageMonth", averageCPUMonth >= 0 ? FormatUtils.cutDecimals(averageCPUMonth) + "%" : "Unavailable"); + addValue("cpuAverageWeek", averageCPUWeek >= 0 ? FormatUtils.cutDecimals(averageCPUWeek) + "%" : "Unavailable"); + addValue("cpuAverageDay", averageCPUDay >= 0 ? FormatUtils.cutDecimals(averageCPUDay) + "%" : "Unavailable"); + + addValue("ramAverageMonth", FormatUtils.cutDecimals(MathUtils.averageLong(tpsDataMonth.stream().map(TPS::getUsedMemory).filter(i -> i != 0)))); + addValue("ramAverageWeek", FormatUtils.cutDecimals(MathUtils.averageLong(tpsDataWeek.stream().map(TPS::getUsedMemory).filter(i -> i != 0)))); + addValue("ramAverageDay", FormatUtils.cutDecimals(MathUtils.averageLong(tpsDataDay.stream().map(TPS::getUsedMemory).filter(i -> i != 0)))); + + addValue("entityAverageMonth", FormatUtils.cutDecimals(MathUtils.averageInt(tpsDataMonth.stream().map(TPS::getEntityCount).filter(i -> i != 0)))); + addValue("entityAverageWeek", FormatUtils.cutDecimals(MathUtils.averageInt(tpsDataWeek.stream().map(TPS::getEntityCount).filter(i -> i != 0)))); + addValue("entityAverageDay", FormatUtils.cutDecimals(MathUtils.averageInt(tpsDataDay.stream().map(TPS::getEntityCount).filter(i -> i != 0)))); + + addValue("chunkAverageMonth", FormatUtils.cutDecimals(MathUtils.averageInt(tpsDataMonth.stream().map(TPS::getChunksLoaded).filter(i -> i != 0)))); + addValue("chunkAverageWeek", FormatUtils.cutDecimals(MathUtils.averageInt(tpsDataWeek.stream().map(TPS::getChunksLoaded).filter(i -> i != 0)))); + addValue("chunkAverageDay", FormatUtils.cutDecimals(MathUtils.averageInt(tpsDataDay.stream().map(TPS::getChunksLoaded).filter(i -> i != 0)))); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/RawData.java b/Plan/src/main/java/com/djrapitops/plan/data/RawData.java similarity index 67% rename from Plan/src/main/java/com/djrapitops/plan/data/analysis/RawData.java rename to Plan/src/main/java/com/djrapitops/plan/data/RawData.java index cb36aa08c..3046885b7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/RawData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/RawData.java @@ -1,4 +1,4 @@ -package main.java.com.djrapitops.plan.data.analysis; +package main.java.com.djrapitops.plan.data; import com.djrapitops.plugin.utilities.Verify; @@ -16,45 +16,13 @@ public abstract class RawData { private final Map replaceMap; - /** - * Status info for call to analyzeData method. - */ - protected boolean analysed; - /** * Only used by subclasses. */ public RawData() { replaceMap = new HashMap<>(); - analysed = false; } - /** - * Condition if analyseData() has been called. - * - * @return true if the method has been called. - */ - public boolean isAnalysed() { - return analysed; - } - - /** - * Analyses the data added together. - *

- * Places place-holders to the replace map. - */ - public void analyseData() { - analysed = true; - this.analyse(); - } - - /** - * Subclasses should analyse the data added together. - *

- * Place-holders should be added to the replace map. - */ - protected abstract void analyse(); - /** * Adds values from an existing replaceMap. * diff --git a/Plan/src/main/java/com/djrapitops/plan/data/ServerProfile.java b/Plan/src/main/java/com/djrapitops/plan/data/ServerProfile.java index 2667be1bc..74cd73049 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/ServerProfile.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/ServerProfile.java @@ -13,7 +13,6 @@ 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 main.java.com.djrapitops.plan.utilities.comparators.PlayerProfileLastPlayedComparator; -import main.java.com.djrapitops.plan.utilities.comparators.TPSComparator; import main.java.com.djrapitops.plan.utilities.html.tables.PlayersTableCreator; import java.util.*; @@ -43,9 +42,6 @@ public class ServerProfile { private long allTimePeak; private int allTimePeakPlayers; - // Active information - private int playersOnline; - private int playersMax; public ServerProfile(UUID serverUUID) { this.serverUUID = serverUUID; @@ -57,8 +53,6 @@ public class ServerProfile { allTimePeakPlayers = -1; lastPeakDate = -1; lastPeakPlayers = -1; - playersOnline = -1; - playersMax = -1; } public List getPlayers() { @@ -85,9 +79,7 @@ public class ServerProfile { this.commandUsage = commandUsage; } - public long getLowSpikeCount(long after, long before) { - List tpsData = getTPSData(after, before).sorted(new TPSComparator()).collect(Collectors.toList()); - + public static long getLowSpikeCount(List tpsData) { int mediumThreshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber(); boolean wasLow = false; @@ -171,7 +163,7 @@ public class ServerProfile { return getNewPlayers(after, before) * 1.0 / AnalysisUtils.getNumberOfDaysBetween(after, before); } - private Stream getPlayersWhoPlayedBetween(long after, long before) { + public Stream getPlayersWhoPlayedBetween(long after, long before) { return players.stream() .filter(player -> player.playedBetween(after, before)); } @@ -209,11 +201,15 @@ public class ServerProfile { return players.size(); } - public List getSessions() { + public Map> getSessions() { + return players.stream().collect(Collectors.toMap(PlayerProfile::getUuid, p -> p.getSessions(serverUUID))); + } + + public List getAllSessions() { return players.stream().map(p -> p.getSessions(serverUUID)).flatMap(Collection::stream).collect(Collectors.toList()); } - public List getPlayerKills(List s) { + public static List getPlayerKills(List s) { List kills = new ArrayList<>(); for (Session session : s) { kills.addAll(session.getPlayerKills()); @@ -221,7 +217,7 @@ public class ServerProfile { return kills; } - public long getMobKillCount(List s) { + public static long getMobKillCount(List s) { long total = 0; for (Session session : s) { total += session.getMobKills(); @@ -229,7 +225,7 @@ public class ServerProfile { return total; } - public long getDeathCount(List s) { + public static long getDeathCount(List s) { long total = 0; for (Session session : s) { total += session.getDeaths(); @@ -279,7 +275,7 @@ public class ServerProfile { this.allTimePeakPlayers = allTimePeakPlayers; } - public int getPlayersOnline() { + public static int getPlayersOnline() { if (Check.isBungeeAvailable()) { return PlanBungee.getInstance().getProxy().getOnlineCount(); } else { @@ -287,7 +283,19 @@ public class ServerProfile { } } - public int getPlayersMax() { + public static int getPlayersMax() { return MiscUtils.getIPlan().getVariable().getMaxPlayers(); } + + public Stream getOps() { + return players.stream().filter(PlayerProfile::isOp); + } + + public Set getUuids() { + Set uuids = new HashSet<>(); + for (PlayerProfile player : players) { + uuids.add(player.getUuid()); + } + return uuids; + } } \ No newline at end of file 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 deleted file mode 100644 index 6efe16f2b..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/ActivityPart.java +++ /dev/null @@ -1,182 +0,0 @@ -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.Settings; -import main.java.com.djrapitops.plan.data.Session; -import main.java.com.djrapitops.plan.data.TPS; -import main.java.com.djrapitops.plan.systems.webserver.theme.Colors; -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.analysis.MathUtils; -import main.java.com.djrapitops.plan.utilities.html.graphs.PlayerActivityGraphCreator; -import main.java.com.djrapitops.plan.utilities.html.graphs.PunchCardGraphCreator; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * Part responsible for all Player Activity related analysis. - *

- * Placeholder values can be retrieved using the get method. - *

- * Contains following placeholders after analyzed: - * ${active} - (Number) - * ${inactive} - (Number) - * ${joinLeaver} - (Number) - * ${banned} - (Number) - * ${activityColors} - Color array - * ${playersGraphColor} - Color - *

- * ${playersOnlineSeries} - Data for HighCharts - * ${sessionLengthSeries} - Data for HighCharts - * ${punchCardSeries} - Data for HighCharts - *

- * ${sessionAverage} - Formatted Time amount - * - * @author Rsl1122 - * @since 3.5.2 - */ -@Deprecated -public class ActivityPart extends RawData { - - private final PlayerCountPart playerCount; - private final JoinInfoPart joins; - private final TPSPart tpsPart; - private final Set bans; - private final Set active; - private final Set inactive; - private final Set joinedOnce; - private List recentPlayers; - private List recentPlayersUUIDs; - - public ActivityPart(PlayerCountPart playerCount, JoinInfoPart joins, TPSPart tps) { - this.playerCount = playerCount; - this.joins = joins; - tpsPart = tps; - bans = new HashSet<>(); - active = new HashSet<>(); - inactive = new HashSet<>(); - joinedOnce = new HashSet<>(); - } - - @Override - public void analyse() { - Verify.nullCheck(recentPlayers); - Verify.nullCheck(recentPlayersUUIDs); - - activityPiechart(); - - playerActivityGraphs(); - - final List sessions = joins.getAllSessions(); - - List lengths = AnalysisUtils.transformSessionDataToLengths(sessions); - long averageLength = MathUtils.averageLong(lengths); - addValue("sessionAverage", FormatUtils.formatTimeAmount(averageLength)); - - List sessionsMonth = sessions.stream() - .filter(s -> s.getSessionStart() > MiscUtils.getTime() - TimeAmount.MONTH.ms()) - .collect(Collectors.toList()); - addValue("punchCardSeries", PunchCardGraphCreator.createDataSeries(sessionsMonth)); - } - - private void playerActivityGraphs() { - List tpsData = tpsPart.getTpsData(); - addValue("playersOnlineSeries", PlayerActivityGraphCreator.buildSeriesDataString(tpsData)); - addValue("playersGraphColor", Colors.PLAYERS_ONLINE.getColor()); - } - - private void activityPiechart() { - calculateActivityAmounts(); - - int[] counts = new int[]{active.size(), inactive.size(), joinedOnce.size(), bans.size()}; - - addValue("activityPieColors", Settings.THEME_GRAPH_ACTIVITY_PIE.toString()); - addValue("playersActive", counts[0]); - addValue("active", counts[0]); - addValue("inactive", counts[1]); - addValue("joinLeaver", counts[2]); - addValue("banned", counts[3]); - } - - private void calculateActivityAmounts() { - Map> allSessions = joins.getSessions(); - for (UUID uuid : playerCount.getUuids()) { - if (bans.contains(uuid)) { - continue; - } - List sessions = allSessions.getOrDefault(uuid, new ArrayList<>()); - long lastSeen = AnalysisUtils.getLastSeen(sessions); - long playtime = AnalysisUtils.getTotalPlaytime(sessions); - int sessionCount = sessions.size(); - if (sessionCount <= 1) { - addJoinedOnce(uuid); - continue; - } - boolean isActive = AnalysisUtils.isActive(MiscUtils.getTime(), lastSeen, playtime, sessionCount); - if (isActive) { - addActive(uuid); - } else { - addInActive(uuid); - } - } - } - - public void addBans(Collection uuids) { - bans.addAll(uuids); - } - - public void addBan(UUID uuid) { - bans.add(Verify.nullCheck(uuid)); - } - - public void addActive(UUID uuid) { - active.add(Verify.nullCheck(uuid)); - } - - public void addInActive(UUID uuid) { - inactive.add(Verify.nullCheck(uuid)); - } - - public void addJoinedOnce(UUID uuid) { - joinedOnce.add(Verify.nullCheck(uuid)); - } - - public Map getPlayersOnline() { - return tpsPart.getTpsData().stream().distinct().collect(Collectors.toMap(TPS::getDate, TPS::getPlayers)); - } - - public List getRecentPlayers() { - return recentPlayers; - } - - public void setRecentPlayers(List recentPlayers) { - this.recentPlayers = recentPlayers; - } - - public List getRecentPlayersUUIDs() { - return recentPlayersUUIDs; - } - - public void setRecentPlayersUUIDs(List recentPlayersUUIDs) { - this.recentPlayersUUIDs = recentPlayersUUIDs; - } - - public Set getBans() { - return bans; - } - - public Set getActive() { - return active; - } - - public Set getInactive() { - return inactive; - } - - public Set getJoinedOnce() { - return joinedOnce; - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/CommandUsagePart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/CommandUsagePart.java deleted file mode 100644 index 319659b4a..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/CommandUsagePart.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package main.java.com.djrapitops.plan.data.analysis; - -import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; -import main.java.com.djrapitops.plan.utilities.html.tables.CommandUseTableCreator; - -import java.util.HashMap; -import java.util.Map; - -/** - * Part responsible for all CommandUsage related analysis. - *

- * Placeholder values can be retrieved using the get method. - *

- * Contains following placeholders after analyzed: - * ${commandCount} - (Number) - * ${commandUniqueCount} - (Number) - * ${tableBodyCommands} - Table body for CommandUsage table. - * - * @author Rsl1122 - * @since 3.5.2 - */ -@Deprecated -public class CommandUsagePart extends RawData { - - private Map commandUsage; - - public CommandUsagePart() { - this.commandUsage = new HashMap<>(); - } - - @Override - public void analyse() { - addValue("commandUniqueCount", String.valueOf(getUniqueCommands())); - addValue("commandCount", String.valueOf(getCommandTotal())); - String commandUsageTable = CommandUseTableCreator.createTable(commandUsage); - addValue("tableBodyCommands", HtmlUtils.removeXSS(commandUsageTable)); - } - - public void setCommandUsage(Map commandUsage) { - this.commandUsage = commandUsage; - } - - public void addCommands(Map commandUsage) { - this.commandUsage.putAll(commandUsage); - } - - public int getUniqueCommands() { - return commandUsage.keySet().size(); - } - - public long getCommandTotal() { - return commandUsage.values().stream().mapToLong(i -> i).sum(); - } - - public Map getCommandUsage() { - return commandUsage; - } -} 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 deleted file mode 100644 index 7a06b0979..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/GeolocationPart.java +++ /dev/null @@ -1,84 +0,0 @@ -package main.java.com.djrapitops.plan.data.analysis; - -import main.java.com.djrapitops.plan.utilities.html.graphs.WorldMapCreator; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * Part responsible for all Geolocation related analysis. - *

- * Placeholder values can be retrieved using the get method. - *

- * Contains following placeholders after analyzed: - * ${geoMapSeries} - * - * @author Rsl1122 - * @since 3.5.2 - */ -@Deprecated -public class GeolocationPart extends RawData { - - private final Map mostCommonGeolocations; - private final Map geoCodes; - private final Map geoCodeCounts; - - public GeolocationPart() { - geoCodes = new HashMap<>(); - geoCodeCounts = new HashMap<>(); - mostCommonGeolocations = new HashMap<>(); - - String[] countries = new String[]{"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas, The", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burma", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo, Democratic Republic of the", "Congo, Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Curacao", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Islas Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Polynesia", "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guernsey", "Guinea-Bissau", "Guinea", "Guyana", "Haiti", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia, Federated States of", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Namibia", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Nigeria", "Niger", "Niue", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Sint Maarten", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands", "West Bank", "Yemen", "Zambia", "Zimbabwe"}; - String[] codes = new String[]{"AFG", "ALB", "DZA", "ASM", "AND", "AGO", "AIA", "ATG", "ARG", "ARM", "ABW", "AUS", "AUT", "AZE", "BHM", "BHR", "BGD", "BRB", "BLR", "BEL", "BLZ", "BEN", "BMU", "BTN", "BOL", "BIH", "BWA", "BRA", "VGB", "BRN", "BGR", "BFA", "MMR", "BDI", "CPV", "KHM", "CMR", "CAN", "CYM", "CAF", "TCD", "CHL", "CHN", "COL", "COM", "COD", "COG", "COK", "CRI", "CIV", "HRV", "CUB", "CUW", "CYP", "CZE", "DNK", "DJI", "DMA", "DOM", "ECU", "EGY", "SLV", "GNQ", "ERI", "EST", "ETH", "FLK", "FRO", "FJI", "FIN", "FRA", "PYF", "GAB", "GMB", "GEO", "DEU", "GHA", "GIB", "GRC", "GRL", "GRD", "GUM", "GTM", "GGY", "GNB", "GIN", "GUY", "HTI", "HND", "HKG", "HUN", "ISL", "IND", "IDN", "IRN", "IRQ", "IRL", "IMN", "ISR", "ITA", "JAM", "JPN", "JEY", "JOR", "KAZ", "KEN", "KIR", "KOR", "PRK", "KSV", "KWT", "KGZ", "LAO", "LVA", "LBN", "LSO", "LBR", "LBY", "LIE", "LTU", "LUX", "MAC", "MKD", "MDG", "MWI", "MYS", "MDV", "MLI", "MLT", "MHL", "MRT", "MUS", "MEX", "FSM", "MDA", "MCO", "MNG", "MNE", "MAR", "MOZ", "NAM", "NPL", "NLD", "NCL", "NZL", "NIC", "NGA", "NER", "NIU", "MNP", "NOR", "OMN", "PAK", "PLW", "PAN", "PNG", "PRY", "PER", "PHL", "POL", "PRT", "PRI", "QAT", "ROU", "RUS", "RWA", "KNA", "LCA", "MAF", "SPM", "VCT", "WSM", "SMR", "STP", "SAU", "SEN", "SRB", "SYC", "SLE", "SGP", "SXM", "SVK", "SVN", "SLB", "SOM", "ZAF", "SSD", "ESP", "LKA", "SDN", "SUR", "SWZ", "SWE", "CHE", "SYR", "TWN", "TJK", "TZA", "THA", "TLS", "TGO", "TON", "TTO", "TUN", "TUR", "TKM", "TUV", "UGA", "UKR", "ARE", "GBR", "USA", "URY", "UZB", "VUT", "VEN", "VNM", "VGB", "WBG", "YEM", "ZMB", "ZWE"}; - for (int i = 0; i < countries.length; i++) { - String country = countries[i]; - String countryCode = codes[i]; - - geoCodes.put(country, countryCode); - geoCodeCounts.put(countryCode, 0); - } - } - - @Override - public void analyse() { - addValue("geoMapSeries", WorldMapCreator.createDataSeries(geoCodeCounts)); - } - - public void addGeolocation(String country) { - String countryCode = geoCodes.get(country); - if (countryCode != null) { - geoCodeCounts.computeIfPresent(countryCode, (computedCountry, amount) -> amount + 1); - } - } - - public void addGeoLocations(Map> geolocations) { - for (Map.Entry> entry : geolocations.entrySet()) { - String mostCommon = getMostCommon(entry.getValue()); - mostCommonGeolocations.put(entry.getKey(), mostCommon); - addGeolocation(mostCommon); - } - } - - private String getMostCommon(List geoLocs) { - Map occurrences = - geoLocs.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); - String mostCommon = "Not Known"; - long count = -1; - for (Map.Entry entry : occurrences.entrySet()) { - Long value = entry.getValue(); - if (value > count) { - mostCommon = entry.getKey(); - count = value; - } - } - return mostCommon; - } - - public Map getMostCommonGeoLocations() { - return mostCommonGeolocations; - } -} 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 deleted file mode 100644 index f6fdeb59f..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/JoinInfoPart.java +++ /dev/null @@ -1,169 +0,0 @@ -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.Session; -import main.java.com.djrapitops.plan.utilities.MiscUtils; -import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; -import main.java.com.djrapitops.plan.utilities.html.structure.SessionTabStructureCreator; -import main.java.com.djrapitops.plan.utilities.html.tables.SessionsTableCreator; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * Part responsible for all Player player related analysis. - *

- * Placeholder values can be retrieved using the get method. - *

- * Contains following placeholders after analyzed: - * ${playersAverage} - (Number) - * ${playersNewAverage} - (Number) - *

- * ${playersDay} - (Number) - * ${playersWeek} - (Number) - * ${playersMonth} - (Number) - * ${playersAverageDay} - (Number) - * ${playersAverageWeek} - (Number) - * ${playersAverageMonth} - (Number) - * ${playersNewDay} - (Number) - * ${playersNewWeek} - (Number) - * ${playersNewMonth} - (Number) - * ${playersNewAverageDay} - (Number) - * ${playersNewAverageWeek} - (Number) - * ${playersNewAverageMonth} - (Number) - * - * @author Rsl1122 - * @since 3.5.2 - */ -@Deprecated -public class JoinInfoPart extends RawData { - - private final Map activeSessions; - private final Map> sessions; - private final Map registered; - private long loginTimes; - - public JoinInfoPart() { - activeSessions = new HashMap<>(); - sessions = new HashMap<>(); - registered = new HashMap<>(); - loginTimes = 0; - } - - @Override - public void analyse() { - newPlayers(); - uniquePlayers(); - uniquePlayersPerDay(); - - addValue("sessionCount", getAllSessions().size()); - - sessionTables(); - } - - private void sessionTables() { - String[] tables = SessionsTableCreator.createTable(this); - String[] sessionContent = SessionTabStructureCreator.creteStructure(this); - addValue("accordionSessions", sessionContent[0]); - addValue("sessionTabGraphViewFunctions", sessionContent[1]); - addValue("tableBodySessions", tables[0]); - addValue("tableBodyRecentLogins", tables[1]); - } - - private void uniquePlayers() { - int uniqueDay = AnalysisUtils.getUniqueJoins(sessions, TimeAmount.DAY.ms()); - int uniqueWeek = AnalysisUtils.getUniqueJoins(sessions, TimeAmount.WEEK.ms()); - int uniqueMonth = AnalysisUtils.getUniqueJoins(sessions, TimeAmount.MONTH.ms()); - - addValue("playersDay", uniqueDay); - addValue("playersWeek", uniqueWeek); - addValue("playersMonth", uniqueMonth); - } - - private void uniquePlayersPerDay() { - int perDay = AnalysisUtils.getUniqueJoinsPerDay(sessions, -1); - int perDayDay = AnalysisUtils.getUniqueJoinsPerDay(sessions, TimeAmount.DAY.ms()); - int perDayWeek = AnalysisUtils.getUniqueJoinsPerDay(sessions, TimeAmount.WEEK.ms()); - int perDayMonth = AnalysisUtils.getUniqueJoinsPerDay(sessions, TimeAmount.MONTH.ms()); - - addValue("playersAverage", perDay); - addValue("playersAverageDay", perDayDay); - addValue("playersAverageWeek", perDayWeek); - addValue("playersAverageMonth", perDayMonth); - } - - private void newPlayers() { - long now = MiscUtils.getTime(); - List registeredList = getRegisteredList(); - long newDay = AnalysisUtils.getNewPlayers(registeredList, TimeAmount.DAY.ms(), now); - long newWeek = AnalysisUtils.getNewPlayers(registeredList, TimeAmount.WEEK.ms(), now); - long newMonth = AnalysisUtils.getNewPlayers(registeredList, TimeAmount.MONTH.ms(), now); - - addValue("playersNewDay", newDay); - addValue("playersNewWeek", newWeek); - addValue("playersNewMonth", newMonth); - - long newPerDay = AnalysisUtils.getNewUsersPerDay(registeredList, -1); - long newPerDayDay = AnalysisUtils.getNewUsersPerDay(registeredList, TimeAmount.DAY.ms()); - long newPerDayWeek = AnalysisUtils.getNewUsersPerDay(registeredList, TimeAmount.WEEK.ms()); - long newPerDayMonth = AnalysisUtils.getNewUsersPerDay(registeredList, TimeAmount.MONTH.ms()); - - addValue("playersNewAverage", newPerDay); - addValue("playersNewAverageDay", newPerDayDay); - addValue("playersNewAverageWeek", newPerDayWeek); - addValue("playersNewAverageMonth", newPerDayMonth); - } - - public void addToLoginTimes() { - addToLoginTimes(1); - } - - public void addToLoginTimes(int amount) { - loginTimes += amount; - } - - public long getLoginTimes() { - return loginTimes; - } - - public Map> getSessions() { - return sessions; - } - - public List getAllSessions() { - List sessions = MiscUtils.flatMap(this.sessions.values()); - sessions.addAll(activeSessions.values()); - return sessions; - } - - public void addRegistered(UUID uuid, long registerDate) { - registered.put(uuid, registerDate); - } - - public void addRegistered(Map registerDates) { - registered.putAll(registerDates); - } - - public Map getRegistered() { - return registered; - } - - public List getRegisteredList() { - return new ArrayList<>(registered.values()); - } - - public void addSessions(Map> sessions) { - this.sessions.putAll(Verify.nullCheck(sessions)); - } - - public void addSessions(UUID uuid, List sessions) { - Verify.nullCheck(uuid); - Verify.nullCheck(sessions); - this.sessions.put(uuid, sessions.stream().distinct().collect(Collectors.toList())); - } - - public void addActiveSessions(Map activeSessions) { - this.activeSessions.putAll(activeSessions); - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/KillPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/KillPart.java deleted file mode 100644 index 71178bcea..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/KillPart.java +++ /dev/null @@ -1,68 +0,0 @@ -package main.java.com.djrapitops.plan.data.analysis; - -import main.java.com.djrapitops.plan.data.PlayerKill; -import main.java.com.djrapitops.plan.data.Session; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -/** - * Part responsible for all Death related analysis. - *

- * Placeholder values can be retrieved using the get method. - *

- * Contains following placeholders after analyzed: - * ${killCount} - (Number) - * ${mobKillCount} - (Number) - * ${deathCount} - (Number) - * - * @author Rsl1122 - * @since 3.5.2 - */ -@Deprecated -public class KillPart extends RawData { - - private final JoinInfoPart joinInfoPart; - - private long playerKills; - private long mobKills; - private long deaths; - - public KillPart(JoinInfoPart joinInfoPart) { - this.joinInfoPart = joinInfoPart; - - playerKills = 0; - mobKills = 0; - deaths = 0; - } - - @Override - public void analyse() { - List sessions = joinInfoPart.getAllSessions(); - deaths += sessions.stream().mapToLong(Session::getDeaths).sum(); - mobKills += sessions.stream().mapToLong(Session::getMobKills).sum(); - playerKills += sessions.stream().map(Session::getPlayerKills).mapToLong(Collection::size).sum(); - - addValue("deathCount", this.deaths); - addValue("mobKillCount", mobKills); - addValue("killCount", playerKills); - } - - public long getPlayerKills() { - return playerKills; - } - - public long getMobKills() { - return mobKills; - } - - public long getDeaths() { - return deaths; - } - - public void addKills(Map> playerKills) { - this.playerKills += playerKills.values().stream().mapToLong(Collection::size).sum(); - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/PlayerCountPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/PlayerCountPart.java deleted file mode 100644 index 607f4c6cd..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/PlayerCountPart.java +++ /dev/null @@ -1,69 +0,0 @@ -package main.java.com.djrapitops.plan.data.analysis; - -import com.djrapitops.plugin.utilities.Verify; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - -/** - * Part responsible for counting players. - *

- * Placeholder values can be retrieved using the get method. - *

- * Contains following placeholders after analyzed: - * ${playersTotal}, ${ops} - * - * @author Rsl1122 - * @since 3.5.2 - */ -@Deprecated -public class PlayerCountPart extends RawData { - - private final Set uuids; - private final Set ops; - - public PlayerCountPart() { - uuids = new HashSet<>(); - ops = new HashSet<>(); - } - - @Override - public void analyse() { - addValue("ops", ops.size()); - addValue("playersTotal", uuids.size()); - } - - public void addPlayer(UUID uuid) { - Verify.nullCheck(uuid); - uuids.add(uuid); - } - - public void addPlayers(Collection uuids) { - Verify.nullCheck(uuids); - this.uuids.addAll(uuids); - } - - public void addOPs(Collection uuids) { - Verify.nullCheck(uuids); - this.ops.addAll(uuids); - } - - public void addOP(UUID uuid) { - Verify.nullCheck(uuid); - ops.add(uuid); - } - - public Set getUuids() { - return uuids; - } - - public int getPlayerCount() { - return uuids.size(); - } - - public Set getOps() { - return ops; - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/PlaytimePart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/PlaytimePart.java deleted file mode 100644 index 651c1f88a..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/PlaytimePart.java +++ /dev/null @@ -1,55 +0,0 @@ -package main.java.com.djrapitops.plan.data.analysis; - -import main.java.com.djrapitops.plan.utilities.FormatUtils; - -/** - * Part responsible for all Playtime related analysis. - *

- * Placeholder values can be retrieved using the get method. - *

- * Contains following placeholders after analyzed: - * ${playtimeTotal} - Formatted time amount - * - * @author Rsl1122 - * @since 3.5.2 - */ -@Deprecated -public class PlaytimePart extends RawData { - - private long totalPlaytime; - private long playtime30d; - private long playtime7d; - private long playtime24h; - - public PlaytimePart() { - totalPlaytime = 0; - } - - @Override - public void analyse() { - addValue("playtimeTotal", FormatUtils.formatTimeAmount(totalPlaytime)); - addValue("playtimeMonth", FormatUtils.formatTimeAmount(playtime30d)); - addValue("playtimeWeek", FormatUtils.formatTimeAmount(playtime7d)); - addValue("playtimeDay", FormatUtils.formatTimeAmount(playtime24h)); - } - - public void addToPlaytime(long amount) { - totalPlaytime += amount; - } - - public void setTotalPlaytime(long totalPlaytime) { - this.totalPlaytime = totalPlaytime; - } - - public void setPlaytime30d(long playtime30d) { - this.playtime30d = playtime30d; - } - - public void setPlaytime7d(long playtime7d) { - this.playtime7d = playtime7d; - } - - public void setPlaytime24h(long playtime24h) { - this.playtime24h = playtime24h; - } -} 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 deleted file mode 100644 index e4fda3777..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/TPSPart.java +++ /dev/null @@ -1,159 +0,0 @@ -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.Settings; -import main.java.com.djrapitops.plan.data.TPS; -import main.java.com.djrapitops.plan.systems.webserver.theme.Colors; -import main.java.com.djrapitops.plan.utilities.FormatUtils; -import main.java.com.djrapitops.plan.utilities.MiscUtils; -import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; -import main.java.com.djrapitops.plan.utilities.html.graphs.CPUGraphCreator; -import main.java.com.djrapitops.plan.utilities.html.graphs.RamGraphCreator; -import main.java.com.djrapitops.plan.utilities.html.graphs.TPSGraphCreator; -import main.java.com.djrapitops.plan.utilities.html.graphs.WorldLoadGraphCreator; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * Part responsible for all TPS related analysis. - *

- * Placeholder values can be retrieved using the get method. - *

- * Contains following placeholders after being analyzed: - * ${tpsSeries} - HighCharts data - * ${cpuSeries} - HighCharts data - * ${ramSeries} - HighCharts data - * ${entitySeries} - HighCharts data - * ${chunkSeries} - HighCharts data - *

- * ${tpsAverageDay} - (Number) - * ${tpsAverageWeek} - (Number) - * ${cpuAverageDay} - (Number)% - * ${cpuAverageWeek} - (Number)% - * ${ramAverageDay} - (Number) MB - * ${ramAverageWeek} - (Number) MB - * ${entityAverageDay} - (Number) - * ${entityAverageWeek} - (Number) - * ${chunkAverageDay} - (Number) - * ${chunkAverageWeek} - (Number) - *

- * ${tpsMedium} - (Number) Color Threshold for Medium TPS - * ${tpsHigh} - (Number) Color Threshold for High TPS - * ${tpsLowColor} - Color of Low TPS - * ${tpsMediumColor} - Color of Low TPS - * ${tpsHighColor} - Color of Low TPS - * - * @author Rsl1122 - * @since 3.5.2 - */ -@Deprecated -public class TPSPart extends RawData { - - private final List tpsData; - private TPS allTimePeak; - private TPS lastPeak; - - public TPSPart() { - this.tpsData = new ArrayList<>(); - } - - @Override - public void analyse() { - long now = MiscUtils.getTime(); - List week = TPSGraphCreator.filterTPS(tpsData, now - TimeAmount.WEEK.ms()); - List day = TPSGraphCreator.filterTPS(tpsData, now - TimeAmount.DAY.ms()); - - tpsGraphOptions(); - - chartData(); - - averages(week, day); - - peaks(); - } - - private void peaks() { - if (lastPeak != null) { - addValue("lastPeakTime", FormatUtils.formatTimeStampYear(lastPeak.getDate())); - addValue("playersLastPeak", lastPeak.getPlayers()); - } else { - addValue("lastPeakTime", "No Data"); - addValue("playersLastPeak", "-"); - } - - if (allTimePeak != null) { - addValue("bestPeakTime", FormatUtils.formatTimeStampYear(allTimePeak.getDate())); - addValue("playersBestPeak", allTimePeak.getPlayers()); - } else { - addValue("bestPeakTime", "No Data"); - addValue("playersBestPeak", "-"); - } - } - - private void averages(List week, List day) { - double averageTPSWeek = MathUtils.averageDouble(week.stream().map(TPS::getTicksPerSecond)); - double averageTPSDay = MathUtils.averageDouble(day.stream().map(TPS::getTicksPerSecond)); - - double averageCPUWeek = MathUtils.averageDouble(week.stream().map(TPS::getCPUUsage).filter(i -> i != 0)); - double averageCPUDay = MathUtils.averageDouble(day.stream().map(TPS::getCPUUsage).filter(i -> i != 0)); - - long averageUsedMemoryWeek = MathUtils.averageLong(week.stream().map(TPS::getUsedMemory).filter(i -> i != 0)); - long averageUsedMemoryDay = MathUtils.averageLong(day.stream().map(TPS::getUsedMemory).filter(i -> i != 0)); - - double averageEntityCountWeek = MathUtils.averageInt(week.stream().map(TPS::getEntityCount).filter(i -> i != 0)); - double averageEntityCountDay = MathUtils.averageInt(day.stream().map(TPS::getEntityCount).filter(i -> i != 0)); - - double averageChunksLoadedWeek = MathUtils.averageInt(week.stream().map(TPS::getChunksLoaded).filter(i -> i != 0)); - double averageChunksLoadedDay = MathUtils.averageInt(day.stream().map(TPS::getChunksLoaded).filter(i -> i != 0)); - - addValue("tpsAverageWeek", FormatUtils.cutDecimals(averageTPSWeek)); - addValue("tpsAverageDay", FormatUtils.cutDecimals(averageTPSDay)); - - addValue("cpuAverageWeek", averageCPUWeek >= 0 ? FormatUtils.cutDecimals(averageCPUWeek) + "%" : "Unavailable"); - addValue("cpuAverageDay", averageCPUDay >= 0 ? FormatUtils.cutDecimals(averageCPUDay) + "%" : "Unavailable"); - - addValue("ramAverageWeek", FormatUtils.cutDecimals(averageUsedMemoryWeek)); - addValue("ramAverageDay", FormatUtils.cutDecimals(averageUsedMemoryDay)); - - addValue("entityAverageWeek", FormatUtils.cutDecimals(averageEntityCountWeek)); - addValue("entityAverageDay", FormatUtils.cutDecimals(averageEntityCountDay)); - - addValue("chunkAverageWeek", FormatUtils.cutDecimals(averageChunksLoadedWeek)); - addValue("chunkAverageDay", FormatUtils.cutDecimals(averageChunksLoadedDay)); - } - - private void chartData() { - addValue("tpsSeries", TPSGraphCreator.buildSeriesDataString(tpsData)); - addValue("cpuSeries", CPUGraphCreator.buildSeriesDataString(tpsData)); - addValue("ramSeries", RamGraphCreator.buildSeriesDataString(tpsData)); - addValue("entitySeries", WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsData)); - addValue("chunkSeries", WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsData)); - } - - private void tpsGraphOptions() { - addValue("tpsHighColor", Colors.TPS_HIGH.getColor()); - addValue("tpsMediumColor", Colors.TPS_MED.getColor()); - addValue("tpsLowColor", Colors.TPS_LOW.getColor()); - addValue("tpsMedium", Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber()); - addValue("tpsHigh", Settings.THEME_GRAPH_TPS_THRESHOLD_HIGH.getNumber()); - } - - public List getTpsData() { - return tpsData; - } - - public void addTpsData(Collection data) { - tpsData.addAll(Verify.nullCheck(data)); - } - - public void setAllTimePeak(TPS allTimePeak) { - this.allTimePeak = allTimePeak; - } - - public void setLastPeak(TPS lastPeak) { - this.lastPeak = lastPeak; - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/WorldPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/WorldPart.java deleted file mode 100644 index 399337c96..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/WorldPart.java +++ /dev/null @@ -1,50 +0,0 @@ -package main.java.com.djrapitops.plan.data.analysis; - -import main.java.com.djrapitops.plan.Settings; -import main.java.com.djrapitops.plan.data.time.WorldTimes; -import main.java.com.djrapitops.plan.utilities.FormatUtils; -import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator; - -import java.util.HashMap; - -/** - * Part responsible for all World Playtime related analysis. - *

- * World times Pie - *

- * Placeholder values can be retrieved using the get method. - *

- * Contains following placeholders after analyzed: - * ${worldTotal} - Total playtime for all worlds - * ${worldSeries} - Data for HighCharts - * - * @author Rsl1122 - * @since 3.6.0 - */ -@Deprecated -public class WorldPart extends RawData { - - private WorldTimes worldTimes; - - public WorldPart() { - worldTimes = new WorldTimes(new HashMap<>()); - } - - @Override - protected void analyse() { - addValue("worldTotal", FormatUtils.formatTimeAmount(worldTimes.getTotal())); - String[] seriesData = WorldPieCreator.createSeriesData(worldTimes); - addValue("worldSeries", seriesData[0]); - addValue("gmSeries", seriesData[1]); - addValue("worldPieColors", Settings.THEME_GRAPH_WORLD_PIE.toString()); - addValue("gmPieColors", Settings.THEME_GRAPH_GM_PIE.toString()); - } - - public WorldTimes getWorldTimes() { - return worldTimes; - } - - public void setWorldTimes(WorldTimes worldTimes) { - this.worldTimes = worldTimes; - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/AnalysisPageParser.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/AnalysisPageParser.java index fe4a76e08..ed9dcbd48 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/AnalysisPageParser.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/AnalysisPageParser.java @@ -7,12 +7,9 @@ package main.java.com.djrapitops.plan.systems.info.parsing; import com.djrapitops.plugin.api.Check; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.PlanBungee; -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.AnalysisData; -import main.java.com.djrapitops.plan.utilities.FormatUtils; -import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.file.FileUtil; import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; @@ -37,12 +34,7 @@ public class AnalysisPageParser extends PageParser { public String parse() throws ParseException { addValues(data.getReplaceMap()); addValue("tabContentPlugins", data.replacePluginsTabLayout()); - addValue("serverName", Settings.SERVER_NAME.toString()); - addValue("timeZone", MiscUtils.getTimeZoneOffsetHours()); - addValue("refresh", FormatUtils.formatTimeStamp(data.getRefreshDate())); - addValue("playersMax", plugin.getVariable().getMaxPlayers()); - addValue("playersOnline", getPlayersOnline()); try { return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("web/server.html"), placeHolders); } catch (IOException e) { 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 089be4592..fdb47afa8 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 @@ -2,36 +2,28 @@ package main.java.com.djrapitops.plan.utilities.analysis; import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.api.Benchmark; -import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.RunnableFactory; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Settings; -import main.java.com.djrapitops.plan.data.*; +import main.java.com.djrapitops.plan.data.AnalysisData; +import main.java.com.djrapitops.plan.data.ServerProfile; import main.java.com.djrapitops.plan.data.additional.AnalysisType; import main.java.com.djrapitops.plan.data.additional.HookHandler; import main.java.com.djrapitops.plan.data.additional.PluginData; -import main.java.com.djrapitops.plan.data.analysis.*; -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.TPSTable; import main.java.com.djrapitops.plan.locale.Locale; import main.java.com.djrapitops.plan.locale.Msg; -import main.java.com.djrapitops.plan.systems.cache.SessionCache; import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager; import main.java.com.djrapitops.plan.systems.info.InformationManager; import main.java.com.djrapitops.plan.systems.webserver.response.ErrorResponse; import main.java.com.djrapitops.plan.systems.webserver.response.InternalErrorResponse; -import main.java.com.djrapitops.plan.utilities.MiscUtils; -import main.java.com.djrapitops.plan.utilities.comparators.UserInfoLastPlayedComparator; import main.java.com.djrapitops.plan.utilities.html.HtmlStructure; -import main.java.com.djrapitops.plan.utilities.html.tables.PlayersTableCreator; import org.apache.commons.lang3.StringUtils; import java.io.Serializable; -import java.sql.SQLException; import java.util.*; import java.util.stream.Collectors; @@ -120,19 +112,22 @@ public class Analysis { analysisData.setPluginsTabLayout(HtmlStructure.createAnalysisPluginsTabLayout(thirdPartyPlugins)); Benchmark.stop("Analysis", "Create Empty dataset"); - fillDataset(analysisData, db); + Benchmark.start("Fetch Phase"); + ServerProfile profile = db.getServerProfile(Plan.getServerUUID()); long fetchPhaseLength = Benchmark.stop("Analysis", "Fetch Phase"); Benchmark.start("Analysis Phase"); Log.logDebug("Analysis", "Analysis Phase"); - log(Locale.get(Msg.ANALYSIS_PHASE_START).parse(analysisData.getPlayerCountPart().getPlayerCount(), fetchPhaseLength)); - analysisData.analyseData(); + log(Locale.get(Msg.ANALYSIS_PHASE_START).parse(profile.getPlayerCount(), fetchPhaseLength)); + + analysisData.analyze(profile); + Benchmark.stop("Analysis", "Analysis Phase"); log(Locale.get(Msg.ANALYSIS_3RD_PARTY).toString()); Log.logDebug("Analysis", "Analyzing additional data sources (3rd party)"); - analysisData.setAdditionalDataReplaceMap(analyzeAdditionalPluginData(analysisData.getPlayerCountPart().getUuids())); + analysisData.setAdditionalDataReplaceMap(analyzeAdditionalPluginData(profile.getUuids())); ((BukkitInformationManager) infoManager).cacheAnalysisData(analysisData); // TODO Export @@ -232,106 +227,4 @@ public class Analysis { public void setTaskId(int id) { taskId = id; } - - private void fillDataset(AnalysisData analysisData, Database db) { - ActivityPart activity = analysisData.getActivityPart(); - CommandUsagePart commandUsagePart = analysisData.getCommandUsagePart(); - GeolocationPart geolocPart = analysisData.getGeolocationPart(); - JoinInfoPart joinInfo = analysisData.getJoinInfoPart(); - KillPart killPart = analysisData.getKillPart(); - PlayerCountPart playerCount = analysisData.getPlayerCountPart(); - PlaytimePart playtime = analysisData.getPlaytimePart(); - TPSPart tpsPart = analysisData.getTpsPart(); - WorldPart worldPart = analysisData.getWorldPart(); - - long now = MiscUtils.getTime(); - - Benchmark.start("Analysis", "Fetch Phase"); - try { - Map commandUse = plugin.getDB().getCommandUse(); - commandUsagePart.setCommandUsage(commandUse); - - TPSTable tpsTable = db.getTpsTable(); - List tpsData = tpsTable.getTPSData(); - tpsTable.getAllTimePeak().ifPresent(tpsPart::setAllTimePeak); - tpsTable.getPeakPlayerCount(now - (TimeAmount.DAY.ms() * 2)).ifPresent(tpsPart::setLastPeak); - - tpsPart.addTpsData(tpsData); - Log.logDebug("Analysis", "TPS Data Size: " + tpsData.size()); - - List userInfo = db.getUserInfoTable().getServerUserInfo().stream().distinct().collect(Collectors.toList()); - - for (UserInfo user : userInfo) { - if (user.isBanned()) { - activity.addBan(user.getUuid()); - } - } - - Map lastSeen = db.getSessionsTable().getLastSeenForAllPlayers(); - for (UserInfo info : userInfo) { - Long userLastSeen = lastSeen.getOrDefault(info.getUuid(), 0L); - info.setLastSeen(userLastSeen); - } - - userInfo.sort(new UserInfoLastPlayedComparator()); - - activity.setRecentPlayersUUIDs(userInfo.stream().map(UserInfo::getUuid).collect(Collectors.toList())); - activity.setRecentPlayers(userInfo.stream().map(UserInfo::getName).collect(Collectors.toList())); - - playerCount.addPlayers(userInfo.stream().map(UserInfo::getUuid).collect(Collectors.toSet())); - - Map registered = userInfo.stream().collect(Collectors.toMap(UserInfo::getUuid, UserInfo::getRegistered)); - joinInfo.addRegistered(registered); - activity.addBans(userInfo.stream().filter(UserInfo::isBanned).map(UserInfo::getUuid).collect(Collectors.toSet())); - - playerCount.addOPs(userInfo.stream().filter(UserInfo::isOpped).map(UserInfo::getUuid).collect(Collectors.toSet())); - - Map activeSessions = SessionCache.getActiveSessions(); - Map> sessions = db.getSessionsTable().getAllSessions(true).get(Plan.getServerUUID()); - joinInfo.addActiveSessions(activeSessions); - if (sessions != null) { - joinInfo.addSessions(sessions); - } - - Map> geolocations = db.getIpsTable().getAllGeoInfo(); -// geolocPart.addGeoLocations(geolocations); - - analysisData.setPlayersTable(PlayersTableCreator.createTable(userInfo, joinInfo, geolocPart)); - - Map> playerKills = db.getKillsTable().getPlayerKills(); - killPart.addKills(playerKills); - - WorldTimes worldTimes = db.getWorldTimesTable().getWorldTimesOfServer(); - AnalysisUtils.addMissingWorlds(worldTimes); - - worldPart.setWorldTimes(worldTimes); - - playtime.setTotalPlaytime(db.getSessionsTable().getPlaytimeOfServer()); - playtime.setPlaytime30d(db.getSessionsTable().getPlaytimeOfServer(now - TimeAmount.MONTH.ms())); - playtime.setPlaytime7d(db.getSessionsTable().getPlaytimeOfServer(now - TimeAmount.WEEK.ms())); - playtime.setPlaytime24h(db.getSessionsTable().getPlaytimeOfServer(now - TimeAmount.DAY.ms())); - - List banSources = plugin.getHookHandler().getAdditionalDataSources() - .stream().filter(PluginData::isBanData).collect(Collectors.toList()); - - for (UUID uuid : playerCount.getUuids()) { - boolean banned = banSources.stream().anyMatch(pluginData -> { - StaticHolder.saveInstance(this.getClass(), plugin.getClass()); - try { - Serializable value = pluginData.getValue(uuid); - return value instanceof Boolean - && (boolean) value; - } catch (Exception | NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) { - Log.toLog(pluginData.getSourcePlugin() + pluginData.getPlaceholder() + " (Cause) ", e); - return false; - } - }); - if (banned) { - activity.addBan(uuid); - } - } - } catch (SQLException e) { - Log.toLog(this.getClass().getName(), e); - } - } } 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 8eac8d770..6cd8f5088 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 @@ -191,16 +191,12 @@ public class AnalysisUtils { return uniqueJoins.size(); } - @Deprecated - public static int getUniqueJoinsPerDay(Map> sessions, long scale) { + public static int getUniqueJoinsPerDay(Map> sessions, long after) { Map> uniqueJoins = new HashMap<>(); - long now = MiscUtils.getTime(); - long nowMinusScale = now - scale; sessions.forEach((uuid, s) -> { for (Session session : s) { - if (scale != -1 - && session.getSessionStart() < nowMinusScale) { + if (session.getSessionStart() < after) { continue; } @@ -221,23 +217,15 @@ public class AnalysisUtils { return total / numberOfDays; } - @Deprecated - public static long getNewUsersPerDay(List registers, long scale) { - long now = MiscUtils.getTime(); - long nowMinusScale = now - scale; - + public static long getNewUsersPerDay(List registers, long after, long total) { Set days = new HashSet<>(); for (Long date : registers) { - if (scale != -1) { - if (date < nowMinusScale) { - continue; - } - int day = getDayOfYear(date); - days.add(day); + if (date < after) { + continue; } + int day = getDayOfYear(date); + days.add(day); } - - long total = registers.stream().filter(date -> date >= nowMinusScale).count(); int numberOfDays = days.size(); if (numberOfDays == 0) { 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 01e05ec95..68632f229 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 @@ -58,7 +58,7 @@ public enum Html { ), TABLE_PLAYERS("" + "" + - "" + + "" + "" + "" + "" + 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 4a02ee554..e2b23de56 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 @@ -13,7 +13,6 @@ import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager; 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.structure.SessionTabStructureCreator; -import main.java.com.djrapitops.plan.utilities.html.tables.SessionsTableCreator; import org.apache.commons.lang3.text.StrSubstitutor; import java.io.Serializable; @@ -106,7 +105,7 @@ public class HtmlStructure { } } - return new String[]{Html.TABLE_SESSIONS.parse(SessionsTableCreator.createTable(uuidByID, allSessions)[0]), ""}; + return new String[]{/*Html.TABLE_SESSIONS.parse(SessionsTableCreator.createTable(uuidByID, allSessions)[0]),*/"", ""}; } public static String createInspectPluginsTabContent(String serverName, List plugins, Map replaceMap) { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java index 9f494c01d..53d73b4dc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java @@ -6,21 +6,18 @@ package main.java.com.djrapitops.plan.utilities.html.structure; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Plan; -import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.data.Session; -import main.java.com.djrapitops.plan.data.analysis.JoinInfoPart; import main.java.com.djrapitops.plan.data.time.WorldTimes; import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; -import main.java.com.djrapitops.plan.utilities.comparators.SessionStartComparator; -import main.java.com.djrapitops.plan.utilities.html.Html; import main.java.com.djrapitops.plan.utilities.html.HtmlStructure; import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator; import main.java.com.djrapitops.plan.utilities.html.tables.KillsTableCreator; -import main.java.com.djrapitops.plan.utilities.html.tables.SessionsTableCreator; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; /** * //TODO Class Javadoc Comment @@ -33,9 +30,9 @@ public class SessionTabStructureCreator { Map uuidsByID = generateIDtoUUIDMap(sessions); - if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) { - return new String[]{Html.TABLE_SESSIONS.parse("", "", "", SessionsTableCreator.createTable(uuidsByID, allSessions)[0]), ""}; - } +// if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) { +// return new String[]{Html.TABLE_SESSIONS.parse("", "", "", SessionsTableCreator.createTable(uuidsByID, allSessions)[0]), ""}; +// } if (Verify.isEmpty(allSessions)) { return new String[]{"
" + @@ -172,20 +169,15 @@ public class SessionTabStructureCreator { return uuidsByID; } - public static String[] creteStructure(JoinInfoPart joinInfoPart) { + public static String[] creteStructure(Map> sessions, List allSessions) { Map>> map = new HashMap<>(); - Map> sessions = joinInfoPart.getSessions(); + for (Map.Entry> entry : sessions.entrySet()) { Map> serverSpecificMap = new HashMap<>(); serverSpecificMap.put("This server", entry.getValue()); map.put(entry.getKey(), serverSpecificMap); } - List allSessions = sessions.values().stream() - .flatMap(Collection::stream) - .sorted(new SessionStartComparator()) - .collect(Collectors.toList()); - return creteStructure(map, allSessions, true); } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/PlayersTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/PlayersTableCreator.java index 3fbef1aeb..0113401f0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/PlayersTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/PlayersTableCreator.java @@ -4,17 +4,12 @@ import com.djrapitops.plugin.api.utility.log.Log; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Settings; 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.analysis.GeolocationPart; -import main.java.com.djrapitops.plan.data.analysis.JoinInfoPart; 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.PlayerProfileLastPlayedComparator; import main.java.com.djrapitops.plan.utilities.html.Html; import java.util.List; -import java.util.Map; import java.util.UUID; /** @@ -29,87 +24,13 @@ public class PlayersTableCreator { throw new IllegalStateException("Utility class"); } - @Deprecated - public static String createTable(List userInfo, JoinInfoPart joinInfoPart, GeolocationPart geolocationPart) { - if (userInfo.isEmpty()) { - return Html.TABLELINE_PLAYERS.parse("No Players", "", "", "", "", "", "", "", "", ""); - } - - StringBuilder html = new StringBuilder(); - - Map> sessions = joinInfoPart.getSessions(); - Map geoLocations = geolocationPart.getMostCommonGeoLocations(); - - long now = MiscUtils.getTime(); - - int i = 0; - for (UserInfo user : userInfo) { - if (i >= 750) { - break; - } - - try { - UUID uuid = user.getUuid(); - boolean isBanned = user.isBanned(); - List userSessions = sessions.get(uuid); - int loginTimes = 0; - long playtime = 0; - if (userSessions != null) { - loginTimes = userSessions.size(); - playtime = AnalysisUtils.getTotalPlaytime(userSessions); - } - boolean isUnknown = loginTimes == 1; - long registered = user.getRegistered(); - - boolean isActive = AnalysisUtils.isActive(now, user.getLastSeen(), playtime, loginTimes); - - long lastSeen = user.getLastSeen(); - - String activityString = getActivityString(isBanned, isUnknown, isActive); - - - String geoLocation = geoLocations.get(uuid); - if (geoLocation == null) { - geoLocation = "Not Known"; - } - html.append(Html.TABLELINE_PLAYERS.parse( - Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(user.getName()), user.getName()), - activityString, - String.valueOf(playtime), FormatUtils.formatTimeAmount(playtime), - String.valueOf(loginTimes), - String.valueOf(registered), FormatUtils.formatTimeStampYear(registered), - String.valueOf(lastSeen), lastSeen != 0 ? FormatUtils.formatTimeStamp(lastSeen) : "-", - String.valueOf(geoLocation) - )); - } catch (NullPointerException e) { - if (Settings.DEV_MODE.isTrue()) { - Log.toLog(PlayersTableCreator.class.getName(), e); - } - } - - i++; - } - - return html.toString(); - } - - private static String getActivityString(boolean isBanned, boolean isUnknown, boolean isActive) { - if (isBanned) { - return "Banned"; - } - - if (isUnknown) { - return "Unknown"; - } - - return isActive ? "Active" : "Inactive"; - } - public static String createTable(List players) { if (players.isEmpty()) { return Html.TABLELINE_PLAYERS.parse("No Players", "", "", "", "", "", "", "", "", ""); } + players.sort(new PlayerProfileLastPlayedComparator()); + StringBuilder html = new StringBuilder(); long now = MiscUtils.getTime(); @@ -125,14 +46,11 @@ public class PlayersTableCreator { boolean isBanned = profile.isBanned(); long loginTimes = profile.getSessionCount(serverUUID); long playtime = profile.getPlaytime(serverUUID); - boolean isUnknown = loginTimes <= 1; long registered = profile.getRegistered(); - boolean isActive = AnalysisUtils.isActive(now, profile.getLastSeen(), playtime, loginTimes); - long lastSeen = profile.getLastSeen(); - String activityString = getActivityString(isBanned, isUnknown, isActive); + String activityString = isBanned ? "Banned" : FormatUtils.cutDecimals(profile.getActivityIndex(now)); String geoLocation = profile.getMostRecentGeoInfo().getGeolocation(); html.append(Html.TABLELINE_PLAYERS.parse( diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java index a923c43d3..08e0bd2d2 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java @@ -7,7 +7,6 @@ package main.java.com.djrapitops.plan.utilities.html.tables; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.WorldAliasSettings; import main.java.com.djrapitops.plan.data.Session; -import main.java.com.djrapitops.plan.data.analysis.JoinInfoPart; import main.java.com.djrapitops.plan.data.time.WorldTimes; import main.java.com.djrapitops.plan.systems.cache.DataCache; import main.java.com.djrapitops.plan.systems.cache.SessionCache; @@ -26,25 +25,25 @@ import java.util.stream.Collectors; */ public class SessionsTableCreator { - public static String[] createTable(JoinInfoPart joinInfoPart) { + private static Map getUUIDsByID(Map> sessionsByUser) { Map uuidByID = new HashMap<>(); - for (Map.Entry> entry : joinInfoPart.getSessions().entrySet()) { + for (Map.Entry> entry : sessionsByUser.entrySet()) { List sessions = entry.getValue(); for (Session session : sessions) { uuidByID.put(session.getSessionID(), entry.getKey()); } } - - List allSessions = joinInfoPart.getAllSessions(); - return createTable(uuidByID, allSessions); + return uuidByID; } - public static String[] createTable(Map uuidByID, List allSessions) { + public static String[] createTable(Map> sessionsByUser, List allSessions) { if (allSessions.isEmpty()) { return new String[]{Html.TABLELINE_4.parse("No Sessions", "", "", ""), Html.TABLELINE_2.parse("No Sessions", "")}; } + Map uuidByID = getUUIDsByID(sessionsByUser); + allSessions.sort(new SessionStartComparator()); StringBuilder sessionTableBuilder = new StringBuilder(); @@ -88,7 +87,11 @@ public class SessionsTableCreator { )); if (recentLoginsNames.size() < 20 && !recentLoginsNames.contains(name)) { - recentLoginsBuilder.append(Html.TABLELINE_2.parse(Html.LINK.parse(inspectUrl, name), start)); + boolean isNew = sessionsByUser.get(uuid).size() <= 2; + + recentLoginsBuilder.append("
  • ").append(name).append("").append(start).append("
  • "); + recentLoginsNames.add(name); }
    Name Active Activity Index Playtime Sessions Registered