Implement Event Ratings

This commit is contained in:
shlok007 2016-09-22 20:06:46 -04:00 committed by Shlok Srivastava
parent 5be1ad52ee
commit 20f4853487
67 changed files with 1298 additions and 378 deletions

View file

@ -0,0 +1,20 @@
namespace :votes do
desc 'Migrate old votes to new voting system'
task migrate: :environment do
ActiveRecord::Base.transaction do
Conference.all.each do |conf|
VotableField.create(title: 'Overall', conference_id: conf.id, for_admin: true, stars: conf.program.rating, votable_type: 'Event')
Event.all.each do |event|
votes = Vote.where(event_id: event.id)
break unless votes.present?
avg_votes = votes.pluck(:rating).sum / votes.count
votes.each do |vote|
Rate.create(dimension: 'Overall', rater_id: vote.user_id, rateable_type: 'Event', stars: vote.rating, rateable_id: event.id )
end
RatingCache.create(cacheable_id: event.id, cacheable_type: 'Event', avg: avg_votes, qty: votes.count, dimension: 'Overall')
end
end
end
puts 'All done!'
end
end