Analysis Fetch Phase

This commit is contained in:
Rsl1122 2017-08-25 12:46:38 +03:00
parent 4f8581bb0c
commit 5fdae6878e
15 changed files with 405 additions and 131 deletions

View File

@ -1,5 +1,6 @@
package main.java.com.djrapitops.plan.command.commands; package main.java.com.djrapitops.plan.command.commands;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils; import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
@ -11,9 +12,16 @@ import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.command.ConditionUtils; import main.java.com.djrapitops.plan.command.ConditionUtils;
import main.java.com.djrapitops.plan.locale.Locale; import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg; import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.utilities.Check; import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
/** /**
* This subcommand is used to run the analysis and access the /server link. * This subcommand is used to run the analysis and access the /server link.
* *
@ -23,6 +31,7 @@ import org.bukkit.ChatColor;
public class AnalyzeCommand extends SubCommand { public class AnalyzeCommand extends SubCommand {
private final Plan plugin; private final Plan plugin;
private final InformationManager infoManager;
/** /**
* Subcommand Constructor. * Subcommand Constructor.
@ -35,6 +44,7 @@ public class AnalyzeCommand extends SubCommand {
Permissions.ANALYZE.getPermission(), Permissions.ANALYZE.getPermission(),
Locale.get(Msg.CMD_USG_ANALYZE).parse()); Locale.get(Msg.CMD_USG_ANALYZE).parse());
this.plugin = plugin; this.plugin = plugin;
infoManager = plugin.getInfoManager();
} }
@Override @Override
@ -48,11 +58,14 @@ public class AnalyzeCommand extends SubCommand {
return true; return true;
} }
// TODO Check if analysis is enabled. Optional<Long> analysisRefreshDate = infoManager.getAnalysisRefreshDate();
// if (!Check.isTrue(analysisCache.isAnalysisEnabled(), Locale.get(Msg.CMD_INFO_ANALYSIS_TEMP_DISABLE).toString(), sender) boolean forcedRefresh = args.length >= 1 && "-r".equals(args[0]);
// && !analysisCache.isCached()) { boolean refresh = !analysisRefreshDate.isPresent()
// return true; || analysisRefreshDate.get() < MiscUtils.getTime() - TimeAmount.MINUTE.ms()
// } || forcedRefresh;
if (refresh) {
updateCache(sender, refresh);
}
sender.sendMessage(Locale.get(Msg.CMD_INFO_FETCH_DATA).toString()); sender.sendMessage(Locale.get(Msg.CMD_INFO_FETCH_DATA).toString());
if (plugin.getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) { if (plugin.getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {
@ -72,21 +85,37 @@ public class AnalyzeCommand extends SubCommand {
} }
}).runTaskAsynchronously(); }).runTaskAsynchronously();
} }
updateCache(sender);
return true; return true;
} }
private void updateCache(ISender sender) { private void updateCache(ISender sender, boolean refresh) {
// TODO // TODO
// if (!analysisCache.isCached() || MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > TimeAmount.MINUTE.ms()) { if (refresh) {
// int bootAnID = plugin.getBootAnalysisTaskID(); int bootAnID = plugin.getBootAnalysisTaskID();
// if (bootAnID != -1) { if (bootAnID != -1) {
// plugin.getServer().getScheduler().cancelTask(bootAnID); plugin.getServer().getScheduler().cancelTask(bootAnID);
// } }
// analysisCache.addNotification(sender); infoManager.addAnalysisNotification(sender);
// analysisCache.updateCache(); infoManager.refreshAnalysis();
// } else { } else {
// analysisCache.sendAnalysisMessage(sender); sendAnalysisMessage(Collections.singletonList(sender));
// } }
}
public static void sendAnalysisMessage(Collection<ISender> senders) {
for (ISender sender : senders) {
sender.sendMessage(Locale.get(Msg.CMD_HEADER_ANALYZE).toString());
// Link
String url = HtmlUtils.getServerAnalysisUrlWithProtocol();
String message = Locale.get(Msg.CMD_INFO_LINK).toString();
boolean console = !CommandUtils.isPlayer(sender);
if (console) {
sender.sendMessage(message + url);
} else {
sender.sendMessage(message);
sender.sendLink(" ", Locale.get(Msg.CMD_INFO_CLICK_ME).toString(), url);
}
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
}
} }
} }

View File

@ -107,6 +107,10 @@ public class ActivityPart extends RawData {
addValue("banned", counts[3]); addValue("banned", counts[3]);
} }
public void addBans(Collection<UUID> uuids) {
bans.addAll(uuids);
}
public void addBan(UUID uuid) { public void addBan(UUID uuid) {
Verify.nullCheck(uuid); Verify.nullCheck(uuid);
bans.add(uuid); bans.add(uuid);

View File

@ -3,7 +3,11 @@ package main.java.com.djrapitops.plan.data.analysis;
import main.java.com.djrapitops.plan.utilities.html.graphs.WorldMapCreator; import main.java.com.djrapitops.plan.utilities.html.graphs.WorldMapCreator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; 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. * Part responsible for all Geolocation related analysis.
@ -18,12 +22,14 @@ import java.util.Map;
*/ */
public class GeolocationPart extends RawData { public class GeolocationPart extends RawData {
private final Map<UUID, String> mostCommonGeolocations;
private final Map<String, String> geoCodes; private final Map<String, String> geoCodes;
private final Map<String, Integer> geoCodeCounts; private final Map<String, Integer> geoCodeCounts;
public GeolocationPart() { public GeolocationPart() {
geoCodes = new HashMap<>(); geoCodes = new HashMap<>();
geoCodeCounts = 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[] 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"}; 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"};
@ -47,4 +53,31 @@ public class GeolocationPart extends RawData {
geoCodeCounts.computeIfPresent(countryCode, (computedCountry, amount) -> amount + 1); geoCodeCounts.computeIfPresent(countryCode, (computedCountry, amount) -> amount + 1);
} }
} }
public void addGeoLocations(Map<UUID, List<String>> geolocations) {
for (Map.Entry<UUID, List<String>> entry : geolocations.entrySet()) {
String mostCommon = getMostCommon(entry.getValue());
mostCommonGeolocations.put(entry.getKey(), mostCommon);
addGeolocation(mostCommon);
}
}
private String getMostCommon(List<String> geoLocs) {
Map<String, Long> occurrences =
geoLocs.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
String mostCommon = "Not Known";
long count = -1;
for (Map.Entry<String, Long> entry : occurrences.entrySet()) {
Long value = entry.getValue();
if (value > count) {
mostCommon = entry.getKey();
count = value;
}
}
return mostCommon;
}
public Map<UUID, String> getMostCommonGeoLocations() {
return mostCommonGeolocations;
}
} }

