From db280d15561b83be0094491fb5a65ccdbf58e114 Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Fri, 4 Oct 2024 17:27:54 +0200 Subject: [PATCH] Update scoring.py --- .../reputation-backend/api/scoring.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docker-stack/golem-reputation-backend/reputation-backend/api/scoring.py b/docker-stack/golem-reputation-backend/reputation-backend/api/scoring.py index fe1fe56..0aaecf6 100644 --- a/docker-stack/golem-reputation-backend/reputation-backend/api/scoring.py +++ b/docker-stack/golem-reputation-backend/reputation-backend/api/scoring.py @@ -26,7 +26,10 @@ def calculate_uptime(node_id, node=None): if node is None: node = Provider.objects.get(node_id=node_id) statuses = NodeStatusHistory.objects.filter(node_id=node_id).order_by("timestamp") - + first_online_status = statuses.first() + + if not first_online_status: + return 0 # Return 0% if the node has never been online online_duration = timedelta(0) last_online_time = None @@ -41,7 +44,7 @@ def calculate_uptime(node_id, node=None): if last_online_time is not None: online_duration += timezone.now() - last_online_time - total_duration = timezone.now() - node.created_at + total_duration = timezone.now() - first_online_status.timestamp uptime_percentage = ( online_duration.total_seconds() / total_duration.total_seconds() ) * 100