Fixes Last Peak time not showing up #726

This commit is contained in:
Rsl1122 2018-09-08 17:11:29 +03:00
parent 0fceaaf9e1
commit ac3e9a969c
2 changed files with 9 additions and 5 deletions

View File

@ -14,9 +14,9 @@ import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plugin.api.TimeAmount;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class SQLFetchOps extends SQLOps implements FetchOperations {
@ -72,7 +72,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
return null;
});
container.putSupplier(ServerKeys.RECENT_PEAK_PLAYERS, () -> {
long twoDaysAgo = System.currentTimeMillis() - (TimeAmount.DAY.ms() * 2L);
long twoDaysAgo = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(2);
Optional<TPS> lastPeak = tpsTable.getPeakPlayerCount(serverUUID, twoDaysAgo);
if (lastPeak.isPresent()) {
TPS peak = lastPeak.get();

View File

@ -151,9 +151,12 @@ 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 sql = Select.all(tableName)
.where(Col.SERVER_ID + "=" + serverTable.statementSelectServerID)
.and(Col.PLAYERS_ONLINE + "= (SELECT MAX(" + Col.PLAYERS_ONLINE + ") FROM " + tableName + ")")
.and(Col.PLAYERS_ONLINE + "= (" + subStatement + ")")
.and(Col.DATE + ">= ?")
.toString();
@ -161,13 +164,14 @@ public class TPSTable extends Table {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
statement.setLong(2, afterDate);
statement.setString(2, serverUUID.toString());
statement.setLong(3, afterDate);
statement.setLong(4, afterDate);
}
@Override
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()))