import math


def computePairN(att_name, att_value, data):
    """
    Sub-function to compute number of pairs that input value > * used in Pairwise oracle

    Attributes:
        att_name: sensitive attribute name
        att_value: value of protected group of above attribute
        data: dataframe that stored the data 
    Return:  number of pairs of att_value > * in input data, number of pairs of att_value > * estimated using proportion, and proportion of group with att_value
    """
    # input checked_atts includes names of checked sensitive attributes
    total_N = len(data)
    # get the unique value of this sensitive attribute
    values_att = list (data[att_name].unique())
    # for each value, compute the current pairs and estimated fair pairs

    position_lists_val = data[data[att_name]==att_value].index+1
    size_vi = len(position_lists_val)
    count_vi_prefered_pairs = 0
    for i in range(len(position_lists_val)):
        cur_position = position_lists_val[i]
        left_vi = size_vi - (i + 1)
        count_vi_prefered_pairs = count_vi_prefered_pairs + (total_N - cur_position - left_vi)
    # compute estimated fair pairs
    total_pairs_vi = size_vi*(total_N-size_vi)
    estimated_vi_pair = math.ceil((size_vi / total_N) * total_pairs_vi)

    return int(count_vi_prefered_pairs),int(estimated_vi_pair),int(size_vi)