def display_state_deaths(clickData, date_choice, state_dropdown):
     # Get states historic data 
    states_historic_df = pd.read_csv(config['historic_loc'])
    states_historic_df['dates_dt'] = pd.to_datetime(states_historic_df['date'], format='%Y%m%d')
    states_historic_df = utils.date_filter(states_historic_df, date_choice)

    changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0]
    # Show the California plot as the default plot if there is no click is recorded on the US map
    if 'main-choro.clickData' not in changed_id and 'states-dropdown.value' not in changed_id :
        perday_state = states_historic_df[states_historic_df['state'] == 'CA']
        title = "Daily Death counts for {}".format("California")
        deaths_fig = px.bar(perday_state,
                            x='dates_dt', 
                            y='deathIncrease', 
                            labels={"deathIncrease":"Total Number of new deaths",
                                        "dates_dt" : "Time"},
                            title=title)
        deaths_fig.update_xaxes(nticks=20)
        deaths_fig.update_layout(dict(paper_bgcolor=config['paper_color'],
                                         plot_bgcolor=config['plot_color'],
                                         font_color="white" ))
        deaths_fig.update_traces(marker_color=config['bar_color'],  marker_line_color=config['marker_line_color'])                            
        deaths_fig.update_xaxes(nticks=20, showgrid=False, gridcolor='grey', mirror=True, gridwidth=1, linecolor='grey', linewidth=3,  zeroline= True)
        deaths_fig.update_yaxes(showgrid=False, gridcolor='grey',  mirror=True, gridwidth=0.1, linecolor='grey', linewidth=3,  zeroline= True)
            
        state_fig = deaths_fig
    else: 
        if 'main-choro.clickData' not in changed_id: 
            single_state = us.states.lookup(state_dropdown).abbr
        else:
            single_state = clickData['points'][0]['location']
        
        states_historic_df = pd.read_csv(config['historic_loc'])
        states_historic_df['dates_dt'] = pd.to_datetime(states_historic_df['date'], format='%Y%m%d')
        states_historic_df = utils.date_filter(states_historic_df, date_choice)

        perday_state = states_historic_df[states_historic_df['state'] == single_state]
        title = "Death counts for {}".format(str(us.states.lookup(single_state)))
        state_fig = px.bar(perday_state, 
                        x='dates_dt', 
                        y='deathIncrease', 
                        labels={"deathIncrease":"Total Number of new deaths",
                                    "dates_dt" : "Time"},
                        title=title)
        state_fig.update_xaxes(nticks=20)
        state_fig.update_layout(dict(paper_bgcolor=config['paper_color'],
                                         plot_bgcolor=config['plot_color'],
                                         font_color="white" ))
        state_fig.update_traces(marker_color=config['bar_color'],  marker_line_color=config['marker_line_color'])                            
        state_fig.update_xaxes(nticks=20, showgrid=False, gridcolor='grey', mirror=True, gridwidth=1, linecolor='grey', linewidth=3,  zeroline= True)
        state_fig.update_yaxes(showgrid=False, gridcolor='grey',  mirror=True, gridwidth=0.1, linecolor='grey', linewidth=3,  zeroline= True)
                
    return state_fig
def county_deaths(county_click, state_click, date_choice, county_dropdown): 
    changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0]
    if 'counties-dropdown.value' in changed_id:
        single_county = county_dropdown
    else: 
        single_county = county_click['points'][0]['location']
    
    if state_click['points']: 
        single_state = state_click['points'][0]['location']
        county_cum_cases, county_day_cases = utils.county_cases_deaths(single_county, single_state, cases=False)
        county_day_cases = utils.date_filter(county_day_cases, date_choice)
        figure = utils.plot_county_data(county_day_cases, single_county, single_state, cases=False, cumulative=False)
    return figure
