Skip to content

Commit f00f023

Browse files
authored
Fix uptime for time range All (#295)
Fixes #289 Signed-off-by: Dave Thaler <[email protected]>
1 parent 5756bca commit f00f023

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

OrcanodeMonitor/Models/Orcanode.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,21 @@ public static int GetUptimePercentage(string orcanodeId, List<OrcanodeEvent> eve
446446
continue;
447447
}
448448
DateTime current = e.DateTimeUtc;
449-
if (IsStateOnline(lastValue))
450-
{
451-
up += (current - start);
452-
}
453-
else
449+
450+
// When collecting "all" events, we only want to count time
451+
// starting with the first event for the node, not across all
452+
// time or we'd end up with about 0% uptime.
453+
// For other time ranges, use the full week or month.
454+
if (start > DateTime.MinValue)
454455
{
455-
down += (current - start);
456+
if (IsStateOnline(lastValue))
457+
{
458+
up += (current - start);
459+
}
460+
else
461+
{
462+
down += (current - start);
463+
}
456464
}
457465
start = current;
458466
lastValue = e.Value;

0 commit comments

Comments
 (0)