Class: Workarea::Insights::ColdSearches
- Inherits:
-
Base
- Object
- Base
- Workarea::Insights::ColdSearches
show all
- Defined in:
- app/models/workarea/insights/cold_searches.rb
Class Method Summary
collapse
Methods inherited from Base
beginning_of_last_month, current, end_of_last_month, generate_daily!, generate_monthly!, #include?, #slug
#releasable?
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
#embedded_children
Class Method Details
.dashboards ⇒ Object
5
6
7
|
# File 'app/models/workarea/insights/cold_searches.rb', line 5
def dashboards
%w(search)
end
|
.find_results(median:, standard_deviation:, min_deviations:) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/models/workarea/insights/cold_searches.rb', line 27
def find_results(median:, standard_deviation:, min_deviations:)
max_revenue_change = median - (standard_deviation * min_deviations)
max_revenue_change = max_revenue_change > 0 ? 0 : max_revenue_change
Metrics::SearchByWeek
.last_week
.where(:revenue_change.lt => max_revenue_change)
.order_by(revenue_change: :asc, prior_week_revenue: :desc, _id: :asc)
.limit(Workarea.config.insights_searches_list_max_results)
.to_a
end
|
.generate_weekly! ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/models/workarea/insights/cold_searches.rb', line 9
def generate_weekly!
median = revenue_change_median
standard_deviation = revenue_change_standard_deviation
[2, 1, 0].each do |min_deviations|
results = find_results(
median: median,
standard_deviation: standard_deviation,
min_deviations: min_deviations
)
if results.present?
create!(results: results.map(&:as_document))
return
end
end
end
|
39
40
41
|
# File 'app/models/workarea/insights/cold_searches.rb', line 39
def revenue_change_median
Metrics::SearchByWeek.last_week.declined_revenue.revenue_change_median
end
|
.revenue_change_standard_deviation ⇒ Object
43
44
45
|
# File 'app/models/workarea/insights/cold_searches.rb', line 43
def revenue_change_standard_deviation
Metrics::SearchByWeek.last_week.declined_revenue.revenue_change_standard_deviation
end
|