Class: Workarea::Insights::BestFullPriceCustomers

Inherits:
Base
  • Object
show all
Defined in:
app/models/workarea/insights/best_full_price_customers.rb

Class Method Summary collapse

Methods inherited from Base

beginning_of_last_month, current, end_of_last_month, generate_daily!, generate_weekly!, #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/best_full_price_customers.rb', line 5

def dashboards
  %w(people)
end

.find_results(ordered_since:) ⇒ Object



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

def find_results(ordered_since:)
  Metrics::User
    .full_price
    .ordered_since(ordered_since)
    .best
    .limit(Workarea.config.insights_users_list_max_results)
    .to_a
end

.generate_monthly!Object



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

def generate_monthly!
  [30.days, 180.days, 365.days].each do |days|
    results = find_results(ordered_since: days.ago)

    if results.present?
      create!(results: results.map(&:as_document))
      return
    end
  end
end