def render_confirmed(tab, date_choice):
    
    overall_us_df = pd.read_csv(config['overall_loc'])
    overall_us_df['dates_dt'] = pd.to_datetime(overall_us_df['date'], format='%Y%m%d')
    overall_us_df = utils.date_filter(overall_us_df, date_choice)
    
    if tab == 'tab-1':
        dc_fig = px.bar(overall_us_df, 
                        x='dates_dt', 
                        y='positiveIncrease', 
                        labels={"positiveIncrease":"Total Number of new cases",
                                "dates_dt" : "Time"},
                        title='New cases per day for US')
        dc_fig.update_xaxes(nticks=20, showgrid=False, gridcolor='grey', mirror=True, gridwidth=1, linecolor='grey', linewidth=3,  zeroline= True)
        dc_fig.update_yaxes(showgrid=False, gridcolor='grey',  mirror=True, gridwidth=0.1, linecolor='grey', linewidth=3,  zeroline= True)

        dc_fig.update_layout(dict(paper_bgcolor=config['paper_color'],
                                         plot_bgcolor=config['plot_color'],
                                         font_color="white" ))
        dc_fig.update_traces(marker_color=config['bar_color'], marker_line_color=config['marker_line_color'])                            
        return dc_fig
    elif tab == 'tab-2':
        dc_fig = px.scatter(overall_us_df, 
                        x='dates_dt', 
                        y='positive', 
                        labels={"positive":"Cumulative total number of cases",
                                "dates_dt" : "Time"},
                        title='New cases per day for US')
        dc_fig.update_xaxes(nticks=20)
        dc_fig.update_traces(marker_color=config['bar_color'],
                             marker_line_color=config['marker_line_color'], marker_size=config['marker_size'])                            
        dc_fig.update_xaxes(nticks=20, showgrid=True, gridcolor='grey', mirror=True, gridwidth=1, linecolor='grey', linewidth=3,  zeroline= True)
        dc_fig.update_yaxes(showgrid=True, gridcolor='grey', mirror=True, gridwidth=0.1, linecolor='grey', linewidth=3, zeroline= True)

        dc_fig.update_layout(dict(paper_bgcolor=config['paper_color'],
                                         plot_bgcolor=config['plot_color'],
                                         font_color="white" ))
        return dc_fig
예제 #4
0
incr_days = 30
diter = utils.date_iterator(first=start_date,
                            last=end_date,
                            incr_days=incr_days)

fulldf = pd.DataFrame()
prevfull = pd.DataFrame(
    columns=['name', 'gempermid', 'pctchouthld', 'state', 'pct'])
prev_date = start_date - datetime.timedelta(incr_days)
evlist = []
for date in diter:
    print(date)
    datedf = pd.DataFrame()
    newev = dict()
    ev = utils.date_filter(df=events,
                           date_col="date",
                           start=prev_date,
                           end=date)
    if ev.shape[0] == 0:
        continue
    ev.sort_values(by="date", inplace=True)
    ev.drop_duplicates(subset=['name', 'gempermid'], inplace=True)
    for idx, ser in ev.iterrows():
        name = ser['name']
        cid = ser['gempermid']
        pct = ser['pctshouthld']
        key = (name, cid)
        newev = dict(name=name, gempermid=cid, pct=pct, date=date)
        try:
            temp = prevfull[np.logical_and(prevfull.name == name,
                                           prevfull.gempermid == cid)]
            lastev = (dict() if temp.shape[0] == 0 else
예제 #5
0
end_date = datetime.date(2018, 1, 1)

incr_days = 30
diter = utils.month_iterator(first=start_date, last=end_date)

lastdf = pd.DataFrame(columns= names + ["end_date"],
                      index = gids)
for name in names:
    for gid in gids:
        lastdf[name].ix[gid] = ("none_init", 0.0)

dflist = []
for start_date in diter:
    print (start_date)
    end_date = utils.add_months(start_date, n=1)
    ev = utils.date_filter(df=events, date_col="date", start=start_date,
                       end=end_date)
    if ev.shape[0] == 0:
        continue
    ev.sort_values(by="date", inplace=True)
    ev.drop_duplicates(subset=['name', 'gempermid'], inplace=True)

    thisdf = pd.DataFrame(columns=names + ["end_date"],
                          index=gids)
    thisdf["end_date"] = end_date
    for name in names:
        for gid in gids:
            prev_state, prev_pct = lastdf[name].ix[gid]
            new_state = prev_state.split("_")[0]
            new_state = new_state + "_unch"
            thisdf[name].ix[gid] = (new_state, prev_pct)