def get_organizations_indexed_by_name():
    """
    Load organizations from FTS and change index to be name, as sadly that's what is used in
    other API calls, so we need to join on it.
    This is a slow call, so it makes sense to cache it.
    """
    organizations = fts_queries.fetch_organizations_json_as_dataframe()
    return organizations.set_index('name')
def get_organizations_indexed_by_name():
    """
    Load organizations from FTS and change index to be name, as sadly that
    string is used in other API results (not id), so we need to join on it.
    This is a slow call, so it makes sense to cache it.
    """
    organizations = fts_queries.fetch_organizations_json_as_dataframe()
    return organizations.set_index('name')
Esempio n. 3
0
def produce_organizations_csv(output_dir):
    organizations = fts_queries.fetch_organizations_json_as_dataframe()
    write_dataframe_to_csv(organizations, build_csv_path(output_dir, 'organizations'))
Take in an appeal ID and generate a report on funding by appealing agency type (roughly CHD items FY180 through FY210)
Appealing Org Type
Funding USD - contributions + commitments, including carry-over from previous year
"""

import fts_queries
import argparse
import sys

parser = argparse.ArgumentParser(description='Produce a report on funding by agency type for a given appeal')
parser.add_argument('appeal_id', type=int)
args = parser.parse_args()
appeal_id = args.appeal_id

# load organizations dataset
organizations = fts_queries.fetch_organizations_json_as_dataframe()
# we'll be joining on name (sadly) so make that the index
organizations = organizations.set_index('name')
# extract out the types Series
organizations_type = organizations.type

# query funding, which includes "carry over" from previous years
funding_by_recipient =\
    fts_queries.fetch_funding_json_for_appeal_as_dataframe(appeal_id, grouping='Recipient', alias='organisation')

# join the funding with the organization type
joined = funding_by_recipient.join(organizations_type)

# now roll up by organization type
aggregated = joined.groupby('type').sum()