Sha256: fbefc33cc4288b467c55168e31f29500be91ad2ec97ff617a802373b0e459355
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
module Recommendations class User module Suggestions def suggestions Recommendations.redis.hgetall("recommendations:suggestions:user:#{id}") .select {|key, value| Float(value) > 0} end def update_suggestions ratings = self.ratings suggestions = ratings.inject({}) do |buffer, (item_id, score)| similars = Item.find(item_id).similars similars.reject! {|i| ratings.key?(i)} similars.each do |similar| buffer[similar] ||= 0 buffer[similar] += (Float(score) - 3) # 0..5 score => -2..2 end buffer end # #self.similars.each do |similar| #similars users #remover os ratings q o usuário já fez # similar_ratings = User.new(similar).ratings # similar_ratings.reject! {|i| ratings.key?(i.key)} # similar_ratings.each do |(item_id, score)| #user ratings # suggestions[item_id] ||= 0 # suggestions[item_id] += (Float(score) - 3) # 0..5 score => -2..2 # end # end # Recommendations.redis.hmset("recommendations:suggestions:user:#{id}", *suggestions.flatten) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
recommendations2-0.0.5 | lib/recommendations/user/suggestions.rb |