Exemple #1
0
def _make_state_graphs(verbose = False):
    df_day = get_state_data_day()
    for state in ['Washington']:
        for the_info in [(None, 'deaths', df_day, 'deaths'), (None, 'cases', df_day, 'cases')]:
            df_day_ = the_info[2]
            p = common.incidents_over_time_bar(df_day_[df_day_['state'] == state ], 
                    key = the_info[3], window= 3, plot_height = 350, 
                plot_width = 350, title = 'Deaths by Day', line_width = 2)
Exemple #2
0
def all_territories(df_week, df_day, territory_key, window = 3, plot_height = 550,
        plot_width = 550, verbose = False):
    """
    Create all the HTML files for the states
    """
    territories = list(set(df_week[territory_key]))
    make_territories_ref_list(territory_key, territories)
    dir_path = make_territories_dir(territory_key)
    for i in territories:
        if verbose:
            print('working on {territory}'.format(territory = i))
        min_value = 10
        df_ = df_week[(df_week[territory_key]==i)]
        p1 = common.bar_over_time(df_, key = 'deaths', 
                plot_height = plot_height, plot_width = plot_width, 
                title = 'Deaths by Week', line_width = 10, ignore_last = True)
        p6 = common.bar_over_time(df_, key = 'cases', 
                plot_height = plot_height, plot_width = plot_width, 
                title = 'Cases by Week', line_width = 10, ignore_last = True)
        p2 = common.incidents_over_time_bar(df_day[df_day[territory_key] == i], 
                key = 'deaths', window= 3, plot_height = plot_height, 
            plot_width = plot_width, title = 'Deaths by Day', line_width = 2)
        p5 = common.incidents_over_time_bar(df_day[df_day[territory_key] == i], 
                key = 'cases', window= 3, plot_height = plot_height, 
            plot_width = plot_width, title = 'Cases by Day', line_width = 2)
        death_ro, death_double_rate, p3 =  dy_dx(territory_key = territory_key, 
                territory = i, df = df_day, window = window, 
                key = 'deaths', plot_height = 300, plot_width = 300)
        cases_ro, cases_double_rate, p4 =  dy_dx(territory_key = territory_key, 
                territory = i, df = df_day, window = window, 
                key = 'cases', plot_height = 300, plot_width = 300)
        grid = gridplot([p1, p2, p6, p5,  p3, p4], ncols = 2)
        script, div = components(grid)
        html = get_html(territory = i, script = script, div = div,
                death_ro = death_ro, cases_ro = cases_ro, 
                death_double_rate = death_double_rate, 
                cases_double_rate = cases_double_rate)
        with open(os.path.join(dir_path, '{territory}.html'.format(
            territory = common.tidy_name(i))), 'w') as write_obj:
            write_obj.write(html)
Exemple #3
0
def make_washington_graphs():
    if not os.path.isdir('html_temp'):
        os.mkdir('html_temp')
    df_states = common.make_dataframe(get_state_data())
    df_counties = make_dataframe_wash_order()
    p_counties = common.graph_wash_county_order(df=df_counties,
                                                start=3,
                                                plot_height=450,
                                                line_width=40)
    df_state = df_states[(df_states['state'] == 'Washington')]
    p_all = common.incidents_over_time_bar(df_state,
                                           key='deaths',
                                           window=3,
                                           plot_height=600,
                                           plot_width=600,
                                           title=None)
    grid = gridplot([p_all, p_counties], ncols=4)
    script, div = components(grid)
    html = get_html(script, div, title='Washington')
    with open('html_temp/wa', 'w') as write_obj:
        write_obj.write(html)
