Skip to content

Commit

Permalink
[#403] Amend publisher statistics calculations to round to the neares…
Browse files Browse the repository at this point in the history
…t integer
  • Loading branch information
dalepotter committed May 24, 2016
1 parent 0990f98 commit d0bc7d6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
16 changes: 12 additions & 4 deletions comprehensiveness.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,23 @@ def generate_row(publisher):

if denominator(slug, publisher_base) != 0:
# Populate the row with the %age
row[slug] = int(float(numerator_all)/denominator(slug, publisher_base)*100)
row[slug+'_valid'] = int(float(numerator_valid)/denominator(slug, publisher_base)*100)
row[slug] = int(round(
float(numerator_all)/denominator(slug, publisher_base)*100
))
row[slug+'_valid'] = int(round(
float(numerator_valid)/denominator(slug, publisher_base)*100
))

# Loop for averages
# Calculate the average for each grouping, and the overall 'summary' average
for page in ['core', 'financials', 'valueadded', 'summary']:
# Note that the summary must be last, so that it can use the average calculations from the other groupings
row[page+'_average'] = sum((row.get(x[0]) or 0)*x[2] for x in columns[page]) / sum(x[2] for x in columns[page])
row[page+'_average_valid'] = sum((row.get(x[0]+'_valid') or 0)*x[2] for x in columns[page]) / sum(x[2] for x in columns[page])
row[page+'_average'] = int(round(
sum((row.get(x[0]) or 0)*x[2] for x in columns[page]) / float(sum(x[2] for x in columns[page]))
))
row[page+'_average_valid'] = int(round(
sum((row.get(x[0]+'_valid') or 0)*x[2] for x in columns[page]) / float(sum(x[2] for x in columns[page]))
))

return row

Expand Down
2 changes: 1 addition & 1 deletion coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def generate_row(publisher):
spend_ratio_candidates.append((row['iati_spend_2015'] / row['reference_spend_2014']) if (row['reference_spend_2014'] > 0) and is_number(row['reference_spend_2014']) else 0)

# Get the maximum value and convert to a percentage
row['spend_ratio'] = int(max(spend_ratio_candidates) * 100)
row['spend_ratio'] = int(round(max(spend_ratio_candidates) * 100))


# Compute coverage score and raise to the top of its quintile
Expand Down
1 change: 1 addition & 0 deletions forwardlooking.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def generate_row(publisher):
# Else, use the hierarchy which they are reported at
row['year_columns'][0][year] = by_hierarchy[hierarchies_with_nonzero_budgets[0]]['forwardlooking_activities_current'].get(year) or 0
row['year_columns'][1][year] = by_hierarchy[hierarchies_with_nonzero_budgets[0]]['forwardlooking_activities_with_budgets'].get(year) or 0

if not int(row['year_columns'][0][year]):
row['year_columns'][2][year] = '-'
else:
Expand Down
8 changes: 4 additions & 4 deletions transparencyindicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def table():
timelag_score = 0

# Compute the percentage
row['timeliness'] = int( (float(frequency_score + timelag_score) / 8) * 100 )
row['timeliness'] = int( round((float(frequency_score + timelag_score) / 8) * 100))


# Compute forward-looking statistic
Expand All @@ -98,7 +98,7 @@ def table():
numbers = [ int(x) for x in publisher_forwardlooking_data['year_columns'][2].itervalues() if is_number(x) ]

# Compute and store the mean average for these fields
row['forwardlooking'] = sum(int(y) for y in numbers) / len(publisher_forwardlooking_data['year_columns'][2])
row['forwardlooking'] = sum(int(round(y)) for y in numbers) / len(publisher_forwardlooking_data['year_columns'][2])


# Compute comprehensive statistic
Expand All @@ -110,7 +110,7 @@ def table():


# Compute score
row['score'] = int( (row['timeliness'] + row['forwardlooking'] + row['comprehensive']) / 3 )
row['score'] = int( round(float(row['timeliness'] + row['forwardlooking'] + row['comprehensive']) / 3 ))


# Get coverage statistic
Expand All @@ -122,7 +122,7 @@ def table():


# Compute coverage-adjusted score
row['score_coverage_adjusted'] = int( row['score'] * (row['coverage_adjustment'] / float(100)) )
row['score_coverage_adjusted'] = int( round(row['score'] * (row['coverage_adjustment'] / float(100))) )


# Return a generator object
Expand Down

0 comments on commit d0bc7d6

Please sign in to comment.