Search in sources :

Example 6 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 7 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 8 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)

Example 9 with TPS

use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.

the class ServerUptimeCalculator method tryToGetServerUptimeMillisFromDatabase.

private Optional<Long> tryToGetServerUptimeMillisFromDatabase(ServerUUID serverUUID) {
    long dataGapThreshold = TimeUnit.MINUTES.toMillis(3);
    Database database = dbSystem.getDatabase();
    Optional<Long> latestDataDate = database.query(TPSQueries.fetchLatestTPSEntryForServer(serverUUID)).map(TPS::getDate);
    Optional<Long> dataBlockStartDate = database.query(TPSQueries.fetchLatestServerStartTime(serverUUID, dataGapThreshold));
    if (!latestDataDate.isPresent() || !dataBlockStartDate.isPresent()) {
        return Optional.empty();
    }
    if (System.currentTimeMillis() - latestDataDate.get() > dataGapThreshold) {
        return Optional.empty();
    }
    return Optional.of(System.currentTimeMillis() - dataBlockStartDate.get());
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) Database(com.djrapitops.plan.storage.database.Database)

Example 10 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)

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