mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-12 06:48:50 +02:00
Added AFK time storage to database
This commit is contained in:
parent
9241ef841f
commit
0e8b80df32
@ -53,11 +53,6 @@ public class Session {
|
|||||||
afkTime = 0;
|
afkTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Session(int id, long sessionStart, long sessionEnd, int mobKills, int deaths) {
|
|
||||||
this(id, sessionStart, sessionEnd, mobKills, deaths, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Session(int id, long sessionStart, long sessionEnd, int mobKills, int deaths, long afkTime) {
|
public Session(int id, long sessionStart, long sessionEnd, int mobKills, int deaths, long afkTime) {
|
||||||
this.sessionID = id;
|
this.sessionID = id;
|
||||||
this.sessionStart = sessionStart;
|
this.sessionStart = sessionStart;
|
||||||
|
@ -133,7 +133,7 @@ public abstract class SQLDB extends Database {
|
|||||||
|
|
||||||
if (newDatabase) {
|
if (newDatabase) {
|
||||||
Log.info("New Database created.");
|
Log.info("New Database created.");
|
||||||
versionTable.setVersion(14);
|
versionTable.setVersion(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
int version = versionTable.getVersion();
|
int version = versionTable.getVersion();
|
||||||
@ -168,6 +168,10 @@ public abstract class SQLDB extends Database {
|
|||||||
transferTable.alterTableV14();
|
transferTable.alterTableV14();
|
||||||
versionTable.setVersion(14);
|
versionTable.setVersion(14);
|
||||||
}
|
}
|
||||||
|
if (version < 15) {
|
||||||
|
sessionsTable.alterTableV15();
|
||||||
|
versionTable.setVersion(15);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DBInitException("Failed to set-up Database", e);
|
throw new DBInitException("Failed to set-up Database", e);
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,11 @@ public class SessionsTable extends UserIDTable {
|
|||||||
+ Col.SESSION_END + ", "
|
+ Col.SESSION_END + ", "
|
||||||
+ Col.DEATHS + ", "
|
+ Col.DEATHS + ", "
|
||||||
+ Col.MOB_KILLS + ", "
|
+ Col.MOB_KILLS + ", "
|
||||||
|
+ Col.AFK_TIME + ", "
|
||||||
+ Col.SERVER_ID
|
+ Col.SERVER_ID
|
||||||
+ ") VALUES ("
|
+ ") VALUES ("
|
||||||
+ usersTable.statementSelectID + ", "
|
+ usersTable.statementSelectID + ", "
|
||||||
+ "?, ?, ?, ?, "
|
+ "?, ?, ?, ?, ?, "
|
||||||
+ serverTable.statementSelectServerID + ")";
|
+ serverTable.statementSelectServerID + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +57,7 @@ public class SessionsTable extends UserIDTable {
|
|||||||
.column(Col.SESSION_END, Sql.LONG).notNull()
|
.column(Col.SESSION_END, Sql.LONG).notNull()
|
||||||
.column(Col.MOB_KILLS, Sql.INT).notNull()
|
.column(Col.MOB_KILLS, Sql.INT).notNull()
|
||||||
.column(Col.DEATHS, Sql.INT).notNull()
|
.column(Col.DEATHS, Sql.INT).notNull()
|
||||||
|
.column(Col.AFK_TIME, Sql.LONG).notNull()
|
||||||
.foreignKey(Col.USER_ID, usersTable.getTableName(), UsersTable.Col.ID)
|
.foreignKey(Col.USER_ID, usersTable.getTableName(), UsersTable.Col.ID)
|
||||||
.foreignKey(Col.SERVER_ID, serverTable.getTableName(), ServerTable.Col.SERVER_ID)
|
.foreignKey(Col.SERVER_ID, serverTable.getTableName(), ServerTable.Col.SERVER_ID)
|
||||||
.primaryKey(usingMySQL, Col.ID)
|
.primaryKey(usingMySQL, Col.ID)
|
||||||
@ -132,7 +134,8 @@ public class SessionsTable extends UserIDTable {
|
|||||||
statement.setLong(3, session.getSessionEnd());
|
statement.setLong(3, session.getSessionEnd());
|
||||||
statement.setInt(4, session.getDeaths());
|
statement.setInt(4, session.getDeaths());
|
||||||
statement.setInt(5, session.getMobKills());
|
statement.setInt(5, session.getMobKills());
|
||||||
statement.setString(6, ServerInfo.getServerUUID().toString());
|
statement.setLong(6, session.getAfkLength());
|
||||||
|
statement.setString(7, ServerInfo.getServerUUID().toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -172,10 +175,12 @@ public class SessionsTable extends UserIDTable {
|
|||||||
throw new IllegalStateException("Server not present");
|
throw new IllegalStateException("Server not present");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
||||||
|
|
||||||
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));
|
sessions.add(new Session(id, start, end, mobKills, deaths, timeAFK));
|
||||||
sessionsByServer.put(serverUUID, sessions);
|
sessionsByServer.put(serverUUID, sessions);
|
||||||
}
|
}
|
||||||
return sessionsByServer;
|
return sessionsByServer;
|
||||||
@ -458,6 +463,7 @@ public class SessionsTable extends UserIDTable {
|
|||||||
Col.SESSION_END + ", " +
|
Col.SESSION_END + ", " +
|
||||||
Col.DEATHS + ", " +
|
Col.DEATHS + ", " +
|
||||||
Col.MOB_KILLS + ", " +
|
Col.MOB_KILLS + ", " +
|
||||||
|
Col.AFK_TIME + ", " +
|
||||||
usersUUIDColumn +
|
usersUUIDColumn +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" INNER JOIN " + usersTable + " on " + usersIDColumn + "=" + Col.USER_ID +
|
" INNER JOIN " + usersTable + " on " + usersIDColumn + "=" + Col.USER_ID +
|
||||||
@ -479,8 +485,11 @@ 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());
|
||||||
|
|
||||||
|
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));
|
sessions.add(new Session(set.getInt(Col.ID.get()), start, end, mobKills, deaths, timeAFK));
|
||||||
sessionsByUser.put(uuid, sessions);
|
sessionsByUser.put(uuid, sessions);
|
||||||
}
|
}
|
||||||
return sessionsByUser;
|
return sessionsByUser;
|
||||||
@ -515,7 +524,6 @@ public class SessionsTable extends UserIDTable {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Write tests for this method
|
|
||||||
public Map<UUID, Long> getLastSeenForAllPlayers() throws SQLException {
|
public Map<UUID, Long> getLastSeenForAllPlayers() throws SQLException {
|
||||||
String usersIDColumn = usersTable + "." + UsersTable.Col.ID;
|
String usersIDColumn = usersTable + "." + UsersTable.Col.ID;
|
||||||
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID + " as uuid";
|
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID + " as uuid";
|
||||||
@ -551,7 +559,8 @@ public class SessionsTable extends UserIDTable {
|
|||||||
Col.SESSION_START + ", " +
|
Col.SESSION_START + ", " +
|
||||||
Col.SESSION_END + ", " +
|
Col.SESSION_END + ", " +
|
||||||
Col.DEATHS + ", " +
|
Col.DEATHS + ", " +
|
||||||
Col.MOB_KILLS +
|
Col.MOB_KILLS + ", " +
|
||||||
|
Col.AFK_TIME +
|
||||||
" FROM " + tableName;
|
" FROM " + tableName;
|
||||||
|
|
||||||
return query(new QueryAllStatement<Map<UUID, Map<UUID, List<Session>>>>(sql, 20000) {
|
return query(new QueryAllStatement<Map<UUID, Map<UUID, List<Session>>>>(sql, 20000) {
|
||||||
@ -572,7 +581,9 @@ public class SessionsTable extends UserIDTable {
|
|||||||
int mobKills = set.getInt(Col.MOB_KILLS.get());
|
int mobKills = set.getInt(Col.MOB_KILLS.get());
|
||||||
int id = set.getInt(Col.ID.get());
|
int id = set.getInt(Col.ID.get());
|
||||||
|
|
||||||
Session session = new Session(id, start, end, mobKills, deaths);
|
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
||||||
|
|
||||||
|
Session session = new Session(id, start, end, mobKills, deaths, timeAFK);
|
||||||
sessions.add(session);
|
sessions.add(session);
|
||||||
|
|
||||||
sessionsByUser.put(uuid, sessions);
|
sessionsByUser.put(uuid, sessions);
|
||||||
@ -598,7 +609,8 @@ public class SessionsTable extends UserIDTable {
|
|||||||
Col.SESSION_START + ", " +
|
Col.SESSION_START + ", " +
|
||||||
Col.SESSION_END + ", " +
|
Col.SESSION_END + ", " +
|
||||||
Col.DEATHS + ", " +
|
Col.DEATHS + ", " +
|
||||||
Col.MOB_KILLS +
|
Col.MOB_KILLS + ", " +
|
||||||
|
Col.AFK_TIME +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" WHERE " + Col.SESSION_START + ">?";
|
" WHERE " + Col.SESSION_START + ">?";
|
||||||
|
|
||||||
@ -625,7 +637,9 @@ public class SessionsTable extends UserIDTable {
|
|||||||
int mobKills = set.getInt(Col.MOB_KILLS.get());
|
int mobKills = set.getInt(Col.MOB_KILLS.get());
|
||||||
int id = set.getInt(Col.ID.get());
|
int id = set.getInt(Col.ID.get());
|
||||||
|
|
||||||
Session session = new Session(id, start, end, mobKills, deaths);
|
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
||||||
|
|
||||||
|
Session session = new Session(id, start, end, mobKills, deaths, timeAFK);
|
||||||
sessions.add(session);
|
sessions.add(session);
|
||||||
|
|
||||||
sessionsByUser.put(uuid, sessions);
|
sessionsByUser.put(uuid, sessions);
|
||||||
@ -655,7 +669,8 @@ public class SessionsTable extends UserIDTable {
|
|||||||
statement.setLong(3, session.getSessionEnd());
|
statement.setLong(3, session.getSessionEnd());
|
||||||
statement.setInt(4, session.getDeaths());
|
statement.setInt(4, session.getDeaths());
|
||||||
statement.setInt(5, session.getMobKills());
|
statement.setInt(5, session.getMobKills());
|
||||||
statement.setString(6, serverUUID.toString());
|
statement.setLong(6, session.getAfkLength());
|
||||||
|
statement.setString(7, serverUUID.toString());
|
||||||
statement.addBatch();
|
statement.addBatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -718,6 +733,10 @@ public class SessionsTable extends UserIDTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void alterTableV15() {
|
||||||
|
addColumns(Col.AFK_TIME + " bigint NOT NULL DEFAULT 0");
|
||||||
|
}
|
||||||
|
|
||||||
public enum Col implements Column {
|
public enum Col implements Column {
|
||||||
USER_ID(UserIDTable.Col.USER_ID.get()),
|
USER_ID(UserIDTable.Col.USER_ID.get()),
|
||||||
ID("id"),
|
ID("id"),
|
||||||
@ -725,7 +744,8 @@ public class SessionsTable extends UserIDTable {
|
|||||||
SESSION_START("session_start"),
|
SESSION_START("session_start"),
|
||||||
SESSION_END("session_end"),
|
SESSION_END("session_end"),
|
||||||
MOB_KILLS("mob_kills"),
|
MOB_KILLS("mob_kills"),
|
||||||
DEATHS("deaths");
|
DEATHS("deaths"),
|
||||||
|
AFK_TIME("afk_time");
|
||||||
|
|
||||||
private final String column;
|
private final String column;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user