Module: Coletivo::Models::Recommendable::ClassMethods

Defined in:
lib/coletivo/models/recommendable.rb

Instance Method Summary collapse

Instance Method Details

#find_recommendations_for(person, options = {}) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/coletivo/models/recommendable.rb', line 10

def find_recommendations_for(person, options = {})
  preferences = options[:preferences] ||=
    load_preferences_for_recommendation(person)
  top = predict_highest_ratings(person, preferences, options)
  ids = top.collect(&:last)
  where(:_id.in => ids).limit(options[:limit]).all
end

#load_preferences_for_recommendation(person) ⇒ Object



31
32
33
34
35
36
# File 'lib/coletivo/models/recommendable.rb', line 31

def load_preferences_for_recommendation(person)
  r = Coletivo::Config.ratings_container\
        .find_for_recommendation(person, self)

  map_ratings_to_preferences(r)
end

#map_ratings_to_preferences(ratings) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/coletivo/models/recommendable.rb', line 18

def map_ratings_to_preferences(ratings)
  #TODO: (???) Item based mapping.
  key, subkey = :person_id, :rateable_id
  preferences = {}

  ratings.each do |rating|
    p = preferences[rating.send(key)] ||= {}
    p[rating.send(subkey)] = rating.weight
  end

  preferences
end