예제 #1
0
def now(config):

    df = get_health.now(config,
                        "br")[config["br"]["simulacovid"]["columns"]["cnes"]]

    # merge cases
    cases = get_cities_cases.now(config, "br")
    cases = cases[cases["is_last"] == True].drop(config["br"]["cases"]["drop"],
                                                 1)

    df = df.merge(cases, on="city_id", how="left", suffixes=("", "_y"))
    df = df[[c for c in df.columns if not c.endswith("_y")]]

    health_region_rate = (df[[
        "health_region_id", "health_region_notification_rate"
    ]].dropna().groupby("health_region_id").mean())

    # get notification for cities without cases
    df["health_region_notification_rate"] = df.apply(
        lambda row: _recover_notification_rate(row, health_region_rate),
        axis=1)

    df["notification_rate"] = np.where(
        df["notification_rate"].isnull(),
        df["health_region_notification_rate"],
        df["notification_rate"],
    )

    df["last_updated"] = pd.to_datetime(df["last_updated"])
    return df
def now(config):

    df = get_health.now(config,
                        "br")[config["br"]["simulacovid"]["columns"]["cnes"]]

    # merge cases
    cases = get_cases.now(config, "br")
    cases = cases[cases["is_last"] == True].drop(config["br"]["cases"]["drop"],
                                                 1)

    df = df.merge(cases, on="city_id", how="left")

    states_rate = (df[["state_id", "state_notification_rate"
                       ]].dropna().groupby("state_id").mean())

    # get notification for cities without cases
    df["state_notification_rate"] = df.apply(
        lambda row: _fix_state_notification(row, states_rate), axis=1)

    df["notification_rate"] = np.where(
        df["notification_rate"].isnull(),
        df["state_notification_rate"],
        df["notification_rate"],
    )

    df["last_updated"] = pd.to_datetime(df["last_updated"])

    return df
예제 #3
0
def now(config):

    # Get resource data
    df = (get_health.now(config, "br").groupby([
        "country_iso",
        "country_name",
        "state_num_id",
        "state_id",
        "state_name",
        "health_region_id",
        "health_region_name",
        "last_updated_number_beds",
        "author_number_beds",
        "last_updated_number_icu_beds",
        "author_number_icu_beds",
    ]).agg({
        "population": sum,
        "number_beds": sum,
        "number_icu_beds": sum
    }).reset_index().sort_values("health_region_id").set_index(
        "health_region_id"))

    df = get_situation_indicators(
        df,
        data=get_health_region_cases.now(config),
        place_id="health_region_id",
        rules=config["br"]["farolcovid"]["rules"],
        classify="situation_classification",
    )

    df = get_control_indicators(
        df,
        data=get_health_region_rt.now(config),
        place_id="health_region_id",
        rules=config["br"]["farolcovid"]["rules"],
        classify="control_classification",
    )

    df = get_trust_indicators(
        df,
        data=get_health_region_cases.now(config),
        place_id="health_region_id",
        rules=config["br"]["farolcovid"]["rules"],
        classify="trust_classification",
    )

    df = get_capacity_indicators(
        df,
        place_id="health_region_id",
        config=config,
        rules=config["br"]["farolcovid"]["rules"],
        classify="capacity_classification",
    )

    cols = [col for col in df.columns if "classification" in col]
    df["overall_alert"] = df.apply(
        lambda row: get_overall_alert(row[cols]),
        axis=1)  # .replace(config["br"]["farolcovid"]["categories"])

    return df.reset_index()
