def get_platform(mode, platform): """ Implements the query_event specification Get filtered results based on the platform of purchase :param platform: a list of platforms :return: """ query = "SELECT fk_customer, misc FROM sales_order" def execute_fn(dbname): cursor = aux.execute_query(query, dbname) return map( lambda k: list(k), list(cursor) ) init_result = aux.execute_on_database(mode, execute_fn) parsed_list = map( lambda l: [l[0], _get_plat_from_misc(l[1])], init_result ) fin_result = filter(lambda k: k[1] in platform, parsed_list) keys, result = aux.convert_to_id_dict(fin_result) return keys, result, ['Platform']
def get_category(mode, cat_list): """ Follows the query_event specifications Get combination list with id_customer where each of these id_customer has bought items from the given category list :param mode: Similar to mode in event_customer, any one of 'all', 'uae', 'ksa' :param cat_list: a list of categories to match :return: A tuple ( keys: A set of id_customer, result: A dictionary { id_customer, [additional] }, headers: A list of headers ) """ r1 = aux.execute_on_database(mode, _step1) # id_cutomer | sku | data ... r2 = _step2(cat_list) # { sku : category } result = {} # { id: [order_number, grand_total, category] keys = set() for tpl in r1: sku = tpl[1] cid = tpl[0] if sku in r2 and cid not in result: data = list(tpl[2:]) data.append(r2[sku]) # Add the category as well result[cid] = data keys.add(cid) return keys, result, headers
def get_platform(mode, platform): """ Implements the query_event specification Get filtered results based on the platform of purchase :param platform: a list of platforms :return: """ query = "SELECT fk_customer, misc FROM sales_order" def execute_fn(dbname): cursor = aux.execute_query(query, dbname) return map(lambda k: list(k), list(cursor)) init_result = aux.execute_on_database(mode, execute_fn) parsed_list = map(lambda l: [l[0], _get_plat_from_misc(l[1])], init_result) fin_result = filter(lambda k: k[1] in platform, parsed_list) keys, result = aux.convert_to_id_dict(fin_result) return keys, result, ['Platform']