Class: Workarea::Reports::Customers
- Inherits:
-
Object
- Object
- Workarea::Reports::Customers
show all
- Includes:
- Report
- Defined in:
- app/queries/workarea/reports/customers.rb
Instance Method Summary
collapse
Methods included from Report
#cache_key, #count, #ends_at, #initialize, #limit, #more_results?, #results, #slug, #sort, #sort_by, #sort_direction, #sort_value, #starts_at
Instance Method Details
#add_returning ⇒ Object
16
17
18
19
20
21
22
|
# File 'app/queries/workarea/reports/customers.rb', line 16
def add_returning
{
'$addFields' => {
'returning' => { '$ne' => ['$first_order_at', '$last_order_at'] }
}
}
end
|
#aggregation ⇒ Object
9
10
11
12
13
14
|
# File 'app/queries/workarea/reports/customers.rb', line 9
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
|
#filter_to_one_time ⇒ Object
28
29
30
|
# File 'app/queries/workarea/reports/customers.rb', line 28
def filter_to_one_time
{ '$match' => { 'returning' => false } }
end
|
#filter_to_returning ⇒ Object
24
25
26
|
# File 'app/queries/workarea/reports/customers.rb', line 24
def filter_to_returning
{ '$match' => { 'returning' => true } }
end
|
#project_fields ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/queries/workarea/reports/customers.rb', line 32
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
|