Improved display of some data

This commit is contained in:
Rsl1122 2017-11-26 19:03:07 +02:00
parent 17d15cfcd9
commit e60a9a77d7
6 changed files with 5 additions and 160 deletions

View File

@ -25,15 +25,6 @@ public class AnalysisUtils {
throw new IllegalStateException("Utility class");
}
@Deprecated
public static boolean isActive(long now, long lastPlayed, long playTime, long loginTimes) {
int timeToActive = 10;
long twoWeeks = 1209600000;
return now - lastPlayed < twoWeeks
&& loginTimes > 3
&& playTime > 60 * timeToActive;
}
public static long getNewPlayers(List<Long> registered, long scale, long now) {
long newPlayers = 0;
if (!registered.isEmpty()) {
@ -46,38 +37,6 @@ public class AnalysisUtils {
return newPlayers;
}
@Deprecated
public static List<Long> transformSessionDataToLengths(Collection<Session> data) {
return data.stream()
.filter(Objects::nonNull)
.filter(session -> session.getLength() > 0)
.map(Session::getLength)
.collect(Collectors.toList());
}
/**
* Used to calculate unique players that have played within the time frame determined by scale.
*
* @param sessions All sessions sorted in a map by User's UUID
* @param scale Scale (milliseconds), time before (Current epoch - scale) will be ignored.
* @return Amount of Unique joins within the time span.
*/
@Deprecated
public static int getUniqueJoins(Map<UUID, List<Session>> sessions, long scale) {
long now = MiscUtils.getTime();
long nowMinusScale = now - scale;
Set<UUID> uniqueJoins = new HashSet<>();
sessions.forEach((uuid, s) ->
s.stream()
.filter(session -> session.getSessionStart() >= nowMinusScale)
.map(session -> uuid)
.forEach(uniqueJoins::add)
);
return uniqueJoins.size();
}
public static int getUniqueJoinsPerDay(Map<UUID, List<Session>> sessions, long after) {
Map<Integer, Set<UUID>> uniqueJoins = new HashMap<>();
@ -176,26 +135,6 @@ public class AnalysisUtils {
return value;
}
@Deprecated
public static long getTotalPlaytime(List<Session> sessions) {
return sessions.stream().mapToLong(Session::getLength).sum();
}
@Deprecated
public static long getLongestSessionLength(List<Session> sessions) {
Optional<Session> longest = sessions.stream().sorted(new SessionLengthComparator()).findFirst();
return longest.map(Session::getLength).orElse(0L);
}
@Deprecated
public static long getLastSeen(List<Session> userSessions) {
OptionalLong max = userSessions.stream().mapToLong(Session::getSessionEnd).max();
if (max.isPresent()) {
return max.getAsLong();
}
return 0;
}
public static void addMissingWorlds(WorldTimes worldTimes) {
try {
// Add 0 time for worlds not present.

View File

@ -60,40 +60,6 @@ public class HtmlStructure {
return builder.toString();
}
@Deprecated
public static String createServerOverviewColumn(Map<String, List<Session>> sessions) {
StringBuilder builder = new StringBuilder("<div class=\"column\">");
if (Verify.isEmpty(sessions)) {
return "<div class=\"column\"><div class=\"box-header\"><h2><i class=\"fa fa-server\" aria-hidden=\"true\"></i> No Sessions</h2> </div>" +
"<div class=\"box\" style=\"margin-bottom: 5px;\"><p>No sessions to calculate server specific playtime.</p></div></div>";
}
for (Map.Entry<String, List<Session>> entry : sessions.entrySet()) {
String serverName = entry.getKey();
List<Session> serverSessions = entry.getValue();
// Header
builder.append("<div class=\"box-header\"><h2><i class=\"fa fa-server\" aria-hidden=\"true\"></i> ").append(serverName).append("</h2> </div>");
// White box
builder.append("<div class=\"box\" style=\"margin-bottom: 5px;\">");
// Content
builder.append("<p>Sessions: ").append(serverSessions.size()).append("<br>");
long playTime = AnalysisUtils.getTotalPlaytime(serverSessions);
builder.append("Playtime: ").append(FormatUtils.formatTimeAmount(playTime)).append("<br>");
builder.append("<br>");
long longestSessionLength = AnalysisUtils.getLongestSessionLength(serverSessions);
builder.append("Longest Session: ").append(FormatUtils.formatTimeAmount(longestSessionLength));
// Content and box end
builder.append("</p></div>");
}
// Column ends
builder.append("</div>");
return builder.toString();
}
public static String[] createSessionsTabContentInspectPage(Map<String, List<Session>> sessions, List<Session> allSessions, UUID uuid) {
if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) {
Map<UUID, List<Session>> sessionsByPlayer = new HashMap<>();

View File

@ -31,46 +31,6 @@ public class AnalysisUtilsTest {
TestInit.init();
}
@Test
public void testIsActive() {
long lastPlayed = MiscUtils.getTime();
long playTime = 12638934876L;
int loginTimes = 4;
boolean result = AnalysisUtils.isActive(System.currentTimeMillis(), lastPlayed, playTime, loginTimes);
assertEquals(true, result);
}
@Test
public void testIsNotActive2() {
long lastPlayed = MiscUtils.getTime();
long playTime = 0L;
int loginTimes = 4;
boolean result = AnalysisUtils.isActive(System.currentTimeMillis(), lastPlayed, playTime, loginTimes);
assertEquals(false, result);
}
@Test
public void testIsNotActive3() {
long lastPlayed = MiscUtils.getTime();
long playTime = 12638934876L;
int loginTimes = 0;
boolean result = AnalysisUtils.isActive(System.currentTimeMillis(), lastPlayed, playTime, loginTimes);
assertEquals(false, result);
}
@Test
public void testIsNotActive() {
long lastPlayed = 0L;
long playTime = 12638934876L;
int loginTimes = 4;
boolean result = AnalysisUtils.isActive(System.currentTimeMillis(), lastPlayed, playTime, loginTimes);
assertEquals(false, result);
}
@Test
public void testGetNewPlayers() {
List<Long> registered = Arrays.asList(5L, 1L);
@ -90,17 +50,4 @@ public class AnalysisUtilsTest {
assertEquals(0L, result);
}
@Test
public void testTransformSessionDataToLengths() {
Collection<Session> data = Arrays.asList(
new Session(1, 0L, 5L, 0, 0),
new Session(1, 0L, 20L, 0, 0)
);
List<Long> expResult = Arrays.asList(5L, 20L);
List<Long> result = AnalysisUtils.transformSessionDataToLengths(data);
assertEquals(expResult, result);
}
}

View File

@ -31,14 +31,4 @@ public class HtmlStructureTest {
sessions.put(RandomData.randomString(10), RandomData.randomSessions());
}
}
@Test
public void createServerOverviewColumn() throws Exception {
String serverOverviewColumn = HtmlStructure.createServerOverviewColumn(sessions);
int opened = StringUtils.countMatches(serverOverviewColumn, "<div");
int closed = StringUtils.countMatches(serverOverviewColumn, "</div");
assertEquals(opened, closed);
}
}

View File

@ -57,10 +57,12 @@ public class EssentialsData extends PluginData {
}
}
analysisContainer.addValue(getWithIcon("Players in Jail", "ban", "red"), jailed.size() + " / " + uuids.size());
analysisContainer.addValue(getWithIcon("Muted", "bell-slash-o", "deep-orange"), muted.size() + " / " + uuids.size());
analysisContainer.addPlayerTableValues(getWithIcon("Jailed", "ban"), jailed);
analysisContainer.addPlayerTableValues(getWithIcon("Muted", "bell-slash-o"), muted);
List<String> warpsList = new ArrayList<>(essentials.getWarps().getList());
if (!warpsList.isEmpty()) {
TableContainer warps = new TableContainer(getWithIcon("Warp", "map-marker"), getWithIcon("Command", "terminal"));

View File

@ -70,8 +70,9 @@ public class TownyData extends PluginData {
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) throws Exception {
List<Town> towns = getTopTowns();
analysisContainer.addValue(getWithIcon("Number of Towns", "bank", "brown"), towns.size());
if (!towns.isEmpty()) {
analysisContainer.addValue(getWithIcon("Number of Towns", "bank", "brown"), towns.size());
Map<UUID, String> userTowns = new HashMap<>();
for (Town town : towns) {