Class: Workarea::Insights::SearchesToImprove
- Inherits:
-
Base
- Object
- Base
- Workarea::Insights::SearchesToImprove
show all
- Defined in:
- app/models/workarea/insights/searches_to_improve.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?
assert_valid_config!, async, disable, enable, inline, #run_callbacks
Class Method Details
.avg_conversion_rate_of_top_five_searches_deciles ⇒ Object
38
39
40
|
# File 'app/models/workarea/insights/searches_to_improve.rb', line 38
def avg_conversion_rate_of_top_five_searches_deciles
Metrics::SearchByWeek.last_week.by_searches_percentile(51..100).avg(:conversion_rate)
end
|
.avg_conversion_rate_of_top_two_searches_deciles ⇒ Object
25
26
27
|
# File 'app/models/workarea/insights/searches_to_improve.rb', line 25
def avg_conversion_rate_of_top_two_searches_deciles
Metrics::SearchByWeek.last_week.by_searches_percentile(81..100).avg(:conversion_rate)
end
|
.dashboards ⇒ Object
5
6
7
|
# File 'app/models/workarea/insights/searches_to_improve.rb', line 5
def dashboards
%w(search)
end
|
.first_pass ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'app/models/workarea/insights/searches_to_improve.rb', line 15
def first_pass
Metrics::SearchByWeek
.last_week
.by_searches_percentile(91..100)
.where(:conversion_rate.lt => avg_conversion_rate_of_top_two_searches_deciles)
.order_by(conversion_rate: :asc, searches: :desc, _id: :asc)
.limit(Workarea.config.insights_searches_list_max_results)
.to_a
end
|
.generate_weekly! ⇒ Object
9
10
11
12
13
|
# File 'app/models/workarea/insights/searches_to_improve.rb', line 9
def generate_weekly!
results = first_pass
results = second_pass if results.blank?
create!(results: results.map(&:as_document)) if results.present?
end
|
.second_pass ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'app/models/workarea/insights/searches_to_improve.rb', line 29
def second_pass
Metrics::SearchByWeek
.last_week
.where(:conversion_rate.lt => avg_conversion_rate_of_top_five_searches_deciles)
.order_by(conversion_rate: :asc, searches: :desc, _id: :asc)
.limit(Workarea.config.insights_searches_list_max_results)
.to_a
end
|