Class: Workarea::Reports::FirstTimeVsReturningSales
- Inherits:
-
Object
- Object
- Workarea::Reports::FirstTimeVsReturningSales
show all
- Includes:
- GroupByTime, Report
- Defined in:
- app/queries/workarea/reports/first_time_vs_returning_sales.rb
Instance Method Summary
collapse
#group_by, #time_group_id
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_calculated_fields ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/queries/workarea/reports/first_time_vs_returning_sales.rb', line 44
def add_calculated_fields
{
'$addFields' => {
'first_time_orders' => { '$subtract' => ['$orders', '$returning_orders'] },
'percent_returning' => {
'$multiply' => [
{ '$divide' => ['$returning_orders', '$orders'] },
100
]
}
}
}
end
|
#aggregation ⇒ Object
10
11
12
|
# File 'app/queries/workarea/reports/first_time_vs_returning_sales.rb', line 10
def aggregation
[filter, project_used_fields, group_by_time, add_calculated_fields]
end
|
#filter ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'app/queries/workarea/reports/first_time_vs_returning_sales.rb', line 14
def filter
{
'$match' => {
'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
'orders' => { '$gt' => 0 }
}
}
end
|
#group_by_time ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'app/queries/workarea/reports/first_time_vs_returning_sales.rb', line 33
def group_by_time
{
'$group' => {
'_id' => time_group_id,
'starts_at' => { '$min' => '$reporting_on' },
'orders' => { '$sum' => '$orders' },
'returning_orders' => { '$sum' => '$returning_orders' },
}
}
end
|
#project_used_fields ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'app/queries/workarea/reports/first_time_vs_returning_sales.rb', line 23
def project_used_fields
{
'$project' => {
'reporting_on' => 1,
'orders' => 1,
'returning_orders' => 1
}
}
end
|