Skip to content

Commit d07517a

Browse files
committed
salvage leaderboard
1 parent 09cbfa8 commit d07517a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

app/marketing/management/commands/assemble_leaderboards.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from django.conf import settings
2121
from django.core.management.base import BaseCommand
2222
from django.db import transaction
23+
from django.db.models import Q
2324
from django.utils import timezone
2425

2526
from cacheops import CacheMiss, cache
@@ -50,7 +51,7 @@
5051
CITIES = 'cities'
5152
CONTINENTS = 'continents'
5253

53-
TIMES = [ALL, WEEKLY, MONTHLY]
54+
TIMES = [WEEKLY, MONTHLY]
5455
BREAKDOWNS = [FULFILLED, ALL, PAYERS, EARNERS, ORGS, KEYWORDS, KUDOS, TOKENS, COUNTRIES, CITIES, CONTINENTS]
5556

5657
WEEKLY_CUTOFF = timezone.now() - timezone.timedelta(days=(30 if settings.DEBUG else 7))
@@ -427,6 +428,7 @@ def do_leaderboard_feed():
427428
def do_leaderboard():
428429
global ranks
429430
global counts
431+
CUTOFF = MONTHLY_CUTOFF
430432

431433
products = ['kudos', 'grants', 'bounties', 'tips', 'all']
432434
for product in products:
@@ -435,10 +437,12 @@ def do_leaderboard():
435437
counts = default_ranks()
436438
index_terms = []
437439

440+
print('---')
438441
if product in ['all', 'grants']:
439442
# get grants
440-
grants = Contribution.objects.filter(subscription__network='mainnet')
443+
grants = Contribution.objects.filter(subscription__network='mainnet').filter(created_on__gt=CUTOFF)
441444
# iterate
445+
print(product, grants.count())
442446
for gc in grants:
443447
try:
444448
index_terms = grant_index_terms(gc)
@@ -449,7 +453,8 @@ def do_leaderboard():
449453

450454
if product in ['all', 'bounties']:
451455
# get bounties
452-
bounties = Bounty.objects.current().filter(network='mainnet')
456+
bounties = Bounty.objects.current().filter(network='mainnet').filter(created_on__gt=CUTOFF)
457+
print(product, bounties.count())
453458

454459
# iterate
455460
for b in bounties:
@@ -461,7 +466,8 @@ def do_leaderboard():
461466

462467
if product in ['all', 'tips']:
463468
# get tips
464-
tips = Tip.objects.send_success().filter(network='mainnet')
469+
tips = Tip.objects.send_success().filter(network='mainnet').filter(created_on__gt=CUTOFF)
470+
print(product, tips.count())
465471

466472
# iterate
467473
for t in tips:
@@ -472,13 +478,17 @@ def do_leaderboard():
472478

473479
if product in ['all', 'kudos']:
474480
# kudos'
475-
for kt in KudosTransfer.objects.send_success().filter(network='mainnet'):
481+
kts = KudosTransfer.objects.send_success().filter(network='mainnet').filter(created_on__gt=CUTOFF)
482+
print(product, kts.count())
483+
for kt in kts:
476484
sum_kudos(kt)
477485

478486
# set old LR as inactive
479487
created_on = timezone.now()
480488
with transaction.atomic():
489+
print(" - saving -")
481490
lrs = LeaderboardRank.objects.active().filter(product=product)
491+
lrs = lrs.filter(Q(leaderboard__startswith=WEEKLY) | Q(leaderboard__startswith=MONTHLY))
482492
lrs.update(active=False)
483493

484494
# save new LR in DB

0 commit comments

Comments
 (0)