Skip to content

Commit dc872b2

Browse files
committed
Merge remote-tracking branch 'upstream/stable'
2 parents 3f7fc14 + a5bc608 commit dc872b2

File tree

10 files changed

+191
-54
lines changed

10 files changed

+191
-54
lines changed

app/dashboard/management/commands/add_main_rnd_tag.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from grants.models import Grant, GrantTag
44

5+
56
class Command(BaseCommand):
67

78
help = 'updates all approved grants to include the main-round tag'

app/dashboard/management/commands/migrate_stamp_data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from django.utils import timezone
2222

2323
from dashboard.models import Passport, PassportStamp
24-
2524
from dashboard.passport_reader import TRUSTED_IAM_ISSUER
2625

2726

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import datetime as dt
2+
from datetime import datetime, timezone
3+
from time import sleep
4+
5+
from django.core.management.base import BaseCommand
6+
from django.db.models import F
7+
8+
import requests
9+
from grants.models import Contribution, Grant, GrantContributionIndex
10+
11+
12+
class Command(BaseCommand):
13+
14+
help = "rebuilds the table GrantContributionIndex"
15+
16+
def handle(self, *args, **kwargs):
17+
self.stdout.write(f"{datetime.now()} Building query for contributions ...")
18+
contributions = (
19+
Contribution.objects.filter(
20+
success=True,
21+
subscription__network="mainnet",
22+
subscription__grant__clr_calculations__latest=True,
23+
subscription__contributor_profile__isnull=False,
24+
created_on__gt=F(
25+
"subscription__grant__clr_calculations__grantclr__start_date"
26+
),
27+
created_on__lt=F(
28+
"subscription__grant__clr_calculations__grantclr__end_date"
29+
),
30+
)
31+
.order_by("id")
32+
.distinct("id")
33+
.values_list(
34+
"profile_for_clr_id",
35+
"subscription__grant__clr_calculations__grantclr__round_num",
36+
"subscription__grant__id",
37+
"amount_per_period_usdt"
38+
)
39+
)
40+
41+
self.stdout.write(f"{datetime.now()} Building contribIndexList ...")
42+
contribIndexList = [
43+
GrantContributionIndex(
44+
profile_id=contribInfo[0],
45+
round_num=contribInfo[1],
46+
grant_id=contribInfo[2],
47+
amount=contribInfo[3]
48+
)
49+
for contribInfo in contributions
50+
]
51+
52+
count = len(contribIndexList)
53+
self.stdout.write(f"{datetime.now()} Length of contribIndexList: {count}")
54+
self.stdout.write(f"{datetime.now()} Clearing GrantContributionIndex ...")
55+
56+
first_id = 0
57+
last_id = 0
58+
59+
try:
60+
first_id = GrantContributionIndex.objects.all().order_by("id")[0].id
61+
last_id = GrantContributionIndex.objects.all().order_by("-id")[0].id
62+
except:
63+
pass
64+
65+
self.stdout.write(
66+
f"{datetime.now()} ... deleting {last_id - first_id + 1} records"
67+
)
68+
69+
count_to_delete = last_id - first_id
70+
count_deleted = 0
71+
batch_size = 50000
72+
for i in range(first_id, last_id, batch_size):
73+
count_deleted += batch_size
74+
self.stdout.write(
75+
f"{datetime.now()} ... {(count_deleted / count_to_delete * 100):.2f}% deleting {count} records up to id {i + batch_size}"
76+
)
77+
GrantContributionIndex.objects.filter(id__lt=i + batch_size).delete()
78+
79+
self.stdout.write(f"{datetime.now()} Saving to GrantContributionIndex ...")
80+
# GrantContributionIndex.objects.bulk_create(contribIndexList, batch_size=1000, ignore_conflicts=True)
81+
for i in range(0, count, batch_size):
82+
self.stdout.write(
83+
f"{datetime.now()} {(i / count * 100):.2f}% Saving to GrantContributionIndex ..."
84+
)
85+
GrantContributionIndex.objects.bulk_create(
86+
contribIndexList[i : i + batch_size], ignore_conflicts=True
87+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 2.2.24 on 2022-08-16 12:10
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
import economy.models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('dashboard', '0210_auto_20220718_1306'),
12+
('grants', '0146_auto_20220809_1134'),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='GrantContributionIndex',
18+
fields=[
19+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('created_on', models.DateTimeField(db_index=True, default=economy.models.get_time)),
21+
('modified_on', models.DateTimeField(default=economy.models.get_time)),
22+
('round_num', models.IntegerField(help_text='The round number a user contributed to')),
23+
('grant', models.ForeignKey(help_text='The grant a user contributed to', on_delete=django.db.models.deletion.CASCADE, to='grants.Grant')),
24+
('profile', models.ForeignKey(help_text='Contributor', on_delete=django.db.models.deletion.CASCADE, to='dashboard.Profile')),
25+
],
26+
options={
27+
'abstract': False,
28+
},
29+
),
30+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.24 on 2022-08-19 10:11
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('grants', '0147_grantcontributionindex'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='grantcontributionindex',
15+
name='amount',
16+
field=models.DecimalField(db_index=True, decimal_places=18, default=0, help_text='The amount contributed', max_digits=64),
17+
),
18+
]