Exemple #4
0
def all_states(df_week,
               df_day,
               window=3,
               plot_height=550,
               plot_width=550,
               verbose=False):
    """
    Create all the HTML files for the states
    """
    states = list(set(df_week['state']))
    for i in states:
        if verbose:
            print('working on {state}'.format(state=i))
        min_value = 10
        df_ = df_week[(df_week['state'] == i)]
        p1 = common.bar_over_time(df_,
                                  key='deaths',
                                  plot_height=plot_height,
                                  plot_width=plot_width,
                                  title='Deaths by Week',
                                  line_width=10,
                                  ignore_last=True)
        p6 = common.bar_over_time(df_,
                                  key='cases',
                                  plot_height=plot_height,
                                  plot_width=plot_width,
                                  title='Cases by Week',
                                  line_width=10,
                                  ignore_last=True)
        p2 = common.incidents_over_time_bar(df_day[df_day['state'] == i],
                                            key='deaths',
                                            window=3,
                                            plot_height=plot_height,
                                            plot_width=plot_width,
                                            title='Deaths by Day',
                                            line_width=2)
        p5 = common.incidents_over_time_bar(df_day[df_day['state'] == i],
                                            key='cases',
                                            window=3,
                                            plot_height=plot_height,
                                            plot_width=plot_width,
                                            title='Cases by Day',
                                            line_width=2)
        death_ro, death_double_rate, p3 = dy_dx(state=i,
                                                df=df_day,
                                                window=window,
                                                key='deaths',
                                                plot_height=300,
                                                plot_width=300)
        cases_ro, cases_double_rate, p4 = dy_dx(state=i,
                                                df=df_day,
                                                window=window,
                                                key='cases',
                                                plot_height=300,
                                                plot_width=300)
        grid = gridplot([p1, p2, p6, p5, p3, p4], ncols=2)
        script, div = components(grid)
        html = get_html(state=i,
                        script=script,
                        div=div,
                        death_ro=death_ro,
                        cases_ro=cases_ro,
                        death_double_rate=death_double_rate,
                        cases_double_rate=cases_double_rate)
        with open(
                os.path.join(
                    'html_temp', 'states',
                    '{state}'.format(state=i.replace(' ', '_').lower())),
                'w') as write_obj:
            write_obj.write(html)
    make_states_ref_list(states)
Exemple #5
0
def make_state_graphs(verbose=False, plot_height=400, plot_width=400):
    if not os.path.isdir('html_temp'):
        os.mkdir('html_temp')
    date = datetime.datetime.now()
    df_deaths = get_data_deaths()
    df_cases = get_data_cases()
    df_day = get_state_data_day()
    dir_path = make_territories_dir('state')
    for state in set(df_deaths['state']):
        if verbose:
            print('working on {state}'.format(state=state))
        ps = []
        for the_info in [(
                df_deaths,
                'death',
                df_day,
                'deaths',
                'Deaths by Week',
                'Deaths by Day',
        ), (df_cases, 'cases', df_day, 'cases', 'Cases by Week',
                'Cases by Day')]:
            df = the_info[0]
            df_day_ = the_info[2]
            rt_death, rt_death2 = common.get_rt(
                df_day_[df_day_['state'] == state]['deaths'], 7, 7)
            rt_cases, rt_cases2 = common.get_rt(
                df_day_[df_day_['state'] == state]['cases'], 7, 7)
            the_dict = {'dates': sorted(list(set(df['dates'].tolist())))}
            for i in range(1, 5):
                shape_data(
                    df,
                    state,
                    i,
                    the_dict,
                    key=the_info[1],
                )
            the_dict = _trim_data(the_dict)
            p = common.graph_stacked(data=the_dict,
                                     start=0,
                                     plot_height=plot_height,
                                     plot_width=plot_width,
                                     line_width=10,
                                     title=the_info[4])
            p_day = common.incidents_over_time_bar(
                df_day_[df_day_['state'] == state],
                key=the_info[3],
                window=3,
                plot_height=plot_height,
                plot_width=plot_width,
                title=the_info[5],
                line_width=2)
            ps.append(p)
            ps.append(p_day)
        grid = gridplot(ps, ncols=2)
        script, div = components(grid)
        html = get_html(territory=state,
                        script=script,
                        div=div,
                        date=date,
                        rt_cases=rt_cases,
                        rt_death=rt_death)
        tt = '{territory}'.format(territory=common.tidy_name(state)) + '.html'
        with open(os.path.join(dir_path, tt), 'w') as write_obj:
            write_obj.write(html)
    make_territories_ref_list('state', list(set(df_day['state'])))