Skip to content

Commit

Permalink
Update scoring.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Oct 4, 2024
1 parent 89d7b33 commit db280d1
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit db280d1

Please sign in to comment.