def sari_br_dataframe(): """ Aggregate SARI vigilance for all states. """ states = mundi.regions_dataframe("BR", type="state").index data = [sari_br_state_dataframe(state) for state in states] return pd.concat(data)
def get_regions(**query): """ Get all children in region that have the same values of the parameters passed as keyword arguments. """ return [ mundi.region(id_) for id_ in mundi.regions_dataframe(**query).index ]
def _brazil_map(): num_codes = (mundi.regions_dataframe( "BR", type="state").mundi["numeric_code"].astype(object) ["numeric_code"].to_dict()) translate = {v: k for k, v in num_codes.items()} geo = geopandas.read_file( PATH / "databases/maps/br/estados.dbf")[["CD_GEOCUF", "geometry"]] geo.index = geo.pop("CD_GEOCUF").apply(translate.__getitem__) geo["geometry"] = geo.simplify(0.1) return geo
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_dataframe("BR", type="state") else: df = mundi.regions_dataframe(type="state", parent_id=opt) return df.index
def sub_regions(code, **kwargs): """ Return a list of mundi codes starting with the given code, followed by all sub-regions queried from the given arguments. """ if len(code) == 2: kwargs["country_code"] = code else: kwargs["parent_id"] = code sub_df = mundi.regions_dataframe(**kwargs) return tuple(sub_df.index)
def collect_inputs(region="BR", where=st.sidebar): states = mundi.regions_dataframe(region, type="state") highlight = where.selectbox(_("Select a state to highlight"), states.index) msg = _("Which kind of curve to you want to analyze?") which = where.selectbox(msg, ["cases", "deaths"]) return { "loc": highlight, "idx": int(which == "deaths"), "states": states, "which": which, }
def abstract_str(top=10, kind=_("Federal Units"), date=None): """ Create a markdown string with an abstract to the dashboard. """ children_refs = mundi.regions_dataframe(country_id="BR", type="state").index children = [mundi.region(ref) for ref in children_refs] n_children = len(children) curves = [child.pydemic.epidemic_curve().diff() for child in children] date = date or max(curve.index.max() for curve in curves) cases = pd.Series([c.loc[date, "cases"] for c in curves], index=children_refs) deaths = pd.Series([c.loc[date, "deaths"] for c in curves], index=children_refs) def list_top(data: pd.Series): *head, last = sk.pipe( data.sort_values(ascending=False).index[:top], sk.map(mundi.region), sk.map("{0.name}".format), ) head = ", ".join(head) return _(" and ").join([head, last]) return _(ABSTRACT).format( cases="{:n}".format(cases.sum()), deaths="{:n}".format(deaths.sum()), date=date, n_children=n_children, n_top_cases=min(top, n_children), n_top_deaths=min(top, n_children), top_cases=list_top(cases), top_deaths=list_top(deaths), unit_kind=_(kind), )
def regions(*args, **kwargs): refs = mundi.regions_dataframe(*args, **kwargs).index return [mundi.region(ref) for ref in refs]
def fetch_states(): return tuple(map(mundi.region, mundi.regions_dataframe("BR", type="state").index))