From 3222465f13ff55f413ce15303195cd67910b0d09 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 25 Nov 2017 10:42:29 +0200 Subject: [PATCH] Server Idle & Downtime calculations --- .../djrapitops/plan/data/ServerProfile.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/ServerProfile.java b/Plan/src/main/java/com/djrapitops/plan/data/ServerProfile.java index 74cd73049..ab64004a0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/ServerProfile.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/ServerProfile.java @@ -5,6 +5,7 @@ package main.java.com.djrapitops.plan.data; import com.djrapitops.plugin.api.Check; +import com.djrapitops.plugin.api.TimeAmount; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.PlanBungee; import main.java.com.djrapitops.plan.Settings; @@ -13,6 +14,7 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; import main.java.com.djrapitops.plan.utilities.comparators.PlayerProfileLastPlayedComparator; +import main.java.com.djrapitops.plan.utilities.comparators.TPSComparator; import main.java.com.djrapitops.plan.utilities.html.tables.PlayersTableCreator; import java.util.*; @@ -298,4 +300,61 @@ public class ServerProfile { } return uuids; } + + public long serverDownTime(long after, long before) { + return serverDownTime(getTPSData(after, before) + .sorted(new TPSComparator()) + .collect(Collectors.toList())); + } + + public static long serverDownTime(List tpsData) { + long lastDate = -1; + long downTime = 0; + for (TPS tps : tpsData) { + long date = tps.getDate(); + if (lastDate == -1) { + lastDate = date; + continue; + } + + long diff = date - lastDate; + if (diff > TimeAmount.MINUTE.ms() * 3L) { + downTime += diff; + } + lastDate = date; + } + + return downTime; + } + + public long serverIdleTime(long after, long before) { + return serverIdleTime(getTPSData(after, before) + .sorted(new TPSComparator()) + .collect(Collectors.toList())); + } + + public static long serverIdleTime(List tpsData) { + long lastDate = -1; + int lastPlayers = 0; + long idleTime = 0; + for (TPS tps : tpsData) { + long date = tps.getDate(); + int players = tps.getPlayers(); + if (lastDate != -1) { + lastDate = date; + lastPlayers = players; + continue; + } + + long diff = date - lastDate; + if (lastPlayers == 0 && players == 0) { + idleTime += diff; + } + + lastDate = date; + lastPlayers = players; + } + + return idleTime; + } } \ No newline at end of file