View File

@ -31,18 +31,21 @@ import java.util.stream.Collectors;
* ${playersNewAverageWeek} - (Number) * ${playersNewAverageWeek} - (Number)
* ${playersNewAverageMonth} - (Number) * ${playersNewAverageMonth} - (Number)
* //TODO ${tableBodySessions}, ${sessionCount}, ${lastPeakTime}, ${playersLastPeak}, ${bestPeakTime}, ${playersBestPeak} * //TODO ${tableBodySessions}, ${sessionCount}, ${lastPeakTime}, ${playersLastPeak}, ${bestPeakTime}, ${playersBestPeak}
*
* @author Rsl1122 * @author Rsl1122
* @since 3.5.2 * @since 3.5.2
*/ */
public class JoinInfoPart extends RawData { public class JoinInfoPart extends RawData {
private final Map<UUID, Session> activeSessions;
private final Map<UUID, List<Session>> sessions; private final Map<UUID, List<Session>> sessions;
private final List<Long> registered; private final Map<UUID, Long> registered;
private long loginTimes; private long loginTimes;
public JoinInfoPart() { public JoinInfoPart() {
activeSessions = new HashMap<>();
sessions = new HashMap<>(); sessions = new HashMap<>();
registered = new ArrayList<>(); registered = new HashMap<>();
loginTimes = 0; loginTimes = 0;
} }
@ -77,18 +80,19 @@ public class JoinInfoPart extends RawData {
private void newPlayers() { private void newPlayers() {
long now = MiscUtils.getTime(); long now = MiscUtils.getTime();
long newDay = AnalysisUtils.getNewPlayers(registered, TimeAmount.DAY.ms(), now); List<Long> registeredList = getRegisteredList();
long newWeek = AnalysisUtils.getNewPlayers(registered, TimeAmount.WEEK.ms(), now); long newDay = AnalysisUtils.getNewPlayers(registeredList, TimeAmount.DAY.ms(), now);
long newMonth = AnalysisUtils.getNewPlayers(registered, TimeAmount.MONTH.ms(), now); long newWeek = AnalysisUtils.getNewPlayers(registeredList, TimeAmount.WEEK.ms(), now);
long newMonth = AnalysisUtils.getNewPlayers(registeredList, TimeAmount.MONTH.ms(), now);
addValue("playersNewDay", newDay); addValue("playersNewDay", newDay);
addValue("playersNewWeek", newWeek); addValue("playersNewWeek", newWeek);
addValue("playersNewMonth", newMonth); addValue("playersNewMonth", newMonth);
long newPerDay = AnalysisUtils.getNewUsersPerDay(registered, -1); long newPerDay = AnalysisUtils.getNewUsersPerDay(registeredList, -1);
long newPerDayDay = AnalysisUtils.getNewUsersPerDay(registered, TimeAmount.DAY.ms()); long newPerDayDay = AnalysisUtils.getNewUsersPerDay(registeredList, TimeAmount.DAY.ms());
long newPerDayWeek = AnalysisUtils.getNewUsersPerDay(registered, TimeAmount.WEEK.ms()); long newPerDayWeek = AnalysisUtils.getNewUsersPerDay(registeredList, TimeAmount.WEEK.ms());
long newPerDayMonth = AnalysisUtils.getNewUsersPerDay(registered, TimeAmount.MONTH.ms()); long newPerDayMonth = AnalysisUtils.getNewUsersPerDay(registeredList, TimeAmount.MONTH.ms());
addValue("playersNewAverage", newPerDay); addValue("playersNewAverage", newPerDay);
addValue("playersNewAverageDay", newPerDayDay); addValue("playersNewAverageDay", newPerDayDay);
@ -116,17 +120,34 @@ public class JoinInfoPart extends RawData {
return MiscUtils.flatMap(sessions.values()); return MiscUtils.flatMap(sessions.values());
} }
public void addRegistered(long registerDate) { public void addRegistered(UUID uuid, long registerDate) {
registered.add(registerDate); registered.put(uuid, registerDate);
} }
public List<Long> getRegistered() { public void addRegistered(Map<UUID, Long> registerDates) {
registered.putAll(registerDates);
}
public Map<UUID, Long> getRegistered() {
return registered; return registered;
} }
public List<Long> getRegisteredList() {
return new ArrayList<>(registered.values());
}
public void addSessions(Map<UUID, List<Session>> sessions) {
Verify.nullCheck(sessions);
this.sessions.putAll(sessions);
}
public void addSessions(UUID uuid, List<Session> sessions) { public void addSessions(UUID uuid, List<Session> sessions) {
Verify.nullCheck(uuid); Verify.nullCheck(uuid);
Verify.nullCheck(sessions); Verify.nullCheck(sessions);
this.sessions.put(uuid, sessions.stream().distinct().collect(Collectors.toList())); this.sessions.put(uuid, sessions.stream().distinct().collect(Collectors.toList()));
} }
public void addActiveSessions(Map<UUID, Session> activeSessions) {
this.activeSessions.putAll(activeSessions);
}
} }

View File

@ -1,14 +1,5 @@
package main.java.com.djrapitops.plan.data.analysis; package main.java.com.djrapitops.plan.data.analysis;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.data.PlayerKill;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/** /**
* Part responsible for all Death related analysis. * Part responsible for all Death related analysis.
* <p> * <p>
@ -24,12 +15,12 @@ import java.util.UUID;
*/ */
public class KillPart extends RawData { public class KillPart extends RawData {
private final Map<UUID, List<PlayerKill>> playerKills; private long playerKills;
private long mobKills; private long mobKills;
private long deaths; private long deaths;
public KillPart() { public KillPart() {
playerKills = new HashMap<>(); playerKills = 0;
mobKills = 0; mobKills = 0;
deaths = 0; deaths = 0;
} }
@ -38,20 +29,17 @@ public class KillPart extends RawData {
public void analyse() { public void analyse() {
addValue("deathCount", deaths); addValue("deathCount", deaths);
addValue("mobKillCount", mobKills); addValue("mobKillCount", mobKills);
int playerKillAmount = getAllPlayerKills().size(); addValue("killCount", playerKills);
addValue("killCount", playerKillAmount);
} }
/** /**
* Adds kills to the dataset. * Adds kills to the dataset.
* *
* @param uuid Player whose kills are being added * @param amount amount of kills
* @param kills all kills of a player
* @throws IllegalArgumentException if kills is null * @throws IllegalArgumentException if kills is null
*/ */
public void addKills(UUID uuid, List<PlayerKill> kills) { public void addKills(long amount) {
Verify.nullCheck(kills); playerKills += amount;
playerKills.put(uuid, kills);
} }
public void addMobKills(long amount) { public void addMobKills(long amount) {
@ -62,14 +50,10 @@ public class KillPart extends RawData {
deaths += amount; deaths += amount;
} }
public Map<UUID, List<PlayerKill>> getPlayerKills() { public long getPlayerKills() {
return playerKills; return playerKills;
} }
public List<PlayerKill> getAllPlayerKills() {
return MiscUtils.flatMap(playerKills.values());
}
public long getMobKills() { public long getMobKills() {
return mobKills; return mobKills;
} }

View File

@ -44,6 +44,11 @@ public class PlayerCountPart extends RawData {
this.uuids.addAll(uuids); this.uuids.addAll(uuids);
} }
public void addOPs(Collection<UUID> uuids) {
Verify.nullCheck(uuids);
this.ops.addAll(uuids);
}
public void addOP(UUID uuid) { public void addOP(UUID uuid) {
Verify.nullCheck(uuid); Verify.nullCheck(uuid);
ops.add(uuid); ops.add(uuid);

View File

@ -16,6 +16,9 @@ import main.java.com.djrapitops.plan.utilities.FormatUtils;
public class PlaytimePart extends RawData { public class PlaytimePart extends RawData {
private long totalPlaytime; private long totalPlaytime;
private long playtime30d;
private long playtime7d;
private long playtime24h;
public PlaytimePart() { public PlaytimePart() {
totalPlaytime = 0; totalPlaytime = 0;
@ -24,9 +27,28 @@ public class PlaytimePart extends RawData {
@Override @Override
public void analyse() { public void analyse() {
addValue("playtimeTotal", FormatUtils.formatTimeAmount(totalPlaytime)); 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) { public void addToPlaytime(long amount) {
totalPlaytime += 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;
}
} }

View File

@ -1,9 +1,10 @@
package main.java.com.djrapitops.plan.data.analysis; package main.java.com.djrapitops.plan.data.analysis;
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 main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
/** /**
* Part responsible for all World Playtime related analysis. * Part responsible for all World Playtime related analysis.
@ -21,21 +22,23 @@ import java.util.Map;
*/ */
public class WorldPart extends RawData { public class WorldPart extends RawData {
private final Map<String, Long> worldTimes; private WorldTimes worldTimes;
public WorldPart() { public WorldPart() {
worldTimes = new HashMap<>(); worldTimes = new WorldTimes(new HashMap<>());
} }
@Override @Override
protected void analyse() { protected void analyse() {
// TODO WorldTimes t = new WorldTimes(worldTimes); addValue("worldTotal", FormatUtils.formatTimeAmount(worldTimes.getTotal()));
// addValue("worldTotal", FormatUtils.formatTimeAmount(t.getTotal()));
addValue("worldSeries", WorldPieCreator.createSeriesData(worldTimes)); addValue("worldSeries", WorldPieCreator.createSeriesData(worldTimes));
} }
public void addToWorld(String worldName, long playTime) { public void setWorldTimes(WorldTimes worldTimes) {
Long value = worldTimes.getOrDefault(worldName, 0L); this.worldTimes = worldTimes;
worldTimes.put(worldName, value + playTime); }
public WorldTimes getWorldTimes() {
return worldTimes;
} }
} }

View File

@ -8,10 +8,7 @@ import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
/** /**
* @author Rsl1122 * @author Rsl1122
@ -67,6 +64,7 @@ public class IPsTable extends UserIDTable {
statement = prepareStatement(Select.from(tableName, column) statement = prepareStatement(Select.from(tableName, column)
.where(columnUserID + "=" + usersTable.statementSelectID) .where(columnUserID + "=" + usersTable.statementSelectID)
.toString()); .toString());
statement.setFetchSize(50);
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
set = statement.executeQuery(); set = statement.executeQuery();
while (set.next()) { while (set.next()) {
@ -128,4 +126,35 @@ public class IPsTable extends UserIDTable {
close(set, statement); close(set, statement);
} }
} }
public Map<UUID, List<String>> getAllGeolocations() throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
try {
Map<UUID, List<String>> geoLocations = new HashMap<>();
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
statement = prepareStatement("SELECT " +
columnGeolocation + ", " +
usersUUIDColumn +
" FROM " + tableName +
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnUserID
);
statement.setFetchSize(5000);
set = statement.executeQuery();
while (set.next()) {
UUID uuid = UUID.fromString(set.getString("uuid"));
List<String> userGeoLocs = geoLocations.getOrDefault(uuid, new ArrayList<>());
userGeoLocs.add(set.getString(columnGeolocation));
geoLocations.put(uuid, userGeoLocs);
}
return geoLocations;
} finally {
endTransaction(statement);
close(set, statement);
}
}
} }

View File

@ -313,6 +313,16 @@ public class SessionsTable extends UserIDTable {
} }
} }
/**
* Used to get the Total Playtime of THIS Server.
*
* @return Milliseconds played on the server. 0 if server not found.
* @throws SQLException
*/
public long getPlaytimeOfServer() throws SQLException {
return getPlaytimeOfServer(Plan.getServerUUID());
}
/** /**
* Used to get the Total Playtime of a Server. * Used to get the Total Playtime of a Server.
* *
@ -324,6 +334,17 @@ public class SessionsTable extends UserIDTable {
return getPlaytimeOfServer(serverUUID, 0L); return getPlaytimeOfServer(serverUUID, 0L);
} }
/**
* Used to get Playtime after a date of THIS Server.
*
* @param afterDate Epoch ms (Playtime after this date is calculated)
* @return Milliseconds played after given epoch ms on the server. 0 if server not found.
* @throws SQLException
*/
public long getPlaytimeOfServer(long afterDate) throws SQLException {
return getPlaytimeOfServer(Plan.getServerUUID(), afterDate);
}
/** /**
* Used to get Playtime after a date of a Server. * Used to get Playtime after a date of a Server.
* *
@ -425,4 +446,52 @@ public class SessionsTable extends UserIDTable {
public String getColumnID() { public String getColumnID() {
return columnID; return columnID;
} }
public Map<UUID, List<Session>> getSessionInfoOfServer() throws SQLException {
return getSessionInfoOfServer(Plan.getServerUUID());
}
public Map<UUID, List<Session>> getSessionInfoOfServer(UUID serverUUID) throws SQLException {
Optional<Integer> id = serverTable.getServerID(serverUUID);
if (!id.isPresent()) {
return new HashMap<>();
}
int serverID = id.get();
Map<UUID, List<Session>> sessionsByUser = new HashMap<>();
PreparedStatement statement = null;
ResultSet set = null;
try {
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
statement = prepareStatement("SELECT " +
columnSessionStart + ", " +
columnSessionEnd + ", " +
columnDeaths + ", " +
columnMobKills + ", " +
usersUUIDColumn +
" FROM " + tableName +
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnUserID +
" WHERE " + columnServerID + "=" + serverTable.statementSelectServerID
);
statement.setFetchSize(5000);
statement.setString(1, serverUUID.toString());
set = statement.executeQuery();
while (set.next()) {
UUID uuid = UUID.fromString(set.getString("uuid"));
long start = set.getLong(columnSessionStart);
long end = set.getLong(columnSessionEnd);
int deaths = set.getInt(columnDeaths);
int mobKills = set.getInt(columnMobKills);
List<Session> sessions = sessionsByUser.getOrDefault(uuid, new ArrayList<>());
sessions.add(new Session(serverID, start, end, deaths, mobKills));
sessionsByUser.put(uuid, sessions);
}
return sessionsByUser;
} finally {
endTransaction(statement);
close(set, statement);
}
}
} }

View File

@ -1,6 +1,7 @@
package main.java.com.djrapitops.plan.database.tables; package main.java.com.djrapitops.plan.database.tables;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.Session; import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.data.time.GMTimes; import main.java.com.djrapitops.plan.data.time.GMTimes;
import main.java.com.djrapitops.plan.data.time.WorldTimes; import main.java.com.djrapitops.plan.data.time.WorldTimes;
@ -154,4 +155,51 @@ public class WorldTimesTable extends UserIDTable {
close(set, statement); close(set, statement);
} }
} }
public WorldTimes getWorldTimesOfServer() throws SQLException {
return getWorldTimesOfServer(Plan.getServerUUID());
}
public WorldTimes getWorldTimesOfServer(UUID serverUUID) throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
try {
String worldIDColumn = worldTable + "." + worldTable.getColumnID();
String worldNameColumn = worldTable + "." + worldTable.getColumnWorldName() + " as world_name";
String sessionIDColumn = sessionsTable + "." + sessionsTable.getColumnID();
String sessionServerIDColumn = sessionsTable + ".server_id";
statement = prepareStatement("SELECT " +
"SUM(" + columnSurvival + ") as survival, " +
"SUM(" + columnCreative + ") as creative, " +
"SUM(" + columnAdventure + ") as adventure, " +
"SUM(" + columnSpectator + ") as spectator, " +
worldNameColumn +
" FROM " + tableName +
" JOIN " + worldTable + " on " + worldIDColumn + "=" + columnWorldId +
" JOIN " + sessionsTable + " on " + sessionIDColumn + "=" + columnSessionID +
" WHERE " + sessionServerIDColumn + "=" + db.getServerTable().statementSelectServerID
);
statement.setString(1, serverUUID.toString());
set = statement.executeQuery();
String[] gms = GMTimes.getGMKeyArray();
WorldTimes worldTimes = new WorldTimes(new HashMap<>());
while (set.next()) {
String worldName = set.getString("world_name");
Map<String, Long> gmMap = new HashMap<>();
gmMap.put(gms[0], set.getLong("survival"));
gmMap.put(gms[1], set.getLong("creative"));
gmMap.put(gms[2], set.getLong("adventure"));
gmMap.put(gms[3], set.getLong("spectator"));
GMTimes gmTimes = new GMTimes(gmMap);
worldTimes.setGMTimesForWorld(worldName, gmTimes);
}
return worldTimes;
} finally {
endTransaction(statement);
close(set, statement);
}
}
} }

View File

@ -66,7 +66,6 @@ public class SessionCache {
* *
* @return key:value UUID:Session * @return key:value UUID:Session
*/ */
@Deprecated
public Map<UUID, Session> getActiveSessions() { public Map<UUID, Session> getActiveSessions() {
return activeSessions; return activeSessions;
} }

View File

@ -4,15 +4,20 @@
*/ */
package main.java.com.djrapitops.plan.systems.info; package main.java.com.djrapitops.plan.systems.info;
import com.djrapitops.plugin.command.ISender;
import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.command.commands.AnalyzeCommand;
import main.java.com.djrapitops.plan.data.AnalysisData; import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.systems.cache.DataCache; import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.cache.SessionCache; import main.java.com.djrapitops.plan.systems.cache.SessionCache;
import main.java.com.djrapitops.plan.systems.info.parsing.UrlParser; import main.java.com.djrapitops.plan.systems.info.parsing.UrlParser;
import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.analysis.Analysis;
import java.util.HashSet;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
/** /**
@ -30,7 +35,10 @@ public class InformationManager {
private boolean usingBungeeWebServer; private boolean usingBungeeWebServer;
private String webServerAddress; private String webServerAddress;
private final Set<ISender> analysisNotification;
private final Analysis analysis;
private AnalysisData analysisData; private AnalysisData analysisData;
private String analysisPluginsTab;
private Long refreshDate; private Long refreshDate;
public InformationManager(Plan plugin) { public InformationManager(Plan plugin) {
@ -41,6 +49,8 @@ public class InformationManager {
.ifPresent(address -> webServerAddress = address); .ifPresent(address -> webServerAddress = address);
dataCache = new DataCache(plugin); dataCache = new DataCache(plugin);
analysis = new Analysis(plugin);
analysisNotification = new HashSet<>();
if (webServerAddress != null) { if (webServerAddress != null) {
attemptBungeeConnection(); attemptBungeeConnection();
@ -65,7 +75,7 @@ public class InformationManager {
} }
public void refreshAnalysis() { public void refreshAnalysis() {
plugin.addToProcessQueue(); // TODO Analysis, PluginData analysis.runAnalysis(this);
} }
public DataCache getDataCache() { public DataCache getDataCache() {
@ -99,6 +109,13 @@ public class InformationManager {
public void cacheAnalysisdata(AnalysisData analysisData) { public void cacheAnalysisdata(AnalysisData analysisData) {
this.analysisData = analysisData; this.analysisData = analysisData;
refreshDate = MiscUtils.getTime(); refreshDate = MiscUtils.getTime();
// TODO Web Caching
AnalyzeCommand.sendAnalysisMessage(analysisNotification);
analysisNotification.clear();
}
public void addAnalysisNotification(ISender sender) {
analysisNotification.add(sender);
} }
public AnalysisData getAnalysisData() { public AnalysisData getAnalysisData() {

View File

@ -1,15 +1,19 @@
package main.java.com.djrapitops.plan.utilities.analysis; package main.java.com.djrapitops.plan.utilities.analysis;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.AnalysisData; import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.data.TPS; import main.java.com.djrapitops.plan.data.TPS;
import main.java.com.djrapitops.plan.data.UserInfo;
import main.java.com.djrapitops.plan.data.additional.AnalysisType; 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.HookHandler;
import main.java.com.djrapitops.plan.data.additional.PluginData; import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.data.analysis.*; 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.Database;
import main.java.com.djrapitops.plan.locale.Locale; import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg; import main.java.com.djrapitops.plan.locale.Msg;
@ -24,6 +28,7 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
import java.io.Serializable; import java.io.Serializable;
import java.sql.SQLException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -91,7 +96,7 @@ public class Analysis {
Log.toLog(this.getClass().getName(), ex); Log.toLog(this.getClass().getName(), ex);
} }
return analyzeData(tpsData, infoManager); return analyzeData(tpsData, infoManager, db);
} }
/** /**
@ -99,7 +104,7 @@ public class Analysis {
* @param infoManager InformationManager of the plugin. * @param infoManager InformationManager of the plugin.
* @return * @return
*/ */
public boolean analyzeData(List<TPS> tpsData, InformationManager infoManager) { public boolean analyzeData(List<TPS> tpsData, InformationManager infoManager, Database db) {
try { try {
// rawData.sort(new UserDataLastPlayedComparator()); // rawData.sort(new UserDataLastPlayedComparator());
// List<UUID> uuids = rawData.stream().map(UserInfo::getUuid).collect(Collectors.toList()); // List<UUID> uuids = rawData.stream().map(UserInfo::getUuid).collect(Collectors.toList());
@ -130,7 +135,7 @@ public class Analysis {
// String playersTable = PlayersTableCreator.createSortablePlayersTable(rawData); // String playersTable = PlayersTableCreator.createSortablePlayersTable(rawData);
// analysisData.setPlayersTable(playersTable); // analysisData.setPlayersTable(playersTable);
fillDataset(analysisData); fillDataset(analysisData, db);
// Analyze // Analyze
analysisData.analyseData(); analysisData.analyseData();
Benchmark.stop("Analysis", "Analysis Phase"); Benchmark.stop("Analysis", "Analysis Phase");
@ -235,60 +240,64 @@ public class Analysis {
taskId = id; taskId = id;
} }
private void fillDataset(AnalysisData analysisData) { private void fillDataset(AnalysisData analysisData, Database db) {
ActivityPart activity = analysisData.getActivityPart(); ActivityPart activity = analysisData.getActivityPart();
GeolocationPart geolocPart = analysisData.getGeolocationPart(); GeolocationPart geolocPart = analysisData.getGeolocationPart();
JoinInfoPart joinInfo = analysisData.getJoinInfoPart(); JoinInfoPart joinInfo = analysisData.getJoinInfoPart();
KillPart killPart = analysisData.getKillPart();
PlayerCountPart playerCount = analysisData.getPlayerCountPart(); PlayerCountPart playerCount = analysisData.getPlayerCountPart();
PlaytimePart playtime = analysisData.getPlaytimePart(); PlaytimePart playtime = analysisData.getPlaytimePart();
WorldPart worldPart = analysisData.getWorldPart(); WorldPart worldPart = analysisData.getWorldPart();
long now = MiscUtils.getTime(); long now = MiscUtils.getTime();
Benchmark.start("Fill Dataset"); Benchmark.start("Fetch Phase");
List<PluginData> banSources = plugin.getHookHandler().getAdditionalDataSources() try {
.stream().filter(PluginData::isBanData).collect(Collectors.toList()); List<UserInfo> userInfo = db.getUserInfoTable().getAllUserInfo();
// rawData.forEach(uData -> { playerCount.addPlayers(userInfo.stream().map(UserInfo::getUuid).collect(Collectors.toSet()));
// TODO Map<String, Long> worldTimes = uData.getWorldTimes().getTimes();
// TODO playtime.addToPlaytime(playTime); Map<UUID, Long> registered = userInfo.stream().collect(Collectors.toMap(UserInfo::getUuid, UserInfo::getRegistered));
// joinInfo.addToLoginTimes(uData.getLoginTimes()); joinInfo.addRegistered(registered);
// joinInfo.addRegistered(uData.getRegistered()); activity.addBans(userInfo.stream().filter(UserInfo::isBanned).map(UserInfo::getUuid).collect(Collectors.toSet()));
//TODO geolocPart.addGeolocation(uData.getGeolocation()); playerCount.addOPs(userInfo.stream().filter(UserInfo::isOpped).map(UserInfo::getUuid).collect(Collectors.toSet()));
// final UUID uuid = uData.getUuid(); Map<UUID, Session> activeSessions = plugin.getDataCache().getActiveSessions();
// if (uData.isOp()) { Map<UUID, List<Session>> sessions = db.getSessionsTable().getSessionInfoOfServer();
// playerCount.addOP(uuid); joinInfo.addActiveSessions(activeSessions);
// } joinInfo.addSessions(sessions);
// boolean banned = uData.isBanned(); Map<UUID, List<String>> geolocations = db.getIpsTable().getAllGeolocations();
// if (!banned) { geolocPart.addGeoLocations(geolocations);
// banned = banSources.stream()
// .anyMatch(banData -> {
// Serializable value = banData.getValue(uuid);
// if (value instanceof Boolean) {
// return (Boolean) value;
// }
// return false;
// });
// }
//
// if (banned) {
// activity.addBan(uuid);
// } else if (uData.getLoginTimes() == 1) {
// activity.addJoinedOnce(uuid);
// TODO } else if (AnalysisUtils.isActive(now, uData.getLastPlayed(), playTime, uData.getSessionCount())) {
// activity.addActive(uuid);
// } else {
// activity.addInActive(uuid);
// }
//TODO List<PlayerKill> playerKills = uData.getPlayerKills();
// List<Session> sessions = uData.getSessions(); WorldTimes worldTimes = db.getWorldTimesTable().getWorldTimesOfServer();
// joinInfo.addSessions(uuid, sessions); worldPart.setWorldTimes(worldTimes);
// });
Benchmark.stop("Analysis", "Fill Dataset"); 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<PluginData> banSources = plugin.getHookHandler().getAdditionalDataSources()
.stream().filter(PluginData::isBanData).collect(Collectors.toList());
for (UUID uuid : playerCount.getUuids()) {
boolean banned = banSources.stream().anyMatch(pluginData -> {
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);
}
Benchmark.stop("Analysis", "Fetch Phase");
} }
} }

View File

@ -1,6 +1,6 @@
package main.java.com.djrapitops.plan.utilities.html.graphs; package main.java.com.djrapitops.plan.utilities.html.graphs;
import java.util.Map; import main.java.com.djrapitops.plan.data.time.WorldTimes;
public class WorldPieCreator { public class WorldPieCreator {
@ -8,25 +8,27 @@ public class WorldPieCreator {
throw new IllegalStateException("Utility Class"); throw new IllegalStateException("Utility Class");
} }
public static String createSeriesData(Map<String, Long> worldTimes) { public static String createSeriesData(WorldTimes worldTimes) {
StringBuilder arrayBuilder = new StringBuilder("["); // TODO Rewrite WorldPie
int i = 0; // StringBuilder arrayBuilder = new StringBuilder("[");
int size = worldTimes.size(); // int i = 0;
for (Map.Entry<String, Long> world : worldTimes.entrySet()) { // int size = worldTimes.size();
arrayBuilder.append("{name:'").append(world.getKey()) // for (Map.Entry<String, Long> world : worldTimes.entrySet()) {
.append("',y:").append(world.getValue()); // arrayBuilder.append("{name:'").append(world.getKey())
// .append("',y:").append(world.getValue());
if (i == 1) { //
arrayBuilder.append(", sliced: true, selected: true"); // if (i == 1) {
} // arrayBuilder.append(", sliced: true, selected: true");
// }
arrayBuilder.append("}"); //
if (i < size - 1) { // arrayBuilder.append("}");
arrayBuilder.append(","); // if (i < size - 1) {
} // arrayBuilder.append(",");
i++; // }
} // i++;
arrayBuilder.append("]"); // }
return arrayBuilder.toString(); // arrayBuilder.append("]");
// return arrayBuilder.toString();
return "[]";
} }
} }