コード例 #1
0
def scatter_reporting_district_data(*, indicator, district, target_year,
                                    target_month, reference_year,
                                    reference_month, **kwargs):

    db = Database()

    df = db.rep_data

    indicator = db.switch_indic_to_numerator(indicator, popcheck=False)

    df = db.filter_by_indicator(df, indicator)

    df = filter_by_district(df, district)

    date_list = get_date_list(target_year, target_month, reference_year,
                              reference_month)

    min_date = min(date_list[0], date_list[3])
    max_date = max(date_list[0], date_list[3])

    df = df[(df.date >= min_date) & (df.date <= max_date)]

    title = f'Percentages of facilities reporting on their 105:1 form, and percentage of reporting facilities that reported a value of one or above for {db.get_indicator_view(indicator)} in {district} district'

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

    return df
コード例 #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 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
コード例 #4
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
コード例 #5
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
コード例 #6
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
コード例 #7
0
def map_reporting_compare_data(
    *,
    indicator,
    target_year,
    target_month,
    reference_year,
    reference_month,
    report_map_compare_agg,
    **kwargs,
):

    db = Database()

    df = db.rep_data

    indicator = db.switch_indic_to_numerator(indicator, popcheck=False)

    df = db.filter_by_indicator(df, indicator)

    df = get_df_compare(
        df,
        indicator,
        target_year,
        target_month,
        reference_year,
        reference_month,
        report_map_compare_agg,
        report=True,
    )

    if report_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 proportion of reporting facilities that reported a non-zero number for 
            {db.get_indicator_view(indicator)} by district between 
            {quarter}{reference_month}-{reference_year} and {target_month}-{target_year}"""

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

    return df
コード例 #8
0
def map_reporting_period_data(
    *,
    indicator,
    target_year,
    target_month,
    reference_year,
    reference_month,
    report_map_period_agg,
    **kwargs,
):

    db = Database()

    df = db.rep_data

    indicator = db.switch_indic_to_numerator(indicator, popcheck=False)

    df = db.filter_by_indicator(df, indicator)

    df = get_df_period(
        df,
        indicator,
        target_year,
        target_month,
        reference_year,
        reference_month,
        report_map_period_agg,
        report=True,
    )

    if report_map_period_agg == "Show only month of interest":
        title = f"""Proportion of reporting facilities that reported a non-zero number for 
            {db.get_indicator_view(indicator)} on {reference_month}-{reference_year}"""

    else:
        title = f"""Average proportion of reporting facilities that reported a non-zero number for 
            {db.get_indicator_view(indicator)} between {reference_month}-{reference_year} and {target_month}-{target_year}"""

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

    return df
コード例 #9
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
コード例 #10
0
def overview_data(
    *,
    outlier,
    target_year,
    target_month,
    reference_year,
    reference_month,
    **kwargs,
):
    db = Database()

    df = db.raw_data

    df = filter_df_by_dates(df, target_year, target_month, reference_year,
                            reference_month)

    return df
コード例 #11
0
def get_title_country_overview(data, indicator_view_name, **controls):
    """
    get title for the first section based on a percentage calcution and the inputs
    """
    country_descrip = get_time_diff_perc(data, **controls)

    title = f"""Overview: Across the country, the {indicator_view_name} {country_descrip}
            between {controls.get('reference_month')}-{controls.get('reference_year')}
            and {controls.get('target_month')}-{controls.get('target_year')} """

    return title


# DATACARD 1 #

db = Database()

# TODO The class would need to include this title function by default to avoid repetition

default_title = get_title_country_overview(
    scatter_country_plot(init_data_set),
    db.get_indicator_view(DEFAULTS.get("indicator")),
    **DEFAULTS,
)

country_overview_scatter = ChartDataCard(
    title=default_title,
    fig_title="$label$",
    data=init_data_set,
    data_transform=scatter_country_plot,
    fig_type="Scatter",
コード例 #12
0
@timeit
def scatter_facility_plot(data):
    data = data.get("facility")

    data = data[data[data.columns[-1]] > 0]

    data = get_year_and_month_cols(data)

    data = get_sub_dfs(data, "year", YEARS,  "month")

    return data


# DATACARD 4 #
db = Database()

dropdown = NestedDropdown(
    id="treemap-agg-dropdown",
    options=[
        "Show only month of interest",
        "Show sum between month of reference and month of interest period",
        "Show average between month of reference and month of interest period",
    ],
    visible_id=False,
)

tree_map_district = AreaDataCard(
    fig_title="$label$",
    data=init_data_set,
    data_transform=tree_map_district_dated_plot,
コード例 #13
0
def get_title_reporting_country(data, indicator_view_name, **controls):
    """
    get title for the reporting section based on a percentage calculation and the inputs
    """
    descrip_reported, descrip_positive = get_report_perc(data, **controls)

    title = f'''Reporting: on {controls.get('target_month')}-{controls.get('target_year')},
            {descrip_reported} of facilities reported on their 105:1 form, and, out of those,
            {descrip_positive} reported one or above for {indicator_view_name}'''

    return title


# DATACARD 5 #

db = Database()

default_title = get_title_reporting_country(
    bar_reporting_country_plot(init_data_set),
    db.get_indicator_view(DEFAULTS.get('indicator')), **DEFAULTS)

stacked_bar_reporting_country = ChartDataCard(
    data=init_data_set,
    data_transform=bar_reporting_country_plot,
    title=default_title,
    fig_title="$label$",
    fig_object="Scatter",
    trace_params=bar_reporting_country_plot_tooltip(init_data_set),
)

stacked_bar_reporting_country.set_colors({