示例#1
0
def build_transfers_timeline(df_opt_pre, df_opt_post, p1, p2, p3):
    df_opt_post.loc[:, 'Date'] = pd.to_datetime(df_opt_post['Date'],
                                                format='y%m%d').dt.date
    timeline_cols = ["Date", "Shortage"]
    df_opt_pre = df_opt_pre.loc[df_opt_pre.State == 'US']
    df_opt_pre = df_opt_pre[timeline_cols]

    no_model_visual = get_no_model_visual()
    model_visual = get_model_visual()

    df_opt_pre.columns = ["Date", no_model_visual["Shortage"]]

    df_opt_post = df_opt_post.loc[
                                    (df_opt_post.State == 'US') & \
                                    (df_opt_post.Param1==float(p1)) & \
                                    (df_opt_post.Param2==float(p2)) & \
                                    (df_opt_post.Param3==float(p3))
                                ]

    df_opt_post = df_opt_post[timeline_cols]
    df_opt_post.columns = ["Date", model_visual["Shortage"]]

    df_opt_effect = pd.merge(df_opt_pre, df_opt_post, on='Date', how='inner')

    return us_timeline(df_opt_effect, "Optimization Effect on Shortage", True)
示例#2
0
def build_transfers_timeline(chosen_model,p1,p2,p3):
    if chosen_model == "Washington IHME":
        df_opt_pre, _ = get_df_mod1_projections()
        df_opt_post = pd.read_csv('data/predicted_ventilator/state_supplies_table-ihme.csv', sep=",", parse_dates = ['Date'])
    else:
        df_opt_pre = get_df_mod2_projections()
        df_opt_post = pd.read_csv('data/predicted_ventilator/state_supplies_table-ode.csv', sep=",", parse_dates = ['Date'])

    df_opt_post.loc[:,'Date'] = pd.to_datetime(df_opt_post['Date'], format='y%m%d').dt.date
    timeline_cols = ["Date","Shortage"]
    df_opt_pre = df_opt_pre.loc[df_opt_pre.State == 'US']
    df_opt_pre = df_opt_pre[timeline_cols]

    no_model_visual = get_no_model_visual()
    model_visual = get_model_visual()

    df_opt_pre.columns = ["Date",no_model_visual["Shortage"]]

    df_opt_post = df_opt_post.loc[
                                    (df_opt_post.State == 'US') & \
                                    (df_opt_post.Param1==float(p1)) & \
                                    (df_opt_post.Param2==float(p2)) & \
                                    (df_opt_post.Param3==float(p3))
                                ]

    df_opt_post = df_opt_post[timeline_cols]
    df_opt_post.columns = ["Date",model_visual["Shortage"]]

    df_opt_effect = pd.merge(df_opt_pre,df_opt_post,on='Date',how='inner')

    return us_timeline(df_opt_effect,"Optimization Effect on Shortage",True)
示例#3
0
def build_shortage_map(chosen_model, chosen_date, val):
    if chosen_model == "Washington IHME":
        df_map, _ = get_df_mod1_projections()
    else:
        df_map = get_df_mod2_projections()
    no_model_visual = get_no_model_visual()
    return us_map(df_map, chosen_date, val, no_model_visual)
 def update_shortage_map(chosen_model,chosen_date,val):
     if chosen_model == "Washington IHME":
         df_map = df_mod1_projections
     else:
         df_map = df_mod2_projections
     no_model_visual = get_no_model_visual()
     return us_map(df_map,chosen_date,val,no_model_visual)
