예제 #1
0
def graph_caller(ylabel,
                 date_selected,
                 premade_df,
                 title,
                 ylog=False,
                 yrange=None,
                 hue='state'):
    '''
    Calls h.line_plotter(). Created to avoid repetitive code.
    
    input
    -----
    yrange: tuple
        None or tuple. If tuple, indicates the min and max values for y axis
    '''
    if not yrange:
        st.plotly_chart(
            h.line_plotter(
                "date",
                ylabel,
                date_selected,
                dataset=premade_df,
                hue=hue,
                ylog=ylog,
                labels={
                    ylabel: h.ylabel_format(ylabel, ylog),
                    "date": "",
                    "state": ""
                },
                title=title,
            ),
            use_container_width=False,
        )
    else:
        st.plotly_chart(
            h.line_plotter(
                "date",
                ylabel,
                date_selected,
                dataset=premade_df,
                hue=hue,
                ylog=ylog,
                range_y=yrange,
                labels={
                    ylabel: h.ylabel_format(ylabel, ylog),
                    "date": "",
                    "state": ""
                },
                title=title,
            ),
            use_container_width=False,
        )
예제 #2
0
def graph_caller(
    ylabel, date_selected, premade_df, title, ylog=False, perc_range=False
):
    """
    Calls h.line_plotter(). Created to avoid repetitive code.
    """
    if perc_range:
        st.info('The CDC [has not defined](https://www.cdc.gov/coronavirus/2019-ncov/communication/vaccination-toolkit.html) a threshold for herd immunity against COVID19, however 70% is cited by the [Mayoclinic](https://www.mayoclinic.org/diseases-conditions/coronavirus/in-depth/herd-immunity-and-coronavirus/art-20486808).')
        fig = h.line_plotter(
            "date",
            ylabel,
            date_selected,
            dataset=premade_df,
            hue="state",
            ylog=ylog,
            range_y=(0, 100),
            labels={
                ylabel: h.ylabel_format(ylabel, ylog),
                "date": "",
                "state": "",
            },
            title=title,
        )
        fig.add_hline(y=70, line_dash='dot', line_color='red', annotation_text='Herd immunity')
        st.plotly_chart(fig, use_container_width=False)
    else:
        st.plotly_chart(
            h.line_plotter(
                "date",
                ylabel,
                date_selected,
                dataset=premade_df,
                hue="state",
                ylog=ylog,
                labels={
                    ylabel: h.ylabel_format(ylabel, ylog),
                    "date": "",
                    "state": "",
                },
                title=title,
            ),
            use_container_width=False,
        )
예제 #3
0
def graph_caller(
    ylabel, date_selected, premade_df, title, ylog=False, perc_range=False
):
    """
    Calls h.line_plotter(). Created to avoid repetitive code.
    """
    if perc_range:
        st.plotly_chart(
            h.line_plotter(
                "date",
                ylabel,
                date_selected,
                dataset=premade_df,
                hue="location",
                ylog=ylog,
                range_y=(0, 100),
                labels={
                    ylabel: h.ylabel_format(ylabel, ylog),
                    "date": "",
                    "location": "",
                },
                title=title,
            ),
            use_container_width=False,
        )
    else:
        st.plotly_chart(
            h.line_plotter(
                "date",
                ylabel,
                date_selected,
                dataset=premade_df,
                hue="location",
                ylog=ylog,
                labels={
                    ylabel: h.ylabel_format(ylabel, ylog),
                    "date": "",
                    "location": "",
                },
                title=title,
            ),
            use_container_width=False,
        )
예제 #4
0
def graph_new_doses(ylabel, date_selected, premade_df, title):
    """
    Sole function to graph new doses and call functions to add annotations to the graph

    Source for annotations: https://plotly.com/python/reference/layout/annotations
    """
    fig = px.line(
        data_frame=premade_df,
        x="date",
        y=ylabel,
        range_x=date_selected,
        labels={
            ylabel: h.ylabel_format(ylabel, ylog=False),
            "state": "",
            "date": "",
        },
        color="state",
        title="New doses administered per million"
    )
    unique_states = premade_df["state"].unique()
    st.plotly_chart(fig)
