Search in sources :

Example 1 with TPS

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;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) Lists(com.djrapitops.plan.utilities.java.Lists) TPS(com.djrapitops.plan.gathering.domain.TPS) ResultSet(java.sql.ResultSet) List(java.util.List)

Example 2 with TPS

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");
        }
    }
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) Test(org.junit.jupiter.api.Test)

Example 3 with TPS

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;
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) ArrayList(java.util.ArrayList)

Example 4 with TPS

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;
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) Point(com.djrapitops.plan.delivery.rendering.json.graphs.line.Point)

Example 5 with TPS

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;
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) TPSComparator(com.djrapitops.plan.utilities.comparators.TPSComparator)

Aggregations

TPS (com.djrapitops.plan.gathering.domain.TPS)19 Test (org.junit.jupiter.api.Test)7 Database (com.djrapitops.plan.storage.database.Database)5 TPSMutator (com.djrapitops.plan.delivery.domain.mutators.TPSMutator)3 ServerUUID (com.djrapitops.plan.identification.ServerUUID)3 TPSStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction)3 TPSComparator (com.djrapitops.plan.utilities.comparators.TPSComparator)3 ResultSet (java.sql.ResultSet)3 HashMap (java.util.HashMap)3 Point (com.djrapitops.plan.delivery.rendering.json.graphs.line.Point)2 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)2 Lists (com.djrapitops.plan.utilities.java.Lists)2 PreparedStatement (java.sql.PreparedStatement)2 List (java.util.List)2 DateObj (com.djrapitops.plan.delivery.domain.DateObj)1 User (com.djrapitops.plan.delivery.domain.auth.User)1 PlayersOnlineResolver (com.djrapitops.plan.delivery.domain.mutators.PlayersOnlineResolver)1 SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)1 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)1 GMTimes (com.djrapitops.plan.gathering.domain.GMTimes)1