Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding up budget-not-provided separately #537 #555

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions forwardlooking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
this_year = datetime.date.today().year

# Create a list containing three years: the current year and two following
years = map(str, range(this_year, this_year+3))
years = map(str, range(this_year, this_year + 3))

# Set column groupings, to be displayed in the user output
column_headers = [
column_headers = [
'Current activities at the start of each year',
'Current activities with budgets for each year',
'Percentage of current activities with budgets'
]

def generate_row(publisher):
"""Generate forward-looking table data for a given publisher
"""Generate forward-looking table data for a given publisher
"""

# Store the data for this publisher as a new variable
publisher_stats = get_publisher_stats(publisher)

# Create a list for publisher data, and populate it with basic data
row = {}
row['publisher'] = publisher
Expand All @@ -33,34 +33,35 @@ def generate_row(publisher):
by_hierarchy = publisher_stats['by_hierarchy']
hierarchies_with_nonzero_budgets = [
h for h, stats in by_hierarchy.items()
if not all(x==0 for x in stats['forwardlooking_activities_with_budgets'].values())
if not all(x == 0 for x in stats['forwardlooking_activities_with_budgets'].values())
]

# Flag if budgets on current activities are reported at more than one hierarchy
row['flag'] = len(hierarchies_with_nonzero_budgets) > 1

hierarchies_with_budget_not_provided = [
h for h, stats in by_hierarchy.items()
if not all(x==0 for x in stats['forwardlooking_activities_with_budget_not_provided'].values())
if not all(x == 0 for x in stats['forwardlooking_activities_with_budget_not_provided'].values())
]

# Loop over each of the three years (i.e. this year and the following two years) to generate the statistics for the table
for year in years:

forwardlooking_budget = 'forwardlooking_activities_with_budgets'
if(len(hierarchies_with_budget_not_provided) > 0):
forwardlooking_budget = 'forwardlooking_activities_with_budget_not_provided'
row['budget_not_provided'] = True
# If 'forwardlooking_activities_current' and 'forwardlooking_activities_with_budgets' are both in the bottom hierarchy
if 'forwardlooking_activities_current' in publisher_stats['bottom_hierarchy'] and forwardlooking_budget in publisher_stats['bottom_hierarchy'] :
# If 'forwardlooking_activities_current' and 'forwardlooking_activities_with_budgets' or 'forwardlooking_activities_with_budget_not_provided' are in the bottom hierarchy
if 'forwardlooking_activities_current' in publisher_stats['bottom_hierarchy'] and ('forwardlooking_activities_with_budgets' in publisher_stats['bottom_hierarchy'] or 'forwardlooking_activities_with_budget_not_provided' in publisher_stats['bottom_hierarchy']):
if len(hierarchies_with_nonzero_budgets) != 1:
# If budgets are at more than one hierarchy (or no hierarchies), just use activities at all hierarchies
row['year_columns'][0][year] = publisher_stats['forwardlooking_activities_current'].get(year) or 0
row['year_columns'][1][year] = publisher_stats[forwardlooking_budget].get(year) or 0
row['year_columns'][1][year] = publisher_stats['forwardlooking_activities_with_budgets'].get(year) or 0
if row['budget_not_provided']:
row['year_columns'][1][year] += publisher_stats['forwardlooking_activities_with_budget_not_provided'].get(year) or 0
else:
# 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_budget].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 row['budget_not_provided']:
by_hierarchy[hierarchies_with_nonzero_budgets[0]]['forwardlooking_activities_with_budget_not_provided'].get(year) or 0
Copy link
Contributor

@andylolz andylolz Jun 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something doesn’t look quite right here – there’s no equals sign on this line. Presumably this is supposed to say:

row['year_columns'][1][year] +=

…or similar?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this has been addressed in #556.


if not int(row['year_columns'][0][year]):
row['year_columns'][2][year] = '-'
Expand Down