add user similarity report
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
#c-reports {
|
||||||
|
#a-similar-users {
|
||||||
|
div.box {
|
||||||
|
h2, h3 {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
margin-bottom: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clearfix hacks */
|
||||||
|
div.box:before, div.box:after {
|
||||||
|
content: "";
|
||||||
|
display: table;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.box:after {
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
class ReportsController < ApplicationController
|
class ReportsController < ApplicationController
|
||||||
|
before_filter :member_only
|
||||||
|
before_filter :gold_only, :only => [:similar_users]
|
||||||
|
|
||||||
def user_promotions
|
def user_promotions
|
||||||
@report = Reports::UserPromotions.new
|
@report = Reports::UserPromotions.new
|
||||||
end
|
end
|
||||||
@@ -14,4 +17,9 @@ class ReportsController < ApplicationController
|
|||||||
def uploads
|
def uploads
|
||||||
@report = Reports::Uploads.new(params[:min_date], params[:max_date], params[:queries])
|
@report = Reports::Uploads.new(params[:min_date], params[:max_date], params[:queries])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def similar_users
|
||||||
|
@report = Reports::UserSimilarity.new(CurrentUser.id)
|
||||||
|
@presenter = UserSimilarityPresenter.new(@report)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
33
app/logical/reports/user_similarity.rb
Normal file
33
app/logical/reports/user_similarity.rb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
module Reports
|
||||||
|
class UserSimilarity
|
||||||
|
attr_reader :user_id
|
||||||
|
|
||||||
|
def initialize(user_id)
|
||||||
|
@user_id = user_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def user
|
||||||
|
User.find(user_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fetch_similar_user_ids
|
||||||
|
return NotImplementedError unless Danbooru.config.report_server
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"key" => Danbooru.config.shared_remote_key,
|
||||||
|
"user_id" => user_id
|
||||||
|
}
|
||||||
|
uri = URI.parse("#{Danbooru.config.listbooru_server}/reports/user_similarity")
|
||||||
|
uri.query = URI.encode_www_form(params)
|
||||||
|
|
||||||
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
||||||
|
resp = http.request_get(uri.request_uri)
|
||||||
|
if resp.is_a?(Net::HTTPSuccess)
|
||||||
|
resp.body
|
||||||
|
else
|
||||||
|
raise "HTTP error code: #{resp.code} #{resp.message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
34
app/presenters/user_similarity_presenter.rb
Normal file
34
app/presenters/user_similarity_presenter.rb
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
class UserSimilarityPresenter
|
||||||
|
attr_reader :report, :not_ready
|
||||||
|
|
||||||
|
def initialize(report)
|
||||||
|
@report = report
|
||||||
|
fetch
|
||||||
|
end
|
||||||
|
|
||||||
|
def not_ready?
|
||||||
|
not_ready
|
||||||
|
end
|
||||||
|
|
||||||
|
def insufficient_data?
|
||||||
|
report.user.favorite_count < 500
|
||||||
|
end
|
||||||
|
|
||||||
|
def fetch
|
||||||
|
user_ids = report.fetch_similar_user_ids
|
||||||
|
|
||||||
|
if user_ids = "not ready"
|
||||||
|
@not_ready = true
|
||||||
|
else
|
||||||
|
@user_ids = user_ids.scan(/\d+/).slice(0, 10)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def each_user(&block)
|
||||||
|
User.where(id: user_ids).each(&block)
|
||||||
|
end
|
||||||
|
|
||||||
|
def each_favorite_for(user, &block)
|
||||||
|
user.favorites.limit(6).joins(:post).reorder("favorites.id desc").map(&:post).each(&block)
|
||||||
|
end
|
||||||
|
end
|
||||||
28
app/views/reports/similar_users.html.erb
Normal file
28
app/views/reports/similar_users.html.erb
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<div id="c-reports">
|
||||||
|
<div id="a-similar-users">
|
||||||
|
<h1>Similar Users</h1>
|
||||||
|
|
||||||
|
<% if @presenter.insufficient_data? %>
|
||||||
|
<p>You need at least 500 favorites before Danbooru can calculate users similar to you.</p>
|
||||||
|
|
||||||
|
<% elsif @presenter.not_ready? %>
|
||||||
|
<p>The report is still being generated. Check back in a few minutes.</p>
|
||||||
|
|
||||||
|
<% else %>
|
||||||
|
<% @presenter.each_user do |user| %>
|
||||||
|
<div class="box">
|
||||||
|
<h2><%= link_to user.pretty_name, user_path(user) %></h2>
|
||||||
|
<div>
|
||||||
|
<% @presenter.each_favorite_for(user) do |post| %>
|
||||||
|
<%= PostPresenter.preview(post, :tags => "fav:#{user.name}") %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
Similar Users - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
@@ -223,6 +223,7 @@ Rails.application.routes.draw do
|
|||||||
get "reports/janitor_trials" => "reports#janitor_trials"
|
get "reports/janitor_trials" => "reports#janitor_trials"
|
||||||
get "reports/contributors" => "reports#contributors"
|
get "reports/contributors" => "reports#contributors"
|
||||||
get "reports/uploads" => "reports#uploads"
|
get "reports/uploads" => "reports#uploads"
|
||||||
|
get "reports/similar_users" => "reports#similar_users"
|
||||||
resources :saved_searches, :except => [:show] do
|
resources :saved_searches, :except => [:show] do
|
||||||
collection do
|
collection do
|
||||||
get :categories
|
get :categories
|
||||||
|
|||||||
Reference in New Issue
Block a user