app/grants/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@
3535
from .hall_of_fame import GrantHallOfFame, GrantHallOfFameGrantee
3636
from .phantom_funding import PhantomFunding
3737
from .subscription import Subscription
38+
from .grant_contribution_index import GrantContributionIndex
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from django.db import models
2+
from django.utils.translation import gettext_lazy as _
3+
4+
from economy.models import SuperModel
5+
6+
7+
class GrantContributionIndex(SuperModel):
8+
"""Stores the grants and round number to shich a user contributed to.
9+
The purpose of this table is to allow a a fast query. This will be used from
10+
the `contributor_statistics` API"""
11+
12+
profile = models.ForeignKey(
13+
"dashboard.Profile",
14+
help_text=_("Contributor"),
15+
on_delete=models.CASCADE,
16+
db_index=True,
17+
)
18+
grant = models.ForeignKey(
19+
"grants.Grant",
20+
help_text=_("The grant a user contributed to"),
21+
on_delete=models.CASCADE,
22+
)
23+
round_num = models.IntegerField(
24+
help_text=_("The round number a user contributed to")
25+
)
26+
amount = models.DecimalField(
27+
default=0,
28+
decimal_places=18,
29+
max_digits=64,
30+
db_index=True,
31+
help_text=_("The amount contributed"),
32+
)

