use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.
the class LargeFetchQueries method fetchAllTPSData.
/**
* Query database for TPS data.
*
* @return Map: Server UUID - List of TPS data
*/
public static Query<Map<ServerUUID, List<TPS>>> fetchAllTPSData() {
String serverIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID;
String serverUUIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_UUID + " as s_uuid";
String sql = SELECT + TPSTable.DATE + ',' + TPSTable.TPS + ',' + TPSTable.PLAYERS_ONLINE + ',' + TPSTable.CPU_USAGE + ',' + TPSTable.RAM_USAGE + ',' + TPSTable.ENTITIES + ',' + TPSTable.CHUNKS + ',' + TPSTable.FREE_DISK + ',' + serverUUIDColumn + FROM + TPSTable.TABLE_NAME + INNER_JOIN + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + TPSTable.SERVER_ID;
return new QueryAllStatement<Map<ServerUUID, List<TPS>>>(sql, 50000) {
@Override
public Map<ServerUUID, List<TPS>> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, List<TPS>> serverMap = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString("s_uuid"));
List<TPS> tpsList = serverMap.computeIfAbsent(serverUUID, Lists::create);
TPS tps = TPSBuilder.get().date(set.getLong(TPSTable.DATE)).tps(set.getDouble(TPSTable.TPS)).playersOnline(set.getInt(TPSTable.PLAYERS_ONLINE)).usedCPU(set.getDouble(TPSTable.CPU_USAGE)).usedMemory(set.getLong(TPSTable.RAM_USAGE)).entities(set.getInt(TPSTable.ENTITIES)).chunksLoaded(set.getInt(TPSTable.CHUNKS)).freeDiskSpace(set.getLong(TPSTable.FREE_DISK)).toTPS();
tpsList.add(tps);
}
return serverMap;
}
};
}
use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.
the class TPSMutatorTest method filterWorksCorrectly.
@Test
void filterWorksCorrectly() {
long monthAgo = time - TimeAmount.MONTH.toMillis(1L);
List<TPS> filtered = new TPSMutator(testData).filterDataBetween(monthAgo, time).all();
for (TPS tps : filtered) {
long date = tps.getDate();
if (date < monthAgo) {
fail("Data from over month ago was present");
}
if (date > time) {
fail("Data from after 'time' was present");
}
}
}
use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.
the class TPSMutator method toArrays.
public List<Number[]> toArrays(LineGraph.GapStrategy gapStrategy) {
List<Number[]> arrays = new ArrayList<>();
Long lastX = null;
for (TPS tps : tpsData) {
long date = tps.getDate();
if (gapStrategy.fillGaps && lastX != null && date - lastX > gapStrategy.acceptableGapMs) {
addMissingPoints(arrays, lastX, date, gapStrategy);
}
lastX = date;
arrays.add(tps.toArray());
}
return arrays;
}
use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.
the class TPSMutator method lowTpsSpikeCount.
public int lowTpsSpikeCount(double threshold) {
boolean wasLow = false;
int spikeCount = 0;
for (TPS tpsObj : tpsData) {
double tps = tpsObj.getTicksPerSecond();
if (0 <= tps && tps < threshold) {
if (!wasLow) {
spikeCount++;
wasLow = true;
}
} else {
wasLow = false;
}
}
return spikeCount;
}
use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.
the class TPSMutator method serverDownTime.
public long serverDownTime() {
long lastDate = -1;
long downTime = 0;
tpsData.sort(new TPSComparator());
for (TPS tps : tpsData) {
long date = tps.getDate();
if (lastDate == -1) {
lastDate = date;
continue;
}
long diff = date - lastDate;
if (diff > TimeUnit.MINUTES.toMillis(3L)) {
downTime += diff;
}
lastDate = date;
}
return downTime;
}
Aggregations