Skip to content
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 3 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/assets/v2/js/pages/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,26 @@ $(document).ready(function() {
$('#key').change(function() {
const val = $(this).val();

document.location.href = `/leaderboard/${val}?cadence=` + $('#cadence').val() + '&keyword=' + $('#tech-keyword').val();
document.location.href = `/leaderboard/${val}?cadence=` + $('#cadence').val() + '&keyword=' + $('#tech-keyword').val() + '&product=' + $('#product').val();
});


$('#cadence').change(function() {

document.location.href = document.location.pathname + '?cadence=' + $('#cadence').val() + '&keyword=' + $('#tech-keyword').val();
document.location.href = document.location.pathname + '?cadence=' + $('#cadence').val() + '&keyword=' + $('#tech-keyword').val() + '&product=' + $('#product').val();
});

$('#product').change(function() {

document.location.href = document.location.pathname + '?cadence=' + $('#cadence').val() + '&keyword=' + $('#tech-keyword').val() + '&product=' + $('#product').val();
});


$('#tech-keyword').change(function() {
const keyword = $(this).val();

if (keyword === 'all') {
document.location.href = document.location.pathname + '?cadence=' + $('#cadence').val() + '&keyword=';
document.location.href = document.location.pathname + '?cadence=' + $('#cadence').val() + '&keyword=' + '&product=' + $('#product').val();

window.location.href = new_location;
} else {
Expand All @@ -59,7 +64,7 @@ $(document).ready(function() {
base_url = window.location.href.split('?')[0];
}

document.location.href = document.location.pathname + '?cadence=' + $('#cadence').val() + '&keyword=' + $('#tech-keyword').val();
document.location.href = document.location.pathname + '?cadence=' + $('#cadence').val() + '&keyword=' + $('#tech-keyword').val() + '&product=' + $('#product').val();
}
});
});
144 changes: 77 additions & 67 deletions app/marketing/management/commands/assemble_leaderboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

index_terms = [kt.kudos_token_cloned_from.url]
for index_term in index_terms:
sum_kudos_helper(kt, ALL, index_term, val_usd)
Expand Down Expand Up @@ -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():
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
19 changes: 19 additions & 0 deletions app/marketing/migrations/0008_leaderboardrank_product.py
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,
),
]
1 change: 1 addition & 0 deletions app/marketing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class LeaderboardRank(SuperModel):
active = models.BooleanField(db_index=True)
count = models.IntegerField(default=0)
rank = models.IntegerField(default=0)
product = models.CharField(max_length=255, db_index=True)
tech_keywords = ArrayField(models.CharField(max_length=50), blank=True, default=list)

objects = LeaderboardRankQuerySet.as_manager()
Expand Down
5 changes: 4 additions & 1 deletion app/marketing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ def leaderboard(request, key=''):
cadences = ['all', 'weekly', 'monthly', 'quarterly', 'yearly']


product = request.GET.get('product', 'all')
keyword_search = request.GET.get('keyword', '')
keyword_search = '' if keyword_search == 'all' else keyword_search
limit = request.GET.get('limit', 50)
Expand Down Expand Up @@ -773,7 +774,7 @@ def leaderboard(request, key=''):

title = titles[key]
which_leaderboard = f"{cadence}_{key}"
ranks = LeaderboardRank.objects.filter(active=True, leaderboard=which_leaderboard)
ranks = LeaderboardRank.objects.filter(active=True, leaderboard=which_leaderboard, product=product)
if keyword_search:
ranks = ranks.filter(tech_keywords__icontains=keyword_search)

Expand Down Expand Up @@ -805,6 +806,8 @@ def leaderboard(request, key=''):
'nav': 'home',
'titles': titles,
'cadence': cadence,
'product': product,
'products': ['kudos', 'grants', 'bounties', 'tips', 'all'],
'selected': title,
'is_linked_to_profile': is_linked_to_profile,
'title': page_title,
Expand Down
11 changes: 11 additions & 0 deletions app/retail/templates/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ <h1 class="font-header font-weight-semibold mb-lg-0">{{title}}</h1>
</select>
</div>

<div class=" mt-2">
<p class="key-title font-body mb-0 font-weight-semibold mr-2">Product :</p>
<select id="product" class="form-control key font-body">
{% for ele in products %}
<option value="{{ele}}"
{% if product == ele %}selected=selected{% endif %} >{{ele|title}}
</option>
{% endfor %}
</select>
</div>

<div class=" mt-2">
{% if technologies|length > 0 %}
<p class="key-title font-body mb-0 font-weight-semibold mr-2">Key : &nbsp; &nbsp; &nbsp; &nbsp;</p>
Expand Down