mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-13 11:41:34 +01:00
Turned Session into a DataContainer, deprecated getters
This commit is contained in:
parent
51d91b63f8
commit
5184f0caf9
@ -10,6 +10,7 @@ import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
|||||||
import com.djrapitops.plan.data.Actions;
|
import com.djrapitops.plan.data.Actions;
|
||||||
import com.djrapitops.plan.data.container.Action;
|
import com.djrapitops.plan.data.container.Action;
|
||||||
import com.djrapitops.plan.data.container.Session;
|
import com.djrapitops.plan.data.container.Session;
|
||||||
|
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||||
import com.djrapitops.plan.system.cache.CacheSystem;
|
import com.djrapitops.plan.system.cache.CacheSystem;
|
||||||
import com.djrapitops.plan.system.cache.DataCache;
|
import com.djrapitops.plan.system.cache.DataCache;
|
||||||
import com.djrapitops.plan.system.cache.SessionCache;
|
import com.djrapitops.plan.system.cache.SessionCache;
|
||||||
@ -17,6 +18,7 @@ import com.djrapitops.plan.system.database.databases.Database;
|
|||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import com.djrapitops.plugin.api.utility.log.Log;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,8 +94,8 @@ public class ShutdownHook extends Thread {
|
|||||||
for (Map.Entry<UUID, Session> entry : activeSessions.entrySet()) {
|
for (Map.Entry<UUID, Session> entry : activeSessions.entrySet()) {
|
||||||
UUID uuid = entry.getKey();
|
UUID uuid = entry.getKey();
|
||||||
Session session = entry.getValue();
|
Session session = entry.getValue();
|
||||||
long sessionEnd = session.getSessionEnd();
|
Optional<Long> end = session.getValue(SessionKeys.END);
|
||||||
if (sessionEnd == -1) {
|
if (!end.isPresent()) {
|
||||||
session.endSession(now);
|
session.endSession(now);
|
||||||
}
|
}
|
||||||
if (!db.isOpen()) {
|
if (!db.isOpen()) {
|
||||||
|
@ -1,78 +1,101 @@
|
|||||||
package com.djrapitops.plan.data.container;
|
package com.djrapitops.plan.data.container;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||||
|
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||||
import com.djrapitops.plan.data.time.WorldTimes;
|
import com.djrapitops.plan.data.time.WorldTimes;
|
||||||
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object for storing various information about a player's play session.
|
* DataContainer for information about a player's play session.
|
||||||
* <p>
|
|
||||||
* Includes:
|
|
||||||
* <ul>
|
|
||||||
* <li>World and GameMode playtimes</li>
|
|
||||||
* <li>Player and Mob kills</li>
|
|
||||||
* <li>Deaths</li>
|
|
||||||
* </ul>
|
|
||||||
* <p>
|
|
||||||
* Following data can be derived from Sessions in the database (Between any time span):
|
|
||||||
* <ul>
|
|
||||||
* <li>Playtime</li>
|
|
||||||
* <li>LoginTimes</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
|
* @see SessionKeys for Key objects.
|
||||||
*/
|
*/
|
||||||
public class Session implements DateHolder {
|
public class Session extends DataContainer implements DateHolder {
|
||||||
|
|
||||||
private final long sessionStart;
|
|
||||||
private Integer sessionID;
|
|
||||||
private WorldTimes worldTimes;
|
|
||||||
private long sessionEnd;
|
|
||||||
private List<PlayerKill> playerKills;
|
|
||||||
private int mobKills;
|
private int mobKills;
|
||||||
private int deaths;
|
private int deaths;
|
||||||
|
|
||||||
private long afkTime;
|
private long afkTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new session with given start and end of -1.
|
* Creates a new session.
|
||||||
*
|
*
|
||||||
* @param sessionStart Epoch millisecond the session was started.
|
* @param uuid UUID of the Player.
|
||||||
|
* @param sessionStart Epoch ms the session started.
|
||||||
|
* @param world Starting world.
|
||||||
|
* @param gm Starting GameMode.
|
||||||
*/
|
*/
|
||||||
public Session(long sessionStart, String world, String gm) {
|
public Session(UUID uuid, long sessionStart, String world, String gm) {
|
||||||
this.worldTimes = new WorldTimes(world, gm);
|
|
||||||
this.sessionStart = sessionStart;
|
|
||||||
this.sessionEnd = -1;
|
|
||||||
playerKills = new ArrayList<>();
|
|
||||||
mobKills = 0;
|
mobKills = 0;
|
||||||
deaths = 0;
|
deaths = 0;
|
||||||
afkTime = 0;
|
afkTime = 0;
|
||||||
|
|
||||||
|
putRawData(SessionKeys.UUID, uuid);
|
||||||
|
putRawData(SessionKeys.START, sessionStart);
|
||||||
|
putRawData(SessionKeys.WORLD_TIMES, new WorldTimes(world, gm));
|
||||||
|
putRawData(SessionKeys.PLAYER_KILLS, new ArrayList<>());
|
||||||
|
putSupplier(SessionKeys.MOB_KILL_COUNT, () -> mobKills);
|
||||||
|
putSupplier(SessionKeys.DEATH_COUNT, () -> deaths);
|
||||||
|
putSupplier(SessionKeys.AFK_TIME, () -> afkTime);
|
||||||
|
|
||||||
|
putSupplier(SessionKeys.PLAYER_KILL_COUNT, getUnsafe(SessionKeys.PLAYER_KILLS)::size);
|
||||||
|
putSupplier(SessionKeys.LENGTH, () ->
|
||||||
|
getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START));
|
||||||
|
putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME));
|
||||||
|
putSupplier(SessionKeys.SERVER_UUID, ServerInfo::getServerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Session(int id, long sessionStart, long sessionEnd, int mobKills, int deaths, long afkTime) {
|
/**
|
||||||
this.sessionID = id;
|
* Recreates a Session found in the database.
|
||||||
this.sessionStart = sessionStart;
|
* <p>
|
||||||
this.sessionEnd = sessionEnd;
|
* WorldTimes and Player kills need to be set separately.
|
||||||
this.worldTimes = new WorldTimes(new HashMap<>());
|
*
|
||||||
this.playerKills = new ArrayList<>();
|
* @param id ID in the database (Used for fetching world times and player kills.
|
||||||
|
* @param uuid UUID of the Player.
|
||||||
|
* @param serverUUID UUID of the Server.
|
||||||
|
* @param sessionStart Epoch ms the session started.
|
||||||
|
* @param sessionEnd Epoch ms the session ended.
|
||||||
|
* @param mobKills Mobs killed during the session.
|
||||||
|
* @param deaths Death count during the session.
|
||||||
|
* @param afkTime Time spent AFK during the session.
|
||||||
|
*/
|
||||||
|
public Session(int id, UUID uuid, UUID serverUUID, long sessionStart, long sessionEnd, int mobKills, int deaths, long afkTime) {
|
||||||
|
putRawData(SessionKeys.DB_ID, id);
|
||||||
|
putRawData(SessionKeys.UUID, uuid);
|
||||||
|
putRawData(SessionKeys.SERVER_UUID, serverUUID);
|
||||||
|
putRawData(SessionKeys.START, sessionStart);
|
||||||
|
putRawData(SessionKeys.END, sessionEnd);
|
||||||
|
putSupplier(SessionKeys.MOB_KILL_COUNT, () -> mobKills);
|
||||||
|
putSupplier(SessionKeys.DEATH_COUNT, () -> deaths);
|
||||||
|
putSupplier(SessionKeys.AFK_TIME, () -> afkTime);
|
||||||
|
|
||||||
this.mobKills = mobKills;
|
this.mobKills = mobKills;
|
||||||
this.deaths = deaths;
|
this.deaths = deaths;
|
||||||
this.afkTime = afkTime;
|
this.afkTime = afkTime;
|
||||||
|
|
||||||
|
putSupplier(SessionKeys.PLAYER_KILL_COUNT, () -> getUnsafe(SessionKeys.PLAYER_KILLS).size());
|
||||||
|
putSupplier(SessionKeys.LENGTH, () ->
|
||||||
|
getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START));
|
||||||
|
putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends the session with given end point.
|
* Ends the session with given end point.
|
||||||
* <p>
|
* <p>
|
||||||
* (Changes the end to the parameter.).
|
* Updates world times to the latest value.
|
||||||
*
|
*
|
||||||
* @param endOfSession Epoch millisecond the session ended.
|
* @param endOfSession Epoch millisecond the session ended.
|
||||||
*/
|
*/
|
||||||
public void endSession(long endOfSession) {
|
public void endSession(long endOfSession) {
|
||||||
sessionEnd = endOfSession;
|
putRawData(SessionKeys.END, endOfSession);
|
||||||
|
WorldTimes worldTimes = getValue(SessionKeys.WORLD_TIMES)
|
||||||
|
.orElseThrow(() -> new IllegalStateException("World times have not been defined"));
|
||||||
worldTimes.updateState(endOfSession);
|
worldTimes.updateState(endOfSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +107,14 @@ public class Session implements DateHolder {
|
|||||||
* @param time Epoch ms of the event.
|
* @param time Epoch ms of the event.
|
||||||
*/
|
*/
|
||||||
public void changeState(String world, String gm, long time) {
|
public void changeState(String world, String gm, long time) {
|
||||||
|
WorldTimes worldTimes = getValue(SessionKeys.WORLD_TIMES)
|
||||||
|
.orElseThrow(() -> new IllegalStateException("World times is not defined"));
|
||||||
worldTimes.updateState(world, gm, time);
|
worldTimes.updateState(world, gm, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playerKilled(PlayerKill kill) {
|
public void playerKilled(PlayerKill kill) {
|
||||||
|
List<PlayerKill> playerKills = getValue(SessionKeys.PLAYER_KILLS)
|
||||||
|
.orElseThrow(() -> new IllegalStateException("Player kills is not defined."));
|
||||||
playerKills.add(kill);
|
playerKills.add(kill);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,16 +131,14 @@ public class Session implements DateHolder {
|
|||||||
*
|
*
|
||||||
* @return Long in ms.
|
* @return Long in ms.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public long getLength() {
|
public long getLength() {
|
||||||
if (sessionEnd == -1) {
|
return getUnsafe(SessionKeys.LENGTH);
|
||||||
return System.currentTimeMillis() - sessionStart;
|
|
||||||
}
|
|
||||||
return sessionEnd - sessionStart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDate() {
|
public long getDate() {
|
||||||
return getSessionStart();
|
return getUnsafe(SessionKeys.START);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,8 +146,9 @@ public class Session implements DateHolder {
|
|||||||
*
|
*
|
||||||
* @return Epoch millisecond the session started.
|
* @return Epoch millisecond the session started.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public long getSessionStart() {
|
public long getSessionStart() {
|
||||||
return sessionStart;
|
return getUnsafe(SessionKeys.START);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,46 +156,53 @@ public class Session implements DateHolder {
|
|||||||
*
|
*
|
||||||
* @return Epoch millisecond the session ended.
|
* @return Epoch millisecond the session ended.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public long getSessionEnd() {
|
public long getSessionEnd() {
|
||||||
return sessionEnd;
|
return getValue(SessionKeys.END).orElse(-1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public WorldTimes getWorldTimes() {
|
public WorldTimes getWorldTimes() {
|
||||||
return worldTimes;
|
return getValue(SessionKeys.WORLD_TIMES).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWorldTimes(WorldTimes worldTimes) {
|
public void setWorldTimes(WorldTimes worldTimes) {
|
||||||
this.worldTimes = worldTimes;
|
putRawData(SessionKeys.WORLD_TIMES, worldTimes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public List<PlayerKill> getPlayerKills() {
|
public List<PlayerKill> getPlayerKills() {
|
||||||
return playerKills;
|
return getValue(SessionKeys.PLAYER_KILLS).orElse(new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerKills(List<PlayerKill> playerKills) {
|
public void setPlayerKills(List<PlayerKill> playerKills) {
|
||||||
this.playerKills = playerKills;
|
putRawData(SessionKeys.PLAYER_KILLS, playerKills);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public int getMobKills() {
|
public int getMobKills() {
|
||||||
return mobKills;
|
return mobKills;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public int getDeaths() {
|
public int getDeaths() {
|
||||||
return deaths;
|
return deaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFetchedFromDB() {
|
public boolean isFetchedFromDB() {
|
||||||
return sessionID != null;
|
return supports(SessionKeys.DB_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAFKTime(long timeAFK) {
|
public void addAFKTime(long timeAFK) {
|
||||||
afkTime += timeAFK;
|
afkTime += timeAFK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public long getAfkLength() {
|
public long getAfkLength() {
|
||||||
return afkTime;
|
return afkTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public long getActiveLength() {
|
public long getActiveLength() {
|
||||||
return getLength() - getAfkLength();
|
return getLength() - getAfkLength();
|
||||||
}
|
}
|
||||||
@ -180,12 +213,13 @@ public class Session implements DateHolder {
|
|||||||
* @return ID if present.
|
* @return ID if present.
|
||||||
* @throws NullPointerException if Session was not fetched from DB. Check {@code isFetchedFromDB} first.
|
* @throws NullPointerException if Session was not fetched from DB. Check {@code isFetchedFromDB} first.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public int getSessionID() {
|
public int getSessionID() {
|
||||||
return sessionID != null ? sessionID : -1;
|
return getValue(SessionKeys.DB_ID).orElseThrow(() -> new NullPointerException("Session not fetched from DB."));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSessionID(int sessionID) {
|
public void setSessionID(int sessionID) {
|
||||||
this.sessionID = sessionID;
|
putRawData(SessionKeys.DB_ID, sessionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -193,28 +227,17 @@ public class Session implements DateHolder {
|
|||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
Session session = (Session) o;
|
Session session = (Session) o;
|
||||||
return sessionStart == session.sessionStart &&
|
return getUnsafe(SessionKeys.START).equals(session.getUnsafe(SessionKeys.START)) &&
|
||||||
sessionEnd == session.sessionEnd &&
|
getValue(SessionKeys.END).orElse(-1L).equals(session.getValue(SessionKeys.END).orElse(-1L)) &&
|
||||||
mobKills == session.mobKills &&
|
mobKills == session.mobKills &&
|
||||||
deaths == session.deaths &&
|
deaths == session.deaths &&
|
||||||
Objects.equals(worldTimes, session.worldTimes) &&
|
Objects.equals(
|
||||||
Objects.equals(playerKills, session.playerKills);
|
getValue(SessionKeys.WORLD_TIMES).orElse(null),
|
||||||
}
|
session.getValue(SessionKeys.WORLD_TIMES).orElse(null)
|
||||||
|
) &&
|
||||||
@Override
|
Objects.equals(
|
||||||
public int hashCode() {
|
getValue(SessionKeys.PLAYER_KILLS).orElse(new ArrayList<>()),
|
||||||
return Objects.hash(sessionStart, sessionID, worldTimes, sessionEnd, playerKills, mobKills, deaths);
|
session.getValue(SessionKeys.PLAYER_KILLS).orElse(new ArrayList<>())
|
||||||
}
|
);
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Session{" +
|
|
||||||
"sessionStart=" + sessionStart + ", " +
|
|
||||||
"sessionID=" + sessionID + ", " +
|
|
||||||
"worldTimes=" + worldTimes + ", " +
|
|
||||||
"sessionEnd=" + sessionEnd + ", " +
|
|
||||||
"playerKills=" + playerKills + ", " +
|
|
||||||
"mobKills=" + mobKills + ", " +
|
|
||||||
"deaths=" + deaths + '}';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ public class CommonKeys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final Key<UUID> UUID = new Key<>(UUID.class, "uuid");
|
public static final Key<UUID> UUID = new Key<>(UUID.class, "uuid");
|
||||||
|
public static final Key<UUID> SERVER_UUID = new Key<>(UUID.class, "server_uuid");
|
||||||
public static final Key<String> NAME = new Key<>(String.class, "name");
|
public static final Key<String> NAME = new Key<>(String.class, "name");
|
||||||
public static final Key<Long> REGISTERED = new Key<>(Long.class, "registered");
|
public static final Key<Long> REGISTERED = new Key<>(Long.class, "registered");
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public class ServerKeys {
|
|||||||
/* Static variable class */
|
/* Static variable class */
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Key<UUID> UUID = CommonKeys.UUID;
|
public static final Key<UUID> SERVER_UUID = CommonKeys.SERVER_UUID;
|
||||||
public static final Key<String> NAME = CommonKeys.NAME;
|
public static final Key<String> NAME = CommonKeys.NAME;
|
||||||
|
|
||||||
public static final Key<List<PlayerContainer>> PLAYERS = new Key<>(new Type<List<PlayerContainer>>() {}, "players");
|
public static final Key<List<PlayerContainer>> PLAYERS = new Key<>(new Type<List<PlayerContainer>>() {}, "players");
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.djrapitops.plan.data.store.keys;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.data.container.PlayerKill;
|
||||||
|
import com.djrapitops.plan.data.store.Key;
|
||||||
|
import com.djrapitops.plan.data.time.WorldTimes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class holding Key objects for Session (DataContainer).
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
* @see com.djrapitops.plan.data.container.Session for DataContainer.
|
||||||
|
*/
|
||||||
|
public class SessionKeys {
|
||||||
|
|
||||||
|
public static final Key<Integer> DB_ID = new Key<>(Integer.class, "db_id");
|
||||||
|
public static final Key<UUID> UUID = CommonKeys.UUID;
|
||||||
|
public static final Key<UUID> SERVER_UUID = CommonKeys.SERVER_UUID;
|
||||||
|
|
||||||
|
public static final Key<Long> START = new Key<>(Long.class, "start");
|
||||||
|
public static final Key<Long> END = new Key<>(Long.class, "end");
|
||||||
|
public static final Key<Long> LENGTH = new Key<>(Long.class, "length");
|
||||||
|
public static final Key<Long> AFK_TIME = new Key<>(Long.class, "afk_time");
|
||||||
|
public static final Key<Long> ACTIVE_TIME = new Key<>(Long.class, "active_time");
|
||||||
|
public static final Key<WorldTimes> WORLD_TIMES = CommonKeys.WORLD_TIMES;
|
||||||
|
public static final Key<List<PlayerKill>> PLAYER_KILLS = CommonKeys.PLAYER_KILLS;
|
||||||
|
public static final Key<Integer> PLAYER_KILL_COUNT = CommonKeys.PLAYER_KILL_COUNT;
|
||||||
|
public static final Key<Integer> MOB_KILL_COUNT = CommonKeys.MOB_KILL_COUNT;
|
||||||
|
public static final Key<Integer> DEATH_COUNT = CommonKeys.DEATH_COUNT;
|
||||||
|
|
||||||
|
private SessionKeys() {
|
||||||
|
/* Static variable class */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -178,7 +178,7 @@ public class SessionsTable extends UserIDTable {
|
|||||||
int deaths = set.getInt(Col.DEATHS.get());
|
int deaths = set.getInt(Col.DEATHS.get());
|
||||||
int mobKills = set.getInt(Col.MOB_KILLS.get());
|
int mobKills = set.getInt(Col.MOB_KILLS.get());
|
||||||
List<Session> sessions = sessionsByServer.getOrDefault(serverUUID, new ArrayList<>());
|
List<Session> sessions = sessionsByServer.getOrDefault(serverUUID, new ArrayList<>());
|
||||||
sessions.add(new Session(id, start, end, mobKills, deaths, timeAFK));
|
sessions.add(new Session(id, uuid, serverUUID, start, end, mobKills, deaths, timeAFK));
|
||||||
sessionsByServer.put(serverUUID, sessions);
|
sessionsByServer.put(serverUUID, sessions);
|
||||||
}
|
}
|
||||||
return sessionsByServer;
|
return sessionsByServer;
|
||||||
@ -473,7 +473,7 @@ public class SessionsTable extends UserIDTable {
|
|||||||
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
||||||
|
|
||||||
List<Session> sessions = sessionsByUser.getOrDefault(uuid, new ArrayList<>());
|
List<Session> sessions = sessionsByUser.getOrDefault(uuid, new ArrayList<>());
|
||||||
sessions.add(new Session(set.getInt(Col.ID.get()), start, end, mobKills, deaths, timeAFK));
|
sessions.add(new Session(set.getInt(Col.ID.get()), uuid, serverUUID, start, end, mobKills, deaths, timeAFK));
|
||||||
sessionsByUser.put(uuid, sessions);
|
sessionsByUser.put(uuid, sessions);
|
||||||
}
|
}
|
||||||
return sessionsByUser;
|
return sessionsByUser;
|
||||||
@ -567,7 +567,7 @@ public class SessionsTable extends UserIDTable {
|
|||||||
|
|
||||||
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
||||||
|
|
||||||
Session session = new Session(id, start, end, mobKills, deaths, timeAFK);
|
Session session = new Session(id, uuid, serverUUID, start, end, mobKills, deaths, timeAFK);
|
||||||
sessions.add(session);
|
sessions.add(session);
|
||||||
|
|
||||||
sessionsByUser.put(uuid, sessions);
|
sessionsByUser.put(uuid, sessions);
|
||||||
@ -623,7 +623,7 @@ public class SessionsTable extends UserIDTable {
|
|||||||
|
|
||||||
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
||||||
|
|
||||||
Session session = new Session(id, start, end, mobKills, deaths, timeAFK);
|
Session session = new Session(id, uuid, serverUUID, start, end, mobKills, deaths, timeAFK);
|
||||||
sessions.add(session);
|
sessions.add(session);
|
||||||
|
|
||||||
sessionsByUser.put(uuid, sessions);
|
sessionsByUser.put(uuid, sessions);
|
||||||
|
@ -96,7 +96,7 @@ public class PlayerOnlineListener implements Listener {
|
|||||||
|
|
||||||
int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline();
|
int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline();
|
||||||
|
|
||||||
SessionCache.getInstance().cacheSession(uuid, new Session(time, world, gm));
|
SessionCache.getInstance().cacheSession(uuid, new Session(uuid, time, world, gm));
|
||||||
|
|
||||||
Processing.submit(
|
Processing.submit(
|
||||||
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline,
|
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline,
|
||||||
|
@ -99,7 +99,7 @@ public class SpongePlayerListener {
|
|||||||
|
|
||||||
int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline();
|
int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline();
|
||||||
|
|
||||||
SessionCache.getInstance().cacheSession(uuid, new Session(time, world, gm));
|
SessionCache.getInstance().cacheSession(uuid, new Session(uuid, time, world, gm));
|
||||||
|
|
||||||
Processing.submit(
|
Processing.submit(
|
||||||
new RegisterProcessor(uuid, time, time, playerName, playersOnline,
|
new RegisterProcessor(uuid, time, time, playerName, playersOnline,
|
||||||
|
@ -116,7 +116,7 @@ public abstract class Importer {
|
|||||||
Benchmark.stop(benchmarkName);
|
Benchmark.stop(benchmarkName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processUserData() throws DBException {
|
private void processUserData() {
|
||||||
String benchmarkName = "Processing User Data";
|
String benchmarkName = "Processing User Data";
|
||||||
String getDataBenchmarkName = "Getting User Data";
|
String getDataBenchmarkName = "Getting User Data";
|
||||||
String insertDataIntoCollectionsBenchmarkName = "Insert User Data into Collections";
|
String insertDataIntoCollectionsBenchmarkName = "Insert User Data into Collections";
|
||||||
@ -215,7 +215,7 @@ public abstract class Importer {
|
|||||||
int mobKills = userImportData.getMobKills();
|
int mobKills = userImportData.getMobKills();
|
||||||
int deaths = userImportData.getDeaths();
|
int deaths = userImportData.getDeaths();
|
||||||
|
|
||||||
Session session = new Session(0, 0L, 0L, mobKills, deaths, 0);
|
Session session = new Session(0, userImportData.getUuid(), ServerInfo.getServerUUID(), 0L, 0L, mobKills, deaths, 0);
|
||||||
|
|
||||||
session.setPlayerKills(userImportData.getKills());
|
session.setPlayerKills(userImportData.getKills());
|
||||||
session.setWorldTimes(new WorldTimes(userImportData.getWorldTimes()));
|
session.setWorldTimes(new WorldTimes(userImportData.getWorldTimes()));
|
||||||
|
@ -34,7 +34,20 @@ public class SessionAccordion extends AbstractAccordion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addElements() {
|
private void addElements() {
|
||||||
|
if (forPlayer) {
|
||||||
|
addElementsForPlayer();
|
||||||
|
} else {
|
||||||
|
addElementsForServer();
|
||||||
|
}
|
||||||
// Requires refactoring of Session object to contain information about player and server
|
// Requires refactoring of Session object to contain information about player and server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addElementsForServer() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addElementsForPlayer() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -9,10 +9,12 @@ import org.junit.BeforeClass;
|
|||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
import utilities.TestConstants;
|
||||||
import utilities.mocks.SystemMockUtil;
|
import utilities.mocks.SystemMockUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertEquals;
|
import static junit.framework.TestCase.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -25,6 +27,8 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class ActivityIndexTest {
|
public class ActivityIndexTest {
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
|
private static final UUID UUID = TestConstants.PLAYER_ONE_UUID;
|
||||||
|
private static final UUID SERVER_UUID = TestConstants.SERVER_UUID;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpClass() throws Exception {
|
public static void setUpClass() throws Exception {
|
||||||
@ -46,9 +50,9 @@ public class ActivityIndexTest {
|
|||||||
int requiredLogins = Settings.ACTIVE_LOGIN_THRESHOLD.getNumber();
|
int requiredLogins = Settings.ACTIVE_LOGIN_THRESHOLD.getNumber();
|
||||||
|
|
||||||
for (int i = 0; i < requiredLogins; i++) {
|
for (int i = 0; i < requiredLogins; i++) {
|
||||||
sessions.add(new Session(0, weekAgo, weekAgo + requiredPlaytime * 4L, 0, 0, 0));
|
sessions.add(new Session(0, UUID, SERVER_UUID, weekAgo, weekAgo + requiredPlaytime * 4L, 0, 0, 0));
|
||||||
sessions.add(new Session(0, twoWeeksAgo, twoWeeksAgo + requiredPlaytime * 4L, 0, 0, 0));
|
sessions.add(new Session(0, UUID, SERVER_UUID, twoWeeksAgo, twoWeeksAgo + requiredPlaytime * 4L, 0, 0, 0));
|
||||||
sessions.add(new Session(0, threeWeeksAgo, threeWeeksAgo + requiredPlaytime * 4L, 0, 0, 0));
|
sessions.add(new Session(0, UUID, SERVER_UUID, threeWeeksAgo, threeWeeksAgo + requiredPlaytime * 4L, 0, 0, 0));
|
||||||
}
|
}
|
||||||
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
||||||
|
|
||||||
@ -70,9 +74,9 @@ public class ActivityIndexTest {
|
|||||||
int requiredLogins = Settings.ACTIVE_LOGIN_THRESHOLD.getNumber();
|
int requiredLogins = Settings.ACTIVE_LOGIN_THRESHOLD.getNumber();
|
||||||
|
|
||||||
for (int i = 0; i < requiredLogins * 2; i++) {
|
for (int i = 0; i < requiredLogins * 2; i++) {
|
||||||
sessions.add(new Session(0, weekAgo, weekAgo + requiredPlaytime * 3L, 0, 0, 0));
|
sessions.add(new Session(0, UUID, SERVER_UUID, weekAgo, weekAgo + requiredPlaytime * 3L, 0, 0, 0));
|
||||||
sessions.add(new Session(0, twoWeeksAgo, twoWeeksAgo + requiredPlaytime * 3L, 0, 0, 0));
|
sessions.add(new Session(0, UUID, SERVER_UUID, twoWeeksAgo, twoWeeksAgo + requiredPlaytime * 3L, 0, 0, 0));
|
||||||
sessions.add(new Session(0, threeWeeksAgo, threeWeeksAgo + requiredPlaytime * 3L, 0, 0, 0));
|
sessions.add(new Session(0, UUID, SERVER_UUID, threeWeeksAgo, threeWeeksAgo + requiredPlaytime * 3L, 0, 0, 0));
|
||||||
}
|
}
|
||||||
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
||||||
assertTrue(container.supports(PlayerKeys.SESSIONS));
|
assertTrue(container.supports(PlayerKeys.SESSIONS));
|
||||||
@ -96,9 +100,9 @@ public class ActivityIndexTest {
|
|||||||
long requiredPlaytime = Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms() / requiredLogins;
|
long requiredPlaytime = Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms() / requiredLogins;
|
||||||
|
|
||||||
for (int i = 0; i < requiredLogins; i++) {
|
for (int i = 0; i < requiredLogins; i++) {
|
||||||
sessions.add(new Session(i, weekAgo, weekAgo + requiredPlaytime, 0, 0, 0));
|
sessions.add(new Session(i, UUID, SERVER_UUID, weekAgo, weekAgo + requiredPlaytime, 0, 0, 0));
|
||||||
sessions.add(new Session(i * 2, twoWeeksAgo, twoWeeksAgo + requiredPlaytime, 0, 0, 0));
|
sessions.add(new Session(i * 2, UUID, SERVER_UUID, twoWeeksAgo, twoWeeksAgo + requiredPlaytime, 0, 0, 0));
|
||||||
sessions.add(new Session(i * 3, threeWeeksAgo, threeWeeksAgo + requiredPlaytime, 0, 0, 0));
|
sessions.add(new Session(i * 3, UUID, SERVER_UUID, threeWeeksAgo, threeWeeksAgo + requiredPlaytime, 0, 0, 0));
|
||||||
}
|
}
|
||||||
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
||||||
|
|
||||||
@ -112,7 +116,7 @@ public class ActivityIndexTest {
|
|||||||
long date = 0;
|
long date = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 5000; i++) {
|
for (int i = 0; i < 5000; i++) {
|
||||||
sessions.add(new Session(0, 0, 0, 0, 0, 0));
|
sessions.add(new Session(0, UUID, SERVER_UUID, 0, 0, 0, 0, 0));
|
||||||
}
|
}
|
||||||
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class SessionCacheTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
sessionCache = new SessionCache(null);
|
sessionCache = new SessionCache(null);
|
||||||
session = new Session(12345L, "World1", "SURVIVAL");
|
session = new Session(uuid, 12345L, "World1", "SURVIVAL");
|
||||||
sessionCache.cacheSession(uuid, session);
|
sessionCache.cacheSession(uuid, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ public class SQLiteTest {
|
|||||||
saveTwoWorlds();
|
saveTwoWorlds();
|
||||||
saveUserOne();
|
saveUserOne();
|
||||||
saveUserTwo();
|
saveUserTwo();
|
||||||
Session session = new Session(12345L, "", "");
|
Session session = new Session(TestConstants.PLAYER_ONE_UUID, 12345L, "", "");
|
||||||
session.endSession(22345L);
|
session.endSession(22345L);
|
||||||
session.setWorldTimes(createWorldTimes());
|
session.setWorldTimes(createWorldTimes());
|
||||||
session.setPlayerKills(createKills());
|
session.setPlayerKills(createKills());
|
||||||
@ -393,7 +393,7 @@ public class SQLiteTest {
|
|||||||
saveUserOne();
|
saveUserOne();
|
||||||
saveUserTwo();
|
saveUserTwo();
|
||||||
|
|
||||||
Session session = new Session(12345L, "", "");
|
Session session = new Session(TestConstants.PLAYER_ONE_UUID, 12345L, "", "");
|
||||||
session.endSession(22345L);
|
session.endSession(22345L);
|
||||||
session.setWorldTimes(createWorldTimes());
|
session.setWorldTimes(createWorldTimes());
|
||||||
session.setPlayerKills(createKills());
|
session.setPlayerKills(createKills());
|
||||||
@ -558,7 +558,7 @@ public class SQLiteTest {
|
|||||||
userInfoTable.registerUserInfo(playerUUID, 223456789L);
|
userInfoTable.registerUserInfo(playerUUID, 223456789L);
|
||||||
saveTwoWorlds();
|
saveTwoWorlds();
|
||||||
|
|
||||||
Session session = new Session(12345L, "", "");
|
Session session = new Session(TestConstants.PLAYER_ONE_UUID, 12345L, "", "");
|
||||||
session.endSession(22345L);
|
session.endSession(22345L);
|
||||||
session.setWorldTimes(createWorldTimes());
|
session.setWorldTimes(createWorldTimes());
|
||||||
session.setPlayerKills(createKills());
|
session.setPlayerKills(createKills());
|
||||||
@ -627,7 +627,7 @@ public class SQLiteTest {
|
|||||||
userInfoTable.registerUserInfo(playerUUID, 223456789L);
|
userInfoTable.registerUserInfo(playerUUID, 223456789L);
|
||||||
saveTwoWorlds(database);
|
saveTwoWorlds(database);
|
||||||
|
|
||||||
Session session = new Session(12345L, "", "");
|
Session session = new Session(TestConstants.PLAYER_ONE_UUID, 12345L, "", "");
|
||||||
session.endSession(22345L);
|
session.endSession(22345L);
|
||||||
session.setWorldTimes(createWorldTimes());
|
session.setWorldTimes(createWorldTimes());
|
||||||
session.setPlayerKills(createKills());
|
session.setPlayerKills(createKills());
|
||||||
@ -717,7 +717,7 @@ public class SQLiteTest {
|
|||||||
saveUserOne();
|
saveUserOne();
|
||||||
saveUserTwo();
|
saveUserTwo();
|
||||||
|
|
||||||
Session session = new Session(12345L, "", "");
|
Session session = new Session(TestConstants.PLAYER_ONE_UUID, 12345L, "", "");
|
||||||
session.endSession(22345L);
|
session.endSession(22345L);
|
||||||
session.setWorldTimes(createWorldTimes());
|
session.setWorldTimes(createWorldTimes());
|
||||||
session.setPlayerKills(createKills());
|
session.setPlayerKills(createKills());
|
||||||
@ -800,7 +800,7 @@ public class SQLiteTest {
|
|||||||
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
||||||
worldTimesTable.saveWorldTimes(playerUUID, 1, worldTimes);
|
worldTimesTable.saveWorldTimes(playerUUID, 1, worldTimes);
|
||||||
|
|
||||||
Session session = new Session(1, 12345L, 23456L, 0, 0, 0);
|
Session session = new Session(1, playerUUID, TestConstants.SERVER_UUID, 12345L, 23456L, 0, 0, 0);
|
||||||
Map<Integer, Session> sessions = new HashMap<>();
|
Map<Integer, Session> sessions = new HashMap<>();
|
||||||
sessions.put(1, session);
|
sessions.put(1, session);
|
||||||
worldTimesTable.addWorldTimesToSessions(playerUUID, sessions);
|
worldTimesTable.addWorldTimesToSessions(playerUUID, sessions);
|
||||||
@ -814,7 +814,7 @@ public class SQLiteTest {
|
|||||||
WorldTimes worldTimes = createWorldTimes();
|
WorldTimes worldTimes = createWorldTimes();
|
||||||
System.out.println(worldTimes);
|
System.out.println(worldTimes);
|
||||||
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
WorldTimesTable worldTimesTable = db.getWorldTimesTable();
|
||||||
Session session = new Session(1, 12345L, 23456L, 0, 0, 0);
|
Session session = new Session(1, playerUUID, TestConstants.SERVER_UUID, 12345L, 23456L, 0, 0, 0);
|
||||||
session.setWorldTimes(worldTimes);
|
session.setWorldTimes(worldTimes);
|
||||||
|
|
||||||
Map<UUID, Map<UUID, List<Session>>> map = new HashMap<>();
|
Map<UUID, Map<UUID, List<Session>>> map = new HashMap<>();
|
||||||
@ -837,7 +837,7 @@ public class SQLiteTest {
|
|||||||
saveUserOne();
|
saveUserOne();
|
||||||
WorldTimes worldTimes = createWorldTimes();
|
WorldTimes worldTimes = createWorldTimes();
|
||||||
System.out.println(worldTimes);
|
System.out.println(worldTimes);
|
||||||
Session session = new Session(1, 12345L, 23456L, 0, 0, 0);
|
Session session = new Session(1, playerUUID, TestConstants.SERVER_UUID, 12345L, 23456L, 0, 0, 0);
|
||||||
session.setWorldTimes(worldTimes);
|
session.setWorldTimes(worldTimes);
|
||||||
|
|
||||||
Map<UUID, Map<UUID, List<Session>>> map = new HashMap<>();
|
Map<UUID, Map<UUID, List<Session>>> map = new HashMap<>();
|
||||||
@ -1060,7 +1060,7 @@ public class SQLiteTest {
|
|||||||
assertTrue(container.supports(PlayerKeys.PLAYER_KILL_COUNT));
|
assertTrue(container.supports(PlayerKeys.PLAYER_KILL_COUNT));
|
||||||
|
|
||||||
assertFalse(container.supports(PlayerKeys.ACTIVE_SESSION));
|
assertFalse(container.supports(PlayerKeys.ACTIVE_SESSION));
|
||||||
container.putRawData(PlayerKeys.ACTIVE_SESSION, new Session(System.currentTimeMillis(), "TestWorld", "SURVIVAL"));
|
container.putRawData(PlayerKeys.ACTIVE_SESSION, new Session(TestConstants.PLAYER_ONE_UUID, System.currentTimeMillis(), "TestWorld", "SURVIVAL"));
|
||||||
assertTrue(container.supports(PlayerKeys.ACTIVE_SESSION));
|
assertTrue(container.supports(PlayerKeys.ACTIVE_SESSION));
|
||||||
|
|
||||||
long end = System.nanoTime();
|
long end = System.nanoTime();
|
||||||
|
@ -48,7 +48,7 @@ public class RandomData {
|
|||||||
public static List<Session> randomSessions() {
|
public static List<Session> randomSessions() {
|
||||||
List<Session> test = new ArrayList<>();
|
List<Session> test = new ArrayList<>();
|
||||||
for (int i = 0; i < 20; i++) {
|
for (int i = 0; i < 20; i++) {
|
||||||
test.add(new Session(1, r.nextLong(), r.nextLong(), 0, 0, 0));
|
test.add(new Session(1, TestConstants.PLAYER_ONE_UUID, TestConstants.SERVER_UUID, r.nextLong(), r.nextLong(), 0, 0, 0));
|
||||||
}
|
}
|
||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user