Ejemplo n.º 1
0
def options(where=st.sidebar):
    st = where

    opts = {
        None: _("Brazil"),
        "BR-1": _("North"),
        "BR-2": _("Northeast"),
        "BR-3": _("Southeast"),
        "BR-4": _("South"),
        "BR-5": _("Midwest"),
    }
    st.subheader(_("Region"))
    opt = st.radio(_("Select region"), [*opts], format_func=opts.get)
    if opt is None:
        regs = regions("BR", type="region", parent_id="BR")
    else:
        regs = regions(type="state", parent_id=opt)

    opts = {"cases": _("Cases"), "deaths": _("Deaths")}
    msg = _("Cases or deaths?")
    column = st.radio(msg, [*opts], format_func=opts.get)

    st.subheader(_("Plotting options"))
    lines = st.checkbox(_("Show Lines"))
    logy = False
    if lines:
        logy = st.checkbox(_("Logarithm scale"))

    return {"lines": lines, "logy": logy, "regions": regs, "column": column}
Ejemplo n.º 2
0
def options(where=st):
    st = where
    regs = regions("BR", type="state")

    # Regions to highlight
    st.subheader(_("Highlight"))
    opts = {
        "BR-1": _("North"),
        "BR-2": _("Northeast"),
        "BR-3": _("Southeast"),
        "BR-4": _("South"),
        "BR-5": _("Midwest"),
        "select": _("Select states"),
        # 'top5': _('Top 5'), NotImplemented
    }
    msg = _("Which states do you want to highlight?")
    opt = st.radio(msg, [*opts], format_func=opts.get)
    if opt == "select":
        fmt = {r.id: r.name for r in regs}.get
        ids = [r.id for r in regs]
        msg = _("Select states to highlight")
        select = set(
            st.multiselect(msg, ids, format_func=fmt, default=[regs[0].id]))
        highlight = [r for r in regs if r.id in select]
    elif opt == "top5":
        highlight = opt
    else:
        highlight = [r for r in regs if r.parent_id == opt]

    # Options
    st.subheader(_("Options"))
    logy = not st.checkbox(_("Linear scale"))

    column = "deaths" if st.checkbox(_("Plot deaths")) else "cases"

    diff = st.checkbox(_("Plot new daily cases"))

    population_adj = st.checkbox(_("Adjust for population"))

    default = (20 if diff else 100) // (1 if column == "cases" else 10)
    thresh = st.number_input(_("Minimum number of cases"),
                             min_value=0,
                             value=default)

    default = 7 if diff else 0
    smooth = st.number_input(_("Smooth over n days"),
                             min_value=0,
                             value=default)

    return {
        "regions": regs,
        "highlight": highlight,
        "diff": diff,
        "thresh": thresh,
        "smoothing": smooth,
        "column": column,
        "logy": logy,
        "population_adj": population_adj,
    }
Ejemplo n.º 3
0
def sidebar(where=st.sidebar):
    st = where

    st.subheader(_("Section"))
    msg = _("Which section do you want to see?")
    key = st.radio(msg, list(APPS), format_func=lambda x: APPS[x].DISPLAY_NAME)
    app = APPS[key]
    opts = app.options(where=where)
    return app.show, opts
Ejemplo n.º 4
0
def select_regions(where=st.sidebar):
    """
    Select regions for app.
    """
    st = where
    opts = {
        "BR": _("Brazil (everything)"),
        "BR-1": _("North Region"),
        "BR-2": _("Northeast Region"),
        "BR-3": _("Southeast Region"),
        "BR-4": _("South Region"),
        "BR-5": _("Center-West Region"),
    }
    opt = st.radio(_("What do you want to show?"), list(opts), format_func=opts.get)
    if opt == "BR":
        df = mundi.regions("BR", type="state")
    else:
        df = mundi.regions(type="state", parent_id=opt)
    return df.index
Ejemplo n.º 5
0
def download_data(data, cmap, where=st, **kwargs):
    opts = {
        "csv": _("Download tables as CSV"),
        "xlsx": _("Download tables as an Excel spreadsheet"),
        "maps": _("Download all maps in a ZIP file"),
        "pdf": _("Download a PDF with the complete report"),
    }
    opt = st.radio(_("What do you want?"), list(opts), format_func=opts.get)

    if opt in ("csv", "xlsx"):
        st.data_anchor(
            data,
            f"full-data-{today()}.{opt}",
            style=None,
            label=_("Click here to download the complete dataset."),
        )
    elif opt == "maps":
        fd = io.BytesIO()

        with zipfile.ZipFile(
            fd, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9
        ) as zip:
            for section in SECTIONS.values():
                rendered_cols = set()

                for col in section.columns:
                    if col.skip_choropleth or col in rendered_cols:
                        continue
                    rendered_cols.add(col)

                    name = f"{section.name}-{col.name}.svg"
                    svg = col.render_choropleth(data, cmap, kind="svg")
                    zip.writestr(name, svg)

        st.data_anchor(fd.getvalue(), filename=f"maps-{today()}.zip")

    elif opt == "pdf":
        ctx = {"sections": SECTIONS.values(), "data": data, "cmap": cmap}
        fd = pdf_from_template("dashboard-report", ctx)
        st.data_anchor(fd.read(), filename=f"report-{today()}.pdf")
Ejemplo n.º 6
0
def sidebar(where=st.sidebar) -> dict:
    """
    Run sidebar that asks for user input.
    """

    st = where
    st.header(_("Brazilian Epidemiological indicators"))

    st.subheader(_("Sections"))
    opts = {k: v.title for k, v in SECTIONS.items()}
    opts["download"] = _("Download data")
    msg = _("Select a section")
    section = st.radio(msg, list(opts), format_func=opts.get)

    st.subheader(_("Filter results"))
    regions = select_regions(where=st)

    st.subheader(_("Options"))
    opts = {
        "static_table": st.checkbox(_("Static tables")),
        "cmap": st.selectbox(_("Colormap"), COLOR_MAPS, index=COLOR_MAPS.index("BuPu")),
    }

    return {"regions": regions, "section": section, **opts}
Ejemplo n.º 7
0
data_size = cm.iter - duration

# Show results
st.header("Simulation results")
st.subheader("Cases and deaths")
plot_cases_and_projection(cm, cases)

#
# Cards
#
st.subheader(_("New deaths"))
progression_cards(cm["deaths"], color="st-red")

st.subheader(_("New cases"))
opts = [_("Estimated"), _("Reported")]
is_reported = st.radio(_("Reporting"), [0, 1], format_func=opts.__getitem__)
mul = notification if is_reported else 1.0
progression_cards(cm["cases"] * mul, color="st-gray-900")

st.subheader(_("Hospitalizations"))
hospitalization_chart(cm, shift=len(cases))

st.subheader(_("Projections"))
m = cm.infection_model
date = m.dates[data_size]
base = cm.infection_model.trim_dates(0, data_size)
assert len(base.data) == data_size, (data_size, len(base.data), len(m.times))

valid_rates = [0.1 * i for i in range(1, 10)]
rates = [valid_rates[i] for i in [6, 4, 2]]
msg = _("Isolation score")