예제 #1
0
def tree_map_district_dated_data(
    *,
    outlier,
    indicator,
    district,
    target_year,
    target_month,
    reference_year,
    reference_month,
    trends_treemap_agg,
    **kwargs,
):

    db = Database()

    df = db.raw_data

    indicator = db.switch_indic_to_numerator(indicator)

    df = db.filter_by_indicator(df, indicator)

    df = filter_by_district(df, district)

    df = get_ratio(df, indicator, agg_level="facility")[0]

    isratio = get_ratio(df, indicator, agg_level="facility")[2]

    df_district_dated = get_df_period(
        df,
        indicator,
        target_year,
        target_month,
        reference_year,
        reference_month,
        trends_treemap_agg,
        index=["id", "facility_name"],
        isratio=isratio,
    )

    if trends_treemap_agg == "Show only month of interest":
        agg = "Contribution"
        period = f"on {target_month}-{target_year}"
    else:
        period = f"between {reference_month}-{reference_year} and {target_month}-{target_year}"

        if trends_treemap_agg == "Show sum between month of reference and month of interest period":
            if isratio:
                agg = "Average contribution"
            else:
                agg = "Total contribution"
        else:
            agg = "Average contribution"

    title = f"""{agg} of individual facilities in {district} district to 
            {db.get_indicator_view(indicator)} {period}"""

    df_district_dated = df_district_dated.rename(columns={indicator: title})

    return df_district_dated
예제 #2
0
def scatter_facility_data(*, outlier, indicator, district, facility, **kwargs):

    db = Database()

    df = db.raw_data

    indicator = db.switch_indic_to_numerator(indicator)

    df = db.filter_by_indicator(df, indicator)

    df = filter_by_district(df, district)

    df, index = get_ratio(df, indicator, agg_level="facility")[0:2]

    if not facility:
        facility = (df.sort_values(
            df.columns[-1], ascending=False).reset_index().facility_name[0])

    df = df[df.facility_name == facility].reset_index(drop=True)

    title = f"Evolution of {db.get_indicator_view(indicator)} in {facility}"

    df = df.rename(columns={indicator: title})

    df = df.set_index(index)

    return df
예제 #3
0
def map_bar_country_period_data(
    *,
    outlier,
    indicator,
    target_year,
    target_month,
    reference_year,
    reference_month,
    trends_map_period_agg,
    **kwargs,
):

    db = Database()

    df = db.raw_data

    df = db.filter_by_indicator(df, indicator)

    df, _, isratio = get_ratio(df, indicator, agg_level="district")

    df = get_df_period(
        df,
        indicator,
        target_year,
        target_month,
        reference_year,
        reference_month,
        trends_map_period_agg,
        isratio=isratio,
    )

    if trends_map_period_agg == "Show only month of interest":
        title = (
            title
        ) = f"Total {db.get_indicator_view(indicator)} on {target_month}-{target_year} by district"

    else:
        if trends_map_period_agg == "Show sum between month of reference and month of interest period":
            if isratio:
                data = "Average"
            else:
                data = "Total"
        else:
            data = "Average"

        title = f"{data} {db.get_indicator_view(indicator)} between {reference_month}-{reference_year} and {target_month}-{target_year}"

    df = df.rename(columns={indicator: title})

    return df
예제 #4
0
def scatter_country_data(*, outlier, indicator, **kwargs):

    # dfs, static,

    db = Database()

    df = db.raw_data

    df = db.filter_by_indicator(df, indicator)

    df, index = get_ratio(df, indicator, agg_level="country")[0:2]

    df = df.set_index(index)

    title = f"Total {db.get_indicator_view(indicator)} across the country"

    df = df.rename(columns={indicator: title})

    return df
예제 #5
0
def scatter_district_data(*, outlier, indicator, district, **kwargs):

    db = Database()

    df = db.raw_data

    df = db.filter_by_indicator(df, indicator)

    df = filter_by_district(df, district)

    df, index = get_ratio(df, indicator, agg_level="district")[0:2]

    df = df.set_index(index)

    title = f"Total {db.get_indicator_view(indicator)} in {district} district"

    df = df.rename(columns={indicator: title})

    return df
예제 #6
0
def map_bar_country_compare_data(
    *,
    outlier,
    indicator,
    target_year,
    target_month,
    reference_year,
    reference_month,
    trends_map_compare_agg,
    **kwargs,
):

    db = Database()

    df = db.raw_data

    df = db.filter_by_indicator(df, indicator)

    df = get_ratio(df, indicator, agg_level="district")[0]

    df = get_df_compare(
        df,
        indicator,
        target_year,
        target_month,
        reference_year,
        reference_month,
        trends_map_compare_agg,
    )

    if trends_map_compare_agg == "Compare quarters averages, using the three month periods ending on month of interest and month of reference":
        quarter = "the three months periods ending in "
    else:
        quarter = ""

    title = f"Percentage change in {db.get_indicator_view(indicator)} between {quarter}{reference_month}-{reference_year} and {target_month}-{target_year}"

    df = df.rename(columns={indicator: title})

    return df