mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-13 11:41:34 +01:00
Removed TPSTable.Col
This commit is contained in:
parent
6f212e2a7d
commit
01f23d22d2
@ -27,13 +27,13 @@ public class DiskUsagePatch extends Patch {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasBeenApplied() {
|
public boolean hasBeenApplied() {
|
||||||
return hasColumn(TPSTable.TABLE_NAME, TPSTable.Col.FREE_DISK.get());
|
return hasColumn(TPSTable.TABLE_NAME, TPSTable.FREE_DISK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void applyPatch() {
|
protected void applyPatch() {
|
||||||
addColumn(TPSTable.TABLE_NAME,
|
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.ExecStatement;
|
||||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||||
import com.djrapitops.plan.db.access.QueryStatement;
|
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.CreateTableParser;
|
||||||
import com.djrapitops.plan.db.sql.parsing.Select;
|
import com.djrapitops.plan.db.sql.parsing.Select;
|
||||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
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.
|
* Table that is in charge of storing TPS, Players Online and Performance data.
|
||||||
* <p>
|
* <p>
|
||||||
* Table Name: plan_tps
|
* Table Name: plan_tps
|
||||||
* <p>
|
|
||||||
* For contained columns {@link Col}
|
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
@ -66,15 +63,15 @@ public class TPSTable extends Table {
|
|||||||
super(TABLE_NAME, db);
|
super(TABLE_NAME, db);
|
||||||
serverTable = db.getServerTable();
|
serverTable = db.getServerTable();
|
||||||
insertStatement = "INSERT INTO " + tableName + " ("
|
insertStatement = "INSERT INTO " + tableName + " ("
|
||||||
+ Col.SERVER_ID + ", "
|
+ SERVER_ID + ", "
|
||||||
+ Col.DATE + ", "
|
+ DATE + ", "
|
||||||
+ Col.TPS + ", "
|
+ TPS + ", "
|
||||||
+ Col.PLAYERS_ONLINE + ", "
|
+ PLAYERS_ONLINE + ", "
|
||||||
+ Col.CPU_USAGE + ", "
|
+ CPU_USAGE + ", "
|
||||||
+ Col.RAM_USAGE + ", "
|
+ RAM_USAGE + ", "
|
||||||
+ Col.ENTITIES + ", "
|
+ ENTITIES + ", "
|
||||||
+ Col.CHUNKS + ", "
|
+ CHUNKS + ", "
|
||||||
+ Col.FREE_DISK
|
+ FREE_DISK
|
||||||
+ ") VALUES ("
|
+ ") VALUES ("
|
||||||
+ serverTable.statementSelectServerID + ", "
|
+ serverTable.statementSelectServerID + ", "
|
||||||
+ "?, ?, ?, ?, ?, ?, ?, ?)";
|
+ "?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
@ -105,7 +102,7 @@ public class TPSTable extends Table {
|
|||||||
|
|
||||||
public List<TPS> getTPSData(UUID serverUUID) {
|
public List<TPS> getTPSData(UUID serverUUID) {
|
||||||
String sql = Select.all(tableName)
|
String sql = Select.all(tableName)
|
||||||
.where(Col.SERVER_ID + "=" + serverTable.statementSelectServerID)
|
.where(SERVER_ID + "=" + serverTable.statementSelectServerID)
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
return query(new QueryStatement<List<TPS>>(sql, 50000) {
|
return query(new QueryStatement<List<TPS>>(sql, 50000) {
|
||||||
@ -120,14 +117,14 @@ public class TPSTable extends Table {
|
|||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
|
|
||||||
TPS tps = TPSBuilder.get()
|
TPS tps = TPSBuilder.get()
|
||||||
.date(set.getLong(Col.DATE.get()))
|
.date(set.getLong(DATE))
|
||||||
.tps(set.getDouble(Col.TPS.get()))
|
.tps(set.getDouble(TPS))
|
||||||
.playersOnline(set.getInt(Col.PLAYERS_ONLINE.get()))
|
.playersOnline(set.getInt(PLAYERS_ONLINE))
|
||||||
.usedCPU(set.getDouble(Col.CPU_USAGE.get()))
|
.usedCPU(set.getDouble(CPU_USAGE))
|
||||||
.usedMemory(set.getLong(Col.RAM_USAGE.get()))
|
.usedMemory(set.getLong(RAM_USAGE))
|
||||||
.entities(set.getInt(Col.ENTITIES.get()))
|
.entities(set.getInt(ENTITIES))
|
||||||
.chunksLoaded(set.getInt(Col.CHUNKS.get()))
|
.chunksLoaded(set.getInt(CHUNKS))
|
||||||
.freeDiskSpace(set.getLong(Col.FREE_DISK.get()))
|
.freeDiskSpace(set.getLong(FREE_DISK))
|
||||||
.toTPS();
|
.toTPS();
|
||||||
|
|
||||||
data.add(tps);
|
data.add(tps);
|
||||||
@ -153,8 +150,8 @@ public class TPSTable extends Table {
|
|||||||
final int pValue = p;
|
final int pValue = p;
|
||||||
|
|
||||||
String sql = "DELETE FROM " + tableName +
|
String sql = "DELETE FROM " + tableName +
|
||||||
" WHERE (" + Col.DATE + "<?)" +
|
" WHERE (" + DATE + "<?)" +
|
||||||
" AND (" + Col.PLAYERS_ONLINE + " != ?)";
|
" AND (" + PLAYERS_ONLINE + " != ?)";
|
||||||
|
|
||||||
execute(new ExecStatement(sql) {
|
execute(new ExecStatement(sql) {
|
||||||
@Override
|
@Override
|
||||||
@ -185,13 +182,13 @@ public class TPSTable extends Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<TPS> getPeakPlayerCount(UUID serverUUID, long afterDate) {
|
public Optional<TPS> getPeakPlayerCount(UUID serverUUID, long afterDate) {
|
||||||
String subStatement = "SELECT MAX(" + Col.PLAYERS_ONLINE + ") FROM " + tableName +
|
String subStatement = "SELECT MAX(" + PLAYERS_ONLINE + ") FROM " + tableName +
|
||||||
" WHERE " + Col.SERVER_ID + "=" + serverTable.statementSelectServerID +
|
" WHERE " + SERVER_ID + "=" + serverTable.statementSelectServerID +
|
||||||
" AND " + Col.DATE + ">= ?";
|
" AND " + DATE + ">= ?";
|
||||||
String sql = Select.all(tableName)
|
String sql = Select.all(tableName)
|
||||||
.where(Col.SERVER_ID + "=" + serverTable.statementSelectServerID)
|
.where(SERVER_ID + "=" + serverTable.statementSelectServerID)
|
||||||
.and(Col.PLAYERS_ONLINE + "= (" + subStatement + ")")
|
.and(PLAYERS_ONLINE + "= (" + subStatement + ")")
|
||||||
.and(Col.DATE + ">= ?")
|
.and(DATE + ">= ?")
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
return query(new QueryStatement<Optional<TPS>>(sql) {
|
return query(new QueryStatement<Optional<TPS>>(sql) {
|
||||||
@ -207,14 +204,14 @@ public class TPSTable extends Table {
|
|||||||
public Optional<TPS> processResults(ResultSet set) throws SQLException {
|
public Optional<TPS> processResults(ResultSet set) throws SQLException {
|
||||||
if (set.next()) {
|
if (set.next()) {
|
||||||
TPS tps = TPSBuilder.get()
|
TPS tps = TPSBuilder.get()
|
||||||
.date(set.getLong(Col.DATE.get()))
|
.date(set.getLong(DATE))
|
||||||
.tps(set.getDouble(Col.TPS.get()))
|
.tps(set.getDouble(TPS))
|
||||||
.playersOnline(set.getInt(Col.PLAYERS_ONLINE.get()))
|
.playersOnline(set.getInt(PLAYERS_ONLINE))
|
||||||
.usedCPU(set.getDouble(Col.CPU_USAGE.get()))
|
.usedCPU(set.getDouble(CPU_USAGE))
|
||||||
.usedMemory(set.getLong(Col.RAM_USAGE.get()))
|
.usedMemory(set.getLong(RAM_USAGE))
|
||||||
.entities(set.getInt(Col.ENTITIES.get()))
|
.entities(set.getInt(ENTITIES))
|
||||||
.chunksLoaded(set.getInt(Col.CHUNKS.get()))
|
.chunksLoaded(set.getInt(CHUNKS))
|
||||||
.freeDiskSpace(set.getLong(Col.FREE_DISK.get()))
|
.freeDiskSpace(set.getLong(FREE_DISK))
|
||||||
.toTPS();
|
.toTPS();
|
||||||
|
|
||||||
return Optional.of(tps);
|
return Optional.of(tps);
|
||||||
@ -244,10 +241,10 @@ public class TPSTable extends Table {
|
|||||||
UUID bungeeUUID = proxyInfo.get().getUuid();
|
UUID bungeeUUID = proxyInfo.get().getUuid();
|
||||||
|
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
Col.DATE + ", " +
|
DATE + ", " +
|
||||||
Col.PLAYERS_ONLINE +
|
PLAYERS_ONLINE +
|
||||||
" FROM " + tableName +
|
" FROM " + tableName +
|
||||||
" WHERE " + Col.SERVER_ID + "=" + serverTable.statementSelectServerID;
|
" WHERE " + SERVER_ID + "=" + serverTable.statementSelectServerID;
|
||||||
|
|
||||||
return query(new QueryStatement<List<TPS>>(sql, 50000) {
|
return query(new QueryStatement<List<TPS>>(sql, 50000) {
|
||||||
@Override
|
@Override
|
||||||
@ -261,8 +258,8 @@ public class TPSTable extends Table {
|
|||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
|
|
||||||
TPS tps = TPSBuilder.get()
|
TPS tps = TPSBuilder.get()
|
||||||
.date(set.getLong(Col.DATE.get()))
|
.date(set.getLong(DATE))
|
||||||
.playersOnline(set.getInt(Col.PLAYERS_ONLINE.get()))
|
.playersOnline(set.getInt(PLAYERS_ONLINE))
|
||||||
.toTPS();
|
.toTPS();
|
||||||
|
|
||||||
tpsList.add(tps);
|
tpsList.add(tps);
|
||||||
@ -307,14 +304,14 @@ public class TPSTable extends Table {
|
|||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
TextStringBuilder sql = new TextStringBuilder("SELECT ");
|
TextStringBuilder sql = new TextStringBuilder("SELECT ");
|
||||||
sql.append(Col.SERVER_ID).append(", ")
|
sql.append(SERVER_ID).append(", ")
|
||||||
.append(Col.DATE).append(", ")
|
.append(DATE).append(", ")
|
||||||
.append(Col.PLAYERS_ONLINE)
|
.append(PLAYERS_ONLINE)
|
||||||
.append(" FROM ").append(tableName)
|
.append(" FROM ").append(tableName)
|
||||||
.append(" WHERE ")
|
.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 (");
|
.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(")");
|
sql.append(")");
|
||||||
|
|
||||||
return query(new QueryAllStatement<Map<Integer, List<TPS>>>(sql.toString(), 10000) {
|
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 {
|
public Map<Integer, List<TPS>> processResults(ResultSet set) throws SQLException {
|
||||||
Map<Integer, List<TPS>> map = new HashMap<>();
|
Map<Integer, List<TPS>> map = new HashMap<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
int serverID = set.getInt(Col.SERVER_ID.get());
|
int serverID = set.getInt(SERVER_ID);
|
||||||
int playersOnline = set.getInt(Col.PLAYERS_ONLINE.get());
|
int playersOnline = set.getInt(PLAYERS_ONLINE);
|
||||||
long date = set.getLong(Col.DATE.get());
|
long date = set.getLong(DATE);
|
||||||
|
|
||||||
List<TPS> tpsList = map.getOrDefault(serverID, new ArrayList<>());
|
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