Commit 7e2ae063 authored by Michael Rose's avatar Michael Rose

experimental: /user/recommendations view to show Sybill recs

parent 1d9c1ff0
class User::RecommendationsController < ApplicationController
include StoryFetchers
before_action :authenticate_user!
def index
top_n = $sybill.recommend(@current_user.id).map { |recommendation| recommendation['story_id'].to_i }
@opened_stories = opened_stories(top_n)
@read_stories = read_stories(top_n)
@queued_stories = queued_stories(top_n)
@stories = Story.where(id: top_n)
.includes([:author, :story_to_thread])
.joins([:author])
.to_a
.reject { |r| r == nil }
end
def create
@queue_entry = @current_user.queue_entries.where(:story_id => params[:story_id]).first
@queue_entry ||= @current_user.queue_entries.build
if @queue_entry.new_record? || !@queue_entry.deleted_at.nil?
@queue_entry.deleted_at = nil
@queue_entry.story_id = params[:story_id]
@queue_entry.save!
render json: @queue_entry, status: :created
else
render json: @queue_entry, status: :conflict
end
end
def show
end
def destroy
@current_user.queue_entries.where(:story_id => params[:story_id]).each(&:soft_delete)
render status: :ok, body: nil
end
end
%h1 Recommended Stories
%p.lead Stories you might like based on your previous activity.
- @stories.each do |story|
.story
= render :partial => 'search/story_result', locals: { story_result: story }
\ No newline at end of file
require 'scryer/scryer_client'
require 'scryer/sybill_client'
$scryer = Scryer::Client.new
$sybill = Scryer::SybillClient.new
......@@ -48,6 +48,7 @@ Rails.application.routes.draw do
post 'queue' => 'queue_entries#create'
delete 'queue' => 'queue_entries#destroy'
resources :saved_searches
get 'recommendations' => 'recommendations#index', :as => :recommendations
end
resources :feedback
......
require 'faraday'
module Scryer
class SybillClient
def initialize(api_base='http://127.0.0.1:1777')
@conn = Faraday.new(:url => api_base) do |faraday|
faraday.request :json
faraday.response :rashify
faraday.response :json
faraday.response :logger, ::Logger.new(STDOUT), bodies: true
faraday.use :instrumentation
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
faraday.headers['User-Agent'] = 'Scryer'
end
end
def recommend(user_id)
resp = @conn.get do |req|
req.url "/recommend/stories/#{user_id}"
end
resp.body
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment