def get_the_last_buyer_name(): """ Returns the customer _name_ of the customer made sale last. Returns: str: Customer name of the last buyer """ item_id = sales.get_item_id_sold_last() customer_id = sales.get_customer_id_by_sale_id(item_id) ui.print_result(crm.get_name_by_id(customer_id), "Last buyer name was: ") return crm.get_name_by_id(customer_id)
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)] """ # 5 most_sales = sales.get_num_of_sales_per_customer_ids() most_frequent = [] for number in range(num): id_ = '' for key, value in most_sales.items(): if value == max(most_sales.values()): id_ = key name = crm.get_name_by_id(id_) most_frequent.append((name, max(most_sales.values()))) most_sales.pop(id_) return most_frequent
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_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)] """ tmp = [] tmp_ordered = [] dictionary = sales.get_num_of_sales_per_customer_ids() for key, value in dictionary.items(): tmp.append((crm.get_name_by_id(key), value)) while tmp: maximum_value = tmp[0][1] maximum = tmp[0] for i in range(len(tmp)): if tmp[i][1] > maximum_value: maximum_value = tmp[i][1] maximum = tmp[i] tmp_ordered.append(maximum) tmp.remove(maximum) if len(tmp_ordered) == num: return (tmp_ordered)
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_most_frequent_buyers_names(num=1): """ Returns 'num' number of buyers (more precisely: the customers' name) who bought most frequently. Returns an ordered list of tuples of customer names and the number of their sales. (The first one bought the most frequent.) eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)] Args: num: the number of the customers to return. Returns: Ordered list of tuples of customer names and num of sales """ # {'kH14Jt#&': 8, 'jH34Jk#&': 11, 'kH14Jh#&': 1} cust_id_and_sum_of_buyed_items = sales.get_num_of_sales_per_customer_ids() for key, value in sorted(cust_id_and_sum_of_buyed_items.items(), key=lambda x: x[1], reverse=True)[num:]: del cust_id_and_sum_of_buyed_items[key] cust_ids = list(cust_id_and_sum_of_buyed_items) cust_names = [] for elem in cust_ids: cust_name = crm.get_name_by_id(elem) cust_names.append(cust_name) for key, val in cust_id_and_sum_of_buyed_items.items(): i = 1 cust_names.insert(i, val) return cust_names
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(table): result = [] result.append( crm.get_name_by_id( get_the_buyer_id_spent_most_and_the_money_spent(table)[0])) result.append(get_the_buyer_id_spent_most_and_the_money_spent(table)[1]) return tuple(result)
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): result = get_the_most_frequent_buyers_ids(num) for i in range(len(result)): result[i] = list(result[i]) name = crm.get_name_by_id(result[i][0]) result[i][0] = name result[i] = tuple(result[i]) return result
def get_the_last_buyer_name(): """ Returns the customer _name_ of the customer made sale last. Returns: str: Customer name of the last buyer """ return crm.get_name_by_id(get_the_last_buyer_id())
def get_the_buyer_name_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 max_name = crm.get_name_by_id(max_id) return (max_name, maxim)
def get_customer_who_did_not_buy_anything(): name_list = [] buyers = list(sales.get_all_customer_ids()) customers = list(crm.get_all_customer_ids()) for i in buyers: customers.remove(i) for customer in customers: name_list.append(crm.get_name_by_id(customer)) return name_list
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)
def get_the_most_frequent_buyers_names(num=1): temp = sales.get_num_of_sales_per_customer_ids() temp = sorted(temp.items(), key=lambda item: item[1], reverse=True) result = [] for i in range(len(temp)): name_and_id = (crm.get_name_by_id(temp[i][0]), temp[i][1]) result.append(name_and_id) return result[:num]
def get_the_last_buyer_name(): """ Returns the customer name of the customer made sale last. Returns: str: Customer name of the last buyer """ # your code return crm.get_name_by_id(sales.get_customer_id_by_sale_id(sales.get_item_id_sold_last()))
def get_the_last_buyer_name(): # Évi """ Returns the customer _name_ of the customer made sale last. Returns: str: Customer name of the last buyer """ sale_id = sales.get_item_id_sold_last() last_buyer_id = sales.get_customer_id_by_sale_id(sale_id) last_buyer_name = crm.get_name_by_id(last_buyer_id) return last_buyer_name
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) """ biggest_spender_id, most_money_spent = get_the_buyer_id_spent_most_and_the_money_spent() biggest_spender_name = crm.get_name_by_id(biggest_spender_id) return biggest_spender_name
def get_the_most_frequent_buyers_names(num=1): dict = sales.get_num_of_sales_per_customer_ids() my_lst = [] for i in dict: name = crm.get_name_by_id(i) appendable = [name, dict[i]] my_lst.append(appendable) my_lst.sort(key=lambda x: x[1], reverse=True) for i in range(len(my_lst)): my_lst[i] = tuple(my_lst[i]) return my_lst[0:num]
def customer_without_purchase(): all_customers = crm.get_all_ids() customers_with_purchase = list(sales.get_all_customer_ids()) for i in customers_with_purchase: all_customers.remove(i) result_list = [] for i in range(len(all_customers)): result_list.append(crm.get_name_by_id(all_customers[i])) return result_list
def get_the_last_buyer_name(): """ Returns the customer _name_ of the customer made sale last. Returns: str: Customer name of the last buyer """ # your code last_sold_item_id = sales.get_item_id_sold_last() customer_id = sales.get_customer_id_by_sale_id(last_sold_item_id) name = crm.get_name_by_id(customer_id) return name
def get_the_buyer_name_spent_most_and_the_money_spent(): # Eszti """ 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) """ BUYER = 0 customer_and_max_spent_money = list( get_the_buyer_id_spent_most_and_the_money_spent()) customer_and_max_spent_money[BUYER] = crm.get_name_by_id( customer_and_max_spent_money[BUYER]) return tuple(customer_and_max_spent_money)
def get_the_last_buyer_name(): """ Returns the customer _name_ of the customer made sale last. Returns: str: Customer name of the last buyer """ # find the _customer_id_ of the last sale in _sales_ # find the _name_ of the given _customer_id_ as _id_ in _crm_ last_buyer_id = last_buyer_name = crm.get_name_by_id(last_buyer_name) return last_buyer_name
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) """ # find the _customer_id_ who spent most in _sales_ # find the _name_ of the given _customer_id_ as _id_ in _crm_ biggest_spender_id = biggest_spender_name = crm.get_name_by_id(biggest_spender_id) return last_buyer_name
def get_the_last_buyer_name(): """ Returns the customer _name_ of the customer made sale last. Returns: Customer name of the last buyer """ # sales -> latest buyed item -> buyer id # crm buyer id -> buyer name sales_id = sales.get_item_id_sold_last() buyer_id = sales.get_customer_id_by_sale_id(sales_id) buyer_name = crm.get_name_by_id(buyer_id) return buyer_name
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
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])
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)] """ frequent_buyers = get_the_most_frequent_buyers_ids(num) result = [] for i in frequent_buyers: result.append((crm.get_name_by_id(i[0]), i[1])) return result
def get_the_most_frequent_buyers_names(num=1): # Max """ 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)] """ result_lst = [] sales_per_customer = sales.get_num_of_sales_per_customer_ids() for ID, NUM_OF_PURCHASES in sales_per_customer.items(): tuple_of_customer = ((crm.get_name_by_id(ID)), NUM_OF_PURCHASES) result_lst.append(tuple_of_customer) return result_lst[:num]
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)