Sha256: 08664998e0c708410e4ce97fe35d117a2f194ed89986de60df4a7816d5c86fd9
Contents?: true
Size: 1.13 KB
Versions: 34
Compression:
Stored size: 1.13 KB
Contents
module Workarea module Reports class Customers include Report self.reporting_class = Metrics::User self.sort_fields = %w(revenue first_order_at last_order_at orders average_order_value) def aggregation result = [add_returning] result << filter_to_returning if params[:results_filter] == 'returning' result << filter_to_one_time if params[:results_filter] == 'one_time' result + [project_fields] end def add_returning { '$addFields' => { 'returning' => { '$ne' => ['$first_order_at', '$last_order_at'] } } } end def filter_to_returning { '$match' => { 'returning' => true } } end def filter_to_one_time { '$match' => { 'returning' => false } } end def project_fields { '$project' => { '_id' => 1, 'first_order_at' => 1, 'last_order_at' => 1, 'orders' => 1, 'revenue' => 1, 'average_order_value' => { '$divide': ['$revenue', '$orders'] } } } end end end end
Version data entries
34 entries across 34 versions & 1 rubygems