Skip to content

Commit

Permalink
Update tasks.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Apr 27, 2024
1 parent c203301 commit 2039437
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions stats-backend/api2/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1791,24 +1791,27 @@ def extract_wallets_and_ids():
from django.db.models import Q, Subquery, OuterRef

# Get the latest NodeStatusHistory for each provider
latest_status = NodeStatusHistory.objects.filter(
provider=OuterRef('pk')
).order_by('-timestamp')
latest_status = NodeStatusHistory.objects.filter(provider=OuterRef("pk")).order_by(
"-timestamp"
)

# Filter offers for online providers only
online_providers = Node.objects.annotate(
latest_is_online=Subquery(latest_status.values('is_online')[:1])
).filter(latest_is_online=True).values_list('id', flat=True)

offers = Offer.objects.filter(provider_id__in=online_providers).values('properties', 'provider__node_id')
online_providers = (
Node.objects.annotate(
latest_is_online=Subquery(latest_status.values("is_online")[:1])
)
.filter(latest_is_online=True)
.values_list("id", flat=True)
)

offers = Offer.objects.filter(provider_id__in=online_providers)
wallets_dict = defaultdict(set)
providers_dict = defaultdict(list)

for offer in offers:
properties = offer['properties']
if not properties:
if not offer.properties:
continue
properties = offer.properties
provider_id = properties.get("id", "")
provider_name = properties.get("golem.node.id.name", "")

Expand All @@ -1819,7 +1822,7 @@ def extract_wallets_and_ids():

# Update providers dictionary
if provider_id and provider_name:
providers_dict[(provider_id, provider_name)].append(offer['provider__node_id'])
providers_dict[(provider_id, provider_name)].append(offer.provider.node_id)

# Convert wallet sets to counts of unique providers using each wallet
wallets_list = [
Expand All @@ -1834,4 +1837,4 @@ def extract_wallets_and_ids():
]

data = {"wallets": wallets_list, "providers": providers_list}
r.set("wallets_and_ids", json.dumps(data))
r.set("wallets_and_ids", json.dumps(data))

0 comments on commit 2039437

Please sign in to comment.