TPSMutator { 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; } TPSMutator(List<TPS> tpsData); static TPSMutator forContainer(DataContainer container); static TPSMutator copyOf(TPSMutator mutator); TPSMutator filterBy(Predicate<TPS> filter); TPSMutator filterDataBetween(long after, long before); TPSMutator filterTPSBetween(int above, int below); List<TPS> all(); List<Point> playersOnlinePoints(); List<Point> tpsPoints(); List<Point> cpuPoints(); List<Point> ramUsagePoints(); List<Point> entityPoints(); List<Point> chunkPoints(); List<Point> freeDiskPoints(); long serverDownTime(); long serverOccupiedTime(); double percentageTPSAboveThreshold(int threshold); int lowTpsSpikeCount(int threshold); double averageTPS(); double averageCPU(); double averageRAM(); double averageEntities(); double averageChunks(); double averageFreeDisk(); long maxFreeDisk(); long minFreeDisk(); double averagePlayersOnline(); Optional<TPS> getLast();  }
@Test void noDowntimeIsCorrect() { long expected = 0; long result = new TPSMutator(testData).serverDownTime(); assertEquals(expected, result); }
@Test void noDowntimeOnSingleEntry() { long expected = 0; long result = new TPSMutator(Collections.singletonList( TPSBuilder.get().date(time - TimeUnit.DAYS.toMillis(1L)) .tps(0.0) .playersOnline(0) .usedCPU(0.0) .usedMemory(0) .entities(0) .chunksLoaded(0) .freeDiskSpace(0) .toTPS() )).serverDownTime(); assertEquals(expected, result); }