app/grants/views_api_vc.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
1919
"""
2020
import logging
21+
from datetime import datetime
2122

2223
from django.conf import settings
2324
from django.db.models import Sum
2425
from django.http import JsonResponse
2526
from django.utils.translation import gettext_lazy as _
2627

27-
from grants.models import Contribution, Grant
28+
from grants.models import Contribution, Grant, GrantContributionIndex
2829
from perftools.models import StaticJsonEnv
2930
from townsquare.models import SquelchProfile
3031

@@ -75,46 +76,39 @@ def contributor_statistics(request):
7576

7677
# Get number of grants the user contributed to
7778
num_grants_contribute_to = (
78-
Contribution.objects.filter(profile_for_clr__handle=handle, success=True)
79+
GrantContributionIndex.objects.filter(profile__handle=handle)
7980
.order_by("grant_id")
8081
.distinct("grant_id")
8182
.count()
8283
)
8384

84-
# Get the number of grants the user contributed to
85+
# Get number of rounds the user contributed to
8586
num_rounds_contribute_to = (
86-
Contribution.objects.filter(
87-
success=True,
88-
subscription__contributor_profile__handle=handle,
89-
subscription__network="mainnet",
90-
subscription__grant__clr_calculations__latest=True,
91-
)
92-
.order_by("subscription__grant__clr_calculations__grantclr__round_num")
93-
.distinct("subscription__grant__clr_calculations__grantclr__round_num")
87+
GrantContributionIndex.objects.filter(profile__handle=handle)
88+
.order_by("round_num")
89+
.distinct("round_num")
9490
.count()
9591
)
9692

97-
total_contribution_amount = Contribution.objects.filter(
98-
profile_for_clr__handle=handle, success=True
99-
).aggregate(Sum("amount_per_period_usdt"))["amount_per_period_usdt__sum"]
100-
total_contribution_amount = (
101-
total_contribution_amount if total_contribution_amount is not None else 0
102-
)
93+
# Get the total contribution amount
94+
total_contribution_amount = GrantContributionIndex.objects.filter(
95+
profile__handle=handle
96+
).aggregate(total_contribution_amount=Sum("amount"))["total_contribution_amount"]
97+
98+
total_contribution_amount
99+
100+
if total_contribution_amount is None:
101+
total_contribution_amount = 0
103102

104103
# GR14 contributor (and not squelched by FDD)
104+
start = datetime.now()
105105
profile_squelch = SquelchProfile.objects.filter(
106106
profile__handle=handle, active=True
107107
).values_list("profile_id", flat=True)
108108

109109
num_gr14_contributions = (
110-
Contribution.objects.filter(
111-
success=True,
112-
subscription__contributor_profile__handle=handle,
113-
subscription__network="mainnet",
114-
subscription__grant__clr_calculations__latest=True,
115-
subscription__grant__clr_calculations__grantclr__round_num=14,
116-
)
117-
.exclude(subscription__contributor_profile_id__in=profile_squelch)
110+
GrantContributionIndex.objects.filter(profile__handle=handle, round_num=14)
111+
.exclude(profile_id__in=profile_squelch)
118112
.count()
119113
)
120114

@@ -123,7 +117,7 @@ def contributor_statistics(request):
123117
"num_grants_contribute_to": num_grants_contribute_to,
124118
"num_rounds_contribute_to": num_rounds_contribute_to,
125119
"total_contribution_amount": total_contribution_amount,
126-
"is_gr14_contributor": num_gr14_contributions > 0,
120+
"num_gr14_contributions": num_gr14_contributions,
127121
}
128122
)
129123

app/perftools/management/commands/create_page_cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ def create_results_cache():
329329
print(f"- executing {keyword}")
330330
data = build_stat_results(keyword)
331331
print("- creating")
332+
if 'hackathons' in data:
333+
del data['hackathons']
332334
items.append(JSONStore(
333335
view=view,
334336
key=keyword,

app/retail/templates/results.html

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -286,33 +286,6 @@ <h4 class="m-1 p-1">{{kudos_leaderboard.0}}</h4>
286286
</div>
287287

288288

289-
<div class="content-block content-block--grey">
290-
<div class="container" >
291-
<h2 class="content-block__title">{{hackathons | length }} {% trans "Virtual Hackathons" %} worth ${{hackathon_total|floatformat:0|intcomma}}.</h2>
292-
293-
<div class="hackathon-breakdown">
294-
{% for hackathon in hackathons %}
295-
<div class="{% if forloop.counter > 7 %}hidden{%endif%}" >
296-
{% if hackathon.1.logo %}
297-
<img data-src="{{hackathon.1.logo}}"/>
298-
{%else %}
299-
<img data-src="/dynamic/avatar/gitcoinbot"/>
300-
{%endif %}
301-
<h4>{{hackathon.0.name}}</h4>
302-
{% if hackathon.1.num_bounties and hackathon.1.total_volume > 1 %}
303-
<p>{{hackathon.1.num_bounties}} Bounties</p>
304-
<p>${{hackathon.1.total_volume|floatformat:0|intcomma}} In Prizes</p>
305-
{% endif %}
306-
<p>{{hackathon.1.range}}</p>
307-
<a href="{% url 'hackathon' hackathon.0.slug %}">View Prize Explorer</a>
308-
</div>
309-
{% endfor %}
310-
<h4>
311-
<a class="btn btn-primary view_more" role="button" href="#">{% trans "See more" %}</a>
312-
</div>
313-
</div>
314-
</div>
315-
316289

317290
<div class="row mt-5 pb-5 text-center">
318291
<div class="col">

0 commit comments

Comments
 (0)