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

GITC-500: Adds ability to recalculate inactive rounds #9678

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions app/grants/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,13 @@ def stats_link(self, instance):
def response_change(self, request, obj):
if "_recalculate_clr" in request.POST:
from grants.tasks import recalc_clr
for grant in obj.grants:
recalc_clr.delay(grant.pk)
self.message_user(request, "submitted recaclulation to queue")
selected_clr = request.POST.get('_selected_clr', False)
if selected_clr:
recalc_clr.delay(False, int(selected_clr))
self.message_user(request, f"submitted recaclulation of GrantCLR:{ selected_clr } to queue")
else:
recalc_clr.delay(False)
self.message_user(request, "submitted recaclulation to queue")
Comment on lines +495 to +498
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recaclulation recalculation


if "_set_current_grant_clr_calculations_to_false" in request.POST:
latest_calculations = GrantCLRCalculation.objects.filter(grantclr=obj, latest=True)
Expand Down
3 changes: 1 addition & 2 deletions app/grants/management/commands/estimate_clr_delay.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def handle(self, *args, **options):
if active_clr_rounds:
for clr_round in active_clr_rounds:
print(f"CALCULATING CLR estimates for ROUND: {clr_round.round_num} {clr_round.sub_round_slug}")
for grant in clr_round.grants:
recalc_clr.delay(grant.pk)
recalc_clr.delay(False, clr_round)

else:
print("No active CLRs found")
2 changes: 1 addition & 1 deletion app/grants/models/grant.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def record_clr_prediction_curve(self, grant, clr_prediction_curve):
grantclr=self,
grant=grant,
clr_prediction_curve=clr_prediction_curve,
latest=True,
latest=True if self.is_active else False,
)


Expand Down
25 changes: 19 additions & 6 deletions app/grants/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from celery import app
from celery.utils.log import get_task_logger
from dashboard.models import Profile
from grants.models import Grant, GrantCollection, Subscription
from grants.models import Grant, GrantCLR, GrantCollection, Subscription
from grants.utils import bsci_script, get_clr_rounds_metadata, save_grant_to_notion
from marketing.mails import (
new_contributions, new_grant, new_grant_admin, notion_failure_email, thank_you_for_supporting,
Expand Down Expand Up @@ -315,25 +315,38 @@ def recalc_clr_if_x_minutes_old(self, grant_id, minutes, retry: bool = True) ->


@app.shared_task(bind=True, max_retries=1)
def recalc_clr(self, grant_id, retry: bool = True) -> None:
def recalc_clr(self, grant_id, grant_clr, retry: bool = True) -> None:

if settings.FLUSH_QUEUE:
return

obj = Grant.objects.get(pk=grant_id)
from django.utils import timezone

from grants.clr import predict_clr
for clr_round in obj.in_active_clrs.all():

if grant_clr:
clr_round = GrantCLR.objects.get(pk=grant_clr)
network = 'mainnet'
predict_clr(
save_to_db=True,
from_date=timezone.now(),
clr_round=clr_round,
network=network,
only_grant_pk=obj.pk,
only_grant_pk=grant_id,
what='slim'
)
elif grant_id:
obj = Grant.objects.get(pk=grant_id)

for clr_round in obj.in_active_clrs.all():
network = 'mainnet'
predict_clr(
save_to_db=True,
from_date=timezone.now(),
clr_round=clr_round,
network=network,
only_grant_pk=obj.pk,
what='slim'
)


@app.shared_task(bind=True, max_retries=1)
Expand Down
2 changes: 1 addition & 1 deletion app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ def grant_details_contributions(request, grant_id):
all_contributions.append(contribution_json)

response['contributions'] = json.loads(json.dumps(all_contributions, default=str))
response['next_page_number'] = page + 1
response['next_page_number'] = page + 1

return JsonResponse(response)

Expand Down
1 change: 1 addition & 0 deletions app/retail/templates/admin/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
{% elif 'grantcollection/' in request.build_absolute_uri %}
<input type="submit" value="Generate Cache" name="_generate_cache" value="1">
{% elif 'grantclr/' in request.build_absolute_uri %}
<input type="hidden" value="{{ original.id }}" name="_selected_clr">
<input type="submit" value="Recalculate CLR" name="_recalculate_clr" value="1">
<input type="submit" value="Reset CLR calculations for this round" name="_set_current_grant_clr_calculations_to_false" value="1">
<input type="submit" value="Reset all CLR calculations for all rounds" name="_set_all_grant_clr_calculations_to_false" value="1">
Expand Down