mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-22 15:23:14 +01:00
1 Bugfix, Additions, 1 Other & Code optimization for 1.4.2
Fixed API adding extra hook not showing up before reload Added 4 data formatting methods to API. Added AAC-ACHIEVEMENTS analysis, but did not add it to list of analyzed tags - waiting for dev to implement new method for offline players Removed analysis from Config because command reloading would be pain in the ass to implement. Optimized code: - Moved analyze to DataUtils - Removed some duplicate code from Analyze and InspectCommand
This commit is contained in:
parent
1afacde1fe
commit
c7fc4d93bd
@ -2,21 +2,6 @@
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/Plan.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/plugin.yml</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/command/hooks/Hook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/command/hooks/VaultHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/command/utils/DataFormatUtils.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/command/hooks/FactionsHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/command/commands/InspectCommand.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/config.yml</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/API.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/PlanCommand.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/command/hooks/PlaceholderAPIHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/command/utils/DataUtils.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/command/commands/AnalyzeCommand.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/PlayerAnalyticsPlugin-0.0.1/src/com/djrapitops/plan/command/hooks/AdvancedAchievementsHook.java</file>
|
||||
</group>
|
||||
<group/>
|
||||
</open-files>
|
||||
</project-private>
|
||||
|
@ -3,6 +3,7 @@ package com.djrapitops.plan;
|
||||
import com.djrapitops.plan.command.hooks.Hook;
|
||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class API {
|
||||
@ -57,6 +58,24 @@ public class API {
|
||||
return DataFormatUtils.removeExtraDataPoints(DataUtils.getData(true, playerName));
|
||||
}
|
||||
|
||||
// use (new Date) on after parameter for time since moment to now
|
||||
public static String formatTimeSinceDate(Date before, Date after) {
|
||||
return DataFormatUtils.formatTimeAmountSinceDate(before, after);
|
||||
}
|
||||
|
||||
// use (new Date) on after parameter for time since moment to now
|
||||
public static String formatTimeSinceString(String before, Date after) {
|
||||
return DataFormatUtils.formatTimeAmountSinceString(before, after);
|
||||
}
|
||||
|
||||
public static String formatTimeAmount(String timeInMs) {
|
||||
return DataFormatUtils.formatTimeAmount(timeInMs);
|
||||
}
|
||||
|
||||
public static String formatTimeStamp(String timeInMs) {
|
||||
return DataFormatUtils.formatTimeStamp(timeInMs);
|
||||
}
|
||||
|
||||
public void addExtraHook(String name, Hook hook) {
|
||||
plugin.addExtraHook(name, hook);
|
||||
}
|
||||
|
@ -179,5 +179,6 @@ public class Plan extends JavaPlugin {
|
||||
|
||||
public void addExtraHook(String name, Hook hook) {
|
||||
this.extraHooks.put(name, hook);
|
||||
this.hooks.put(name, hook);
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,7 @@ public class PlanCommand implements CommandExecutor {
|
||||
|
||||
commands.add(new HelpCommand(plugin, this));
|
||||
commands.add(new InspectCommand(plugin));
|
||||
if (plugin.getConfig().getBoolean("analysis")) {
|
||||
commands.add(new AnalyzeCommand(plugin));
|
||||
}
|
||||
commands.add(new AnalyzeCommand(plugin));
|
||||
commands.add(new ReloadCommand(plugin));
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,8 @@ import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -28,11 +23,6 @@ public class AnalyzeCommand extends SubCommand {
|
||||
public AnalyzeCommand(Plan plugin) {
|
||||
super("analyze", "plan.analyze", "Analyze data of all players /plan analyze [-refresh]", CommandType.CONSOLE);
|
||||
this.plugin = plugin;
|
||||
// this.plugin.log("Refreshing playerDataMap, this might take a while..");
|
||||
// this.playerData = DataUtils.getTotalData();
|
||||
// this.analyzedPlayerdata = analyze(this.playerData);
|
||||
// this.refreshDate = new Date();
|
||||
// this.plugin.log("PlayerDataMap refresh complete.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,33 +32,20 @@ public class AnalyzeCommand extends SubCommand {
|
||||
for (String arg : args) {
|
||||
if (arg.toLowerCase().equals("-refresh")) {
|
||||
if (sender.hasPermission("plan.analyze.refresh")) {
|
||||
sender.sendMessage(textColor + "[" + operatorColor + "Plan" + textColor + "] "
|
||||
+ "Refreshing playerData, this might take a while..");
|
||||
this.playerData = DataUtils.getTotalData();
|
||||
this.refreshDate = new Date();
|
||||
this.analyzedPlayerdata = analyze(this.playerData);
|
||||
|
||||
refreshAnalysisData(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.playerData == null || this.refreshDate == null || this.analyzedPlayerdata == null) {
|
||||
sender.sendMessage(textColor + "[" + operatorColor + "Plan" + textColor + "] "
|
||||
+ "Refreshing playerData, this might take a while..");
|
||||
this.playerData = DataUtils.getTotalData();
|
||||
this.refreshDate = new Date();
|
||||
this.analyzedPlayerdata = analyze(this.playerData);
|
||||
refreshAnalysisData(sender);
|
||||
}
|
||||
List<String[]> dataList = new ArrayList<>();
|
||||
sender.sendMessage(textColor + "-- [" + operatorColor + "PLAN - Analysis results, refreshed " + DataFormatUtils.formatTimeAmount(refreshDate, new Date()) + " ago:" + textColor + "] --");
|
||||
for (String key : this.analyzedPlayerdata.keySet()) {
|
||||
dataList.add(new String[]{key, this.analyzedPlayerdata.get(key)});
|
||||
}
|
||||
Collections.sort(dataList, new Comparator<String[]>() {
|
||||
public int compare(String[] strings, String[] otherStrings) {
|
||||
return strings[0].compareTo(otherStrings[0]);
|
||||
}
|
||||
});
|
||||
sender.sendMessage("" + textColor + "Averages for "+this.playerData.size()+" player(s)");
|
||||
|
||||
//header
|
||||
sender.sendMessage(textColor + "-- [" + operatorColor + "PLAN - Analysis results, refreshed " + DataFormatUtils.formatTimeAmountSinceDate(refreshDate, new Date()) + " ago:" + textColor + "] --");
|
||||
|
||||
List<String[]> dataList = DataFormatUtils.turnDataHashMapToSortedListOfArrays(analyzedPlayerdata);
|
||||
|
||||
sender.sendMessage("" + textColor + "Averages for " + this.playerData.size() + " player(s)");
|
||||
for (String[] dataString : dataList) {
|
||||
sender.sendMessage("" + operatorColor + dataString[0].charAt(4) + dataString[0].toLowerCase().substring(5) + ": " + textColor + dataString[1]);
|
||||
}
|
||||
@ -76,94 +53,18 @@ public class AnalyzeCommand extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
private HashMap<String, String> analyze(HashMap<UUID, HashMap<String, String>> playerData) {
|
||||
HashMap<String, List<String>> playerDataLists = new HashMap<>();
|
||||
String[] ignore = {"ESS-BAN REASON", "ESS-OPPED", "ESS-MUTE TIME", "ESS-LOCATION", "ESS-HUNGER", "ESS-LOCATION WORLD",
|
||||
"ESS-NICKNAME", "ESS-UUID", "FAC-FACTION", "ONT-LAST LOGIN", "TOW-TOWN", "TOW-REGISTERED",
|
||||
"TOW-LAST LOGIN", "TOW-OWNER OF", "TOW-PLOT PERMS", "TOW-PLOT OPTIONS", "TOW-FRIENDS", "ESS-ONLINE SINCE",
|
||||
"ESS-OFFLINE SINCE"};
|
||||
List<String> ignoreKeys = new ArrayList<>();
|
||||
ignoreKeys.addAll(Arrays.asList(ignore));
|
||||
for (UUID key : playerData.keySet()) {
|
||||
for (String dataKey : playerData.get(key).keySet()) {
|
||||
if (!ignoreKeys.contains(dataKey)) {
|
||||
if (playerDataLists.get(dataKey) == null) {
|
||||
playerDataLists.put(dataKey, new ArrayList<>());
|
||||
}
|
||||
playerDataLists.get(dataKey).add(playerData.get(key).get(dataKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String[] numbers = {"ESS-HEALTH", "ESS-XP LEVEL", "FAC-POWER", "FAC-POWER PER HOUR",
|
||||
"FAC-POWER PER DEATH", "SVO-VOTES", "ONT-TOTAL VOTES", "ONT-TOTAL REFERRED", "ECO-BALANCE"};
|
||||
List<String> numberKeys = new ArrayList<>();
|
||||
numberKeys.addAll(Arrays.asList(numbers));
|
||||
String[] booleanValues = {"ESS-BANNED", "ESS-JAILED", "ESS-MUTED", "ESS-FLYING", "TOW-ONLINE"};
|
||||
List<String> boolKeys = new ArrayList<>();
|
||||
boolKeys.addAll(Arrays.asList(booleanValues));
|
||||
String[] timeValues = {"ONT-TOTAL PLAY"};
|
||||
List<String> timeKeys = new ArrayList<>();
|
||||
timeKeys.addAll(Arrays.asList(timeValues));
|
||||
|
||||
HashMap<String, String> analyzedData = new HashMap<>();
|
||||
int errors = 0;
|
||||
HashSet<String> errorTypes = new HashSet<>();
|
||||
|
||||
for (String dataKey : playerDataLists.keySet()) {
|
||||
if (numberKeys.contains(dataKey)) {
|
||||
double sum = 0;
|
||||
|
||||
for (String dataPoint : playerDataLists.get(dataKey)) {
|
||||
try {
|
||||
if (dataKey.equals("FAC-POWER")) {
|
||||
sum += Double.parseDouble(dataPoint.split(" ")[0]);
|
||||
} else if (dataKey.equals("ECO-BALANCE")) {
|
||||
sum += Double.parseDouble(DataFormatUtils.removeLetters(dataPoint));
|
||||
} else {
|
||||
sum += Double.parseDouble(dataPoint);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errors++;
|
||||
errorTypes.add("" + e);
|
||||
}
|
||||
}
|
||||
analyzedData.put(dataKey, "" + (sum / this.playerData.size()));
|
||||
|
||||
} else if (boolKeys.contains(dataKey)) {
|
||||
int amount = 0;
|
||||
for (String dataPoint : playerDataLists.get(dataKey)) {
|
||||
try {
|
||||
if (Boolean.parseBoolean(dataPoint)) {
|
||||
amount++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errors++;
|
||||
errorTypes.add("" + e);
|
||||
}
|
||||
}
|
||||
analyzedData.put(dataKey, "" + ((amount / this.playerData.size())*100) + "%");
|
||||
} else if (timeKeys.contains(dataKey)) {
|
||||
Long time = Long.parseLong("0");
|
||||
for (String dataPoint : playerDataLists.get(dataKey)) {
|
||||
try {
|
||||
time += Long.parseLong(dataPoint);
|
||||
} catch (Exception e) {
|
||||
errors++;
|
||||
errorTypes.add("" + e);
|
||||
}
|
||||
}
|
||||
analyzedData.put(dataKey, "" + (time / this.playerData.size()));
|
||||
}
|
||||
}
|
||||
if (errors > 0) {
|
||||
String log = "ANALYZE\n" + errors + " error(s) occurred while analyzing total data.\nFollowing types:";
|
||||
for (String errorType : errorTypes) {
|
||||
log += "\n " + errorType;
|
||||
}
|
||||
plugin.logToFile(log);
|
||||
}
|
||||
return DataFormatUtils.formatAnalyzed(analyzedData);
|
||||
private void refreshAnalysisData(CommandSender sender) {
|
||||
ChatColor operatorColor = ChatColor.DARK_GREEN;
|
||||
ChatColor textColor = ChatColor.GRAY;
|
||||
sender.sendMessage(textColor + "[" + operatorColor + "Plan" + textColor + "] "
|
||||
+ "Refreshing playerData, this might take a while..");
|
||||
this.playerData = DataUtils.getTotalData();
|
||||
this.refreshDate = new Date();
|
||||
this.analyzedPlayerdata = DataUtils.analyze(this.playerData);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private HashMap<String, String> analyze(HashMap<UUID, HashMap<String, String>> playerData) {
|
||||
return DataUtils.analyze(playerData);
|
||||
}
|
||||
}
|
||||
|
@ -32,10 +32,6 @@ public class InspectCommand extends SubCommand {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
String playerName = getPlayerDisplayname(args, sender);
|
||||
// if (args.length < 1 && !(sender instanceof Player)) {
|
||||
// sender.sendMessage(ChatColor.RED+"Console use of inspect requires arguments.");
|
||||
// return false;
|
||||
// }
|
||||
if (this.plugin.getHooks().isEmpty()) {
|
||||
this.plugin.logError("noHookedPluginsError on InspectCommand");
|
||||
|
||||
@ -55,9 +51,9 @@ public class InspectCommand extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<String, String> data = getData(allData, playerName);
|
||||
HashMap<String, String> data = DataUtils.getData(allData, playerName);
|
||||
if (format && !data.isEmpty()) {
|
||||
data = format(data);
|
||||
data = DataFormatUtils.removeExtraDataPoints(data);
|
||||
}
|
||||
if (data.isEmpty()) {
|
||||
data.put("ERR-NO RESULTS", "No results were found.");
|
||||
@ -66,19 +62,12 @@ public class InspectCommand extends SubCommand {
|
||||
|
||||
}
|
||||
|
||||
List<String[]> dataList = new ArrayList<>();
|
||||
for (String key : data.keySet()) {
|
||||
dataList.add(new String[]{key, data.get(key)});
|
||||
}
|
||||
Collections.sort(dataList, new Comparator<String[]>() {
|
||||
public int compare(String[] strings, String[] otherStrings) {
|
||||
return strings[0].compareTo(otherStrings[0]);
|
||||
}
|
||||
});
|
||||
List<String[]> dataList = DataFormatUtils.turnDataHashMapToSortedListOfArrays(data);
|
||||
|
||||
ChatColor operatorColor = ChatColor.DARK_GREEN;
|
||||
ChatColor textColor = ChatColor.GRAY;
|
||||
|
||||
//header
|
||||
sender.sendMessage(textColor + "-- [" + operatorColor + "PLAN - Inspect results: " + playerName + textColor + "] --");
|
||||
|
||||
for (String[] dataString : dataList) {
|
||||
@ -88,10 +77,12 @@ public class InspectCommand extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, String> getData(boolean allData, String playerName) {
|
||||
return DataUtils.getData(allData, playerName);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HashMap<String, String> format(HashMap<String, String> data) throws NumberFormatException {
|
||||
return DataFormatUtils.removeExtraDataPoints(data);
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ package com.djrapitops.plan.command.utils;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -85,7 +87,7 @@ public class DataFormatUtils {
|
||||
if (key.equals("ONT-TOTAL PLAY")) {
|
||||
formatted = formatTimeAmount(data.get(key));
|
||||
} else {
|
||||
formatted = formatTimeAmount(data.get(key), new Date());
|
||||
formatted = formatTimeAmountSinceString(data.get(key), new Date());
|
||||
}
|
||||
if (formatted != null) {
|
||||
data.replace(key, formatted);
|
||||
@ -138,7 +140,7 @@ public class DataFormatUtils {
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
public static String formatTimeAmount(String string, Date date) throws NumberFormatException {
|
||||
public static String formatTimeAmountSinceString(String string, Date date) throws NumberFormatException {
|
||||
String returnValue = "";
|
||||
long ms = (date.toInstant().getEpochSecond() * 1000) - Long.parseLong(string);
|
||||
long x = ms / 1000;
|
||||
@ -163,7 +165,7 @@ public class DataFormatUtils {
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
public static String formatTimeAmount(Date before, Date now) throws NumberFormatException {
|
||||
public static String formatTimeAmountSinceDate(Date before, Date now) throws NumberFormatException {
|
||||
String returnValue = "";
|
||||
long ms = (now.toInstant().getEpochSecond() * 1000) - (before.toInstant().getEpochSecond() * 1000);
|
||||
long x = ms / 1000;
|
||||
@ -208,4 +210,17 @@ public class DataFormatUtils {
|
||||
}
|
||||
return returnString;
|
||||
}
|
||||
|
||||
public static List<String[]> turnDataHashMapToSortedListOfArrays(HashMap<String, String> data) {
|
||||
List<String[]> dataList = new ArrayList<>();
|
||||
for (String key : data.keySet()) {
|
||||
dataList.add(new String[]{key, data.get(key)});
|
||||
}
|
||||
Collections.sort(dataList, new Comparator<String[]>() {
|
||||
public int compare(String[] strings, String[] otherStrings) {
|
||||
return strings[0].compareTo(otherStrings[0]);
|
||||
}
|
||||
});
|
||||
return dataList;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,11 @@ package com.djrapitops.plan.command.utils;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -66,4 +70,96 @@ public class DataUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HashMap<String, String> analyze(HashMap<UUID, HashMap<String, String>> playerData) {
|
||||
Plan plugin = getPlugin(Plan.class);
|
||||
HashMap<String, List<String>> playerDataLists = new HashMap<>();
|
||||
String[] ignore = {"ESS-BAN REASON", "ESS-OPPED", "ESS-MUTE TIME", "ESS-LOCATION", "ESS-HUNGER", "ESS-LOCATION WORLD",
|
||||
"ESS-NICKNAME", "ESS-UUID", "FAC-FACTION", "ONT-LAST LOGIN", "TOW-TOWN", "TOW-REGISTERED",
|
||||
"TOW-LAST LOGIN", "TOW-OWNER OF", "TOW-PLOT PERMS", "TOW-PLOT OPTIONS", "TOW-FRIENDS", "ESS-ONLINE SINCE",
|
||||
"ESS-OFFLINE SINCE"};
|
||||
List<String> ignoreKeys = new ArrayList<>();
|
||||
ignoreKeys.addAll(Arrays.asList(ignore));
|
||||
for (UUID key : playerData.keySet()) {
|
||||
for (String dataKey : playerData.get(key).keySet()) {
|
||||
if (ignoreKeys.contains(dataKey)) {
|
||||
continue;
|
||||
}
|
||||
if (playerDataLists.get(dataKey) == null) {
|
||||
playerDataLists.put(dataKey, new ArrayList<>());
|
||||
}
|
||||
playerDataLists.get(dataKey).add(playerData.get(key).get(dataKey));
|
||||
}
|
||||
}
|
||||
|
||||
String[] numbers = {"ESS-HEALTH", "ESS-XP LEVEL", "FAC-POWER", "FAC-POWER PER HOUR",
|
||||
"FAC-POWER PER DEATH", "SVO-VOTES", "ONT-TOTAL VOTES", "ONT-TOTAL REFERRED", "ECO-BALANCE"};
|
||||
List<String> numberKeys = new ArrayList<>();
|
||||
numberKeys.addAll(Arrays.asList(numbers));
|
||||
String[] booleanValues = {"ESS-BANNED", "ESS-JAILED", "ESS-MUTED", "ESS-FLYING", "TOW-ONLINE"};
|
||||
List<String> boolKeys = new ArrayList<>();
|
||||
boolKeys.addAll(Arrays.asList(booleanValues));
|
||||
String[] timeValues = {"ONT-TOTAL PLAY"};
|
||||
List<String> timeKeys = new ArrayList<>();
|
||||
timeKeys.addAll(Arrays.asList(timeValues));
|
||||
|
||||
HashMap<String, String> analyzedData = new HashMap<>();
|
||||
int errors = 0;
|
||||
HashSet<String> errorTypes = new HashSet<>();
|
||||
|
||||
for (String dataKey : playerDataLists.keySet()) {
|
||||
if (numberKeys.contains(dataKey)) {
|
||||
double sum = 0;
|
||||
|
||||
for (String dataPoint : playerDataLists.get(dataKey)) {
|
||||
try {
|
||||
if (dataKey.equals("FAC-POWER") || dataKey.equals("AAC-ACHIEVEMENTS")) {
|
||||
sum += Double.parseDouble(dataPoint.split(" ")[0]);
|
||||
} else if (dataKey.equals("ECO-BALANCE")) {
|
||||
sum += Double.parseDouble(DataFormatUtils.removeLetters(dataPoint));
|
||||
} else {
|
||||
sum += Double.parseDouble(dataPoint);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errors++;
|
||||
errorTypes.add("" + e);
|
||||
}
|
||||
}
|
||||
analyzedData.put(dataKey, "" + (sum / playerData.size()));
|
||||
|
||||
} else if (boolKeys.contains(dataKey)) {
|
||||
int amount = 0;
|
||||
for (String dataPoint : playerDataLists.get(dataKey)) {
|
||||
try {
|
||||
if (Boolean.parseBoolean(dataPoint)) {
|
||||
amount++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errors++;
|
||||
errorTypes.add("" + e);
|
||||
}
|
||||
}
|
||||
analyzedData.put(dataKey, "" + ((amount / playerData.size()) * 100) + "%");
|
||||
} else if (timeKeys.contains(dataKey)) {
|
||||
Long time = Long.parseLong("0");
|
||||
for (String dataPoint : playerDataLists.get(dataKey)) {
|
||||
try {
|
||||
time += Long.parseLong(dataPoint);
|
||||
} catch (Exception e) {
|
||||
errors++;
|
||||
errorTypes.add("" + e);
|
||||
}
|
||||
}
|
||||
analyzedData.put(dataKey, "" + (time / playerData.size()));
|
||||
}
|
||||
}
|
||||
if (errors > 0) {
|
||||
String log = "ANALYZE\n" + errors + " error(s) occurred while analyzing total data.\nFollowing types:";
|
||||
for (String errorType : errorTypes) {
|
||||
log += "\n " + errorType;
|
||||
}
|
||||
plugin.logToFile(log);
|
||||
}
|
||||
return DataFormatUtils.formatAnalyzed(analyzedData);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
debug: true
|
||||
analysis: true
|
||||
|
||||
visible:
|
||||
ontime: true
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: Plan
|
||||
main: com.djrapitops.plan.Plan
|
||||
version: 1.4.0
|
||||
version: 1.4.2
|
||||
|
||||
commands:
|
||||
plan:
|
||||
|
Loading…
Reference in New Issue
Block a user