Fixed last bugs with the new AnalysisContainer, deprecated a lot of things

This commit is contained in:
Rsl1122 2018-06-20 13:22:54 +03:00
parent 201cb98055
commit 4c709464be
28 changed files with 212 additions and 247 deletions

View File

@ -11,6 +11,7 @@ import org.apache.commons.text.WordUtils;
*
* @author Rsl1122
*/
@Deprecated
public enum Actions {
UNKNOWN(-1),
FIRST_SESSION(1),

View File

@ -26,6 +26,7 @@ import java.util.stream.Stream;
*
* @author Rsl1122
*/
@Deprecated
public class PlayerProfile {
// Identification

View File

@ -27,6 +27,7 @@ import java.util.stream.Stream;
*
* @author Rsl1122
*/
@Deprecated
public class ServerProfile {
private final UUID serverUUID;

View File

@ -50,6 +50,7 @@ import java.util.stream.Collectors;
* @author Rsl1122
* @since 3.5.2
*/
@Deprecated
public class AnalysisData extends RawData {
private long refreshDate;

View File

@ -12,6 +12,7 @@ import java.util.Map;
* @author Rsl1122
* @since 3.5.2
*/
@Deprecated
public abstract class RawData {
private final Map<String, Serializable> replaceMap;

View File

@ -16,6 +16,7 @@ import java.util.Objects;
*
* @author Rsl1122
*/
@Deprecated
public class Action implements DateHolder {
private final long date;
private final Actions doneAction;

View File

@ -67,16 +67,16 @@ public class TableContainer {
body.append("<tr>");
for (int i = 0; i < header.length; i++) {
try {
Serializable value = row[i];
Formatter formatter = formatters[i];
body.append("<td").append(formatter != null ? " data-order=\"" + value + "\">" : ">");
if (i > maxIndex) {
body.append("-");
body.append("<td>-");
} else {
Serializable value = row[i];
Formatter formatter = formatters[i];
body.append("<td").append(formatter != null ? " data-order=\"" + value + "\">" : ">");
body.append(formatter != null ? formatter.apply(value) : value);
}
body.append("</td>");
} catch (ClassCastException e) {
} catch (ClassCastException | ArrayIndexOutOfBoundsException e) {
throw new IllegalStateException("Invalid formatter given at index " + i + ": " + e.getMessage(), e);
}
}

View File

@ -1,5 +1,7 @@
package com.djrapitops.plan.data.store;
import java.util.Objects;
/**
* Similar to Google's TypeToken but without requiring whole gson package.
* <p>
@ -9,7 +11,10 @@ package com.djrapitops.plan.data.store;
*/
public abstract class Type<T> {
private final String genericsSuperClass;
public Type() {
genericsSuperClass = getGenericsClass().getGenericSuperclass().getTypeName();
}
public static <K> Type<K> ofClass(Class<K> of) {
@ -23,4 +28,18 @@ public abstract class Type<T> {
public Class<Type<T>> getGenericsClass() {
return (Class<Type<T>>) getClass();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Type)) return false;
Type<?> type = (Type<?>) o;
return Objects.equals(genericsSuperClass, type.genericsSuperClass);
}
@Override
public int hashCode() {
return Objects.hash(genericsSuperClass);
}
}

View File

@ -184,7 +184,8 @@ public class AnalysisContainer extends DataContainer {
});
putSupplier(AnalysisKeys.PLAYERS_RETAINED_DAY_PERC, () -> {
try {
return Formatters.percentage().apply(1.0 * getUnsafe(retentionDay) / getUnsafe(AnalysisKeys.PLAYERS_NEW_DAY));
Integer playersNewDay = getUnsafe(AnalysisKeys.PLAYERS_NEW_DAY);
return playersNewDay != 0 ? Formatters.percentage().apply(1.0 * getUnsafe(retentionDay) / playersNewDay) : "-";
} catch (IllegalStateException e) {
return "Not enough data";
}
@ -220,8 +221,11 @@ public class AnalysisContainer extends DataContainer {
putSupplier(AnalysisKeys.PLAYTIME_F, () -> Formatters.timeAmount()
.apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL))
);
putSupplier(AnalysisKeys.AVERAGE_PLAYTIME_F, () -> Formatters.timeAmount()
.apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL) / (long) getUnsafe(AnalysisKeys.PLAYERS_TOTAL))
putSupplier(AnalysisKeys.AVERAGE_PLAYTIME_F, () -> {
long players = getUnsafe(AnalysisKeys.PLAYERS_TOTAL);
return players != 0 ? Formatters.timeAmount()
.apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL) / players) : "-";
}
);
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F, () -> Formatters.timeAmount()
.apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
@ -257,11 +261,17 @@ public class AnalysisContainer extends DataContainer {
getUnsafe(AnalysisKeys.ANALYSIS_TIME)
).count()
);
putSupplier(AnalysisKeys.PLAYERS_RETAINED_WEEK_PERC, () -> Formatters.percentage().apply(
1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_WEEK) / getUnsafe(AnalysisKeys.PLAYERS_NEW_WEEK))
putSupplier(AnalysisKeys.PLAYERS_RETAINED_WEEK_PERC, () -> {
Integer playersNewWeek = getUnsafe(AnalysisKeys.PLAYERS_NEW_WEEK);
return playersNewWeek != 0 ? Formatters.percentage().apply(
1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_WEEK) / playersNewWeek) : "-";
}
);
putSupplier(AnalysisKeys.PLAYERS_RETAINED_MONTH_PERC, () -> Formatters.percentage().apply(
1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_MONTH) / getUnsafe(AnalysisKeys.PLAYERS_NEW_MONTH))
putSupplier(AnalysisKeys.PLAYERS_RETAINED_MONTH_PERC, () -> {
Integer playersNewMonth = getUnsafe(AnalysisKeys.PLAYERS_NEW_MONTH);
return playersNewMonth != 0 ? Formatters.percentage().apply(
1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_MONTH) / playersNewMonth) : "-";
}
);
}
@ -292,7 +302,8 @@ public class AnalysisContainer extends DataContainer {
new ActivityPie(getUnsafe(AnalysisKeys.ACTIVITY_DATA).get(getUnsafe(AnalysisKeys.ANALYSIS_TIME))).toHighChartsSeries()
);
putSupplier(AnalysisKeys.PLAYERS_REGULAR, () -> {
Map<String, Set<UUID>> activityNow = getUnsafe(AnalysisKeys.ACTIVITY_DATA).get(getUnsafe(AnalysisKeys.ANALYSIS_TIME));
Map<String, Set<UUID>> activityNow = getUnsafe(AnalysisKeys.ACTIVITY_DATA)
.floorEntry(getUnsafe(AnalysisKeys.ANALYSIS_TIME)).getValue();
Set<UUID> veryActiveNow = activityNow.getOrDefault("Very Active", new HashSet<>());
Set<UUID> activeNow = activityNow.getOrDefault("Active", new HashSet<>());
Set<UUID> regularNow = activityNow.getOrDefault("Regular", new HashSet<>());

View File

@ -35,7 +35,7 @@ public class AnalysisKeys {
public static final PlaceholderKey<Integer> PLAYERS_TOTAL = new PlaceholderKey<>(Integer.class, "playersTotal");
//
public static final PlaceholderKey<String> WORLD_PIE_COLORS = new PlaceholderKey<>(String.class, "worldPieColors");
public static final PlaceholderKey<String> GM_PIE_COLORS = new PlaceholderKey<>(String.class, "gm_pie_colors");
public static final PlaceholderKey<String> GM_PIE_COLORS = new PlaceholderKey<>(String.class, "gmPieColors");
public static final PlaceholderKey<String> ACTIVITY_PIE_COLORS = new PlaceholderKey<>(String.class, "activityPieColors");
public static final PlaceholderKey<String> PLAYERS_GRAPH_COLOR = new PlaceholderKey<>(String.class, "playersGraphColor");
public static final PlaceholderKey<String> TPS_HIGH_COLOR = new PlaceholderKey<>(String.class, "tpsHighColor");

View File

@ -8,7 +8,6 @@ import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.analysis.MathUtils;
import com.djrapitops.plan.utilities.html.Html;
import com.djrapitops.plugin.api.TimeAmount;
@ -142,12 +141,12 @@ public class HealthInformation {
long playersRetainedMonth = analysisContainer.getValue(AnalysisKeys.PLAYERS_RETAINED_MONTH).orElse(0);
if (playersNewMonth != 0) {
double stuckPerc = MathUtils.averageDouble(playersRetainedMonth, playersNewMonth) * 100;
if (stuckPerc >= 25) {
notes.add("<p>" + Html.GREEN_THUMB.parse() + " " + FormatUtils.cutDecimals(stuckPerc)
+ "% of new players have stuck around (" + playersRetainedMonth + "/" + playersNewMonth + ")</p>");
double retainPercentage = playersRetainedMonth / playersNewMonth;
if (retainPercentage >= 0.25) {
notes.add("<p>" + Html.GREEN_THUMB.parse() + " " + Formatters.percentage().apply(retainPercentage)
+ " of new players have stuck around (" + playersRetainedMonth + "/" + playersNewMonth + ")</p>");
} else {
notes.add("<p>" + Html.YELLOW_FLAG.parse() + " " + FormatUtils.cutDecimals(stuckPerc)
notes.add("<p>" + Html.YELLOW_FLAG.parse() + " " + Formatters.percentage().apply(retainPercentage)
+ "% of new players have stuck around (" + playersRetainedMonth + "/" + playersNewMonth + ")</p>");
}
}
@ -167,8 +166,8 @@ public class HealthInformation {
}
int activeCount = currentlyActive.count();
if (activeCount != 0) {
long avgFourToTwoWeeks = MathUtils.averageLong(totalFourToTwoWeeks, activeCount);
long avgLastTwoWeeks = MathUtils.averageLong(totalLastTwoWeeks, activeCount);
long avgFourToTwoWeeks = totalFourToTwoWeeks / (long) activeCount;
long avgLastTwoWeeks = totalLastTwoWeeks / (long) activeCount;
String avgLastTwoWeeksString = Formatters.timeAmount().apply(avgLastTwoWeeks);
String avgFourToTwoWeeksString = Formatters.timeAmount().apply(avgFourToTwoWeeks);
if (avgFourToTwoWeeks >= avgLastTwoWeeks) {

View File

@ -112,6 +112,8 @@ public class PlayersMutator {
activityData.put(time, map);
}
}
} else {
activityData.put(date, Collections.emptyMap());
}
return activityData;
}

View File

@ -16,8 +16,10 @@ public interface FetchOperations {
ServerContainer getServerContainer(UUID serverUUID);
@Deprecated
ServerProfile getServerProfile(UUID serverUUID);
@Deprecated
List<PlayerProfile> getPlayers(UUID serverUUID);
// UUIDs
@ -66,6 +68,7 @@ public interface FetchOperations {
List<String> getNicknamesOfPlayerOnServer(UUID uuid, UUID serverUUID);
@Deprecated
List<Action> getActions(UUID uuid);
Map<UUID, UserInfo> getUsers();

View File

@ -8,7 +8,6 @@ import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.data.container.builders.TPSBuilder;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.processing.CriticalRunnable;
import com.djrapitops.plan.utilities.analysis.MathUtils;
import java.util.List;
@ -29,12 +28,12 @@ public class TPSInsertProcessor implements CriticalRunnable {
public void run() {
List<TPS> history = tpsList;
final long lastDate = history.get(history.size() - 1).getDate();
final double averageTPS = MathUtils.round(MathUtils.averageDouble(history.stream().map(TPS::getTicksPerSecond)));
final double averageTPS = history.stream().mapToDouble(TPS::getTicksPerSecond).average().orElse(0);
final int peakPlayersOnline = history.stream().mapToInt(TPS::getPlayers).max().orElse(0);
final double averageCPUUsage = MathUtils.round(MathUtils.averageDouble(history.stream().map(TPS::getCPUUsage)));
final long averageUsedMemory = MathUtils.averageLong(history.stream().map(TPS::getUsedMemory));
final int averageEntityCount = (int) MathUtils.averageInt(history.stream().map(TPS::getEntityCount));
final int averageChunksLoaded = (int) MathUtils.averageInt(history.stream().map(TPS::getChunksLoaded));
final double averageCPUUsage = history.stream().mapToDouble(TPS::getCPUUsage).average().orElse(0);
final long averageUsedMemory = (long) history.stream().mapToLong(TPS::getUsedMemory).average().orElse(0);
final int averageEntityCount = (int) history.stream().mapToInt(TPS::getEntityCount).average().orElse(0);
final int averageChunksLoaded = (int) history.stream().mapToInt(TPS::getChunksLoaded).average().orElse(0);
TPS tps = TPSBuilder.get()
.date(lastDate)

View File

@ -3,7 +3,6 @@ package com.djrapitops.plan.system.tasks.server;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.system.tasks.TPSCountTimer;
import com.djrapitops.plan.utilities.analysis.MathUtils;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
@ -43,7 +42,7 @@ public class BukkitTPSCountTimer extends TPSCountTimer<Plan> {
private TPS calculateTPS(long diff, long now) {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
int availableProcessors = operatingSystemMXBean.getAvailableProcessors();
double averageCPUUsage = MathUtils.round(operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0);
double averageCPUUsage = operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0;
if (averageCPUUsage < 0) { // If unavailable, getSystemLoadAverage() returns -1
averageCPUUsage = -1;

View File

@ -2,7 +2,6 @@ package com.djrapitops.plan.system.tasks.server;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.utilities.analysis.MathUtils;
import org.bukkit.World;
public class PaperTPSCountTimer extends BukkitTPSCountTimer {
@ -24,8 +23,6 @@ public class PaperTPSCountTimer extends BukkitTPSCountTimer {
tps = 20;
}
tps = MathUtils.round(tps);
return new TPS(now, tps, playersOnline, cpuUsage, usedMemory, entityCount, chunksLoaded);
}

View File

@ -5,7 +5,6 @@ import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.data.container.builders.TPSBuilder;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.tasks.TPSCountTimer;
import com.djrapitops.plan.utilities.analysis.MathUtils;
import com.djrapitops.plugin.api.utility.log.Log;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.world.World;
@ -46,7 +45,7 @@ public class SpongeTPSCountTimer extends TPSCountTimer<PlanSponge> {
private TPS calculateTPS(long diff, long now) {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
int availableProcessors = operatingSystemMXBean.getAvailableProcessors();
double averageCPUUsage = MathUtils.round(operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0);
double averageCPUUsage = operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0;
if (averageCPUUsage < 0) { // If unavailable, getSystemLoadAverage() returns -1
averageCPUUsage = -1;

View File

@ -12,6 +12,8 @@ import com.djrapitops.plan.utilities.file.FileUtil;
import java.io.IOException;
import static com.djrapitops.plan.data.store.keys.AnalysisKeys.*;
/**
* Used for parsing a Html String out of AnalysisData and the html file.
*
@ -36,48 +38,48 @@ public class AnalysisPage extends Page {
@Override
public String toHtml() throws ParseException {
PlaceholderReplacer placeholderReplacer = new PlaceholderReplacer();
// placeholderReplacer.addAllPlaceholdersFrom(analysisContainer,
// VERSION, SERVER_NAME, TIME_ZONE,
// FIRST_DAY, TPS_MEDIUM, TPS_HIGH,
// PLAYERS_MAX, PLAYERS_ONLINE, PLAYERS_TOTAL,
//
// WORLD_PIE_COLORS, GM_PIE_COLORS, ACTIVITY_PIE_COLORS,
// PLAYERS_GRAPH_COLOR, TPS_HIGH_COLOR, TPS_MEDIUM_COLOR,
// TPS_LOW_COLOR, WORLD_MAP_HIGH_COLOR, WORLD_MAP_LOW_COLOR,
//
// PLAYERS_TABLE, SESSION_ACCORDION_HTML, SESSION_ACCORDION_FUNCTIONS,
// SESSION_TABLE, RECENT_LOGINS, COMMAND_USAGE_TABLE,
// HEALTH_NOTES, PLUGINS_TAB, PLUGINS_TAB_NAV,
//
// REFRESH_TIME_F, LAST_PEAK_TIME_F, ALL_TIME_PEAK_TIME_F,
// AVERAGE_SESSION_LENGTH_F, AVERAGE_PLAYTIME_F, PLAYTIME_F,
//
// PLAYERS_LAST_PEAK, PLAYERS_ALL_TIME_PEAK, OPERATORS,
// PLAYERS_REGULAR, SESSION_COUNT, DEATHS,
// MOB_KILL_COUNT, PLAYER_KILL_COUNT, HEALTH_INDEX,
// COMMAND_COUNT, COMMAND_COUNT_UNIQUE,
//
// PLAYERS_DAY, PLAYERS_WEEK, PLAYERS_MONTH,
// PLAYERS_NEW_DAY, PLAYERS_NEW_WEEK, PLAYERS_NEW_MONTH,
// AVG_PLAYERS, AVG_PLAYERS_DAY, AVG_PLAYERS_WEEK,
// AVG_PLAYERS_MONTH, AVG_PLAYERS_NEW, AVG_PLAYERS_NEW_DAY,
// AVG_PLAYERS_NEW_WEEK, AVG_PLAYERS_NEW_MONTH, PLAYERS_STUCK_DAY,
// PLAYERS_STUCK_DAY_PERC, PLAYERS_RETAINED_WEEK, PLAYERS_RETAINED_WEEK_PERC,
// PLAYERS_RETAINED_MONTH, PLAYERS_RETAINED_MONTH_PERC,
//
// TPS_SPIKE_MONTH, TPS_SPIKE_WEEK, TPS_SPIKE_DAY,
// AVG_TPS_MONTH, AVG_TPS_WEEK, AVG_TPS_DAY,
// AVG_CPU_MONTH, AVG_CPU_WEEK, AVG_CPU_DAY,
// AVG_RAM_MONTH, AVG_RAM_WEEK, AVG_RAM_DAY,
// AVG_ENTITY_MONTH, AVG_ENTITY_WEEK, AVG_ENTITY_DAY,
// AVG_CHUNK_MONTH, AVG_CHUNK_WEEK, AVG_CHUNK_DAY,
//
// WORLD_PIE_SERIES, GM_PIE_SERIES, PLAYERS_ONLINE_SERIES,
// TPS_SERIES, CPU_SERIES, RAM_SERIES,
// ENTITY_SERIES, CHUNK_SERIES, PUNCHCARD_SERIES,
// WORLD_MAP_SERIES, ACTIVITY_STACK_SERIES, ACTIVITY_STACK_CATEGORIES,
// ACTIVITY_PIE_SERIES, CALENDAR_SERIES
// );
placeholderReplacer.addAllPlaceholdersFrom(analysisContainer,
VERSION, SERVER_NAME, TIME_ZONE,
FIRST_DAY, TPS_MEDIUM, TPS_HIGH,
PLAYERS_MAX, PLAYERS_ONLINE, PLAYERS_TOTAL,
WORLD_PIE_COLORS, GM_PIE_COLORS, ACTIVITY_PIE_COLORS,
PLAYERS_GRAPH_COLOR, TPS_HIGH_COLOR, TPS_MEDIUM_COLOR,
TPS_LOW_COLOR, WORLD_MAP_HIGH_COLOR, WORLD_MAP_LOW_COLOR,
PLAYERS_TABLE, SESSION_ACCORDION_HTML, SESSION_ACCORDION_FUNCTIONS,
SESSION_TABLE, RECENT_LOGINS, COMMAND_USAGE_TABLE,
HEALTH_NOTES, PLUGINS_TAB, PLUGINS_TAB_NAV,
REFRESH_TIME_F, LAST_PEAK_TIME_F, ALL_TIME_PEAK_TIME_F,
AVERAGE_SESSION_LENGTH_F, AVERAGE_PLAYTIME_F, PLAYTIME_F,
PLAYERS_LAST_PEAK, PLAYERS_ALL_TIME_PEAK, OPERATORS,
PLAYERS_REGULAR, SESSION_COUNT, DEATHS,
MOB_KILL_COUNT, PLAYER_KILL_COUNT, HEALTH_INDEX,
COMMAND_COUNT, COMMAND_COUNT_UNIQUE,
PLAYERS_DAY, PLAYERS_WEEK, PLAYERS_MONTH,
PLAYERS_NEW_DAY, PLAYERS_NEW_WEEK, PLAYERS_NEW_MONTH,
AVG_PLAYERS, AVG_PLAYERS_DAY, AVG_PLAYERS_WEEK,
AVG_PLAYERS_MONTH, AVG_PLAYERS_NEW, AVG_PLAYERS_NEW_DAY,
AVG_PLAYERS_NEW_WEEK, AVG_PLAYERS_NEW_MONTH, PLAYERS_RETAINED_DAY,
PLAYERS_RETAINED_DAY_PERC, PLAYERS_RETAINED_WEEK, PLAYERS_RETAINED_WEEK_PERC,
PLAYERS_RETAINED_MONTH, PLAYERS_RETAINED_MONTH_PERC,
TPS_SPIKE_MONTH, TPS_SPIKE_WEEK, TPS_SPIKE_DAY,
AVG_TPS_MONTH, AVG_TPS_WEEK, AVG_TPS_DAY,
AVG_CPU_MONTH, AVG_CPU_WEEK, AVG_CPU_DAY,
AVG_RAM_MONTH, AVG_RAM_WEEK, AVG_RAM_DAY,
AVG_ENTITY_MONTH, AVG_ENTITY_WEEK, AVG_ENTITY_DAY,
AVG_CHUNK_MONTH, AVG_CHUNK_WEEK, AVG_CHUNK_DAY,
WORLD_PIE_SERIES, GM_PIE_SERIES, PLAYERS_ONLINE_SERIES,
TPS_SERIES, CPU_SERIES, RAM_SERIES,
ENTITY_SERIES, CHUNK_SERIES, PUNCHCARD_SERIES,
WORLD_MAP_SERIES, ACTIVITY_STACK_SERIES, ACTIVITY_STACK_CATEGORIES,
ACTIVITY_PIE_SERIES, CALENDAR_SERIES
);
try {
return placeholderReplacer.apply(FileUtil.getStringFromResource("web/server.html"));

View File

@ -30,6 +30,7 @@ import java.util.stream.Collectors;
/**
* @author Rsl1122
*/
@Deprecated
public class Analysis implements Callable<AnalysisData> {
private static Long refreshDate;
@ -156,6 +157,7 @@ public class Analysis implements Callable<AnalysisData> {
return containers;
}
@Deprecated
public static boolean isAnalysisBeingRun() {
return serverProfile != null;
}
@ -164,7 +166,7 @@ public class Analysis implements Callable<AnalysisData> {
Analysis.serverProfile = serverProfile;
}
private AnalysisData analyze() throws Exception {
private AnalysisData analyze() {
log(Locale.get(Msg.ANALYSIS_FETCH).toString());
Log.logDebug("Analysis", "Analysis Fetch Phase");
Benchmark.start("Analysis", "Analysis: Fetch Phase");

View File

@ -5,7 +5,6 @@ import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.keys.SessionKeys;
import com.djrapitops.plan.data.store.mutators.ActivityIndex;
import com.djrapitops.plan.data.store.mutators.RetentionData;
import com.djrapitops.plan.data.time.GMTimes;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.system.settings.WorldAliasSettings;
import com.djrapitops.plan.utilities.FormatUtils;
@ -15,17 +14,17 @@ import java.util.*;
import java.util.stream.Collectors;
/**
* Class that contains various methods that are used in analysis.
*
* @author Rsl1122
*/
public class AnalysisUtils {
/**
* Constructor used to hide the public constructor
*/
private AnalysisUtils() {
throw new IllegalStateException("Utility class");
/* static method class.*/
}
@Deprecated
public static long getNewPlayers(List<Long> registered, long scale, long now) {
long newPlayers = 0;
if (!registered.isEmpty()) {
@ -38,6 +37,7 @@ public class AnalysisUtils {
return newPlayers;
}
@Deprecated
public static int getUniquePlayers(Map<UUID, List<Session>> sessions, long after) {
Set<UUID> uuids = new HashSet<>();
@ -71,7 +71,7 @@ public class AnalysisUtils {
}
});
int total = MathUtils.sumInt(uniqueJoins.values().stream().map(Set::size));
int total = uniqueJoins.values().stream().mapToInt(Set::size).sum();
int numberOfDays = uniqueJoins.size();
if (numberOfDays == 0) {
@ -81,6 +81,7 @@ public class AnalysisUtils {
return total / numberOfDays;
}
@Deprecated
public static long getNewUsersPerDay(List<Long> registers, long after, long total) {
Set<Integer> days = new HashSet<>();
for (Long date : registers) {
@ -128,7 +129,7 @@ public class AnalysisUtils {
}
public static int getDayOfYear(Session session) {
return getDayOfYear(session.getSessionStart());
return getDayOfYear(session.getUnsafe(SessionKeys.START));
}
@ -216,33 +217,6 @@ public class AnalysisUtils {
return playtimePerAlias;
}
public static Map<String, GMTimes> getGMTimesPerAlias(WorldTimes worldTimes) {
Map<String, String> aliases = WorldAliasSettings.getAliases();
Map<String, GMTimes> gmTimesPerAlias = new HashMap<>();
String[] gms = GMTimes.getGMKeyArray();
for (Map.Entry<String, GMTimes> entry : worldTimes.getWorldTimes().entrySet()) {
String worldName = entry.getKey();
GMTimes gmTimes = entry.getValue();
if (!aliases.containsKey(worldName)) {
aliases.put(worldName, worldName);
WorldAliasSettings.addWorld(worldName);
}
String alias = aliases.get(worldName);
GMTimes aliasGMTimes = gmTimesPerAlias.getOrDefault(alias, new GMTimes());
for (String gm : gms) {
aliasGMTimes.addTime(gm, gmTimes.getTime(gm));
}
gmTimesPerAlias.put(alias, aliasGMTimes);
}
return gmTimesPerAlias;
}
public static RetentionData average(Collection<RetentionData> stuck) {
int size = stuck.size();

View File

@ -11,6 +11,7 @@ import java.util.stream.Stream;
/**
* @author Rsl1122
*/
@Deprecated
public class MathUtils {
private static final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH);

View File

@ -9,6 +9,7 @@ import java.util.Comparator;
*
* @author Rsl1122
*/
@Deprecated
public class ActionComparator implements Comparator<Action> {
@Override

View File

@ -14,6 +14,7 @@ import java.util.Comparator;
*
* @author Rsl1122
*/
@Deprecated
public class PlayerProfileLastPlayedComparator implements Comparator<PlayerProfile> {
@Override

View File

@ -3,15 +3,13 @@ package com.djrapitops.plan.utilities.html.graphs.pie;
import com.djrapitops.plan.data.time.GMTimes;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.WorldAliasSettings;
import com.djrapitops.plan.system.settings.theme.Theme;
import com.djrapitops.plan.system.settings.theme.ThemeVal;
import com.djrapitops.plan.utilities.analysis.AnalysisUtils;
import com.djrapitops.plan.utilities.comparators.PieSliceComparator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
public class WorldPie extends AbstractPieChartWithDrilldown {
@ -49,12 +47,39 @@ public class WorldPie extends AbstractPieChartWithDrilldown {
return slices;
}
private Map<String, GMTimes> getGMTimesPerAlias() {
Map<String, String> aliases = WorldAliasSettings.getAliases();
Map<String, GMTimes> gmTimesPerAlias = new HashMap<>();
String[] gms = GMTimes.getGMKeyArray();
for (Map.Entry<String, GMTimes> entry : worldTimes.getWorldTimes().entrySet()) {
String worldName = entry.getKey();
GMTimes gmTimes = entry.getValue();
if (!aliases.containsKey(worldName)) {
aliases.put(worldName, worldName);
WorldAliasSettings.addWorld(worldName);
}
String alias = aliases.get(worldName);
GMTimes aliasGMTimes = gmTimesPerAlias.getOrDefault(alias, new GMTimes());
for (String gm : gms) {
aliasGMTimes.addTime(gm, gmTimes.getTime(gm));
}
gmTimesPerAlias.put(alias, aliasGMTimes);
}
return gmTimesPerAlias;
}
@Override
public String toHighChartsDrilldown() {
StringBuilder drilldownBuilder = new StringBuilder();
int i = 0;
Map<String, GMTimes> gmTimesAliasMap = AnalysisUtils.getGMTimesPerAlias(worldTimes);
Map<String, GMTimes> gmTimesAliasMap = getGMTimesPerAlias();
if (gmTimesAliasMap.isEmpty()) {
return "[]";
}

View File

@ -18,6 +18,7 @@ import java.util.List;
*
* @author Rsl1122
*/
@Deprecated
public class ActionsTable extends TableContainer {
public ActionsTable(List<Action> actions) {

View File

@ -0,0 +1,53 @@
package com.djrapitops.plan.data.store;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
/**
* Equals test for Key objects.
*
* @author Rsl1122
*/
public class KeyTest {
@Test
public void twoInstancesAreEqual() {
Key<Integer> testKey = new Key<>(Integer.class, "test");
Key<Integer> testKey2 = new Key<>(Integer.class, "test");
assertEquals(testKey, testKey2);
}
@Test
public void twoComplexInstancesAreEqual() {
Key<List<Integer>> testKey = new Key<>(new Type<List<Integer>>() {}, "test");
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
assertEquals(testKey, testKey2);
}
@Test
public void twoComplexInstancesAreNotEqual() {
Key<List<Long>> testKey = new Key<>(new Type<List<Long>>() {}, "test");
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
assertNotEquals(testKey, testKey2);
}
@Test
public void twoComplexInstancesAreNotEqual2() {
Key<ArrayList<Integer>> testKey = new Key<>(new Type<ArrayList<Integer>>() {}, "test");
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
assertNotEquals(testKey, testKey2);
}
@Test
public void twoInstancesAreNotEqual() {
Key<Integer> testKey = new Key<>(Integer.class, "test");
Key<List<Integer>> testKey2 = new Key<>(new Type<List<Integer>>() {}, "test");
assertNotEquals(testKey, testKey2);
}
}

View File

@ -24,7 +24,6 @@ import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.processors.player.RegisterProcessor;
import com.djrapitops.plan.utilities.Base64Util;
import com.djrapitops.plan.utilities.SHA256Hash;
import com.djrapitops.plan.utilities.analysis.MathUtils;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
@ -652,7 +651,7 @@ public class SQLiteTest {
Random r = new Random();
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
int availableProcessors = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors();
final double averageCPUUsage = MathUtils.round(operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0);
final double averageCPUUsage = operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0;
final long usedMemory = 51231251254L;
final int entityCount = 6123;
final int chunksLoaded = 2134;

View File

@ -1,128 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.djrapitops.plan.utilities.analysis;
import org.junit.Test;
import utilities.RandomData;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertTrue;
/**
* @author Rsl1122
*/
public class MathUtilsTest {
@Test
public void testAverageInt() {
List<Integer> integers = Arrays.asList(0, 20, 5, 15);
double exp = 10;
double result = MathUtils.averageInt(integers.stream());
assertTrue(Double.compare(exp, result) == 0);
}
@Test
public void testAverageIntEmpty() {
List<Integer> integers = Collections.emptyList();
double exp = 0;
double result = MathUtils.averageInt(integers.stream());
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
}
@Test
public void testAverageLongCollection() {
List<Long> longs = Arrays.asList(0L, 20L, 5L, 15L);
double exp = 10;
double result = MathUtils.averageLong(longs);
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
}
@Test
public void testAverageDouble() {
List<Double> doubles = Arrays.asList(0.0, 20.5, 4.5, 15.0);
double exp = 10;
double result = MathUtils.averageDouble(doubles.stream());
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
}
@Test
public void testAverage() {
double exp = 10;
double result = MathUtils.average(40, 4);
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
}
@Test
public void testCountTrueBoolean() {
List<Boolean> booleans = new ArrayList<>();
int exp = RandomData.randomInt(0, 1000);
for (int i = 0; i < exp; i++) {
booleans.add(true);
}
for (int i = exp; i < RandomData.randomInt(100, 1000); i++) {
booleans.add(false);
}
long result = MathUtils.countTrueBoolean(booleans.stream());
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
}
@Test
public void testSumInt() {
List<Serializable> serializable = Arrays.asList(0, 20, 5, 15);
double exp = 40;
double result = MathUtils.sumInt(serializable.stream());
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
}
@Test
public void testSumLong() {
List<Serializable> serializable = Arrays.asList(0L, 20L, 5L, 15L);
long exp = 40;
long result = MathUtils.sumLong(serializable.stream());
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
}
@Test
public void testSumDouble() {
List<Serializable> serializable = Arrays.asList(0.0, 50.4, 45.0, 5.0531541);
double exp = 100.4531541;
double result = MathUtils.sumDouble(serializable.stream());
assertTrue(result + "/" + exp, Double.compare(exp, result) == 0);
}
@Test
public void testRoundDouble() {
double exp = 412.5123125123;
double result = MathUtils.round(exp);
assertTrue(result + "/" + exp, Double.compare(412.51, result) == 0);
}
}