Guest User

Untitled

a guest
Feb 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. Rails.logger.level = 4
  2. _pry_.config.print = proc {}
  3.  
  4.  
  5. # Create Gamify::Matchups
  6.  
  7. load 'script/create_gamify_matchups.rb'
  8. begin
  9. Gamify::CreateMatchups.new(start_date: Time.zone.today - 2.weeks - 2.days).call!; 0
  10. rescue ActiveRecord::RecordInvalid
  11. end
  12.  
  13.  
  14. # Add some automatically awarded Gamify::Activities for today and yesterday
  15.  
  16. Visit.where.not(status: :unused).visit_start_between(Time.zone.yesterday.beginning_of_day, Time.zone.today.end_of_day).each do |visit|
  17. if rand(2) == 0
  18. begin
  19. visit.transaction do
  20. visit.update!(status: :completed)
  21. Gamify::Activity::CreateForVisit.new(visit: visit).call! if visit.gamify_activities.empty?; 0
  22. end
  23. rescue => e
  24. end
  25. end
  26. end
  27.  
  28.  
  29. # Award winners of games
  30.  
  31. Gamify::AssignGameWinnersJob.perform_now
  32.  
  33.  
  34. # Find expert with a gamify_activity and gamify_matchup for today
  35.  
  36. expert = Gamify::Activity.joins(visit: :calendar_block).where('calendar_blocks.start_time BETWEEN ? AND ?', Time.zone.today.beginning_of_day, Time.zone.today.end_of_day).joins(expert: :enjoyment_center).joins('INNER JOIN gamify_matchups ON gamify_matchups.home_enjoyment_center_id = enjoyment_centers.id OR gamify_matchups.away_enjoyment_center_id = enjoyment_centers.id').where('gamify_matchups.start_date <= ? AND gamify_matchups.end_date >= ?', Time.zone.today, Time.zone.today).first.expert
  37.  
  38.  
  39. Rails.logger.level = 0
  40. _pry_.config.print = Pry::DEFAULT_PRINT
Add Comment
Please, Sign In to add comment