def get_shortage():
    firstDate = get_first_date()
    _, params = get_df_mod1_projections(True)
    state_cols = ["Shortage", "Supply", "Demand"]
    no_model_visual = get_no_model_visual()
    # Defines the top of the page, where the current situation is displayed (no optimization yet)
    shortage = \
        [dbc.Row(
            [
                dbc.Col(
                [
                    dbc.Alert("The total ventilator supply in the US exceeds projected demand, \
                    but imbalanced demand from local 'hot spots' leads to shortages."                                                                                     , color="danger"),
                ]
                )
            ]
        )] + \
        [dbc.Row(
            [
                dbc.Col(
                [
                    html.Div(
                        id = 'us_ventilator_graph',
                        children = [],
                        style={
                            'width': '100%',
                            'display': 'inline-block',
                            }
                    ),
                ],
                xs=12,
                sm=12,
                md=6,
                lg=6,
                ),
                dbc.Col(
                [
                    html.Div(
                        id = 'us_map_projections_vent',
                        children = [],
                        style={
                            'width': '100%',
                            'display': 'inline-block',
                            }
                    ),
                    dbc.Row(
                        [
                            dbc.Col(
                            [
                                html.H6('Date:',id="date-projections"),
                                html.Div(
                                    dcc.DatePickerSingle(
                                        id='us-map-date-picker-range-vent',
                                        min_date_allowed=params[0],
                                        max_date_allowed=params[1],
                                        date=firstDate,
                                        initial_visible_month=firstDate,
                                        style={'marginBottom':20}
                                    ),
                                    id="date-projections-picker-div"
                                ),
                            ],
                            xs=12,
                            sm=4,
                            md='auto',
                            lg='auto',
                            ),
                            dbc.Col(
                            [
                                html.H6('Plotted Value:',id="date-projections"),
                                html.Div(
                                    dcc.Dropdown(
                                        id = 'us_map_dropdown-vent',
                                        options = [{'label': no_model_visual[x], 'value': x} for x in state_cols],
                                        value = 'Shortage',
                                        style={'marginBottom':20}
                                    ),
                                ),
                            ],
                            xs=12,
                            sm=8,
                            md=True,
                            lg=True,
                            )
                        ]
                    ),
                ],
                xs=12,
                sm=12,
                md=6,
                lg=6,
                ),
            ]
        )
    ]
    return shortage
示例#6
0
def get_shortage():
    df = pd.read_csv(
        'data/predicted_ventilator/state_supplies_table_baseline-ihme.csv',
        sep=",",
        parse_dates=['Date'])
    df.loc[:, 'Date'] = pd.to_datetime(df['Date'], format='y%m%d').dt.date
    min_shortage_date = min(df.Date.values)
    max_shortage_date = max(df.Date.values)
    del df

    firstDate = get_first_date()
    state_cols = ["Shortage", "Supply", "Demand"]
    no_model_visual = get_no_model_visual()

    # Defines the top of the page, where the current situation is displayed (no optimization yet)
    shortage = \
        [dbc.Row(
            [
                dbc.Col(
                [
                    dbc.Alert("The total ventilator supply in the US exceeds projected demand, \
                    but imbalanced demand from local 'hot spots' leads to shortages."                                                                                     , color="danger"),
                ]
                )
            ]
        )] + \
        [dbc.Row(
            [
                dbc.Col(
                [
                    html.Div(
                        id = 'us_ventilator_graph',
                        children = [],
                        style={
                            'width': '100%',
                            'display': 'inline-block',
                            }
                    ),
                ],
                xs=12,
                sm=12,
                md=6,
                lg=6,
                ),
                dbc.Col(
                [
                    html.Div(
                        id = 'us_map_projections_vent',
                        children = [],
                        style={
                            'width': '100%',
                            'display': 'inline-block',
                            }
                    ),
                    dbc.Row(
                        [
                            dbc.Col(
                            [
                                html.H6('Date:',id="date-projections"),
                                html.Div(
                                    dcc.DatePickerSingle(
                                        id='us-map-date-picker-range-vent',
                                        min_date_allowed=min_shortage_date,
                                        max_date_allowed=max_shortage_date,
                                        date=firstDate,
                                        initial_visible_month=firstDate,
                                        style={'marginBottom':20}
                                    ),
                                    id="date-projections-picker-div"
                                ),
                            ],
                            xs=12,
                            sm=4,
                            md='auto',
                            lg='auto',
                            ),
                            dbc.Col(
                            [
                                html.H6('Plotted Value:',id="date-projections"),
                                html.Div(
                                    dcc.Dropdown(
                                        id = 'us_map_dropdown-vent',
                                        options = [{'label': no_model_visual[x], 'value': x} for x in state_cols],
                                        value = 'Shortage',
                                        style={'marginBottom':20}
                                    ),
                                ),
                            ],
                            xs=12,
                            sm=8,
                            md=True,
                            lg=True,
                            )
                        ]
                    ),
                ],
                xs=12,
                sm=12,
                md=6,
                lg=6,
                ),
            ]
        )
    ]
    return shortage