コード例 #1
0
def get_the_buyer_id_spent_most_and_the_money_spent():
    """
    Returns the customer's _id_ who spent more in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer id and the sum the customer spent eg.: (aH34Jq#&, 42)
    """

    # your code
    sales_id_dict = sales.get_all_sales_ids_for_customer_ids()
    list_of_tuples = []
    for key in sales_id_dict.keys():
        sum_per_id  = sales.get_the_sum_of_prices(sales_id_dict[key])
        list_of_tuples.append((key, sum_per_id))

    maxi = list_of_tuples[0][1]

    returnable_list = []
    for elem in list_of_tuples:
        if elem[1] > maxi:
            maxi = elem[1]
    for elem in list_of_tuples:
        if elem[1] == maxi:
            returnable_list.append((elem))
    ui.print_result(returnable_list,'Most frequent buyer(s) ID.')        
コード例 #2
0
def get_the_buyer_name_spent_most_and_the_money_spent():
    """
    Returns the customer's _name_ who spent the most in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer name and the sum the customer spent eg.: ('Daniele Coach', 42)
    """

    # your code
    sales_id_dict = sales.get_all_sales_ids_for_customer_ids()
    list_of_tuples = []
    for key in sales_id_dict.keys():
        sum_per_id  = sales.get_the_sum_of_prices(sales_id_dict[key])
        list_of_tuples.append((key, sum_per_id))

    maxi = list_of_tuples[0][1]

    returnable_list = []
    for elem in list_of_tuples:
        if elem[1] > maxi:
            maxi = elem[1]
    for elem in list_of_tuples:
        if elem[1] == maxi:
            returnable_list.append((crm.get_name_by_id(elem[0]), elem[1]))
    ui.print_result(returnable_list,'Most frequent buyer(s) Name(s).')        
def get_the_buyer_name_spent_most_and_the_money_spent():
    """
    Returns the customer's _name_ who spent the most in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer name and the sum the customer spent eg.: ('Daniele Coach', 42)
    """

    # your code
    FIRST = 0
    ID = 1
    cmr_price = []
    list_of_prices = []
    all_IDs = sales.get_all_sales_ids_for_customer_ids()

    for key, value in all_IDs.items():
        cmr_price.append(
            (crm.get_name_by_id(key), sales.get_the_sum_of_prices(value)))

    maxnum = cmr_price[FIRST][ID]

    for tuple in cmr_price:
        list_of_prices.append(tuple[ID])
    maxnum = max(list_of_prices)

    for cmr in cmr_price:
        if cmr[ID] == maxnum:
            return cmr
def get_the_buyer_name_spent_most_and_the_money_spent():
    """
    Returns the customer's name who spent the most in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer name and the sum the customer spent eg.: ('Daniele Coach', 42)
    """
    # your code
    dicc=sales.get_all_sales_ids_for_customer_ids()
    lmao=[]
    for key, value in dicc.items():
        temp=[key,value]
        lmao.append(temp)
    sums=[]
    for i in range(len(lmao)):
        for j in range(len(lmao[i])):
            sums.append(sales.get_the_sum_of_prices(lmao[i][j]))

    highest=sums[0]
    place=0
    for i in range(len(sums)):
        if highest<sums[i]:
            highest=sums[i]
            place=i-1
    ID=lmao[place][0]
    andhisnameisJOHNCENA=crm.get_name_by_id(ID)
    reli=[andhisnameisJOHNCENA,highest]
    return tuple(reli)    
def get_the_most_frequent_buyers_names(num=1):
    """
    Returns 'num' number of buyers (more precisely: the customer's name) who bought most frequently in an
    ordered list of tuples of customer names and the number of their sales.

    Args:
        num: the number of the customers to return.

    Returns:
        list of tuples: Ordered list of tuples of customer names and num of sales
            The first one bought the most frequent. eg.: [('Genoveva Dingess', 8), ('Missy Stoney', 3)]
    """

    # your code
    sales_dict = sales.get_all_sales_ids_for_customer_ids()
    sales_keys = []
    sales_names = []
    for keys in sales_dict.keys():
        sales_keys.append(keys)
    for key in sales_keys:
        sales_names.append(crm.get_name_by_id(key))
    buyer_names = []
    #for i in range (len(sales_dict.values())):
    for i in range(num):
        buyer_names.append((sales_names[i], len(sales_dict[sales_keys[i]])))
    return buyer_names
