20
20
from django .conf import settings
21
21
from django .core .management .base import BaseCommand
22
22
from django .db import transaction
23
+ from django .db .models import Q
23
24
from django .utils import timezone
24
25
25
26
from cacheops import CacheMiss , cache
50
51
CITIES = 'cities'
51
52
CONTINENTS = 'continents'
52
53
53
- TIMES = [ALL , WEEKLY , MONTHLY ]
54
+ TIMES = [WEEKLY , MONTHLY ]
54
55
BREAKDOWNS = [FULFILLED , ALL , PAYERS , EARNERS , ORGS , KEYWORDS , KUDOS , TOKENS , COUNTRIES , CITIES , CONTINENTS ]
55
56
56
57
WEEKLY_CUTOFF = timezone .now () - timezone .timedelta (days = (30 if settings .DEBUG else 7 ))
@@ -427,6 +428,7 @@ def do_leaderboard_feed():
427
428
def do_leaderboard ():
428
429
global ranks
429
430
global counts
431
+ CUTOFF = MONTHLY_CUTOFF
430
432
431
433
products = ['kudos' , 'grants' , 'bounties' , 'tips' , 'all' ]
432
434
for product in products :
@@ -435,10 +437,12 @@ def do_leaderboard():
435
437
counts = default_ranks ()
436
438
index_terms = []
437
439
440
+ print ('---' )
438
441
if product in ['all' , 'grants' ]:
439
442
# get grants
440
- grants = Contribution .objects .filter (subscription__network = 'mainnet' )
443
+ grants = Contribution .objects .filter (subscription__network = 'mainnet' ). filter ( created_on__gt = CUTOFF )
441
444
# iterate
445
+ print (product , grants .count ())
442
446
for gc in grants :
443
447
try :
444
448
index_terms = grant_index_terms (gc )
@@ -449,7 +453,8 @@ def do_leaderboard():
449
453
450
454
if product in ['all' , 'bounties' ]:
451
455
# 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 ())
453
458
454
459
# iterate
455
460
for b in bounties :
@@ -461,7 +466,8 @@ def do_leaderboard():
461
466
462
467
if product in ['all' , 'tips' ]:
463
468
# 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 ())
465
471
466
472
# iterate
467
473
for t in tips :
@@ -472,13 +478,17 @@ def do_leaderboard():
472
478
473
479
if product in ['all' , 'kudos' ]:
474
480
# 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 :
476
484
sum_kudos (kt )
477
485
478
486
# set old LR as inactive
479
487
created_on = timezone .now ()
480
488
with transaction .atomic ():
489
+ print (" - saving -" )
481
490
lrs = LeaderboardRank .objects .active ().filter (product = product )
491
+ lrs = lrs .filter (Q (leaderboard__startswith = WEEKLY ) | Q (leaderboard__startswith = MONTHLY ))
482
492
lrs .update (active = False )
483
493
484
494
# save new LR in DB
0 commit comments