Exemplo n.º 1
0
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',
    )
Exemplo n.º 2
0
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',
    )
Exemplo n.º 3
0
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',
    )
Exemplo n.º 4
0
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',
    )
Exemplo n.º 5
0
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',
    )
Exemplo n.º 6
0
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',
    )
Exemplo n.º 7
0
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',
    )
Exemplo n.º 8
0
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',
    )
Exemplo n.º 9
0
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),
    )
Exemplo n.º 10
0
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',
    )
Exemplo n.º 11
0
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',
    )
Exemplo n.º 12
0
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',
    )
Exemplo n.º 13
0
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',
    )