Class: Workarea::Insights::MostDiscountedProducts
- Inherits:
-
Base
- Object
- Base
- Workarea::Insights::MostDiscountedProducts
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
#releasable?
assert_valid_config!, async, disable, enable, inline, #run_callbacks
Class Method Details
.dashboards ⇒ Object
5
6
7
|
# File 'app/models/workarea/insights/most_discounted_products.rb', line 5
def dashboards
%w(catalog marketing)
end
|
.generate_results ⇒ Object
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
|