def run_infectious_model(Debug): epidemiology = extract_keys(PARAMS, params) clinical = extract_keys(CLINICAL, params) model = clinical_model = results = None try: model = ConstructModel(disease=disease, **epidemiology).new_model() clinical_model = model.clinical.overflow_model( icu_occupancy=0, hospital_occupancy=0, **clinical) clinical_model.extra_info = params self.show(clinical_model) finally: if Debug: Debug.information_message(results, params, epidemiology, clinical, model, clinical_model)
def from_children( cls, region: Union[Region, str], model_cls: Type[Model], options=MappingProxyType({}), **kwargs, ) -> "ModelGroup": """ Create a group from children of the given Region. """ region: Region = mundi.region(region) children = region.children( **extract_keys(("deep", "type", "subtype", "which"), kwargs)) name = kwargs.pop("name", "{region.name}") group = [] if options: options = {mundi.region(k): v for k, v in options.items()} for child in children: opts = options.get(child, {}) if isinstance(name, str): opts["name"] = name.format(region=child, **kwargs, **opts) group.append(model_cls(region=child, **kwargs, **opts)) return ModelGroup(group)
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)
def process_data(self): show_opts = extract_keys(SHOW_OPTS, self.user_inputs) clinical_opts = extract_keys(CLINICAL_OPTS, self.user_inputs) run_opts = extract_keys(RUN_OPTS, self.user_inputs) # Start model with known R0 region = self.user_inputs["region"] plot_opts = show_opts["plot_opts"] self.where = st self.where.header(_("Cases and deaths")) region.ui.epidemic_summary() region.ui.cases_and_deaths(title=None, download=f"cases-{region.id}.csv", **plot_opts) model = self.start_model(region=self.user_inputs['region']) group = self.start_group(model, **run_opts) self.cmodels = group.clinical.overflow_model(**clinical_opts) self.show_outputs(model, group, clinical_opts=clinical_opts, **self.user_inputs, **show_opts)
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)
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)