예제 #1
0
    def main(self, region="BR", disease=covid19):
        st.css()
        params = self.ask(region=region,
                          disease=disease,
                          secret_date=Secret.date)

        if Secret.is_easter_egg_activated(params):
            return

        Debug = DebugCalc(st, DEBUG)
        run_infectious_model(Debug)
예제 #2
0
def main(embed=False):
    if not embed:
        st.css(keep_menu=True)
        st.sidebar.logo()

    models = ["crude", "delay", "overflow"]
    kind = st.sidebar.selectbox(_("Clinical model"), models)
    m = SEAIR(region="BR", disease=covid19)

    cm = m.clinical(kind)
    cm.ui.summary_table(subheader=_("Parameters table"))
예제 #3
0
 def __init__(self, embed=False, disease="covid-19", **kwargs):
     super().__init__(embed=embed, **kwargs)
     self.embed
     if not self.embed:
         self.css = st.css(keep_menu=True)
     self.logo = True
     self.where = st if self.embed else st.sidebar
     self.disease = disease
예제 #4
0
def main(embed=False, disease=None):
    """
    Run application.
    """
    if not embed:
        st.css(keep_menu=True)
        st.sidebar.logo()
        title = st.empty().title
        title(_("Covid risk factors"))
    else:
        title = lambda *args: None

    opts = sidebar(title,
                   where=st if embed else st.sidebar,
                   embed=embed,
                   disease=disease)
    show_opts = extract_keys(SHOW_OPTS, opts)
    clinical_opts = extract_keys(CLINICAL_OPTS, opts)
    run_opts = extract_keys(RUN_OPTS, opts)

    # Start model with known R0
    region = opts["region"]
    plot_opts = show_opts["plot_opts"]

    st.header(_("Cases and deaths"))
    region.ui.epidemic_summary()
    region.ui.cases_and_deaths(title=None,
                               download=f"cases-{region.id}.csv",
                               **plot_opts)

    model = start_model(**opts)
    group = start_group(model, **run_opts)
    show_outputs(model,
                 group,
                 clinical_opts=clinical_opts,
                 **opts,
                 **show_opts)
예제 #5
0
def main(embed=False, disease=None):
    """
    Main interface of the API explorer.
    """
    if not embed:
        st.css(keep_menu=True)
        st.sidebar.logo()
    where = st if embed else st.sidebar

    st.title(_("Pydemic-UI API explorer"))
    where.header(_("Options"))

    region = where.text_input(_("Mundi region code"), value="BR")
    try:
        region = mundi.region(region)
    except LookupError:
        where.error("Invalid mundi region code.")
        return

    opts = {
        "model": _("A Pydemic Model"),
        "region": _("A Mundi Region"),
        "components": _("Input components"),
    }
    msg = _("What do you want to explore?")
    opt = where.radio(msg, list(opts), format_func=opts.get)

    if opt == "model":
        model = SEAIR(region=region, disease="covid-19")
        model.run(180)
        obj = model.clinical.overflow_model()
    elif opt == "region":
        obj = region
    else:
        import pydemic_ui.components as obj

    explore_object_attribute(opt, obj, where=where)
예제 #6
0
def main(embed=False, where=st, **kwargs):
    """
    Main application function.
    """

    st = where
    if not embed:
        st.css(keep_menu=True)
        st.sidebar.logo()
        st.title(_("Epidemic situation dashboard (Brazil)"))

    options = sidebar(where=st.sidebar)
    kwargs = extract_keys(("cmap", "static_table"), options)
    kwargs["where"] = where

    data = get_data()
    data = data.loc[options.pop("regions")]

    section_opt = options["section"]
    if section_opt == "download":
        download_data(data, **kwargs)
    else:
        section = SECTIONS[section_opt]
        section.show(data, **kwargs)
예제 #7
0
 def __init__(self, embed=False, **kwargs):
     super().__init__(embed=embed, **kwargs)
     if not embed:
         self.css = st.css(keep_menu=True)
     self.logo = True
     self.where = st if self.embed else st.sidebar
예제 #8
0
파일: calc.py 프로젝트: pydemic/pydemic-ui
def main(region="BR", disease=covid19):
    st.css()
    params = sidebar(
        region=region,
        disease=disease,
        secret_date=datetime.date(1904, 11, 10),
        secret_function=lambda: easter_egg(disease),
    )
    if params is None:  # Secret function was activated
        return

    debug = False

    if DEBUG and st.checkbox(_("Enable debug")):
        st.info(_("Running in debug mode!"))
        st.html(
            """
        <ul>
            <li><a href="#debug">{}</a></li>
        </ul>""".format(
                _("Debug section!")
            )
        )
        debug = True

    epidemiology = extract_keys(PARAMS, params)
    clinical = extract_keys(CLINICAL, params)

    # Run infections model
    m = cm = results = None
    try:
        m = model(disease=disease, **epidemiology)
        cm = m.clinical.overflow_model(icu_occupancy=0, hospital_occupancy=0, **clinical)
        cm.extra_info = params
        output(cm)

    finally:
        if debug:
            if results:
                st.html('<div style="height: 15rem"></div>')
            st.html('<h2 id="debug">{}</h2>'.format(_("Debug information")))

            st.subheader(_("Generic parameters"))
            st.write(params)

            st.subheader(_("Epidemiological parameters"))
            st.write(epidemiology)

            st.subheader(_("Clinical parameters"))
            st.write(clinical)

            st.subheader(_("Output"))
            st.write(results)

            if m:
                st.line_chart(m.data)

            if cm:
                st.line_chart(cm[["infectious", "severe", "critical"]])

                st.subheader(_("Distribution of deaths"))
                df = cm[DEATH_DISTRIBUTION_COLUMNS]
                df.columns = [DEATH_DISTRIBUTION_COL_NAMES[k] for k in df.columns]
                st.area_chart(df)
예제 #9
0
 def __init__(self, embed=False, where=st, **kwargs):
     super().__init__(embed=embed, where=where, **kwargs)
     if not embed:
         self.css = st.css(keep_menu=True)
     self.logo = True
예제 #10
0
@st.cache(allow_output_mutation=True)
def run_model(region, duration, R0, notification_rate):
    m = models.SEAIR(region=region, disease=covid19, R0=R0)

    data = info.get_seair_curves_for_region(
        region, notification_rate=notification_rate)
    m.set_data(data)
    m.initial_cases = info.get_cases_for_region(region)["cases"].iloc[0]
    m.run(duration)
    return m.clinical.overflow_model()


#
# ASK INFO
#
st.css()
st.sidebar.logo()
code = st.sidebar.region_input("BR", healthcare_regions=True)
region = mundi.region(code)
params = covid19.params(region=region)

st.sidebar.subheader(_("Parameters"))
duration = 60  # st.sidebar.number_input(_("Duration (days)"), 1, 120, value=60)
notification = st.sidebar.slider(_("Ascertainment ratio"),
                                 0.01,
                                 0.50,
                                 value=0.10)
R0 = st.sidebar.slider(_("R0"), 0.1, 5.0, value=params.R0)

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