mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-10-31 07:50:09 +01:00
Removed TPSTable.Col
This commit is contained in:
parent
6f212e2a7d
commit
01f23d22d2
@ -27,13 +27,13 @@ public class DiskUsagePatch extends Patch {
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
return hasColumn(TPSTable.TABLE_NAME, TPSTable.Col.FREE_DISK.get());
|
||||
return hasColumn(TPSTable.TABLE_NAME, TPSTable.FREE_DISK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyPatch() {
|
||||
addColumn(TPSTable.TABLE_NAME,
|
||||
TPSTable.Col.FREE_DISK + " bigint NOT NULL DEFAULT -1"
|
||||
TPSTable.FREE_DISK + " bigint NOT NULL DEFAULT -1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.access.ExecStatement;
|
||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.sql.parsing.Column;
|
||||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Select;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
@ -43,8 +42,6 @@ import java.util.*;
|
||||
* Table that is in charge of storing TPS, Players Online and Performance data.
|
||||
* <p>
|
||||
* Table Name: plan_tps
|
||||
* <p>
|
||||
* For contained columns {@link Col}
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@ -66,15 +63,15 @@ public class TPSTable extends Table {
|
||||
super(TABLE_NAME, db);
|
||||
serverTable = db.getServerTable();
|
||||
insertStatement = "INSERT INTO " + tableName + " ("
|
||||
+ Col.SERVER_ID + ", "
|
||||
+ Col.DATE + ", "
|
||||
+ Col.TPS + ", "
|
||||
+ Col.PLAYERS_ONLINE + ", "
|
||||
+ Col.CPU_USAGE + ", "
|
||||
+ Col.RAM_USAGE + ", "
|
||||
+ Col.ENTITIES + ", "
|
||||
+ Col.CHUNKS + ", "
|
||||
+ Col.FREE_DISK
|
||||
+ SERVER_ID + ", "
|
||||
+ DATE + ", "
|
||||
+ TPS + ", "
|
||||
+ PLAYERS_ONLINE + ", "
|
||||
+ CPU_USAGE + ", "
|
||||
+ RAM_USAGE + ", "
|
||||
+ ENTITIES + ", "
|
||||
+ CHUNKS + ", "
|
||||
+ FREE_DISK
|
||||
+ ") VALUES ("
|
||||
+ serverTable.statementSelectServerID + ", "
|
||||
+ "?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
@ -105,7 +102,7 @@ public class TPSTable extends Table {
|
||||
|
||||
public List<TPS> getTPSData(UUID serverUUID) {
|
||||
String sql = Select.all(tableName)
|
||||
.where(Col.SERVER_ID + "=" + serverTable.statementSelectServerID)
|
||||
.where(SERVER_ID + "=" + serverTable.statementSelectServerID)
|
||||
.toString();
|
||||
|
||||
return query(new QueryStatement<List<TPS>>(sql, 50000) {
|
||||
@ -120,14 +117,14 @@ public class TPSTable extends Table {
|
||||
while (set.next()) {
|
||||
|
||||
TPS tps = TPSBuilder.get()
|
||||
.date(set.getLong(Col.DATE.get()))
|
||||
.tps(set.getDouble(Col.TPS.get()))
|
||||
.playersOnline(set.getInt(Col.PLAYERS_ONLINE.get()))
|
||||
.usedCPU(set.getDouble(Col.CPU_USAGE.get()))
|
||||
.usedMemory(set.getLong(Col.RAM_USAGE.get()))
|
||||
.entities(set.getInt(Col.ENTITIES.get()))
|
||||
.chunksLoaded(set.getInt(Col.CHUNKS.get()))
|
||||
.freeDiskSpace(set.getLong(Col.FREE_DISK.get()))
|
||||
.date(set.getLong(DATE))
|
||||
.tps(set.getDouble(TPS))
|
||||
.playersOnline(set.getInt(PLAYERS_ONLINE))
|
||||
.usedCPU(set.getDouble(CPU_USAGE))
|
||||
.usedMemory(set.getLong(RAM_USAGE))
|
||||
.entities(set.getInt(ENTITIES))
|
||||
.chunksLoaded(set.getInt(CHUNKS))
|
||||
.freeDiskSpace(set.getLong(FREE_DISK))
|
||||
.toTPS();
|
||||
|
||||
data.add(tps);
|
||||
@ -153,8 +150,8 @@ public class TPSTable extends Table {
|
||||
final int pValue = p;
|
||||
|
||||
String sql = "DELETE FROM " + tableName +
|
||||
" WHERE (" + Col.DATE + "<?)" +
|
||||
" AND (" + Col.PLAYERS_ONLINE + " != ?)";
|
||||
" WHERE (" + DATE + "<?)" +
|
||||
" AND (" + PLAYERS_ONLINE + " != ?)";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
@ -185,13 +182,13 @@ public class TPSTable extends Table {
|
||||
}
|
||||
|
||||
public Optional<TPS> getPeakPlayerCount(UUID serverUUID, long afterDate) {
|
||||
String subStatement = "SELECT MAX(" + Col.PLAYERS_ONLINE + ") FROM " + tableName +
|
||||
" WHERE " + Col.SERVER_ID + "=" + serverTable.statementSelectServerID +
|
||||
" AND " + Col.DATE + ">= ?";
|
||||
String subStatement = "SELECT MAX(" + PLAYERS_ONLINE + ") FROM " + tableName +
|
||||
" WHERE " + SERVER_ID + "=" + serverTable.statementSelectServerID +
|
||||
" AND " + DATE + ">= ?";
|
||||
String sql = Select.all(tableName)
|
||||
.where(Col.SERVER_ID + "=" + serverTable.statementSelectServerID)
|
||||
.and(Col.PLAYERS_ONLINE + "= (" + subStatement + ")")
|
||||
.and(Col.DATE + ">= ?")
|
||||
.where(SERVER_ID + "=" + serverTable.statementSelectServerID)
|
||||
.and(PLAYERS_ONLINE + "= (" + subStatement + ")")
|
||||
.and(DATE + ">= ?")
|
||||
.toString();
|
||||
|
||||
return query(new QueryStatement<Optional<TPS>>(sql) {
|
||||
@ -207,14 +204,14 @@ public class TPSTable extends Table {
|
||||
public Optional<TPS> processResults(ResultSet set) throws SQLException {
|
||||
if (set.next()) {
|
||||
TPS tps = TPSBuilder.get()
|
||||
.date(set.getLong(Col.DATE.get()))
|
||||
.tps(set.getDouble(Col.TPS.get()))
|
||||
.playersOnline(set.getInt(Col.PLAYERS_ONLINE.get()))
|
||||
.usedCPU(set.getDouble(Col.CPU_USAGE.get()))
|
||||
.usedMemory(set.getLong(Col.RAM_USAGE.get()))
|
||||
.entities(set.getInt(Col.ENTITIES.get()))
|
||||
.chunksLoaded(set.getInt(Col.CHUNKS.get()))
|
||||
.freeDiskSpace(set.getLong(Col.FREE_DISK.get()))
|
||||
.date(set.getLong(DATE))
|
||||
.tps(set.getDouble(TPS))
|
||||
.playersOnline(set.getInt(PLAYERS_ONLINE))
|
||||
.usedCPU(set.getDouble(CPU_USAGE))
|
||||
.usedMemory(set.getLong(RAM_USAGE))
|
||||
.entities(set.getInt(ENTITIES))
|
||||
.chunksLoaded(set.getInt(CHUNKS))
|
||||
.freeDiskSpace(set.getLong(FREE_DISK))
|
||||
.toTPS();
|
||||
|
||||
return Optional.of(tps);
|
||||
@ -244,10 +241,10 @@ public class TPSTable extends Table {
|
||||
UUID bungeeUUID = proxyInfo.get().getUuid();
|
||||
|
||||
String sql = "SELECT " +
|
||||
Col.DATE + ", " +
|
||||
Col.PLAYERS_ONLINE +
|
||||
DATE + ", " +
|
||||
PLAYERS_ONLINE +
|
||||
" FROM " + tableName +
|
||||
" WHERE " + Col.SERVER_ID + "=" + serverTable.statementSelectServerID;
|
||||
" WHERE " + SERVER_ID + "=" + serverTable.statementSelectServerID;
|
||||
|
||||
return query(new QueryStatement<List<TPS>>(sql, 50000) {
|
||||
@Override
|
||||
@ -261,8 +258,8 @@ public class TPSTable extends Table {
|
||||
while (set.next()) {
|
||||
|
||||
TPS tps = TPSBuilder.get()
|
||||
.date(set.getLong(Col.DATE.get()))
|
||||
.playersOnline(set.getInt(Col.PLAYERS_ONLINE.get()))
|
||||
.date(set.getLong(DATE))
|
||||
.playersOnline(set.getInt(PLAYERS_ONLINE))
|
||||
.toTPS();
|
||||
|
||||
tpsList.add(tps);
|
||||
@ -307,14 +304,14 @@ public class TPSTable extends Table {
|
||||
return new HashMap<>();
|
||||
}
|
||||
TextStringBuilder sql = new TextStringBuilder("SELECT ");
|
||||
sql.append(Col.SERVER_ID).append(", ")
|
||||
.append(Col.DATE).append(", ")
|
||||
.append(Col.PLAYERS_ONLINE)
|
||||
sql.append(SERVER_ID).append(", ")
|
||||
.append(DATE).append(", ")
|
||||
.append(PLAYERS_ONLINE)
|
||||
.append(" FROM ").append(tableName)
|
||||
.append(" WHERE ")
|
||||
.append(Col.DATE.get()).append(">").append(System.currentTimeMillis() - TimeAmount.WEEK.toMillis(2L))
|
||||
.append(DATE).append(">").append(System.currentTimeMillis() - TimeAmount.WEEK.toMillis(2L))
|
||||
.append(" AND (");
|
||||
sql.appendWithSeparators(servers.stream().map(server -> Col.SERVER_ID + "=" + server.getId()).iterator(), " OR ");
|
||||
sql.appendWithSeparators(servers.stream().map(server -> SERVER_ID + "=" + server.getId()).iterator(), " OR ");
|
||||
sql.append(")");
|
||||
|
||||
return query(new QueryAllStatement<Map<Integer, List<TPS>>>(sql.toString(), 10000) {
|
||||
@ -322,9 +319,9 @@ public class TPSTable extends Table {
|
||||
public Map<Integer, List<TPS>> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, List<TPS>> map = new HashMap<>();
|
||||
while (set.next()) {
|
||||
int serverID = set.getInt(Col.SERVER_ID.get());
|
||||
int playersOnline = set.getInt(Col.PLAYERS_ONLINE.get());
|
||||
long date = set.getLong(Col.DATE.get());
|
||||
int serverID = set.getInt(SERVER_ID);
|
||||
int playersOnline = set.getInt(PLAYERS_ONLINE);
|
||||
long date = set.getLong(DATE);
|
||||
|
||||
List<TPS> tpsList = map.getOrDefault(serverID, new ArrayList<>());
|
||||
|
||||
@ -339,33 +336,4 @@ public class TPSTable extends Table {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public enum Col implements Column {
|
||||
@Deprecated SERVER_ID("server_id"),
|
||||
@Deprecated DATE("date"),
|
||||
@Deprecated TPS("tps"),
|
||||
@Deprecated PLAYERS_ONLINE("players_online"),
|
||||
@Deprecated CPU_USAGE("cpu_usage"),
|
||||
@Deprecated RAM_USAGE("ram_usage"),
|
||||
@Deprecated ENTITIES("entities"),
|
||||
@Deprecated CHUNKS("chunks_loaded"),
|
||||
@Deprecated FREE_DISK("free_disk_space");
|
||||
|
||||
private final String column;
|
||||
|
||||
Col(String column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user