Exemplo n.º 1
0
def progression_cards(deaths, color="st-blue"):
    deaths = deaths.values[-60:]
    st.cards(
        {
            _("7 days"): fmt(deaths[6]),
            _("15 days"): fmt(deaths[14]),
            _("30 days"): fmt(deaths[29]),
            _("60 days"): fmt(deaths[59]),
        },
        color=color,
    )
Exemplo n.º 2
0
    def show(self):
        curves = self.get_epidemic_curves(self.user_inputs['states'].index).fillna(0)

        # Acc cases
        ax = curves.iloc[-30:, self.user_inputs['idx']::2].plot(legend=False, grid=True)
        curves[self.user_inputs['loc'], self.user_inputs['which']].iloc[-30:].plot(ax=ax, legend=False, grid=True)
        st.pyplot()

        # Daily cases
        # ax = curves.iloc[-30:, self.user_inputs['idx']::2]
        # curves[self.user_inputs['loc'], self.user_inputs['which']] \
        #     .iloc[-30:] \
        #     .diff() \
        #     .plot(ax=ax, legend=False, grid=True)
        # st.pyplot()

        # # Growth factors
        growths = self.get_growths(self.user_inputs['states'].index, self.user_inputs['which'])
        ci = pd.DataFrame({"low": growths["value"] - growths["std"], "std": growths["std"]})

        st.header("Growth factor +/- error")
        ci.plot.bar(width=0.9, ylim=(0.8, 2), stacked=True, grid=True)
        plt.plot(self.user_inputs['states'].index, [1] * len(self.user_inputs['states']), "k--")
        st.pyplot()

        # # Duplication times
        st.header("Duplication time")
        (np.log(2) / np.log(growths["value"])).plot.bar(grid=True, ylim=(0, 30))
        st.pyplot()

        # R0
        st.header("R0")
        params = covid19.params(region=self.user_inputs['loc'])
        (
            np.log(growths["value"])
            .apply(lambda K: formulas.R0_from_K("SEAIR", params, K=K))
            .plot.bar(width=0.9, grid=True, ylim=(0, 4))
        )
        st.pyplot()

        ms_good, ms_keep, ms_bad = self.run_models(self.user_inputs['states'].index, self.user_inputs['which'])

        # ICU overflow
        for ms, msg in [
            (ms_keep, "keep trends"),
            (ms_bad, "no distancing"),
            (ms_good, "more distancing"),
        ]:
            st.header(f"Deaths and ICU overflow ({msg})")

            deaths = pd.DataFrame({m.region.id: m["deaths:dates"] for m in ms})
            deaths.plot(legend=False, color="0.5")
            deaths.sum(1).plot(grid=True)
            deaths[self.user_inputs['loc']].plot(legend=True, grid=True)

            st.cards({"Total de mortes": fmt(deaths.iloc[-1].sum())})
            st.pyplot()

            data = {}
            for m in ms:
                overflow = m.results["dates.icu_overflow"]
                if overflow:
                    data[m.region.id] = (overflow - pd.to_datetime(today())).days
            if data:
                data = pd.Series(data)
                data.plot.bar(width=0.9, grid=True)
                st.pyplot()
Exemplo n.º 3
0
def show_outputs(base, group, region: RegionT, plot_opts, clinical_opts,
                 **kwargs):
    """
    Show results from user input.
    """
    cmodels = group.clinical.overflow_model(**clinical_opts)
    cforecast = cmodels[0]
    start = base.info["event.simulation_start"]

    #
    # Introduction
    #
    st.header(_("Introduction"))
    st.markdown(report_intro(region))
    st.cards(
        {
            _("Basic reproduction number"): fmt(base.R0),
            _("Ascertainment rate"): pc(
                base.info["observed.notification_rate"]),
        },
        color="st-gray-900",
    )

    #
    # Forecast
    #
    st.header(_("Forecasts"))
    st.markdown(forecast_intro(region))

    # Infectious curve
    group["infectious:dates"].plot(**plot_opts)
    mark_x(start.date, "k--")
    plt.legend()
    plt.title(_("Active cases"))
    plt.tight_layout()
    st.pyplot()

    st.markdown("#### " + _("Download data"))
    opts = ["critical", "severe", "infectious", "cases", "deaths"]
    default_columns = ["critical", "severe", "cases", "deaths"]
    columns = st.multiselect(_("Select columns"),
                             opts,
                             default=default_columns)

    rename = dict(zip(range(len(columns)), columns))
    columns = [c + ":dates" for c in columns]
    data = pd.concat([cm[columns].rename(rename, axis=1) for cm in cmodels],
                     axis=1,
                     keys=cmodels.names)
    st.data_anchor(data.astype(int), f"data-{region.id}.csv")

    #
    # Reopening
    #
    st.header(_("When can we reopen?"))
    st.markdown(reopening_intro(region))

    st.subheader(_("Step 1: Controlling the curve"))
    st.markdown(rt_intro(region))

    st.subheader(_("Step 2: Testing"))
    st.markdown(rt_intro(region))
    if kwargs.get("show_weekday_rate"):
        region.ui.weekday_rate()

    st.subheader(_("Step 3: Hospital capacity"))
    st.markdown(rt_intro(region))

    # Hospitalization
    cmodels["critical:dates"].plot(**plot_opts)
    mark_x(start.date, "k--")
    mark_y(cforecast.icu_surge_capacity, "k:")
    plt.legend()
    plt.title(_("Critical cases"))
    plt.tight_layout()
    st.pyplot()