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
17
# 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 => ids).limit(options[:limit]).all
end

#load_preferences_for_recommendation(person) ⇒ Object



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

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



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

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