Esempio n. 1
0
def explore_object(name, obj, where=st):
    """
    Explore methods of object.
    """

    fn = select_method(name, obj, where=where)
    args, kwargs = select_arguments(fn, where=where)

    t0 = time.time()
    msg = st.empty()
    result = fn(*args, **kwargs)
    msg.info(_("Method executed in {} seconds.").format(fmt(time.time() - t0)))

    st.line()
    st.subheader(_("Method help and signature"))
    st.help(fn)

    if result is not None:
        st.line()
        st.subheader(_("Function output"))

        if isinstance(result, plt.Axes):
            st.markdown(_("Function returned a matplotlib **ax** object. Showing it..."))
            st.pyplot(result.get_figure())
        else:
            st.write(result)
Esempio n. 2
0
def backcasting(
        predictor,
        window,
        curves,
        distance="RMS",
        columns=("cases", "deaths"),
        min_series=14,
        step=1,
):
    """
    Perform a backcasting performance analysis of the given model. For the sake
    of this method, the model is just a function that receives an epidemic curve
    dataframe and a list of time windows and return the forecasts for cases and
    deaths for the specified times.
    """
    windows = np.array(as_seq(windows))
    min_window = windows.min(initial=len(curves))

    def distance(x, y):
        return (x - y).dropna().abs() / x

    results = []
    for k in range(min_window, len(curves) - min_series, step):
        data = curves.iloc[:-k]
        prediction = fn(data, windows)
        results.append(distance(curves, prediction))
    st.write(results[-1])

    return pd.concat(results, axis=0)
Esempio n. 3
0
def main(**kwargs):
    df = sari_br_dataframe()
    st.write(
        df.astype({
            k: str
            for k in df.dtypes[(df.dtypes == "string")
                               | (df.dtypes == "category")].index
        }))
    x = df.reset_index()[["age", "id"]].groupby("age").count()
    st.bar_chart(x)
Esempio n. 4
0
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)
Esempio n. 5
0
  right: 0;
  bottom: 0;
  padding: 20px;
  border: 1px solid #ccc;
}
[type=radio]:checked ~ label {
  background: white;
  border-bottom: 1px solid white;
  z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
  z-index: 1;
}
</style>
""")
st.write("dfsd")
st.html("""
<div class="tabs">
   <div class="tab">
       <input type="radio" id="tab-1" name="tab-group-1" checked/>
       <label for="tab-1">Tab One</label>
       <div class="content">stuff one</div>
   </div>
   <div class="tab">
       <input type="radio" id="tab-2" name="tab-group-1">
       <label for="tab-2">Tab Two</label>
       <div class="content">stuff two</div>
   </div>
</div>
""")
Esempio n. 6
0
    "xlsx": _("Excel"),
}
mime = {"csv": "text/csv", "xls": "application/vnd.ms-excel"}

opt = st.radio(_("How do you want your data?"),
               list(opts),
               format_func=opts.get)
df = pd.concat(data, axis=1)
df.index = base.to_dates(df.index)
df = df.astype(int)

if not st.checkbox(_("Keep observed period")):
    df = df.iloc[data_size:]

if opt == "show":
    st.write(df)
else:
    df.index = [d.strftime("%Y-%m-%d") for d in df.index]
    if opt == "csv":
        fd = io.StringIO()
        df.to_csv(fd)
        data = fd.getvalue().encode("utf8")
    else:
        fd = io.BytesIO()
        df.to_excel(fd)
        data = fd.getvalue()
    data = base64.b64encode(data).decode("utf8")
    name = f"curves-%s.{opt}" % region.id
    msg = _("Right click link to download")
    st.html(f'<a href="data:{opt};base64,{data}" download="{name}">{msg}</a>')