예제 #4
0
def now(config, country="br"):

    if country == "br":
        infectious_period = (
            config["br"]["seir_parameters"]["severe_duration"] +
            config["br"]["seir_parameters"]["critical_duration"])

        # Get data & clean table
        df = (download_brasilio_table(config["br"]["cases"]["url"]).query(
            "place_type == 'state'").fillna(0).rename(
                columns=config["br"]["cases"]["rename"]).assign(
                    last_updated=lambda x: pd.to_datetime(x["last_updated"])).
              sort_values(
                  ["state_id", "last_updated"]).groupby("state_id").apply(
                      lambda group: get_until_last(group)).reset_index(
                          drop=True).drop(columns="estimated_population_2019"))

        # Fix places_ids by city_id => Get health_region_id
        df = df.merge(
            get_places_id.now(config).assign(
                state_num_id=lambda df: df["state_num_id"].astype(int), )[[
                    "state_name",
                    "state_id",
                    "state_num_id",
                ]].drop_duplicates(),
            on="state_id",
        )

        cols = [
            "state_num_id",
            "state_id",
            "state_name",
            "last_updated",
            "confirmed_cases",
            "deaths",
            "daily_cases",
            "new_deaths",
        ]

        # Add population data from CNES
        df = df[cols].merge(
            get_health.now(config).assign(
                state_num_id=lambda df: df["state_num_id"].astype(int),
            ).groupby("state_num_id")["population"].sum().reset_index(),
            on="state_num_id",
        )

        # Transform cases data
        df = (
            df.groupby([
                "state_num_id",
                "state_id",
                "state_name",
            ]).apply(correct_negatives)  # correct negative values
            .pipe(
                get_infectious_period_cases,
                infectious_period,
                config["br"]["cases"],
                "state_num_id",
            )  # get infectious period cases
            .rename(columns=config["br"]["cases"]["rename"]))

        # Get indicators of mavg & growth
        df = get_mavg_indicators(df, "daily_cases", place_id="state_num_id")
        df = get_mavg_indicators(df, "new_deaths", place_id="state_num_id")

        # Get notification rates & active cases on date
        df = df.merge(
            get_notification_rate.now(df, "state_num_id"),
            on=["state_num_id", "last_updated"],
            how="left",
        ).assign(active_cases=lambda x: np.where(
            x["notification_rate"].isnull(),
            np.nan,  # round(x["infectious_period_cases"], 0),
            round(x["infectious_period_cases"] / x["notification_rate"], 0),
        ))

    return df
예제 #5
0
def now(config, country="br"):

    if country == "br":

        infectious_period = (
            config["br"]["seir_parameters"]["severe_duration"] +
            config["br"]["seir_parameters"]["critical_duration"])

        # Filter and rename columns
        df = (download_brasilio_table(
            config["br"]["cases"]["url"]).query("place_type == 'city'").dropna(
                subset=["city_ibge_code"]).fillna(0).rename(
                    columns=config["br"]["cases"]["rename"]).assign(
                        last_updated=lambda x: pd.to_datetime(x[
                            "last_updated"])).sort_values(
                                ["city_id", "state_id",
                                 "last_updated"]).groupby("city_id").
              apply(lambda group: get_until_last(group)).reset_index(
                  drop=True).drop(
                      ["city_name", "estimated_population_2019"],
                      1).assign(city_id=lambda df: df["city_id"].astype(int)))

        # Fix places name & ID + Get total population
        places_ids = get_health.now(config).assign(
            city_id=lambda df: df["city_id"].astype(int))

        df = df.merge(
            places_ids[[
                "city_id",
                "city_name",
                "health_region_name",
                "health_region_id",
                "state_name",
                "state_num_id",
                "population",
            ]],
            on="city_id",
        )

        # Correct negative values, get infectious period cases and get median of new cases
        df = (df.groupby("city_id").apply(correct_negatives).pipe(
            get_infectious_period_cases,
            infectious_period,
            config["br"]["cases"],
            "city_id",
        ).rename(columns=config["br"]["cases"]["rename"]))

        # Get indicators of mavg & growth
        df = get_mavg_indicators(df, "daily_cases", place_id="city_id")
        df = get_mavg_indicators(df, "new_deaths", place_id="city_id")

        # Get notification rates & active cases on date
        df = df.merge(
            get_notification_rate.now(df, "health_region_id"),
            on=["health_region_id", "last_updated"],
            how="left",
        ).assign(
            active_cases=lambda x: np.where(
                x["notification_rate"].isnull(),
                np.nan,  # round(x["infectious_period_cases"], 0),
                round(x["infectious_period_cases"] / x["notification_rate"], 0
                      ),
            ),
            city_id=lambda x: x["city_id"].astype(int),
        )

    return df