Beispiel #1
0
def refresh_data_store(vault_password: Optional[str] = None) -> None:
    """When run, this function runs all the functions that compose the data
    store. The app itself should not be running this function; in fact, this
    function will raise an error if the app is turned on. This should only be
    run from the command line or a Python console.
    """
    os.environ['OFFLINE_MODE'] = 'false'
    if vault_password:
        os.environ['VAULT_PASSWORD'] = vault_password

    from flask import current_app
    if current_app:
        raise Exception('The app should not be running when the data store is '
                        'being refreshed.')

    from flagging_site.data.keys import get_data_store_file_path

    from flagging_site.data.hobolink import get_live_hobolink_data
    from flagging_site.data.hobolink import STATIC_FILE_NAME as hobolink_file
    get_live_hobolink_data('code_for_boston_export_21d')\
        .to_pickle(get_data_store_file_path(hobolink_file))

    from flagging_site.data.usgs import get_live_usgs_data
    from flagging_site.data.usgs import STATIC_FILE_NAME as usgs_file
    get_live_usgs_data().to_pickle(get_data_store_file_path(usgs_file))
Beispiel #2
0
def test_model_output_api_parameters(app):
    """test_model_output_api_parameters() should test that hours=10 returns 10 rows of data,
    that setting the reach returns only that reach."""
    with app.app_context():
        df = reach_2_model(process_data(df_usgs=get_live_usgs_data(), df_hobolink=get_live_hobolink_data('code_for_boston_export_21d')), 10)
        row_count = len(df)
        assert row_count == 10
        test_reach = model_api([3], 10)
        test_reach = list(test_reach.values())
        expected_reach = list(test_reach[2].items())[0][0]
        assert 'reach_3' == expected_reach
Beispiel #3
0
def test_usgs_data_is_recent(app):
    with app.app_context():
        df = get_live_usgs_data()
        last_timestamp = df['time'].iloc[-1]
        time_difference = (pd.to_datetime('today') - last_timestamp)
        assert time_difference < pd.Timedelta(hours=2)