mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-20 19:52:45 +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;
|
||||
}
|
||||
|
||||
@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) {
|
||||
this.sessionID = id;
|
||||
this.sessionStart = sessionStart;
|
||||
|
|
|
@ -133,7 +133,7 @@ public abstract class SQLDB extends Database {
|
|||
|
||||
if (newDatabase) {
|
||||
Log.info("New Database created.");
|
||||
versionTable.setVersion(14);
|
||||
versionTable.setVersion(15);
|
||||
}
|
||||
|
||||
int version = versionTable.getVersion();
|
||||
|
@ -168,6 +168,10 @@ public abstract class SQLDB extends Database {
|
|||
transferTable.alterTableV14();
|
||||
versionTable.setVersion(14);
|
||||
}
|
||||
if (version < 15) {
|
||||
sessionsTable.alterTableV15();
|
||||
versionTable.setVersion(15);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DBInitException("Failed to set-up Database", e);
|
||||
}
|
||||
|
|
|
@ -36,10 +36,11 @@ public class SessionsTable extends UserIDTable {
|
|||
+ Col.SESSION_END + ", "
|
||||
+ Col.DEATHS + ", "
|
||||
+ Col.MOB_KILLS + ", "
|
||||
+ Col.AFK_TIME + ", "
|
||||
+ Col.SERVER_ID
|
||||
+ ") VALUES ("
|
||||
+ usersTable.statementSelectID + ", "
|
||||
+ "?, ?, ?, ?, "
|
||||
+ "?, ?, ?, ?, ?, "
|
||||
+ serverTable.statementSelectServerID + ")";
|
||||
}
|
||||
|
||||
|
@ -56,6 +57,7 @@ public class SessionsTable extends UserIDTable {
|
|||
.column(Col.SESSION_END, Sql.LONG).notNull()
|
||||
.column(Col.MOB_KILLS, 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.SERVER_ID, serverTable.getTableName(), ServerTable.Col.SERVER_ID)
|
||||
.primaryKey(usingMySQL, Col.ID)
|
||||
|
@ -132,7 +134,8 @@ public class SessionsTable extends UserIDTable {
|
|||
statement.setLong(3, session.getSessionEnd());
|
||||
statement.setInt(4, session.getDeaths());
|
||||
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");
|
||||
}
|
||||
|
||||
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
||||
|
||||
int deaths = set.getInt(Col.DEATHS.get());
|
||||
int mobKills = set.getInt(Col.MOB_KILLS.get());
|
||||
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);
|
||||
}
|
||||
return sessionsByServer;
|
||||
|
@ -458,6 +463,7 @@ public class SessionsTable extends UserIDTable {
|
|||
Col.SESSION_END + ", " +
|
||||
Col.DEATHS + ", " +
|
||||
Col.MOB_KILLS + ", " +
|
||||
Col.AFK_TIME + ", " +
|
||||
usersUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" 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 mobKills = set.getInt(Col.MOB_KILLS.get());
|
||||
|
||||
long timeAFK = set.getLong(Col.AFK_TIME.get());
|
||||
|
||||
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);
|
||||
}
|
||||
return sessionsByUser;
|
||||
|
@ -515,7 +524,6 @@ public class SessionsTable extends UserIDTable {
|
|||
});
|
||||
}
|
||||
|
||||
// TODO Write tests for this method
|
||||
public Map<UUID, Long> getLastSeenForAllPlayers() throws SQLException {
|
||||
String usersIDColumn = usersTable + "." + UsersTable.Col.ID;
|
||||
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID + " as uuid";
|
||||
|
@ -551,7 +559,8 @@ public class SessionsTable extends UserIDTable {
|
|||
Col.SESSION_START + ", " +
|
||||
Col.SESSION_END + ", " +
|
||||
Col.DEATHS + ", " +
|
||||
Col.MOB_KILLS +
|
||||
Col.MOB_KILLS + ", " +
|
||||
Col.AFK_TIME +
|
||||
" FROM " + tableName;
|
||||
|
||||
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 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);
|
||||
|
||||
sessionsByUser.put(uuid, sessions);
|
||||
|
@ -598,7 +609,8 @@ public class SessionsTable extends UserIDTable {
|
|||
Col.SESSION_START + ", " +
|
||||
Col.SESSION_END + ", " +
|
||||
Col.DEATHS + ", " +
|
||||
Col.MOB_KILLS +
|
||||
Col.MOB_KILLS + ", " +
|
||||
Col.AFK_TIME +
|
||||
" FROM " + tableName +
|
||||
" WHERE " + Col.SESSION_START + ">?";
|
||||
|
||||
|
@ -625,7 +637,9 @@ public class SessionsTable extends UserIDTable {
|
|||
int mobKills = set.getInt(Col.MOB_KILLS.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);
|
||||
|
||||
sessionsByUser.put(uuid, sessions);
|
||||
|
@ -655,7 +669,8 @@ public class SessionsTable extends UserIDTable {
|
|||
statement.setLong(3, session.getSessionEnd());
|
||||
statement.setInt(4, session.getDeaths());
|
||||
statement.setInt(5, session.getMobKills());
|
||||
statement.setString(6, serverUUID.toString());
|
||||
statement.setLong(6, session.getAfkLength());
|
||||
statement.setString(7, serverUUID.toString());
|
||||
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 {
|
||||
USER_ID(UserIDTable.Col.USER_ID.get()),
|
||||
ID("id"),
|
||||
|
@ -725,7 +744,8 @@ public class SessionsTable extends UserIDTable {
|
|||
SESSION_START("session_start"),
|
||||
SESSION_END("session_end"),
|
||||
MOB_KILLS("mob_kills"),
|
||||
DEATHS("deaths");
|
||||
DEATHS("deaths"),
|
||||
AFK_TIME("afk_time");
|
||||
|
||||
private final String column;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user