def get_month(mode, months): query = """ SELECT fk_customer, created_at FROM sales_order WHERE EXTRACT(YEAR_MONTH FROM created_at) in ('%s')""" % "','".join(months) return aux.typical_event_routing(mode, query, ['Purchased at'])
def get_payment(mode, payment_method): query = """ SELECT distinct(fk_customer), payment_method FROM sales_order WHERE payment_method = '%s'""" % payment_method return aux.typical_event_routing(mode, query, ['Payment Method'])
def get_month(mode, months): query = """ SELECT fk_customer, created_at FROM sales_order WHERE EXTRACT(MONTH FROM created_at) in (%s)""" % json.dumps(months).strip("[]") return aux.typical_event_routing(mode, query, ['Purchased at'])
def get_payment(mode, payment_method): query = """ SELECT distinct(fk_customer), payment_method FROM sales_order WHERE payment_method IN ('%s')""" % "','".join(payment_method) return aux.typical_event_routing(mode, query, ['Payment Method'])
def get_status(mode, item_status): query = """ SELECT so.fk_customer, sois.name FROM sales_order so JOIN sales_order_item soi ON so.id_sales_order = soi.fk_sales_order JOIN sales_order_item_status sois on sois.id_sales_order_item_status = soi.fk_sales_order_item_status WHERE sois.name in (%s) """ % json.dumps(item_status).strip("[]") return aux.typical_event_routing(mode, query, ['Item Status'])
def get_platform(mode, regex): """ Implements the query_event specification :param regex: The regular expression used by sql to match on lasttouch_click """ query = """ SELECT fk_customer, lasttouch_click FROM sales_order WHERE lasttouch_click REGEXP '%s'""" % regex return aux.typical_event_routing(mode, query, ['Last Touch Click'])
def get_repeat(mode, repeat): """ Implements the query_event specification :param mode: usual mode :param repeat: A string which contains the limits to check for the repeat frequency :return: """ query = """ SELECT fk_customer, count(*) as total FROM sales_order GROUP BY fk_customer HAVING %s""" % aux.extract_limits(input=repeat, item='total') return aux.typical_event_routing(mode, query, ['Repeat Frequency'])
def get_item(mode, item_count): """ Implements the query_event specification :param mode: usual mode :param item_count: a string representing the required range, supported values are "1", "n-m", "more than m" where "m" is an integer :return: (keys: set, result: dict > {id_customer, [data]}, headers: list) """ # return set(), {'mode': mode, 'item_count': item_count} # TODO, need to test query = """ SELECT distinct(a.fk_customer), count(*) as items FROM sales_order a JOIN sales_order_item b ON a.id_sales_order = b.fk_sales_order GROUP BY b.fk_sales_order HAVING %s """ % aux.extract_limits(input=item_count, item="items") return aux.typical_event_routing(mode, query, ['Item Count']) """