From 43a693403d0d6e35dbbfa24dc7770f066d6bdd85 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 18 Mar 2017 22:40:14 +0200 Subject: [PATCH] [2.9.0-DEV] Added demographics tab to analysis page, Bugfixes Fix #53 Fix #54 --- .../main/java/com/djrapitops/plan/Phrase.java | 2 +- .../commands/manage/ManageBackupCommand.java | 9 --- .../commands/manage/ManageImportCommand.java | 5 -- .../commands/manage/ManageMoveCommand.java | 6 -- .../djrapitops/plan/data/AnalysisData.java | 31 +++++++ .../djrapitops/plan/data/RawAnalysisData.java | 35 +++++++- .../plan/ui/webserver/Response.java | 6 +- .../djrapitops/plan/utilities/Analysis.java | 30 ++++++- .../plan/utilities/AnalysisUtils.java | 3 - .../plan/utilities/PlaceholderUtils.java | 3 + Plan/src/main/resources/analysis.html | 80 +++++++++++++++++-- 11 files changed, 173 insertions(+), 37 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/Phrase.java b/Plan/src/main/java/com/djrapitops/plan/Phrase.java index f6194d500..d46a053fd 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Phrase.java +++ b/Plan/src/main/java/com/djrapitops/plan/Phrase.java @@ -74,7 +74,7 @@ public enum Phrase { ERROR_NO_DATA_VIEW(ChatColor.YELLOW + "Webserver disabled but Alternative IP/PlanLite not used, no way to view data!"), ERROR_WEBSERVER_OFF_ANALYSIS(ChatColor.YELLOW + "" + PREFIX + "This command can be only used if the webserver is running on this server."), ERROR_WEBSERVER_OFF_INSPECT(ChatColor.YELLOW + "" + PREFIX + "This command can be only used if webserver/planlite is enabled on this server."), - ERROR_LOGGED("Caugth "+REPLACE0+". It has been logged to the Errors.txt"), + ERROR_LOGGED("Caught "+REPLACE0+". It has been logged to the Errors.txt"), ERROR_SESSIONDATA_INITIALIZATION("Player's session was initialized in a wrong way! (" + REPLACE0 + ")"), // CMD_FOOTER(COLOR_TER.color() + "" + ARROWS_RIGHT), diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java index 902a4250c..7399e9de9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java @@ -1,19 +1,10 @@ package main.java.com.djrapitops.plan.command.commands.manage; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Set; -import java.util.UUID; import main.java.com.djrapitops.plan.Phrase; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.command.CommandType; import main.java.com.djrapitops.plan.command.SubCommand; -import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor; import main.java.com.djrapitops.plan.database.Database; -import main.java.com.djrapitops.plan.database.databases.SQLiteDB; import main.java.com.djrapitops.plan.utilities.ManageUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java index b361a6919..82a65b0a7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java @@ -10,21 +10,16 @@ import main.java.com.djrapitops.plan.Phrase; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.command.CommandType; import main.java.com.djrapitops.plan.command.SubCommand; -import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor; import main.java.com.djrapitops.plan.data.cache.DataCacheHandler; import main.java.com.djrapitops.plan.data.importing.Importer; import main.java.com.djrapitops.plan.data.importing.OnTimeImporter; import main.java.com.djrapitops.plan.utilities.ManageUtils; import org.bukkit.Bukkit; -import org.bukkit.GameMode; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; -import static org.bukkit.Bukkit.getOfflinePlayer; -import static org.bukkit.Bukkit.getOfflinePlayer; /** * diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java index b2f38b70a..eae07a03f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java @@ -1,18 +1,12 @@ package main.java.com.djrapitops.plan.command.commands.manage; -import java.sql.SQLException; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.List; -import java.util.Set; import java.util.UUID; import main.java.com.djrapitops.plan.Phrase; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.command.CommandType; import main.java.com.djrapitops.plan.command.SubCommand; -import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor; import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.utilities.ManageUtils; import org.bukkit.command.Command; 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 c7ddb4c39..65ade50f0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/AnalysisData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/AnalysisData.java @@ -44,6 +44,10 @@ public class AnalysisData { private long totaldeaths; private long sessionAverage; + + private String geomapCountries; + private String geomapZ; + private String geomapCodes; /** * Class constructor. @@ -55,11 +59,38 @@ public class AnalysisData { commandUseTableHtml = Html.ERROR_NOT_SET+""; top20ActivePlayers = Html.ERROR_NOT_SET+""; recentPlayers = Html.ERROR_NOT_SET+""; + geomapCountries = Html.ERROR_NOT_SET+""; + geomapZ = Html.ERROR_NOT_SET+""; + geomapCodes = Html.ERROR_NOT_SET+""; playersDataArray = new String[]{"[0]","[\"No data\"]","[0]","[\"No data\"]","[0]","[\"No data\"]"}; } // Getters and setters v---------------------------------v + public String getGeomapCountries() { + return geomapCountries; + } + + public void setGeomapCountries(String geomapCountries) { + this.geomapCountries = geomapCountries; + } + + public String getGeomapZ() { + return geomapZ; + } + + public void setGeomapZ(String geomapZ) { + this.geomapZ = geomapZ; + } + + public String getGeomapCodes() { + return geomapCodes; + } + + public void setGeomapCodes(String geomapCodes) { + this.geomapCodes = geomapCodes; + } + /** * * @return diff --git a/Plan/src/main/java/com/djrapitops/plan/data/RawAnalysisData.java b/Plan/src/main/java/com/djrapitops/plan/data/RawAnalysisData.java index 7d1292c15..fef3fa924 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/RawAnalysisData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/RawAnalysisData.java @@ -29,6 +29,8 @@ public class RawAnalysisData { private HashMap playtimes; private List sessiondata; private HashMap commandUse; + private HashMap geolocations; + private HashMap geocodes; private List registered; /** @@ -51,11 +53,42 @@ public class RawAnalysisData { ages = new ArrayList<>(); latestLogins = new HashMap<>(); playtimes = new HashMap<>(); - sessiondata = new ArrayList<>(); + sessiondata = new ArrayList<>(); commandUse = new HashMap<>(); + geolocations = new HashMap<>(); + geocodes = new HashMap<>(); registered = new ArrayList<>(); } + public void addGeoloc(String country) { + if (geolocations.get(country) == null) { + return; + } + geolocations.put(country, geolocations.get(country) + 1); + } + + public void fillGeolocations() { + 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]; + if (geolocations.get(country) == null) { + geolocations.put(country, 0); + } + if (geocodes.get(country) == null) { + geocodes.put(country, codes[i]); + } + } + } + + public HashMap getGeolocations() { + return geolocations; + } + + public HashMap getGeocodes() { + return geocodes; + } + /** * * @param gmZero diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Response.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Response.java index 1f0ce4730..c18f9b8d4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Response.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Response.java @@ -47,7 +47,7 @@ public class Response { String[] requestArgs = request.getUri().split("/"); boolean forbidden = false; String securityCode = ""; - if (requestArgs.length < 2) { + if (requestArgs.length <= 2) { forbidden = true; } else { securityCode = requestArgs[1]; @@ -81,7 +81,7 @@ public class Response { if (requestHandler.checkIfCached(uuid)) { try { String dataHtml = requestHandler.getInspectHtml(uuid); - String htmlDef = "HTTP/1.1 OK\r\n" + String htmlDef = "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html; charset=utf-8\r\n" + "Content-Length: " + dataHtml.length() + "\r\n" + "\r\n"; @@ -101,7 +101,7 @@ public class Response { } else if (command.equals("server")) { if (requestHandler.checkIfAnalysisIsCached()) { String analysisHtml = requestHandler.getAnalysisHtml(); - String htmlDef = "HTTP/1.1 OK\r\n" + String htmlDef = "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html; charset=utf-8\r\n" + "Content-Length: " + analysisHtml.length() + "\r\n" + "\r\n"; diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java index aea2a31f1..b35bddc1f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java @@ -92,7 +92,8 @@ public class Analysis { /** * Caches analyzed data of db to the provided cache analysisCache. * - * @param analysisCache Cache that will contain AnalysisData result of this method. + * @param analysisCache Cache that will contain AnalysisData result of this + * method. * @param db Database which data will be analyzed. * @return Whether or not analysis was successful. */ @@ -132,6 +133,7 @@ public class Analysis { log(Phrase.ANALYSIS_BEGIN_ANALYSIS + ""); AnalysisData analysisData = new AnalysisData(); analysisData.setSortablePlayersTable(AnalysisUtils.createSortablePlayersTable(rawData)); + sorted.fillGeolocations(); // Fill Dataset with userdata. rawData.parallelStream().forEach((uData) -> { try { @@ -176,12 +178,14 @@ public class Analysis { sorted.addTotalDeaths(uData.getDeaths()); sorted.getSessiondata().addAll(uData.getSessions()); sorted.getRegistered().add(uData.getRegistered()); + sorted.addGeoloc(uData.getDemData().getGeoLocation()); uData.stopAccessing(); } catch (NullPointerException e) { plugin.logError(Phrase.DATA_CORRUPTION_WARN.parse(uData.getUuid() + "")); plugin.toLog(this.getClass().getName(), e); } - }); + }); + createCloroplethMap(analysisData, sorted.getGeolocations(), sorted.getGeocodes()); // Analyze & Save RawAnalysisData to AnalysisData createPlayerActivityGraphs(analysisData, sorted.getSessiondata(), sorted.getRegistered()); analysisData.setRecentPlayers(RecentPlayersButtonsCreator.createRecentLoginsButtons(sorted.getLatestLogins(), 20)); @@ -276,4 +280,26 @@ public class Analysis { plugin.log(msg); } } + + private void createCloroplethMap(AnalysisData aData, HashMap geolocations, HashMap geocodes) { + String locations = "["; + String z = "["; + String text = "["; + for (String c : geolocations.keySet()) { + locations += "\""+c+"\"" + ","; + z += geolocations.get(c) + ","; + String code = geocodes.get(c); + if (code != null) { + text += "\""+code+"\"" + ","; + } else { + text += "\"UNK\","; + } + } + locations += "]"; + z += "]"; + text += "]"; + aData.setGeomapCountries(locations.replace(",]", "]")); + aData.setGeomapZ(z.replace(",]", "]")); + aData.setGeomapCodes(text.replace(",]", "]")); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java index e663191da..ac65ce9ca 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java @@ -2,17 +2,14 @@ package main.java.com.djrapitops.plan.utilities; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.data.SessionData; import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.ui.Html; import main.java.com.djrapitops.plan.ui.tables.SortableCommandUseTableCreator; import main.java.com.djrapitops.plan.ui.tables.SortablePlayersTableCreator; -import main.java.com.djrapitops.plan.utilities.comparators.MapComparator; /** * 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 5497dd610..f9d47961e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/PlaceholderUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/PlaceholderUtils.java @@ -99,6 +99,9 @@ public class PlaceholderUtils { + "\",\"#" + Settings.HCOLOR_GMP_2 + "\",\"#" + Settings.HCOLOR_GMP_3 + "\""); replaceMap.putAll(plugin.getHookHandler().getAdditionalAnalysisReplaceRules()); replaceMap.put("%sessionaverage%", FormatUtils.formatTimeAmount(data.getSessionAverage() + "")); + replaceMap.put("%geomapcountries%", data.getGeomapCountries()); + replaceMap.put("%geomapz%", data.getGeomapZ()); + replaceMap.put("%geomapcodes%", data.getGeomapCodes()); return replaceMap; } diff --git a/Plan/src/main/resources/analysis.html b/Plan/src/main/resources/analysis.html index 33a81696e..41d8990e2 100644 --- a/Plan/src/main/resources/analysis.html +++ b/Plan/src/main/resources/analysis.html @@ -7,6 +7,7 @@ +