Class: Workarea::InsightsSeeds
- Inherits:
-
Object
- Object
- Workarea::InsightsSeeds
- Includes:
- ActiveSupport::Testing::TimeHelpers
- Defined in:
- app/seeds/workarea/insights_seeds.rb
Instance Method Summary collapse
- #add_orders ⇒ Object
- #add_previous_month_insights ⇒ Object
- #add_previous_week_insights ⇒ Object
- #add_searches ⇒ Object
- #add_views ⇒ Object
- #perform ⇒ Object
- #process ⇒ Object
Instance Method Details
#add_orders ⇒ Object
56 57 58 |
# File 'app/seeds/workarea/insights_seeds.rb', line 56 def add_orders Order.all.each_by(1000) { |order| SaveOrderMetrics.perform(order) } end |
#add_previous_month_insights ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'app/seeds/workarea/insights_seeds.rb', line 78 def add_previous_month_insights (1...3).each do |months| travel_to months.months.ago GenerateInsights.generate_monthly_insights travel_back end end |
#add_previous_week_insights ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'app/seeds/workarea/insights_seeds.rb', line 68 def add_previous_week_insights (1...12).each do |weeks| travel_to weeks.weeks.ago GenerateInsights.generate_weekly_insights travel_back end end |
#add_searches ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/seeds/workarea/insights_seeds.rb', line 35 def add_searches terms = Catalog::Product .asc(:name) .limit(20) .flat_map { |product| product.name.split(' ') } .uniq terms.each do |term| 12.times do |weeks| travel_to weeks.weeks.ago rand(3).times { Metrics::SearchByDay.save_search(term, 0) } rand(3).times do Metrics::SearchByDay.save_search(term, rand(100)) end travel_back end end end |
#add_views ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/seeds/workarea/insights_seeds.rb', line 17 def add_views Catalog::Product.limit(100).pluck(:id).each do |id| 12.times do |weeks| travel_to weeks.weeks.ago rand(10).times { Metrics::ProductByDay.inc(key: { product_id: id }, views: 10) } travel_back end end Catalog::Category.limit(100).pluck(:id).each do |id| 12.times do |weeks| travel_to weeks.weeks.ago rand(10).times { Metrics::CategoryByDay.inc(key: { category_id: id }, views: 10) } travel_back end end end |
#perform ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'app/seeds/workarea/insights_seeds.rb', line 7 def perform puts 'Adding insights...' add_views add_searches add_orders process end |
#process ⇒ Object
60 61 62 63 64 65 66 |
# File 'app/seeds/workarea/insights_seeds.rb', line 60 def process add_previous_week_insights add_previous_month_insights ProcessProductRecommendations.new.perform GenerateInsights.generate_all! end |