Пример #1
0
def test_file_upload(get_file, m, test_app):
    with test_app.app_context():
        files = [
            'sample-data/ExampleTrust-grants-fixed.json',
            'sample-data/ExampleTrust-grants-fixed.xlsx',
            'sample-data/ExampleTrust-grants-fixed.csv',
        ]
        for filename in files:
            salt = ''.join(
                random.choices(string.ascii_uppercase + string.digits, k=6))
            with open(get_file(filename), 'rb') as a:
                fileid, return_filename = get_dataframe_from_file(filename,
                                                                  a.read(),
                                                                  date=salt)
                assert isinstance(fileid, str)
                assert return_filename == filename

            df = get_from_cache(fileid)
            assert isinstance(df, pd.DataFrame)
            assert len(df) > 0

            metadata = get_metadata_from_cache(fileid)
            assert len(metadata.keys()) == 5
            assert isinstance(metadata["expires"], str)

            delete_from_cache(fileid)
Пример #2
0
def dashboard_output(fileid, *args):
    filter_args = dict(zip(FILTERS.keys(), args))
    df = get_filtered_df(fileid, **filter_args)
    logging.debug("dashboard_output", fileid, df is None)

    metadata = get_metadata_from_cache(fileid)

    if df is None:
        return [
            html.H1(
                html.Span("Dataset not found",
                          className="results-page__body__content__date"),
                    className="results-page__body__content__header"),
            html.P(([
                html.A("Try to fetch this file", href="/?fetch={}".format(fileid)),
                " or "
            ] if fileid else []) + [
                html.A("Go to homepage",
                       href="/"),
            ], className="results-page__body__section-description"),
        ]

    if len(df) == 0:
        return html.Div('No grants meet criteria')

    outputs = []
    
    outputs.extend(get_funder_output(df, filter_args.get("grant_programmes")))
    outputs.append(get_statistics(df))
    outputs.extend(get_file_output(metadata))

    charts = []
    
    charts.append(funder_chart(df))
    charts.append(amount_awarded_chart(df))
    charts.append(grant_programme_chart(df))
    charts.append(awards_over_time_chart(df))
    charts.append(organisation_type_chart(df))
    # charts.append(org_identifier_chart(df))
    charts.append(region_and_country_chart(df))
    charts.append(location_map(
        df,
        app.server.config.get("MAPBOX_ACCESS_TOKEN"),
        app.server.config.get("MAPBOX_STYLE")
    ))
    charts.append(organisation_age_chart(df))
    charts.append(organisation_income_chart(df))
    # charts.append(imd_chart(df))

    outputs.extend(charts)

    return outputs
Пример #3
0
def test_file_fetch_from_url(get_file, m, test_app):
    with test_app.app_context():
        test_urls = [
            'https://findthatcharity.uk/grants/grants.json',
            'https://findthatcharity.uk/grants/grants.xlsx',
            'https://findthatcharity.uk/grants/grants.csv',
        ]

        for url in test_urls:
            fileid, return_filename, headers = get_dataframe_from_url(url)
            assert isinstance(fileid, str)
            assert return_filename == url

            df = get_from_cache(fileid)
            assert isinstance(df, pd.DataFrame)
            assert len(df) > 0

            metadata = get_metadata_from_cache(fileid)
            assert len(metadata.keys()) == 6
            assert metadata["url"] == url

            delete_from_cache(fileid)
Пример #4
0
def dashboard_output(fileid, *args):
    filter_args = dict(zip(FILTERS.keys(), args))
    df = get_filtered_df(fileid, **filter_args)

    metadata = get_metadata_from_cache(fileid)
    className = "results-page__body__content"

    if df is None:
        return (
            [
                html.H1(
                    html.Span(
                        "Dataset not found",
                        className="results-page__body__content__date",
                    ),
                    className="results-page__body__content__header",
                ),
                html.P(
                    ([
                        html.A(
                            "Try to fetch this file",
                            href="/?fetch={}".format(fileid),
                        ),
                        " or ",
                    ] if fileid else []) + [
                        html.A("Go to homepage", href="/"),
                    ],
                    className="results-page__body__section-description",
                ),
            ],
            None,
            className,
        )

    whatsnext = what_next_missing_fields(df, fileid)

    if len(df) == 0:
        return (html.Div("No grants meet criteria"), whatsnext, className)

    # if tabid == 'giving-map':
    #     return [
    #         get_funder_output(df, filter_args.get("grant_programmes")) + [
    #             location_map_iframe(fileid, filter_args),
    #             # imd_chart(df),
    #         ],
    #         None,
    #         className + ' giving-map'
    #     ]

    outputs = []

    outputs.extend(get_funder_output(df, filter_args.get("grant_programmes")))
    outputs.extend(get_statistics_output(df))
    outputs.extend(get_file_output(metadata))

    charts = []

    charts.append(funder_chart(df))
    charts.append(amount_awarded_chart(df))
    charts.append(grant_programme_chart(df))
    charts.append(awards_over_time_chart(df))
    charts.append(organisation_type_chart(df))
    # charts.append(org_identifier_chart(df))
    charts.append(region_and_country_chart(df))
    charts.append(location_map_iframe(fileid, filter_args))
    # charts.append(location_map(
    #     df,
    #     app.server.config.get("MAPBOX_ACCESS_TOKEN"),
    #     app.server.config.get("MAPBOX_STYLE")
    # ))
    charts.append(organisation_age_chart(df))
    charts.append(organisation_income_chart(df))
    # charts.append(imd_chart(df))

    outputs.extend(charts)

    return (outputs, whatsnext, className)