From f5b0134de2673e1daae5572290dfe773a8dda752 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Tue, 17 Dec 2019 01:04:50 +0530 Subject: [PATCH] minor fixes --- app/grants/clr.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/grants/clr.py b/app/grants/clr.py index d68bd1cdd4e..27dc1b24623 100644 --- a/app/grants/clr.py +++ b/app/grants/clr.py @@ -34,7 +34,8 @@ ''' - Helper function that translates existing grant data structure to a list of lists. + Helper function that translates existing grant data structure + to a list of lists. Args: { @@ -60,7 +61,9 @@ def translate_data(grants_data): ''' - Helper function that aggregates contributions by contributor, and then uses the aggregated contributors by contributor and calculates total contributions by unique pairs. + Helper function that aggregates contributions by contributor, and then + uses the aggregated contributors by contributor and calculates total + contributions by unique pairs. Args: from translate_data: @@ -93,14 +96,15 @@ def aggregate_contributions(grant_contributions): ''' - Helper function that runs the pairwise clr formula while "binary" searching for the correct threshold. + Helper function that runs the pairwise clr formula while "binary" + searching for the correct threshold. Args: set variables: lower_bound: set at 0.0 total_pot: set at 100000.0 - + from the helper function aggregate_contributions: aggregated_contributions: {grant_id (str): {user_id (str): aggregated_amount (float)}} pair_totals: {user_id (str): {user_id (str): pair_total (float)}} @@ -109,7 +113,7 @@ def aggregate_contributions(grant_contributions): bigtot: should equal total pot totals: clr totals ''' -def iter_threshold(aggregated_contributions, pair_totals, lower_bound=0.0, total_pot=100000.0): +def iter_threshold(aggregated_contributions, pair_totals, lower_bound=0.0, total_pot=100000.0): lower = lower_bound upper = total_pot iterations = 0 @@ -117,8 +121,8 @@ def iter_threshold(aggregated_contributions, pair_totals, lower_bound=0.0, total threshold = (lower + upper) / 2 iterations += 1 if iterations == 100: - print("--- %s seconds ---" % (time.time() - start_time)) - print(f'iterations reached, bigtot at {bigtot}') + # print("--- %s seconds ---" % (time.time() - start_time)) + # print(f'iterations reached, bigtot at {bigtot}') break bigtot = 0 totals = [] @@ -128,24 +132,20 @@ def iter_threshold(aggregated_contributions, pair_totals, lower_bound=0.0, total for k1, v1 in contribz.items(): for k2, v2 in contribz.items(): if k2 > k1: # remove pairs - # # pairwise matching formula - # tot += (v1 * v2) ** 0.5 * min(1, threshold / pair_totals[k1][k2]) - # vitalik's division formula tot += ((v1 * v2) ** 0.5) / (pair_totals[k1][k2] / threshold + 1) bigtot += tot - # totals.append((proj, tot)) totals.append({'id': proj, 'clr_amount': tot}) # print(f'threshold {threshold} yields bigtot {bigtot} vs totalpot {total_pot} at iteration {iterations}') if bigtot == total_pot: - print("--- %s seconds ---" % (time.time() - start_time)) - print(f'bigtot {bigtot} = total_pot {total_pot} with threshold {threshold}') - print(totals) + # print("--- %s seconds ---" % (time.time() - start_time)) + # print(f'bigtot {bigtot} = total_pot {total_pot} with threshold {threshold}') + # print(totals) break elif bigtot < total_pot: lower = threshold elif bigtot > total_pot: upper = threshold - return bigtot, totals + return bigtot, totals '''