Sha256: cf7561567c82b37076ff60ef91a1678b70057f0b10adff80976e26f8d1fa2925
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
namespace :recommendations do desc 'builds the recommendations dataset' task :build => [:environment] do MadeByMany::ActsAsRecommendable::Logic.module_eval do # This will need to change to your specific model: options = User.aar_options puts 'Finding items...' # You may want to optimize this SQL, like this: items = options[:on_class].pluck(:id) prefs = {} puts 'Finding users...' # You may want to optimize this SQL users = options[:class].includes(options[:on]) pbar = ProgressBar.create(:title => 'Gen matrix', :total => items.length) items.each do |item_id| prefs[item_id] ||= {} users.each do |user| if user.aar_items_with_scores[item_id] score = user.aar_items_with_scores[item_id].aar_score prefs[item_id][user.id] = score end end pbar.increment end pbar.finish matrix = [users.collect(&:id), prefs] pbar = ProgressBar.create(:title => 'Gen dataset', :total => prefs.keys.length) if options[:split_dataset] generate_dataset(options, matrix) {|item, scores| Rails.cache.write("aar_#{options[:on]}_#{item}", scores) pbar.inc } else result = {} generate_dataset(options, matrix) {|item, scores| result[item] = scores pbar.increment } Rails.cache.write("aar_#{options[:on]}_dataset", result) end pbar.finish puts 'Rebuild successful' end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts_as_recommendable-0.0.2 | lib/tasks/acts_as_recommendable_tasks.rake |