Class: Workarea::Insights::MostDiscountedProducts

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

add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list

Methods included from Mongoid::Document

#embedded_children

Class Method Details

.dashboardsObject



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

def dashboards
  %w(catalog marketing)
end

.generate_resultsObject



14
15
16
17
18
19
20
21
# File 'app/models/workarea/insights/most_discounted_products.rb', line 14

def generate_results
  Metrics::ProductByWeek
    .last_week
    .where(:discount_rate.gt => 0, :orders.gt => 0)
    .order_by(average_discount: :desc, discount_rate: :desc, conversion_rate: :desc, _id: :asc)
    .limit(Workarea.config.insights_products_list_max_results)
    .to_a
end

.generate_weekly!Object



9
10
11
12
# File 'app/models/workarea/insights/most_discounted_products.rb', line 9

def generate_weekly!
  results = generate_results
  create!(results: results.map(&:as_document)) if results.present?
end