Esempio n. 1
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)
Esempio n. 2
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)