def calculate_bool_stats(df, groupby_col, bool_col='bool_of_effective_complaints', count_col='id_llamado'):
    """
    Given a data frame with a group column, a boolean column and a value column,
    calculates stats by group:
        - Total value (bool0 + bool1)
        - Rate of bool1 over total for each group
        - Percentage of bool1 over complete df
        - Cumulative percentage over complete df

    Parameters
    ----------
    df: pandas.DataFrame
        Table schema
    groupby_col: string
        Column name for which to group by
    bool_col: string
        Boolean column
    count_col: string
        Numeric column over which calculate stats

    Return
    -------
    pandas.DataFrame
        Stats table
    """

    groupby_df = df.groupby([groupby_col, bool_col])[count_col].nunique().to_frame().reset_index()

    stats_df = groupby_df.pivot(index=groupby_col, columns=bool_col, values=count_col)\
    .fillna(0).reset_index().rename(index=str, columns={0: 'n_bool_0', 1: 'n_bool_1'})
    stats_df.columns.name = None

    stats_df['n_total'] = stats_df['n_bool_1'] + stats_df['n_bool_0']
    stats_df['rate'] = stats_df['n_bool_1'] / stats_df['n_total'] * 100
    stats_df['percentage'] = stats_df['n_bool_1'] / stats_df['n_bool_1'].sum() * 100

    stats_df = stats_df.sort_values('percentage', ascending=False)
    stats_df['cum_percentage'] = stats_df['percentage'].cumsum()

    return stats_df