-
-
Save halan/4171492 to your computer and use it in GitHub Desktop.
Sugestão de leituras com base no Tracking de leituras anteriores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'redis' | |
class Datanosql | |
def initialize | |
@r = Redis.new | |
end | |
def get_noticias_lida_por(user_id) | |
@r.smembers(user_id) | |
end | |
def get_leitores_que_leram(not_id) | |
@r.smembers(not_id) | |
end | |
end | |
class Noticia | |
def initialize | |
@d = Datanosql.new | |
end | |
def get_readers(not_id) | |
@d.get_leitores_que_leram(not_id) | |
end | |
end | |
class Leitor | |
def initialize | |
@d = Datanosql.new | |
end | |
def noticias_lidas(user_id) | |
@d.get_noticias_lida_por(user_id) | |
end | |
end | |
class Sugestao | |
def get(usuario, noticia) | |
@l = Leitor.new | |
@n = Noticia.new | |
@n.get_readers(noticia).map { |user_id| @l.noticias_lidas('user_' + user_id ) } | |
sugestao = noticias - @l.noticias_lidas(usuario) | |
sugestao.uniq!.sort | |
end | |
end | |
s = Sugestao.new | |
puts 'leituras sugeridas...' | |
puts s.get('user_13', 'not_16') | |
puts 'lido....' | |
l = Leitor.new | |
puts l.noticias_lidas('user_13') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment