Class: Workarea::Insights::ProductsPurchasedTogether

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

.dashboardsObject



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

def dashboards
  %w(catalog orders)
end

.generate_weekly!Object



9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/workarea/insights/products_purchased_together.rb', line 9

def generate_weekly!
  predictor = Recommendation::ProductPredictor.new

  results = top_sellers.map do |top_seller|
    related = predictor.similarities_for(top_seller.product_id)
    top_seller.as_document.merge(related_product_id: related.first)
  end

  results.reject! { |r| r.blank? || r['related_product_id'].blank? }
  create!(results: results) if results.present?
end

.top_sellersObject



21
22
23
24
25
26
# File 'app/models/workarea/insights/products_purchased_together.rb', line 21

def top_sellers
  Metrics::ProductByWeek
    .last_week
    .top_sellers
    .limit(Workarea.config.insights_products_list_max_results)
end