예제 #1
0
def get_predictions():
    '''Function that runs once a week to calculte new predictions on the current data and stores the predictions on a Postgres DB.'''

    now = datetime.now()
    current_time = now.strftime("%H:%M:%S")
    print('UPDATING PREDICTION DATA ' + str(datetime.today()) + ' AT ' +
          str(current_time) + "\n\n\n")
    df = __get_data()
    location_list = hf.get_df_by_location(df)
    location_list = hf.format_dfs_for_prediction(location_list)
    tampa_prediction = hf.get_prediction(location_list[0])
    st_pete_prediction = hf.get_prediction(location_list[1])
    health_prediction = hf.get_prediction(location_list[2])
    # sarasota_prediction = hf.get_prediction(location_list[3])

    new_df = pd.merge(tampa_prediction, st_pete_prediction, on=['ds'])
    new_df = pd.merge(new_df, health_prediction, on=['ds'])
    # new_df = pd.merge(new_df, sarasota_prediction, on=['ds'])
    new_df = new_df.rename(
        columns={
            'ds': 'DS',
            'yhat_x': 'YHAT_TAMPA',
            'yhat_y': 'YHAT_ST_PETE',
            'yhat': 'YHAT_HEALTH'
        })
    new_df.to_sql('prediction',
                  con=db.engine,
                  if_exists='replace',
                  index=False)
예제 #2
0
def create_general_graphs(data, graph_type):
    df = hf.string_to_df(data)
    prediction_df = pd.read_sql_table('prediction', con=db.engine)
    df['dates'] = df['dates'].apply(lambda date: datetime.strptime(date, "%B %d %Y"))

    location_list = hf.get_daily_cases_by_location(hf.get_df_by_location(df))
    prediction_list = hf.get_prediction_by_location(prediction_df)

    return dict(data=gg.generate_daily_bar_graph(location_list),
                layout=gg.generate_bar_layout('Daily Cases on USF Campuses', 'group')), \
           dict(data=gg.generate_total_scatter(graph_type, location_list, prediction_list),
                layout=gg.general_graph_layout('Total Cases USF Campuses'))
예제 #3
0
def update_cards(data):
    df = hf.string_to_df(data)

    dfs_by_location = hf.get_df_by_location(df)
    total_cases_tampa, total_cases_st_pete, total_cases_health = hf.get_total_cases_by_location(dfs_by_location)
    daily_cases_tampa, daily_cases_st_pete, daily_cases_tampa_health = hf.get_daily_cases_by_location(
        dfs_by_location)

    return str(total_cases_tampa), \
           str(total_cases_health), \
           str(total_cases_st_pete), \
           hf.create_daily_cases_str(daily_cases_tampa), \
           hf.create_daily_cases_str(daily_cases_tampa_health), \
           hf.create_daily_cases_str(daily_cases_st_pete), \
예제 #4
0
def updateCards(data):
    try:
        df = hf.string_to_df(data)

        # Get for each location
        dfByLocation = hf.get_df_by_location(df)

        # Get total cases for each location
        totalCasesTampa, totalCasesStPete, totalCasesHealth, totalCasesSarasota = hf.get_total_cases_by_location(
            dfByLocation)

        # Get daily cases for each location
        dailyCasesTampa, dailyCasesStPete, dailyCasesHealth, dailyCasesSarasota = hf.get_daily_cases_by_location(
            dfByLocation)

        return totalCasesTampa + ' cases', totalCasesHealth + ' cases',totalCasesStPete + ' cases',\
            hf.create_daily_cases_string(dailyCasesTampa), hf.create_daily_cases_string(dailyCasesHealth),\
            hf.create_daily_cases_string(dailyCasesStPete), totalCasesSarasota + ' cases',\
            hf.create_daily_cases_string(dailyCasesSarasota)

    except Exception as e:
        print('updateCards: ', e)
        raise PreventUpdate