def process(self): from dashboard.models import Profile mr = self print("_") with transaction.atomic(): mr.ranking.all().delete() data = get_eligible_input_data(mr) total_pot = mr.amount print(mr, f"{len(data)} earnings to process") results = clr.run_calc(data, total_pot) for result in results: try: profile = Profile.objects.get(pk=result['id']) contributions_by_this_user = [ele for ele in data if int(ele[0]) == profile.pk] contributions = len(contributions_by_this_user) contributions_total = sum([ele[2] for ele in contributions_by_this_user]) MatchRanking.objects.create( profile=profile, round=mr, contributions=contributions, contributions_total=contributions_total, match_total=result['clr_amount'], ) except Exception as e: if settings.DEBUG: raise e # update number rankings number = 1 for mri in mr.ranking.order_by('-match_total'): mri.number = number mri.save() number += 1
def process(self): from dashboard.models import Profile mr = self print("_") with transaction.atomic(): mr.ranking.all().delete() data = get_eligible_input_data(mr) total_pot = mr.amount print(mr, f"{len(data)} earnings to process") results = [] try: results = clr.run_calc(data, total_pot) except ZeroDivisionError: print( 'ZeroDivisionError; probably theres just not enough contribtuions in round' ) for result in results: try: profile = Profile.objects.get(pk=result['id']) match_curve = clr.run_live_calc(data, result['id'], 999999, total_pot) contributors = len( set([ ele[1] for ele in data if int(ele[0]) == profile.pk ])) contributions_for_this_user = [ ele for ele in data if int(ele[0]) == profile.pk ] contributions = len(contributions_for_this_user) contributions_total = sum( [ele[2] for ele in contributions_for_this_user]) MatchRanking.objects.create( profile=profile, round=mr, contributors=contributors, contributions=contributions, contributions_total=contributions_total, match_total=result['clr_amount'], match_curve=match_curve, ) except Exception as e: if settings.DEBUG: raise e # update number rankings number = 1 for mri in mr.ranking.order_by('-match_total'): mri.number = number mri.save() number += 1