-
-
Notifications
You must be signed in to change notification settings - Fork 775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allows leaderboard to be browsed by product #5505
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,6 +290,8 @@ def sum_tip_helper(t, time, index_term, val_usd): | |
|
||
def sum_kudos(kt): | ||
val_usd = kt.value_in_usdt_now | ||
if not kt.kudos_token_cloned_from: | ||
return | ||
index_terms = [kt.kudos_token_cloned_from.url] | ||
for index_term in index_terms: | ||
sum_kudos_helper(kt, ALL, index_term, val_usd) | ||
|
@@ -372,70 +374,78 @@ class Command(BaseCommand): | |
|
||
def handle(self, *args, **options): | ||
|
||
# get grants | ||
grants = Contribution.objects.filter(subscription__network='mainnet')[0:5] | ||
# iterate | ||
for gc in grants: | ||
index_terms = grant_index_terms(gc) | ||
sum_grants(gc, index_terms) | ||
|
||
# get bounties | ||
bounties = Bounty.objects.current().filter(network='mainnet') | ||
|
||
# iterate | ||
for b in bounties: | ||
if not b._val_usd_db: | ||
continue | ||
|
||
index_terms = bounty_index_terms(b) | ||
sum_bounties(b, index_terms) | ||
|
||
# get tips | ||
tips = Tip.objects.send_success().filter(network='mainnet') | ||
|
||
# iterate | ||
for t in tips: | ||
if not t.value_in_usdt_now: | ||
continue | ||
index_terms = tip_index_terms(t) | ||
sum_tips(t, index_terms) | ||
|
||
# kudos' | ||
for kt in KudosTransfer.objects.send_success().filter(network='mainnet'): | ||
sum_kudos(kt) | ||
|
||
# set old LR as inactive | ||
with transaction.atomic(): | ||
lrs = LeaderboardRank.objects.active() | ||
lrs.update(active=False) | ||
|
||
# save new LR in DB | ||
for key, rankings in ranks.items(): | ||
rank = 1 | ||
for index_term, amount in sorted(rankings.items(), key=lambda x: x[1], reverse=True): | ||
count = counts[key][index_term] | ||
lbr_kwargs = { | ||
'count': count, | ||
'active': True, | ||
'amount': amount, | ||
'rank': rank, | ||
'leaderboard': key, | ||
'github_username': index_term | ||
} | ||
|
||
try: | ||
profile = Profile.objects.get(handle__iexact=index_term) | ||
lbr_kwargs['profile'] = profile | ||
lbr_kwargs['tech_keywords'] = profile.keywords | ||
except Profile.MultipleObjectsReturned: | ||
profile = Profile.objects.filter(handle__iexact=index_term).latest('id') | ||
lbr_kwargs['profile'] = profile | ||
lbr_kwargs['tech_keywords'] = profile.keywords | ||
print(f'Multiple profiles found for username: {index_term}') | ||
except Profile.DoesNotExist: | ||
print(f'No profiles found for username: {index_term}') | ||
|
||
# TODO: Bucket LeaderboardRank objects and .bulk_create | ||
LeaderboardRank.objects.create(**lbr_kwargs) | ||
rank += 1 | ||
print(key, index_term, amount, count, rank) | ||
products = ['kudos', 'grants', 'bounties', 'tips', 'all'] | ||
for product in products: | ||
|
||
if product in ['all', 'grants']: | ||
# get grants | ||
grants = Contribution.objects.filter(subscription__network='mainnet') | ||
# iterate | ||
for gc in grants: | ||
index_terms = grant_index_terms(gc) | ||
sum_grants(gc, index_terms) | ||
|
||
if product in ['all', 'bounties']: | ||
# get bounties | ||
bounties = Bounty.objects.current().filter(network='mainnet') | ||
|
||
# iterate | ||
for b in bounties: | ||
if not b._val_usd_db: | ||
continue | ||
|
||
index_terms = bounty_index_terms(b) | ||
sum_bounties(b, index_terms) | ||
|
||
if product in ['all', 'tips']: | ||
# get tips | ||
tips = Tip.objects.send_success().filter(network='mainnet') | ||
|
||
# iterate | ||
for t in tips: | ||
if not t.value_in_usdt_now: | ||
continue | ||
index_terms = tip_index_terms(t) | ||
sum_tips(t, index_terms) | ||
|
||
if product in ['all', 'kudos']: | ||
# kudos' | ||
for kt in KudosTransfer.objects.send_success().filter(network='mainnet'): | ||
sum_kudos(kt) | ||
|
||
# set old LR as inactive | ||
with transaction.atomic(): | ||
lrs = LeaderboardRank.objects.active() | ||
lrs.update(active=False) | ||
|
||
# save new LR in DB | ||
for key, rankings in ranks.items(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all indentation changes from here on out |
||
rank = 1 | ||
for index_term, amount in sorted(rankings.items(), key=lambda x: x[1], reverse=True): | ||
count = counts[key][index_term] | ||
lbr_kwargs = { | ||
'count': count, | ||
'active': True, | ||
'amount': amount, | ||
'rank': rank, | ||
'leaderboard': key, | ||
'github_username': index_term, | ||
'product': product, | ||
} | ||
|
||
try: | ||
profile = Profile.objects.get(handle__iexact=index_term) | ||
lbr_kwargs['profile'] = profile | ||
lbr_kwargs['tech_keywords'] = profile.keywords | ||
except Profile.MultipleObjectsReturned: | ||
profile = Profile.objects.filter(handle__iexact=index_term).latest('id') | ||
lbr_kwargs['profile'] = profile | ||
lbr_kwargs['tech_keywords'] = profile.keywords | ||
print(f'Multiple profiles found for username: {index_term}') | ||
except Profile.DoesNotExist: | ||
print(f'No profiles found for username: {index_term}') | ||
|
||
# TODO: Bucket LeaderboardRank objects and .bulk_create | ||
LeaderboardRank.objects.create(**lbr_kwargs) | ||
rank += 1 | ||
print(key, index_term, amount, count, rank, product) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 2.2.3 on 2019-11-17 00:44 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('marketing', '0007_job'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='leaderboardrank', | ||
name='product', | ||
field=models.CharField(db_index=True, default='all', max_length=255), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm.. what does this logic do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a kudos transfer that has a null
kudos_token_cloned_from
and this logic prevents an exception here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah nice thanks for the info