Class: Workarea::Insights::ProductsToImprove

Inherits:
Base
  • Object
show all
Defined in:
app/models/workarea/insights/products_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

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

assert_valid_config!, async, disable, enable, inline, #run_callbacks

Methods included from Mongoid::Document

#embedded_children

Class Method Details

.avg_conversion_rate_of_top_five_views_decilesObject



38
39
40
# File 'app/models/workarea/insights/products_to_improve.rb', line 38

def avg_conversion_rate_of_top_five_views_deciles
  Metrics::ProductByWeek.last_week.by_views_percentile(51..100).avg(:conversion_rate)
end

.avg_conversion_rate_of_top_two_views_decilesObject



25
26
27
# File 'app/models/workarea/insights/products_to_improve.rb', line 25

def avg_conversion_rate_of_top_two_views_deciles
  Metrics::ProductByWeek.last_week.by_views_percentile(81..100).avg(:conversion_rate)
end

.dashboardsObject



5
6
7
# File 'app/models/workarea/insights/products_to_improve.rb', line 5

def dashboards
  %w(catalog)
end

.first_passObject



15
16
17
18
19
20
21
22
23
# File 'app/models/workarea/insights/products_to_improve.rb', line 15

def first_pass
  Metrics::ProductByWeek
    .last_week
    .by_views_percentile(91..100)
    .where(:conversion_rate.lt => avg_conversion_rate_of_top_two_views_deciles)
    .order_by(conversion_rate: :asc, views: :desc, _id: :asc)
    .limit(Workarea.config.insights_products_list_max_results)
    .to_a
end

.generate_weekly!Object



9
10
11
12
13
# File 'app/models/workarea/insights/products_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_passObject



29
30
31
32
33
34
35
36
# File 'app/models/workarea/insights/products_to_improve.rb', line 29

def second_pass
  Metrics::ProductByWeek
    .last_week
    .where(:conversion_rate.lt => avg_conversion_rate_of_top_five_views_deciles)
    .order_by(conversion_rate: :asc, views: :desc, _id: :asc)
    .limit(Workarea.config.insights_products_list_max_results)
    .to_a
end