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_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'])
    """
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'])

    """