From bb8e3685fa2431084d9b0dca7af357b45ef7a378 Mon Sep 17 00:00:00 2001 From: Graham Dixon Date: Thu, 11 Nov 2021 08:39:28 +0000 Subject: [PATCH 1/2] GITC-500: Adds ability to recalculate inactive rounds --- app/grants/admin.py | 10 +++++--- .../management/commands/estimate_clr_delay.py | 3 +-- app/grants/tasks.py | 25 ++++++++++++++----- app/grants/views.py | 2 +- app/retail/templates/admin/change_form.html | 1 + 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/grants/admin.py b/app/grants/admin.py index e864b76bd73..1843dae90ba 100644 --- a/app/grants/admin.py +++ b/app/grants/admin.py @@ -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") if "_set_current_grant_clr_calculations_to_false" in request.POST: latest_calculations = GrantCLRCalculation.objects.filter(grantclr=obj, latest=True) diff --git a/app/grants/management/commands/estimate_clr_delay.py b/app/grants/management/commands/estimate_clr_delay.py index 550449d180f..ca41e934436 100644 --- a/app/grants/management/commands/estimate_clr_delay.py +++ b/app/grants/management/commands/estimate_clr_delay.py @@ -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") diff --git a/app/grants/tasks.py b/app/grants/tasks.py index 1bf69d623bf..5f54b379a7a 100644 --- a/app/grants/tasks.py +++ b/app/grants/tasks.py @@ -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, @@ -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) diff --git a/app/grants/views.py b/app/grants/views.py index ece8c3a8716..c95a5cb3946 100644 --- a/app/grants/views.py +++ b/app/grants/views.py @@ -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) diff --git a/app/retail/templates/admin/change_form.html b/app/retail/templates/admin/change_form.html index 6444c76aefb..ccb5c27cc84 100644 --- a/app/retail/templates/admin/change_form.html +++ b/app/retail/templates/admin/change_form.html @@ -70,6 +70,7 @@ {% elif 'grantcollection/' in request.build_absolute_uri %} {% elif 'grantclr/' in request.build_absolute_uri %} + From 6af7f09b0dc56d7b923c681806ad3397d6bdd26c Mon Sep 17 00:00:00 2001 From: Graham Dixon Date: Thu, 11 Nov 2021 16:02:01 +0000 Subject: [PATCH 2/2] GITC-500: Prep form merge - we should make this check on active once GITC-475 is merged --- app/grants/models/grant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/grants/models/grant.py b/app/grants/models/grant.py index 10e37df6da6..967946c1efb 100644 --- a/app/grants/models/grant.py +++ b/app/grants/models/grant.py @@ -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, )