def get_the_buyer_id_spent_most_and_the_money_spent():
    """
    Returns the customer's _id_ who spent more in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer id and the sum the customer spent eg.: (aH34Jq#&, 42)
    """

    # your code
    FIRST = 0
    PRICE = 1
    cmr_price = []
    list_of_prices = []
    customer_sales = sales.get_all_sales_ids_for_customer_ids()

    for key, value in customer_sales.items():
        cmr_price.append((key, sales.get_the_sum_of_prices(value)))

    maxnum = cmr_price[FIRST][PRICE]

    for tuple in cmr_price:
        list_of_prices.append(tuple[PRICE])

    maxnum = max(list_of_prices)

    for cmr in cmr_price:
        if cmr[PRICE] == maxnum:
            return cmr
def get_the_buyer_id_spent_most_and_the_money_spent():
    """
    Returns the customer's id who spent more in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer id and the sum the customer spent eg.: (aH34Jq#&, 42)
    """
    
    # your code
    dicc=sales.get_all_sales_ids_for_customer_ids()
    lmao=[]
    for key, value in dicc.items():
        temp=[key,value]
        lmao.append(temp)
    sums=[]
    for i in range(len(lmao)):
        for j in range(len(lmao[i])):
            sums.append(sales.get_the_sum_of_prices(lmao[i][j]))

    highest=sums[0]
    place=0
    for i in range(len(sums)):
        if highest<sums[i]:
            highest=sums[i]
            place=i-1
    ID=lmao[place][0]
    reli=[ID,highest]
    return tuple(reli)    
コード例 #8
0
def get_the_buyer_id_spent_most_and_the_money_spent():
    dictionary = sales.get_all_sales_ids_for_customer_ids()
    maxim = 0
    for i in dictionary:
        if sales.get_the_sum_of_prices(dictionary[i]) > maxim:
            maxim = sales.get_the_sum_of_prices(dictionary[i])
            max_id = i
    return (max_id, maxim)
def get_the_most_frequent_buyers_ids(num=1):
    """
    Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent in an
    ordered list of tuples of customer id and the number their sales.

    Args:
        num: the number of the customers to return.

    Returns:
        list of tuples: Ordered list of tuples of customer ids and num of sales
            The first one bought the most frequent. eg.: [(aH34Jq#&, 😎, (bH34Jq#&, 3)]
    """

    # your code
    dicc=sales.get_all_sales_ids_for_customer_ids()
    lmao=[]
    for key, value in dicc.items():
        temp=[key,value]
        lmao.append(temp)
   
    #lmao=[['jH34Jk#&', ['kH34Ju#&', 'jH34Ju#&', 'tH34Ju#&', 
    # 'eH34Ju#&', 'kH14Ju#&', 'kH35Ju#&', 'kH38Ju#&', 'kH94Ju#&', 
    # 'tH34Jl#&', 'eH34Jy#&', 'bH34Jx#&']], 
    # ['kH14Jt#&', ['bH34Ju#&', 'vH34Ju#&', 'kH34Ji#&', 'vH34Jz#&',
    #  'kH14Jt#&', 'kH35Jr#&', 'kH38Je#&', 'kH94Jw#&']],
    # ['kH14Jh#&', ['jH34Jk#&']]]
    sums=[]
    for i in range(len(lmao)):
        for j in range(len(lmao[i])):
            n=0
            for k in range(len(lmao[i][j])):
                    
                n+=1
            sums.append(n)
    #sums=[8, 11, 8, 8, 8, 1]
    nums=[]
    n=0
    while n!=len(sums):
        nums.append(sums[n+1])
        n+=2
    #nums=[11,8,1]
    ids=[lmao[0][0],lmao[1][0],lmao[2][0]]
    #ids=['jH34Jk#&', 'kH14Jt#&', 'kH14Jh#&'] 
    names=[]
    for i in range(len(ids)):
        names.append(crm.get_name_by_id(ids[i]))
    #names=['Missy Stoney', 'Sadye Hession', 'Kanesha Moshier']
    lsd={}
    for i in range(num):
        nameplusnum=[nums[i],ids[i]]
        lsd.update({nameplusnum[1]:nameplusnum[0]})
    reli=[]
    for key, value in lsd.items():
        temp=(key,value)
        reli.append(temp)
    return (reli)
コード例 #10
0
def get_the_buyer_id_spent_most_and_the_money_spent():
    result = []
    money_spent_by_customers = []
    ids_dict = sales.get_all_sales_ids_for_customer_ids()
    for key, value in ids_dict.items():
        ids_dict[key] = sales.get_the_sum_of_prices(ids_dict[key])
        money_spent_by_customers.append(ids_dict[key])
        max_money_spent = max(money_spent_by_customers)
    for key, value in ids_dict.items():
        if max_money_spent == ids_dict[key]:
            result.append(key)
            result.append(max_money_spent)
    return tuple(result)
