1.5.1 - Moved stuff around & minor bug fixes, added analysis test
Added attempt to determine if undefined data is usable Bugfixes: - Removed faulty towny import from Search - Analysis now calculates averages from data point amount instead of player amounts - "-p" and playername removed from search arguments when -p is used
This commit is contained in:
parent
92f43c4dae
commit
5756c21e5b
|
@ -0,0 +1 @@
|
||||||
|
/dist/
|
|
@ -3,7 +3,11 @@
|
||||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
<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">
|
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||||
<group>
|
<group>
|
||||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/Plan.java</file>
|
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/utils/Analysis.java</file>
|
||||||
|
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/commands/SearchCommand.java</file>
|
||||||
|
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/commands/AnalyzeCommand.java</file>
|
||||||
|
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/utils/DataFormatUtils.java</file>
|
||||||
|
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/PlanCommand.java</file>
|
||||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/utils/DataUtils.java</file>
|
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/utils/DataUtils.java</file>
|
||||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/plugin.yml</file>
|
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/plugin.yml</file>
|
||||||
</group>
|
</group>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import com.djrapitops.plan.command.commands.HelpCommand;
|
||||||
import com.djrapitops.plan.command.commands.InspectCommand;
|
import com.djrapitops.plan.command.commands.InspectCommand;
|
||||||
import com.djrapitops.plan.command.commands.ReloadCommand;
|
import com.djrapitops.plan.command.commands.ReloadCommand;
|
||||||
import com.djrapitops.plan.command.commands.SearchCommand;
|
import com.djrapitops.plan.command.commands.SearchCommand;
|
||||||
import com.djrapitops.plan.javaTools.Editor;
|
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
@ -54,8 +54,7 @@ public class PlanCommand implements CommandExecutor {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
command = "help";
|
command = "help";
|
||||||
}
|
}
|
||||||
Editor edit = new Editor();
|
onCommand(sender, cmd, commandLabel, DataFormatUtils.mergeArrays(new String[]{command}, args));
|
||||||
onCommand(sender, cmd, commandLabel, edit.mergeArrays(new String[]{command}, args));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.djrapitops.plan.command.CommandType;
|
||||||
import com.djrapitops.plan.command.SubCommand;
|
import com.djrapitops.plan.command.SubCommand;
|
||||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||||
import com.djrapitops.plan.command.utils.DataUtils;
|
import com.djrapitops.plan.command.utils.DataUtils;
|
||||||
|
import com.djrapitops.plan.command.utils.Analysis;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -62,7 +63,7 @@ public class AnalyzeCommand extends SubCommand {
|
||||||
+ "Refreshing playerData, this might take a while..");
|
+ "Refreshing playerData, this might take a while..");
|
||||||
this.playerData = DataUtils.getTotalData(DataUtils.getMatchingDisplaynames(true));
|
this.playerData = DataUtils.getTotalData(DataUtils.getMatchingDisplaynames(true));
|
||||||
this.refreshDate = new Date();
|
this.refreshDate = new Date();
|
||||||
this.analyzedPlayerdata = DataUtils.analyze(this.playerData);
|
this.analyzedPlayerdata = Analysis.analyze(this.playerData);
|
||||||
sender.sendMessage(textColor + "[" + operatorColor + "Plan" + textColor + "] "
|
sender.sendMessage(textColor + "[" + operatorColor + "Plan" + textColor + "] "
|
||||||
+ "Refreshed, took "+DataFormatUtils.formatTimeAmountSinceDate(refreshDate, new Date()));
|
+ "Refreshed, took "+DataFormatUtils.formatTimeAmountSinceDate(refreshDate, new Date()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@ import com.djrapitops.plan.command.CommandType;
|
||||||
import com.djrapitops.plan.command.SubCommand;
|
import com.djrapitops.plan.command.SubCommand;
|
||||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||||
import com.djrapitops.plan.command.utils.DataUtils;
|
import com.djrapitops.plan.command.utils.DataUtils;
|
||||||
import static com.palmergames.bukkit.towny.Towny.plugin;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
|
||||||
|
package com.djrapitops.plan.command.utils;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.Plan;
|
||||||
|
import com.djrapitops.plan.command.hooks.AdvancedAchievementsHook;
|
||||||
|
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||||
|
|
||||||
|
public class Analysis {
|
||||||
|
|
||||||
|
public static HashMap<String, String> analyze(HashMap<UUID, HashMap<String, String>> playerData) {
|
||||||
|
Plan plugin = getPlugin(Plan.class);
|
||||||
|
HashMap<String, List<String>> playerDataLists = new HashMap<>();
|
||||||
|
// Ignore following keys (Strings, unprocessable or irrelevant data)
|
||||||
|
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<>();
|
||||||
|
try {
|
||||||
|
AdvancedAchievementsHook aaHook = (AdvancedAchievementsHook) plugin.getHooks().get("AdvancedAchievements");
|
||||||
|
if (!aaHook.isUsingUUID()) {
|
||||||
|
ignoreKeys.add("AAC-ACHIEVEMENTS");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
ignoreKeys.add("AAC-ACHIEVEMENTS");
|
||||||
|
}
|
||||||
|
ignoreKeys.addAll(Arrays.asList(ignore));
|
||||||
|
|
||||||
|
// Turn playerData into Hashmap of Lists sorted by keys.
|
||||||
|
playerData.keySet().parallelStream().forEach((key) -> {
|
||||||
|
playerData.get(key).keySet().parallelStream()
|
||||||
|
.filter((dataKey) -> !(ignoreKeys.contains(dataKey)))
|
||||||
|
.map((dataKey) -> {
|
||||||
|
if (playerDataLists.get(dataKey) == null) {
|
||||||
|
playerDataLists.put(dataKey, new ArrayList<>());
|
||||||
|
}
|
||||||
|
return dataKey;
|
||||||
|
})
|
||||||
|
.forEach((dataKey) -> {
|
||||||
|
playerDataLists.get(dataKey).add(playerData.get(key).get(dataKey));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Define analysis method for keys
|
||||||
|
String[] numbers = {"AAC-ACHIEVEMENTS", "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"};
|
||||||
|
String[] booleanValues = {"ESS-BANNED", "ESS-JAILED", "ESS-MUTED", "ESS-FLYING", "TOW-ONLINE"};
|
||||||
|
String[] timeValues = {"ONT-TOTAL PLAY"};
|
||||||
|
|
||||||
|
List<String> numberKeys = new ArrayList<>();
|
||||||
|
List<String> boolKeys = new ArrayList<>();
|
||||||
|
List<String> timeKeys = new ArrayList<>();
|
||||||
|
|
||||||
|
numberKeys.addAll(Arrays.asList(numbers));
|
||||||
|
boolKeys.addAll(Arrays.asList(booleanValues));
|
||||||
|
timeKeys.addAll(Arrays.asList(timeValues));
|
||||||
|
|
||||||
|
// Attempt to determine if undefined data is usable
|
||||||
|
List<String> unusedKeys = new ArrayList<>();
|
||||||
|
unusedKeys.addAll(playerDataLists.keySet());
|
||||||
|
unusedKeys.removeAll(numberKeys);
|
||||||
|
unusedKeys.removeAll(boolKeys);
|
||||||
|
unusedKeys.removeAll(timeKeys);
|
||||||
|
unusedKeys.removeAll(ignoreKeys);
|
||||||
|
for (String key : unusedKeys) {
|
||||||
|
try {
|
||||||
|
Double.parseDouble(playerDataLists.get(key).get(0));
|
||||||
|
numberKeys.add(key);
|
||||||
|
continue;
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Boolean.parseBoolean(playerDataLists.get(key).get(0));
|
||||||
|
boolKeys.add(key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, String> averagesAndPercents = new HashMap<>();
|
||||||
|
int errors = 0;
|
||||||
|
HashSet<String> errorTypes = new HashSet<>();
|
||||||
|
|
||||||
|
// Analyze - Go through each key - Go through each point of data in the list.
|
||||||
|
for (String dataKey : playerDataLists.keySet()) {
|
||||||
|
if (numberKeys.contains(dataKey)) {
|
||||||
|
double sum = 0;
|
||||||
|
|
||||||
|
for (String dataPoint : playerDataLists.get(dataKey)) {
|
||||||
|
// Special cases separated.
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Average
|
||||||
|
averagesAndPercents.put(dataKey, "" + (sum * 1.0 / playerDataLists.get(dataKey).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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Percent
|
||||||
|
averagesAndPercents.put(dataKey, "" + ((amount * 1.0 / playerDataLists.get(dataKey).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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Average
|
||||||
|
averagesAndPercents.put(dataKey, "" + (time * 1.0 / playerDataLists.get(dataKey).size()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Log errors
|
||||||
|
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(averagesAndPercents);
|
||||||
|
}
|
||||||
|
}
|
|
@ -112,6 +112,101 @@ public class DataFormatUtils {
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Analysis data Formatting, will be updated after more analysis is added
|
||||||
|
public static HashMap<String, String> formatAnalyzed(HashMap<String, String> analyzedData) {
|
||||||
|
return removeExtraDataPoints(analyzedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format Search Results
|
||||||
|
public static HashMap<String, String> removeExtraDataPointsSearch(HashMap<String, String> dataMap, String[] args) {
|
||||||
|
if (args.length <= 1) {
|
||||||
|
return removeExtraDataPoints(dataMap);
|
||||||
|
}
|
||||||
|
HashMap<String, String> returnMap = new HashMap<>();
|
||||||
|
String errors = "FORMAT-SEARCH\n";
|
||||||
|
for (String key : dataMap.keySet()) {
|
||||||
|
for (String arg : args) {
|
||||||
|
try {
|
||||||
|
if (key.toLowerCase().contains(arg.toLowerCase())) {
|
||||||
|
returnMap.put(key, dataMap.get(key));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (!errors.contains(Arrays.toString(args))) {
|
||||||
|
errors += Arrays.toString(args)+"\n";
|
||||||
|
}
|
||||||
|
errors += (e + "\n" + key + " " + arg + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!errors.equals("FORMAT-SEARCH\n")) {
|
||||||
|
Plan plugin = getPlugin(Plan.class);
|
||||||
|
plugin.logToFile(errors);
|
||||||
|
}
|
||||||
|
return removeExtraDataPoints(returnMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace certain items of search terms with plugin tags and remove playername if -p
|
||||||
|
public static String[] parseSearchArgs(String[] args) {
|
||||||
|
String[] aacTerms = {"aac", "advanced", "achiev"};
|
||||||
|
String[] svoTerms = {"svo", "superb", "vote"};
|
||||||
|
String[] ontTerms = {"ont", "onoime", "time"};
|
||||||
|
String[] ecoTerms = {"eco", "money", "bal"};
|
||||||
|
String[] towTerms = {"tow", "town", "nation", "res", "plot", "perm"};
|
||||||
|
|
||||||
|
List<String> aac = new ArrayList<>();
|
||||||
|
List<String> svo = new ArrayList<>();
|
||||||
|
List<String> ont = new ArrayList<>();
|
||||||
|
List<String> eco = new ArrayList<>();
|
||||||
|
List<String> tow = new ArrayList<>();
|
||||||
|
|
||||||
|
aac.addAll(Arrays.asList(aacTerms));
|
||||||
|
svo.addAll(Arrays.asList(svoTerms));
|
||||||
|
ont.addAll(Arrays.asList(ontTerms));
|
||||||
|
eco.addAll(Arrays.asList(ecoTerms));
|
||||||
|
tow.addAll(Arrays.asList(towTerms));
|
||||||
|
String[] returnArray = new String[args.length];
|
||||||
|
argloop:
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
if (args[i].equals("-p")) {
|
||||||
|
args[0] = "";
|
||||||
|
returnArray[0] = "";
|
||||||
|
returnArray[i] = "";
|
||||||
|
}
|
||||||
|
for (String s : aac) {
|
||||||
|
if (args[i].toLowerCase().contains(s)) {
|
||||||
|
returnArray[i] = "AAC";
|
||||||
|
continue argloop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String s : svo) {
|
||||||
|
if (args[i].toLowerCase().contains(s)) {
|
||||||
|
returnArray[i] = "SVO";
|
||||||
|
continue argloop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String s : ont) {
|
||||||
|
if (args[i].toLowerCase().contains(s)) {
|
||||||
|
returnArray[i] = "ONT";
|
||||||
|
continue argloop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String s : eco) {
|
||||||
|
if (args[i].toLowerCase().contains(s)) {
|
||||||
|
returnArray[i] = "ECO";
|
||||||
|
continue argloop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String s : tow) {
|
||||||
|
if (args[i].toLowerCase().contains(s)) {
|
||||||
|
returnArray[i] = "TOW";
|
||||||
|
continue argloop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
returnArray[i] = args[i];
|
||||||
|
}
|
||||||
|
return returnArray;
|
||||||
|
}
|
||||||
|
|
||||||
// Creates a new Date with Epoch second and returns Date and Time String
|
// Creates a new Date with Epoch second and returns Date and Time String
|
||||||
public static String formatTimeStamp(String string) throws NumberFormatException {
|
public static String formatTimeStamp(String string) throws NumberFormatException {
|
||||||
|
@ -167,11 +262,6 @@ public class DataFormatUtils {
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Analysis data Formatting, will be updated after more analysis is added
|
|
||||||
public static HashMap<String, String> formatAnalyzed(HashMap<String, String> analyzedData) {
|
|
||||||
return removeExtraDataPoints(analyzedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removes letters from a string leaving only numbers and dots.
|
// Removes letters from a string leaving only numbers and dots.
|
||||||
public static String removeLetters(String dataPoint) {
|
public static String removeLetters(String dataPoint) {
|
||||||
String numbers = "0123456789.";
|
String numbers = "0123456789.";
|
||||||
|
@ -195,94 +285,22 @@ public class DataFormatUtils {
|
||||||
data.keySet().parallelStream().forEach((key) -> {
|
data.keySet().parallelStream().forEach((key) -> {
|
||||||
dataList.add(new String[]{key, data.get(key)});
|
dataList.add(new String[]{key, data.get(key)});
|
||||||
});
|
});
|
||||||
Collections.sort(dataList, new Comparator<String[]>() {
|
Collections.sort(dataList, (String[] strings, String[] otherStrings) -> strings[0].compareTo(otherStrings[0]));
|
||||||
public int compare(String[] strings, String[] otherStrings) {
|
|
||||||
return strings[0].compareTo(otherStrings[0]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return dataList;
|
return dataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String, String> removeExtraDataPointsSearch(HashMap<String, String> dataMap, String[] args) {
|
public static String[] mergeArrays(String[]... arrays) {
|
||||||
if (args.length <= 1) {
|
int arraySize = 0;
|
||||||
return removeExtraDataPoints(dataMap);
|
for (String[] array : arrays) {
|
||||||
|
arraySize += array.length;
|
||||||
}
|
}
|
||||||
HashMap<String, String> returnMap = new HashMap<>();
|
String[] result = new String[arraySize];
|
||||||
String errors = "FORMAT-SEARCH\n";
|
int j = 0;
|
||||||
for (String key : dataMap.keySet()) {
|
for (String[] array : arrays) {
|
||||||
for (String arg : args) {
|
for (String string : array) {
|
||||||
try {
|
result[j++] = string;
|
||||||
if (key.toLowerCase().contains(arg.toLowerCase())) {
|
|
||||||
returnMap.put(key, dataMap.get(key));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (!errors.contains(Arrays.toString(args))) {
|
|
||||||
errors += Arrays.toString(args)+"\n";
|
|
||||||
}
|
|
||||||
errors += (e + "\n" + key + " " + arg + "\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!errors.equals("FORMAT-SEARCH\n")) {
|
return result;
|
||||||
Plan plugin = getPlugin(Plan.class);
|
|
||||||
plugin.logToFile(errors);
|
|
||||||
}
|
|
||||||
return removeExtraDataPoints(returnMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] parseSearchArgs(String[] args) {
|
|
||||||
String[] aacTerms = {"aac", "advanced", "achiev"};
|
|
||||||
String[] svoTerms = {"svo", "superb", "vote"};
|
|
||||||
String[] ontTerms = {"ont", "onoime", "time"};
|
|
||||||
String[] ecoTerms = {"eco", "money", "bal"};
|
|
||||||
String[] towTerms = {"tow", "town", "nation", "res", "plot", "perm"};
|
|
||||||
|
|
||||||
List<String> aac = new ArrayList<>();
|
|
||||||
List<String> svo = new ArrayList<>();
|
|
||||||
List<String> ont = new ArrayList<>();
|
|
||||||
List<String> eco = new ArrayList<>();
|
|
||||||
List<String> tow = new ArrayList<>();
|
|
||||||
|
|
||||||
aac.addAll(Arrays.asList(aacTerms));
|
|
||||||
svo.addAll(Arrays.asList(svoTerms));
|
|
||||||
ont.addAll(Arrays.asList(ontTerms));
|
|
||||||
eco.addAll(Arrays.asList(ecoTerms));
|
|
||||||
tow.addAll(Arrays.asList(towTerms));
|
|
||||||
String[] returnArray = new String[args.length];
|
|
||||||
argloop:
|
|
||||||
for (int i = 0; i < args.length; i++) {
|
|
||||||
for (String s : aac) {
|
|
||||||
if (args[i].toLowerCase().contains(s)) {
|
|
||||||
returnArray[i] = "AAC";
|
|
||||||
continue argloop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (String s : svo) {
|
|
||||||
if (args[i].toLowerCase().contains(s)) {
|
|
||||||
returnArray[i] = "SVO";
|
|
||||||
continue argloop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (String s : ont) {
|
|
||||||
if (args[i].toLowerCase().contains(s)) {
|
|
||||||
returnArray[i] = "ONT";
|
|
||||||
continue argloop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (String s : eco) {
|
|
||||||
if (args[i].toLowerCase().contains(s)) {
|
|
||||||
returnArray[i] = "ECO";
|
|
||||||
continue argloop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (String s : tow) {
|
|
||||||
if (args[i].toLowerCase().contains(s)) {
|
|
||||||
returnArray[i] = "TOW";
|
|
||||||
continue argloop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
returnArray[i] = args[i];
|
|
||||||
}
|
|
||||||
return returnArray;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,119 +80,9 @@ public class DataUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String, String> analyze(HashMap<UUID, HashMap<String, String>> playerData) {
|
@Deprecated
|
||||||
Plan plugin = getPlugin(Plan.class);
|
public static HashMap<String, String> analyze(HashMap<UUID, HashMap<String, String>> playerData) {
|
||||||
HashMap<String, List<String>> playerDataLists = new HashMap<>();
|
return Analysis.analyze(playerData);
|
||||||
// Ignore following keys (Strings, unprocessable or irrelevant data)
|
|
||||||
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<>();
|
|
||||||
try {
|
|
||||||
AdvancedAchievementsHook aaHook = (AdvancedAchievementsHook) plugin.getHooks().get("AdvancedAchievements");
|
|
||||||
if (!aaHook.isUsingUUID()) {
|
|
||||||
ignoreKeys.add("AAC-ACHIEVEMENTS");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ignoreKeys.add("AAC-ACHIEVEMENTS");
|
|
||||||
}
|
|
||||||
ignoreKeys.addAll(Arrays.asList(ignore));
|
|
||||||
|
|
||||||
// Turn playerData into Hashmap of Lists sorted by keys.
|
|
||||||
playerData.keySet().parallelStream().forEach((key) -> {
|
|
||||||
playerData.get(key).keySet().parallelStream()
|
|
||||||
.filter((dataKey) -> !(ignoreKeys.contains(dataKey)))
|
|
||||||
.map((dataKey) -> {
|
|
||||||
if (playerDataLists.get(dataKey) == null) {
|
|
||||||
playerDataLists.put(dataKey, new ArrayList<>());
|
|
||||||
}
|
|
||||||
return dataKey;
|
|
||||||
})
|
|
||||||
.forEach((dataKey) -> {
|
|
||||||
playerDataLists.get(dataKey).add(playerData.get(key).get(dataKey));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Define analysis method for keys
|
|
||||||
String[] numbers = {"AAC-ACHIEVEMENTS", "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"};
|
|
||||||
String[] booleanValues = {"ESS-BANNED", "ESS-JAILED", "ESS-MUTED", "ESS-FLYING", "TOW-ONLINE"};
|
|
||||||
String[] timeValues = {"ONT-TOTAL PLAY"};
|
|
||||||
|
|
||||||
List<String> numberKeys = new ArrayList<>();
|
|
||||||
List<String> boolKeys = new ArrayList<>();
|
|
||||||
List<String> timeKeys = new ArrayList<>();
|
|
||||||
|
|
||||||
numberKeys.addAll(Arrays.asList(numbers));
|
|
||||||
boolKeys.addAll(Arrays.asList(booleanValues));
|
|
||||||
timeKeys.addAll(Arrays.asList(timeValues));
|
|
||||||
|
|
||||||
// TODO: Add extrahook analysis methods here
|
|
||||||
HashMap<String, String> analyzedData = new HashMap<>();
|
|
||||||
int errors = 0;
|
|
||||||
HashSet<String> errorTypes = new HashSet<>();
|
|
||||||
|
|
||||||
// Analyze - Go through each key - Go through each point of data in the list.
|
|
||||||
for (String dataKey : playerDataLists.keySet()) {
|
|
||||||
if (numberKeys.contains(dataKey)) {
|
|
||||||
double sum = 0;
|
|
||||||
|
|
||||||
for (String dataPoint : playerDataLists.get(dataKey)) {
|
|
||||||
// Special cases separated.
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Average
|
|
||||||
analyzedData.put(dataKey, "" + (sum * 1.0 / 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Average
|
|
||||||
analyzedData.put(dataKey, "" + ((amount * 1.0 / 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Average
|
|
||||||
analyzedData.put(dataKey, "" + (time * 1.0 / playerData.size()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Log errors
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPlayerDisplayname(String[] args, CommandSender sender) {
|
public static String getPlayerDisplayname(String[] args, CommandSender sender) {
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
|
|
||||||
package com.djrapitops.plan.javaTools;
|
|
||||||
|
|
||||||
public class Editor {
|
|
||||||
|
|
||||||
public String[] mergeArrays( String[]... arrays )
|
|
||||||
{
|
|
||||||
int arraySize = 0;
|
|
||||||
|
|
||||||
for( String[] array : arrays )
|
|
||||||
{
|
|
||||||
arraySize += array.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] result = new String[arraySize];
|
|
||||||
|
|
||||||
int j = 0;
|
|
||||||
|
|
||||||
for( String[] array : arrays )
|
|
||||||
{
|
|
||||||
for( String string : array )
|
|
||||||
{
|
|
||||||
result[j++] = string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: Plan
|
name: Plan
|
||||||
main: com.djrapitops.plan.Plan
|
main: com.djrapitops.plan.Plan
|
||||||
version: 1.5.0
|
version: 1.5.1
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
plan:
|
plan:
|
||||||
|
|
Loading…
Reference in New Issue