From e864f2a0009d6dc2e8a6c93cb86d55d80257b974 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Tue, 14 Dec 2021 10:42:51 +0530 Subject: [PATCH] bug: ignore grant removed from round in clr calculation (#9876) * bug: ignore grant removed from round in clr calculation * Update app/grants/clr.py Co-authored-by: Graham Dixon Co-authored-by: Graham Dixon --- app/grants/clr.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/grants/clr.py b/app/grants/clr.py index a952e5e07e4..9cf031c9ad2 100644 --- a/app/grants/clr.py +++ b/app/grants/clr.py @@ -24,6 +24,7 @@ import numpy as np from grants.clr_data_src import fetch_contributions, fetch_grants, fetch_summed_contributions +from grants.models import GrantCLRCalculation def populate_data_for_clr(grants, contributions, clr_round): @@ -485,7 +486,11 @@ def predict_clr(save_to_db=False, from_date=None, clr_round=None, network='mainn print(f"- starting grants iter at {round(time.time(),1)}") # for full calc - calculate the clr for each grant given additional potential_donations total_count = grants.count() + + invalid_clr_calculations = GrantCLRCalculation.objects.filter(latest=True, grantclr=clr_round.pk) + for grant in grants: + invalid_clr_calculations.exclude(grant=grant.pk) # five potential additional donations plus the base case of 0 potential_donations = [0, 1, 10, 100, 1000, 10000] @@ -545,6 +550,8 @@ def predict_clr(save_to_db=False, from_date=None, clr_round=None, network='mainn debug_output.append({'grant': grant.id, "title": grant.title, "clr_prediction_curve": (potential_donations, potential_clr), "grants_clr": grants_clr}) + invalid_clr_calculations.update(latest=False, active=False) + print(f"\nTotal execution time: {(timezone.now() - clr_calc_start_time)}\n") return debug_output