コード例 #11
0
def get_the_buyer_id_spent_most_and_the_money_spent():  # Eszti
    """
    Returns the customer's _id_ who spent more in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer id and the sum the customer spent eg.: (aH34Jq#&, 42)
    """
    sales_ids_to_customer_id = sales.get_all_sales_ids_for_customer_ids()
    customer_and_max_spent_money = [None, 0]
    MONEY = 1
    for customer_id, sales_ids in sales_ids_to_customer_id.items():
        sum_of_prices = sales.get_the_sum_of_prices(sales_ids)
        if sum_of_prices > customer_and_max_spent_money[MONEY]:
            customer_and_max_spent_money = [customer_id, sum_of_prices]
    return tuple(customer_and_max_spent_money)
コード例 #12
0
def get_the_buyer_name_spent_most_and_the_money_spent():
    """
    Returns the customer's _name_ who spent the most in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer name and the sum the customer spent eg.: ('Daniele Coach', 42)
    """
    names = sales.get_all_sales_ids_for_customer_ids()
    new_dict = {}
    for key, values in names.items():
        new_dict.update(
            {crm.get_name_by_id(key): sales.get_the_sum_of_prices(values)})
    valami = []
    for key, values in new_dict.items():
        valami.append((key, values))
    result = valami[0]
    return result
コード例 #13
0
def get_the_buyer_id_spent_most_and_the_money_spent():
    """
    Returns the customer's _id_ who spent more in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer id and the sum the customer spent eg.: (aH34Jq#&, 42)
    """

    tmp = []
    dictionary = sales.get_all_sales_ids_for_customer_ids()
    for key, value in dictionary.items():
        if not tmp:
            tmp.append((key, sales.get_the_sum_of_prices(value)))
        elif sales.get_the_sum_of_prices(value) > tmp[0][1]:
            tmp[0] = (key, sales.get_the_sum_of_prices(value))

    return (tmp[0][0], tmp[0][1])
コード例 #14
0
def get_the_buyer_name_spent_most_and_the_money_spent():
    """
    Returns the customer's _name_ who spent the most in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer name and the sum the customer spent eg.: ('Daniele Coach', 42)
    """

    tmp = []
    dictionary = sales.get_all_sales_ids_for_customer_ids()
    for key, value in dictionary.items():
        if not tmp:
            tmp.append((key, sales.get_the_sum_of_prices(value)))
        elif sales.get_the_sum_of_prices(value) > tmp[0][1]:
            tmp[0] = (key, sales.get_the_sum_of_prices(value))

    return (crm.get_name_by_id(tmp[0][0]), tmp[0][1])
コード例 #15
0
def get_the_buyer_id_spent_most_and_the_money_spent():
    """
    Returns the customer's _id_ who spent more in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer id and the sum the customer spent eg.: (aH34Jq#&, 42)
    """

    customer_ids = sales.get_all_customer_ids()
    sales_for_customer_dict = sales.get_all_sales_ids_for_customer_ids()
    most_money_spent = 0
    for customer_id in customer_ids:
        sum_of_prices = get_the_sum_of_prices(sales_for_customer_dict[customer_id])
        if sum_of_prices > most_money_spent:
            most_money_spent = sum_of_prices
            biggest_spender_id = customer_id
    return (biggest_spender_id, most_money_spent)
コード例 #16
0
def get_the_buyer_id_spent_most_and_the_money_spent():
    """
    Returns the customer's _id_ who spent more in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer id and the sum the customer spent eg.: (aH34Jq#&, 42)
    """

    names = sales.get_all_sales_ids_for_customer_ids()
    new_dict = {}
    for key, values in names.items():
        new_dict.update({key: sales.get_the_sum_of_prices(values)})
    valami = []
    for key, values in new_dict.items():
        valami.append((key, values))
    result = valami[0]
    return result
コード例 #17
0
def get_the_buyer_id_spent_most_and_the_money_spent():
    """
    Returns the customer's _id_ who spent more in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer id and the sum the customer spent eg.: (aH34Jq#&, 42)
    """

    # 4
    most_sales = sales.get_num_of_sales_per_customer_ids()
    id_ = ''
    for key, value in most_sales.items():
        if value == max(most_sales.values()):
            id_ = key
    all_sale_ids = sales.get_all_sales_ids_for_customer_ids()
    sum_sales = sales.get_the_sum_of_prices(all_sale_ids[id_])
    return (id_, sum_sales)