예제 #5
0
def overview(yesterday, dataframe):
    '''
    Show who's winning the vaccine wars
    '''
    choose = st.sidebar.radio("", options = ["Fully vaccinated", "Partially vaccinated"]).lower()
    top_df = dataframe[dataframe.date.apply(lambda x: True if x.date() == yesterday else False)]
    color = None
    sort = st.checkbox("Sort by region")
    if sort:
        color = 'region'
    if "fully" in choose:
        col = 'all_doses_vaccinated_per_hundred'
        res = top_df.sort_values(col, ascending=False)
        title='Fully vaccinated population'
        description = "__Description:__ Percent of population who are fully vaccinated, whether through one (ex: JJ) or two (ex: Pfizer) doses"

    elif "partially" in choose:
        col = 'one_dose_vaccinated_per_hundred'
        res = top_df.sort_values(col, ascending=False)
        title='At least one dose administered'
        description = "__Description:__ Percent of population who are only partially vaccinated (ex: one dose of Pfizer)"
    res = res[~res['state'].str.contains('Puerto')]
    fig = px.bar(
        data_frame = res,
        x='state',
        y=col,
        color=color,
        range_y=(0,100),
        title=title,
        labels={
            col:h.ylabel_format(col, ylog=False),
            'state':'',
            'region':'Region'
        }
    )

    fig.add_hline(y=70, line_dash='dot', line_color='red', annotation_text='Herd immunity')
    st.plotly_chart(fig)
    st.write("")
    st.write(description)
예제 #6
0
def graph_new_doses(ylabel, date_selected, premade_df, title):
    """
    Sole function to graph new doses and call functions to add annotations to the graph

    Source for annotations: https://plotly.com/python/reference/layout/annotations
    """
    info_box = st.empty()
    show_annot = st.checkbox("Show annotations",value=True)
    fig = px.line(
        data_frame=premade_df,
        x="date",
        y=ylabel,
        range_x=date_selected,
        labels={
            ylabel: h.ylabel_format(ylabel, ylog=False),
            "location": "",
            "date": "",
        },
        color="location",
        title="New doses administered per million"
    )
    unique_locations = premade_df["location"].unique()
    
    if show_annot:
        all_annotations = h.get_annotation_data(unique_locations, label='vax', conn=news_cnx)
        if not all_annotations:
            st.plotly_chart(fig)
        else:
            for country in all_annotations.keys():
                h.annotation_creator( # add annotations to the graph
                    fig=fig, ylabel=ylabel, df=premade_df, annotation_settings=all_annotations[country]
                )
            info_box.info("__Tip__: Move cursor over annotations for more details")
            st.plotly_chart(fig)
    else:
        info_box.info("__Tip__: Move cursor over annotations for more details")
        st.plotly_chart(fig)
예제 #7
0
def graph_caller(ylabel,
                 date_selected,
                 premade_df,
                 title,
                 show_annot=False,
                 ylog=False,
                 yrange=None,
                 hue='location'):
    '''
    Calls h.line_plotter(). Created to avoid repetitive code.
    
    input
    -----
    yrange: tuple
        None or tuple. If tuple, indicates the min and max values for y axis
    '''
    if not yrange:  # no limit on the y axis
        fig = h.line_plotter(  # h.lineplotter returns a tuple with 1 item, the fig
            "date",
            ylabel,
            date_selected,
            dataset=premade_df,
            hue=hue,
            ylog=ylog,
            labels={
                ylabel: h.ylabel_format(ylabel, ylog),
                "date": "",
                "location": ""
            },
            title=title,
        ),

    else:  # y axis is limited by tuple
        fig = h.line_plotter(  # h.lineplotter returns a tuple with 1 item, the fig
            "date",
            ylabel,
            date_selected,
            dataset=premade_df,
            hue=hue,
            ylog=ylog,
            range_y=yrange,
            labels={
                ylabel: h.ylabel_format(ylabel, ylog),
                "date": "",
                "location": ""
            },
            title=title,
        ),
    if show_annot:
        all_locations = premade_df['location'].unique()
        all_annotations = h.get_annotation_data(all_locations,
                                                label='cases',
                                                conn=news_cnx)

        if not all_annotations:  # all_annotations is None, dont call annotation creator
            st.plotly_chart(fig[0])
        else:
            for country in all_annotations.keys():
                h.annotation_creator(
                    fig[0],
                    ylabel,
                    df=premade_df,
                    annotation_settings=all_annotations[country])
            st.plotly_chart(fig[0])
    else:
        st.plotly_chart(fig[0])