def test_total_in_traffic_and_total_out_traffic_by_shop(elasticsearch_traffic): # Total in traffic and out traffic by shop id write_fquery_output( FQuery(get_search()).values( Sum(TrafficCount.incoming_traffic), Sum(TrafficCount.outgoing_traffic), ).group_by(TrafficCount.shop_id, ), 'total_in_traffic_and_total_out_traffic_by_shop', )
def test_total_in_traffic_and_total_out_traffic(elasticsearch_traffic): # Total in traffic and out traffic write_fquery_output( FQuery(get_search()).values( Sum(TrafficCount.incoming_traffic), Sum(TrafficCount.outgoing_traffic), ), 'total_in_traffic_and_total_out_traffic', )
def test_total_sales_by_payment_type(elasticsearch_sale): # Total sales by payment type write_fquery_output( FQuery(get_search()).values(total_sales=Sum(Sale.price), ).group_by( Sale.payment_type, ), 'total_sales_by_payment_type', )
def test_total_sales_by_shop(elasticsearch_sale): # Total sales by shop write_fquery_output( FQuery(get_search()).values(total_sales=Sum(Sale.price), ).group_by( Sale.shop_id, ), 'total_sales_by_shop', )
def test_total_sales_by_shop_limited_size(elasticsearch_sale): # Total sales by shop limited size write_fquery_output( FQuery(get_search(), default_size=2).values(total_sales=Sum(Sale.price), ).group_by( Sale.shop_id, ), 'total_sales_by_shop_limited_size', )
def test_total_sales_and_avg_sales(elasticsearch_sale): # Total sales and avg sales, no aggregations write_fquery_output( FQuery(get_search()).values( total_sales=Sum(Sale.price), avg_sales=Avg(Sale.price), ), 'total_sales_and_avg_sales', )
def test_total_sales_by_shop_range_by_payment_type(elasticsearch_sale): # Total sales by shop range by payment_type ranges = [[1, 5], [5, 11], [11, 15]] write_fquery_output( FQuery(get_search()).values(total_sales=Sum(Sale.price), ).group_by( FieldWithRanges(Sale.shop_id, ranges=ranges), Sale.payment_type, ), 'total_sales_by_shop_range_by_payment_type', )
def test_total_sales_every_four_days(elasticsearch_sale): # Total sales every four days write_fquery_output( FQuery(get_search()).values(total_sales=Sum(Sale.price), ).group_by( DateHistogram( Sale.timestamp, interval='4d', ), ), 'total_sales_every_four_days', )
def test_total_sales_by_period(elasticsearch_sale, interval, pretty_period): # Total sales period by period write_fquery_output( FQuery(get_search()).values(total_sales=Sum(Sale.price), ).group_by( DateHistogram( Sale.timestamp, interval=interval, ), ), 'total_sales_{}_by_{}'.format(pretty_period, pretty_period), )
def test_total_sales_by_price_histogram(elasticsearch_sale): # Total sales by price histogram write_fquery_output( FQuery(get_search()).values(total_sales=Sum(Sale.price), ).group_by( Histogram( Sale.price, interval=100, ), ), 'total_sales_by_price_histogram', )
def test_total_sales_by_day_offset(elasticsearch_sale): # Total sales by day, with offset write_fquery_output( FQuery(get_search()).values(total_sales=Sum(Sale.price), ).group_by( DateHistogram( Sale.timestamp, interval='1d', offset='+8h', ), ), 'total_sales_by_day_offset_8hours', )
def test_total_and_avg_sales_by_product_type(elasticsearch_sale): # Average sale price by product type write_fquery_output( FQuery(get_search()).values( ReverseNested( Sale, avg_sales=Avg(Sale.price), total_sales=Sum(Sale.price), ), ).group_by(Sale.product_type, ), 'total_and_avg_sales_by_product_type', )
def test_total_sales_by_shop_range(elasticsearch_sale): # Total sales by shop range ranges = [{ 'from': 1, 'to': 5, 'key': '1 - 5', }, { 'from': 5, 'key': '5+', }] write_fquery_output( FQuery(get_search()).values(total_sales=Sum(Sale.price), ).group_by( FieldWithRanges(Sale.shop_id, ranges=ranges), ), 'total_sales_by_shop_range', )