コード例 #18
0
def get_the_buyer_name_spent_most_and_the_money_spent():
    """
    Returns the customer's _name_ who spent the most in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer name and the sum the customer spent eg.: ('Daniele Coach', 42)
    """

    # 3
    most_sales = sales.get_num_of_sales_per_customer_ids()
    id_ = ''
    for key, value in most_sales.items():
        if value == max(most_sales.values()):
            id_ = key
    name = crm.get_name_by_id(id_)
    all_sale_ids = sales.get_all_sales_ids_for_customer_ids()
    sum_sales = sales.get_the_sum_of_prices(all_sale_ids[id_])
    return (name, sum_sales)
コード例 #19
0
def get_the_buyer_name_spent_most_and_the_money_spent():
    """
    Returns the customer's _name_ who spent the most in sum and the money (s)he spent.

    Returns:
        tuple: Tuple of customer name and the sum the customer spent eg.: ('Daniele Coach', 42)
    """
    table = data_manager.get_table_from_file('sales/sales.csv')
    customer_dictionary = sales.get_all_sales_ids_for_customer_ids()
    customer_list = []
    for key, value in customer_dictionary.items():
        sales_sum = 0
        for i in value:
            for line in table:
                if i == line[0]:
                    sales_sum += int(line[2])
        customer_list.append((crm.get_name_by_id(key), sales_sum))
    max_name = max(customer_list, key=lambda t: t[1])
    return max_name
def get_the_buyer_id_spent_most_and_the_money_spent():
    """
    Returns the customer's _id_ who spent more in sum and the money (s)he spent.
    Returns a tuple of customer id and the sum the customer spent.
    eg.: (aH34Jq#&, 42)

   Returns:
        Tuple of customer id and the sum the customer spent
    """

    max_spent_money_cust_id = None
    max_spent_money = 0
    cust_id_sales_id = sales.get_all_sales_ids_for_customer_ids()
    for key, value in cust_id_sales_id.items():
        sum_of_one_cust = sales.get_the_sum_of_prices(value)
        if sum_of_one_cust > max_spent_money:
            max_spent_money = sum_of_one_cust
            max_spent_money_cust_id = key
    return max_spent_money_cust_id
コード例 #21
0
def get_names_no_sale_belongs_to():
    get_all_sales_for_customer = sales.get_all_sales_ids_for_customer_ids()
    content_of_table = common.get_crm_table()
    have_bought = True
    list_of_buyers_ids = []
    not_buyers_id = []
    not_buyers = []
    for key, value in get_all_sales_for_customer.items():
        if get_all_sales_for_customer[key] != []:
            have_bought = True
            list_of_buyers_ids.append(key)
        else:
            have_bought = False
            not_buyers.append(key)

    for i in range(len(content_of_table)):
        if content_of_table[i][0] not in list_of_buyers_ids:
            not_buyers_id.append(content_of_table[i][0])
    for id in not_buyers_id:
        not_buyers.append(crm.get_name_by_id(id))
    return not_buyers
def get_the_most_frequent_buyers_ids(num=1):
    """
    Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent in an
    ordered list of tuples of customer id and the number their sales.

    Args:
        num: the number of the customers to return.

    Returns:
        list of tuples: Ordered list of tuples of customer ids and num of sales
            The first one bought the most frequent. eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)]
    """

    # your code
    sales_dict = sales.get_all_sales_ids_for_customer_ids()
    sales_keys = []
    for keys in sales_dict.keys():
        sales_keys.append(keys)
    buyer_ids = []
    #for i in range (len(sales_dict.values())):
    for i in range(num):
        buyer_ids.append((sales_keys[i], len(sales_dict[sales_keys[i]])))
    return buyer_ids
コード例 #23
0
def get_the_most_frequent_buyers_ids(num=1):
    """
    Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent in an
    ordered list of tuples of customer id and the number their sales.

    Args:
        num: the number of the customers to return.

    Returns:
        list of tuples: Ordered list of tuples of customer ids and num of sales
            The first one bought the most frequent. eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)]
    """

    ID_ = 0
    SALES = 1

    customer_ids = sales.get_all_customer_ids()
    sales_for_customer_dict = sales.get_all_sales_ids_for_customer_ids()
    sales_for_customer_iterable = sales_for_customer_dict.items()
    # which ones are biggest buyers?
    sales_for_customer_tuples = [(sales_for_customer_iterable[ID_], len(sales_for_customer_iterable[SALES])) for customer in sales_for_customer_iterable]
    sales_for_customer_tuples.sort(key=lambda x: -x[SALES])
    return sales_for_customer_tuples