Skip to content

Commit

Permalink
Update api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed May 31, 2024
1 parent 5db2dc4 commit 51b64ff
Showing 1 changed file with 1 addition and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,8 @@ def get_provider_details(request, node_id: str):
@api.get("/providers/online")
def online_provider_summary(request):

# Get the latest online status for each provider
latest_online_statuses = NodeStatusHistory.objects.annotate(
latest=Max('timestamp', filter=Q(is_online=True))
).filter(
timestamp=F('latest'), is_online=True
).values_list('provider_id', flat=True)

# Get the success rate for each provider
providers = Provider.objects.filter(node_id__in=latest_online_statuses).annotate(
providers = Provider.objects.annotate(
success_count=Count('taskcompletion', filter=Q(taskcompletion__is_successful=True)),
total_count=Count('taskcompletion')
).all()
Expand All @@ -386,30 +379,3 @@ def online_provider_summary(request):

return JsonResponse(result, safe=False)


@api.get("/provider/{node_id}/status")
def get_provider_status(request, node_id: str):
# Get the provider details
provider = Provider.objects.filter(node_id=node_id).annotate(
success_count=Count('taskcompletion', filter=Q(taskcompletion__is_successful=True)),
total_count=Count('taskcompletion')
).first()
if not provider:
return JsonResponse({"detail": "Provider not found"}, status=404)

# Calculate success rate
success_rate = (provider.success_count / provider.total_count * 100) if provider.total_count > 0 else None

# Get the blacklist status
is_blacklisted_provider = node_id in set(BlacklistedProvider.objects.values_list('provider__node_id', flat=True))
payment_address_key = 'golem.com.payment.platform.erc20-mainnet-glm.address' if provider.network == 'mainnet' else 'golem.com.payment.platform.erc20-holesky-tglm.address'
is_blacklisted_wallet = provider.payment_addresses.get(payment_address_key) in set(BlacklistedOperator.objects.values_list('wallet', flat=True))

result = {
"node_id": provider.node_id,
"success_rate": success_rate,
"is_blacklisted_provider": is_blacklisted_provider,
"is_blacklisted_wallet": is_blacklisted_wallet
}

return JsonResponse(result)

0 comments on commit 51b64ff

Please sign in to comment.