From bb5195e26d61d7fdb4f77452803a664735965977 Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+Rsl1122@users.noreply.github.com> Date: Wed, 20 Jan 2021 08:52:20 +0200 Subject: [PATCH] Changed all player tables to show active playtime Previously the tables showed playtime (with afk time) - Query result table - Server players table - Players page table Affects issues: - #1235 --- .../plan/delivery/domain/TablePlayer.java | 16 ++++++++-------- .../rendering/json/PlayersTableJSONCreator.java | 6 +++--- .../plan/settings/locale/lang/HtmlLang.java | 1 + .../playertable/NetworkTablePlayersQuery.java | 6 +++--- .../playertable/QueryTablePlayersQuery.java | 6 +++--- .../playertable/ServerTablePlayersQuery.java | 6 +++--- .../database/queries/SessionQueriesTest.java | 4 ++-- .../src/test/java/utilities/RandomData.java | 1 + 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/TablePlayer.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/TablePlayer.java index b84b3905a..88f60b282 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/TablePlayer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/TablePlayer.java @@ -33,7 +33,7 @@ public class TablePlayer implements Comparable { private UUID uuid; private String name; private ActivityIndex activityIndex; - private Long playtime; + private Long activePlaytime; private Integer sessionCount; private Long registered; private Long lastSeen; @@ -67,8 +67,8 @@ public class TablePlayer implements Comparable { return Optional.ofNullable(activityIndex); } - public Optional getPlaytime() { - return Optional.ofNullable(playtime); + public Optional getActivePlaytime() { + return Optional.ofNullable(activePlaytime); } public Optional getSessionCount() { @@ -105,7 +105,7 @@ public class TablePlayer implements Comparable { if (this == o) return true; if (!(o instanceof TablePlayer)) return false; TablePlayer that = (TablePlayer) o; - return playtime.equals(that.playtime) && + return activePlaytime.equals(that.activePlaytime) && sessionCount.equals(that.sessionCount) && registered.equals(that.registered) && lastSeen.equals(that.lastSeen) && @@ -116,7 +116,7 @@ public class TablePlayer implements Comparable { @Override public int hashCode() { - return Objects.hash(name, activityIndex, playtime, sessionCount, registered, lastSeen, geolocation); + return Objects.hash(name, activityIndex, activePlaytime, sessionCount, registered, lastSeen, geolocation); } @Override @@ -125,7 +125,7 @@ public class TablePlayer implements Comparable { "uuid=" + uuid + ", name='" + name + '\'' + ", activityIndex=" + activityIndex + - ", playtime=" + playtime + + ", activePlaytime=" + activePlaytime + ", sessionCount=" + sessionCount + ", registered=" + registered + ", lastSeen=" + lastSeen + @@ -165,8 +165,8 @@ public class TablePlayer implements Comparable { return this; } - public Builder playtime(long playtime) { - player.playtime = playtime; + public Builder activePlaytime(long activePlaytime) { + player.activePlaytime = activePlaytime; return this; } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/PlayersTableJSONCreator.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/PlayersTableJSONCreator.java index f860f2902..95f20ffec 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/PlayersTableJSONCreator.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/PlayersTableJSONCreator.java @@ -125,7 +125,7 @@ public class PlayersTableJSONCreator { String url = "../player/" + Html.encodeToURL(name); int loginTimes = player.getSessionCount().orElse(0); - long playtime = player.getPlaytime().orElse(-1L); + long activePlaytime = player.getActivePlaytime().orElse(-1L); long registered = player.getRegistered().orElse(-1L); long lastSeen = player.getLastSeen().orElse(-1L); @@ -140,7 +140,7 @@ public class PlayersTableJSONCreator { putDataEntry(dataJson, link.create(url, StringUtils.replace(StringEscapeUtils.escapeHtml4(name), "\\", "\\\\") /* Backslashes escaped to prevent json errors */), "name"); putDataEntry(dataJson, activityIndex.getValue(), activityString, "index"); - putDataEntry(dataJson, playtime, numberFormatters.get(FormatType.TIME_MILLISECONDS).apply(playtime), "playtime"); + putDataEntry(dataJson, activePlaytime, numberFormatters.get(FormatType.TIME_MILLISECONDS).apply(activePlaytime), "activePlaytime"); putDataEntry(dataJson, loginTimes, "sessions"); putDataEntry(dataJson, registered, numberFormatters.get(FormatType.DATE_YEAR).apply(registered), "registered"); putDataEntry(dataJson, lastSeen, numberFormatters.get(FormatType.DATE_YEAR).apply(lastSeen), "seen"); @@ -189,7 +189,7 @@ public class PlayersTableJSONCreator { columnHeaders.add(makeColumnHeader(Icon.called("user") + " " + locale.get(HtmlLang.LABEL_NAME), "name")); columnHeaders.add(makeFColumnHeader(Icon.called("check") + " " + locale.get(HtmlLang.LABEL_ACTIVITY_INDEX), "index")); - columnHeaders.add(makeFColumnHeader(Icon.called("clock").of(Family.REGULAR) + " " + locale.get(HtmlLang.LABEL_PLAYTIME), "playtime")); + columnHeaders.add(makeFColumnHeader(Icon.called("clock").of(Family.REGULAR) + " " + locale.get(HtmlLang.LABEL_ACTIVE_PLAYTIME), "activePlaytime")); columnHeaders.add(makeColumnHeader(Icon.called("calendar-plus").of(Family.REGULAR) + " " + locale.get(HtmlLang.SIDE_SESSIONS), "sessions")); columnHeaders.add(makeFColumnHeader(Icon.called("user-plus") + " " + locale.get(HtmlLang.LABEL_REGISTERED), "registered")); columnHeaders.add(makeFColumnHeader(Icon.called("calendar-check").of(Family.REGULAR) + " " + locale.get(HtmlLang.LABEL_LAST_SEEN), "seen")); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/lang/HtmlLang.java b/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/lang/HtmlLang.java index 1004b2623..d491424a6 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/lang/HtmlLang.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/lang/HtmlLang.java @@ -71,6 +71,7 @@ public enum HtmlLang implements Lang { LABEL_PLAYERS_ONLINE("Players Online"), LABEL_TOTAL_PLAYTIME("Total Playtime"), LABEL_PLAYTIME("Playtime"), + LABEL_ACTIVE_PLAYTIME("Active Playtime"), LABEL_LAST_PEAK("Last Peak"), LABEL_BEST_PEAK("Best Peak"), LABEL_AVG_PLAYTIME("Average Playtime"), diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/NetworkTablePlayersQuery.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/NetworkTablePlayersQuery.java index a27657bce..c8f2533d5 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/NetworkTablePlayersQuery.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/NetworkTablePlayersQuery.java @@ -75,7 +75,7 @@ public class NetworkTablePlayersQuery implements Query> { String selectSessionData = SELECT + "s." + SessionsTable.USER_UUID + ',' + "MAX(" + SessionsTable.SESSION_END + ") as last_seen," + "COUNT(1) as count," + - "SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + ") as playtime" + + "SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + '-' + SessionsTable.AFK_TIME + ") as active_playtime" + FROM + SessionsTable.TABLE_NAME + " s" + GROUP_BY + "s." + SessionsTable.USER_UUID; @@ -91,7 +91,7 @@ public class NetworkTablePlayersQuery implements Query> { "geoloc." + GeoInfoTable.GEOLOCATION + ',' + "ses.last_seen," + "ses.count," + - "ses.playtime," + + "ses.active_playtime," + "act.activity_index" + FROM + UsersTable.TABLE_NAME + " u" + LEFT_JOIN + '(' + selectBanned + ") ban on ban." + UserInfoTable.USER_UUID + "=u." + UsersTable.USER_UUID + @@ -119,7 +119,7 @@ public class NetworkTablePlayersQuery implements Query> { .registered(set.getLong(UsersTable.REGISTERED)) .lastSeen(set.getLong("last_seen")) .sessionCount(set.getInt("count")) - .playtime(set.getLong("playtime")) + .activePlaytime(set.getLong("active_playtime")) .activityIndex(new ActivityIndex(set.getDouble("activity_index"), date)); if (set.getString("banned") != null) { player.banned(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/QueryTablePlayersQuery.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/QueryTablePlayersQuery.java index d78e3765f..8a099b7e0 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/QueryTablePlayersQuery.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/QueryTablePlayersQuery.java @@ -88,7 +88,7 @@ public class QueryTablePlayersQuery implements Query> { String selectSessionData = SELECT + "s." + SessionsTable.USER_UUID + ',' + "MAX(" + SessionsTable.SESSION_END + ") as last_seen," + "COUNT(1) as count," + - "SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + ") as playtime" + + "SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + '-' + SessionsTable.AFK_TIME + ") as active_playtime" + FROM + SessionsTable.TABLE_NAME + " s" + WHERE + "s." + SessionsTable.SESSION_START + ">=?" + AND + "s." + SessionsTable.SESSION_END + "<=?" + @@ -104,7 +104,7 @@ public class QueryTablePlayersQuery implements Query> { "geoloc." + GeoInfoTable.GEOLOCATION + ',' + "ses.last_seen," + "ses.count," + - "ses.playtime," + + "ses.active_playtime," + "act.activity_index" + FROM + UsersTable.TABLE_NAME + " u" + INNER_JOIN + UserInfoTable.TABLE_NAME + " on u." + UsersTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID + @@ -134,7 +134,7 @@ public class QueryTablePlayersQuery implements Query> { .registered(set.getLong(UsersTable.REGISTERED)) .lastSeen(set.getLong("last_seen")) .sessionCount(set.getInt("count")) - .playtime(set.getLong("playtime")) + .activePlaytime(set.getLong("active_playtime")) .activityIndex(new ActivityIndex(set.getDouble("activity_index"), beforeDate)); if (set.getBoolean(UserInfoTable.BANNED)) { player.banned(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/ServerTablePlayersQuery.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/ServerTablePlayersQuery.java index 90016cf35..77701f55c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/ServerTablePlayersQuery.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/playertable/ServerTablePlayersQuery.java @@ -85,7 +85,7 @@ public class ServerTablePlayersQuery implements Query> { String selectSessionData = SELECT + "s." + SessionsTable.USER_UUID + ',' + "MAX(" + SessionsTable.SESSION_END + ") as last_seen," + "COUNT(1) as count," + - "SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + ") as playtime" + + "SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + '-' + SessionsTable.AFK_TIME + ") as active_playtime" + FROM + SessionsTable.TABLE_NAME + " s" + WHERE + "s." + SessionsTable.SERVER_UUID + "=?" + GROUP_BY + "s." + SessionsTable.USER_UUID; @@ -98,7 +98,7 @@ public class ServerTablePlayersQuery implements Query> { "geoloc." + GeoInfoTable.GEOLOCATION + ',' + "ses.last_seen," + "ses.count," + - "ses.playtime," + + "ses.active_playtime," + "act.activity_index" + FROM + UsersTable.TABLE_NAME + " u" + INNER_JOIN + UserInfoTable.TABLE_NAME + " on u." + UsersTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID + @@ -128,7 +128,7 @@ public class ServerTablePlayersQuery implements Query> { .registered(set.getLong(UsersTable.REGISTERED)) .lastSeen(set.getLong("last_seen")) .sessionCount(set.getInt("count")) - .playtime(set.getLong("playtime")) + .activePlaytime(set.getLong("active_playtime")) .activityIndex(new ActivityIndex(set.getDouble("activity_index"), date)); if (set.getBoolean(UserInfoTable.BANNED)) { player.banned(); diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/SessionQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/SessionQueriesTest.java index 1d95f3cec..da207b2a7 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/SessionQueriesTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/SessionQueriesTest.java @@ -280,8 +280,8 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { .stream().filter(player -> playerUUID.equals(player.getPlayerUUID())).findAny() .orElseThrow(AssertionError::new); - long expected = SessionsMutator.forContainer(playerContainer).toPlaytime(); - long got = tablePlayer.getPlaytime().orElseThrow(AssertionError::new); + long expected = SessionsMutator.forContainer(playerContainer).toActivePlaytime(); + long got = tablePlayer.getActivePlaytime().orElseThrow(AssertionError::new); assertEquals(expected, got); } diff --git a/Plan/common/src/test/java/utilities/RandomData.java b/Plan/common/src/test/java/utilities/RandomData.java index 8469ca045..fbf86c2a7 100644 --- a/Plan/common/src/test/java/utilities/RandomData.java +++ b/Plan/common/src/test/java/utilities/RandomData.java @@ -108,6 +108,7 @@ public class RandomData { Session session = new Session(uuids[0], serverUUID, RandomData.randomTime(), pickAtRandom(worlds), randomGameMode()); session.endSession(RandomData.randomTimeAfter(session.getDate())); session.setWorldTimes(RandomData.randomWorldTimes(worlds)); + session.addAFKTime(RandomData.randomLong(1, session.getLength())); if (uuids.length >= 2) { session.setPlayerKills(RandomData.randomKills(uuids[0], pickAtRandom(Arrays.copyOfRange(uuids, 1, uuids.length)))); }