Class: Recommendations::User
- Inherits:
-
Object
- Object
- Recommendations::User
- Includes:
- Ratings
- Defined in:
- lib/recommendations/user.rb,
lib/recommendations/user/ratings.rb
Defined Under Namespace
Modules: Ratings
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(id) ⇒ User
constructor
A new instance of User.
- #recommendations ⇒ Object
- #update_recommendations ⇒ Object
Methods included from Ratings
Constructor Details
#initialize(id) ⇒ User
Returns a new instance of User.
9 10 11 |
# File 'lib/recommendations/user.rb', line 9 def initialize(id) @id = id end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/recommendations/user.rb', line 7 def id @id end |
Instance Method Details
#recommendations ⇒ Object
13 14 15 16 |
# File 'lib/recommendations/user.rb', line 13 def recommendations Recommendations.redis.hgetall("recommendations:user:#{id}") .select {|key, value| Float(value) > 0} end |
#update_recommendations ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/recommendations/user.rb', line 18 def update_recommendations = self. recommendations = .inject({}) do |buffer, (item_id, score)| similars = Item.find(item_id).similars similars.reject! {|i| .key?(i)} similars.each do |similar| buffer[similar] ||= 0 buffer[similar] += (Float(score) - 3) # 0..5 score => -2..2 end buffer end Recommendations.redis.hmset("recommendations:user:#{id}", *recommendations.flatten) end |