forked from e621ng/e621ng
remove similar users report
This commit is contained in:
parent
d999bd124c
commit
718e641f51
@ -87,7 +87,6 @@ The following features are delegated to the [Reportbooru service](https://github
|
||||
* Popular searches report
|
||||
* Favorite searches
|
||||
* Upload trend graphs
|
||||
* Similar users (via favorites and post votes)
|
||||
|
||||
### Recommender Service
|
||||
|
||||
|
@ -1,17 +1,11 @@
|
||||
class ReportsController < ApplicationController
|
||||
before_action :member_only, :except => [:upload_tags]
|
||||
before_action :gold_only, :only => [:similar_users]
|
||||
before_action :moderator_only, :only => [:post_versions, :post_versions_create, :down_voting_post_report, :down_voting_post_report_create]
|
||||
|
||||
def uploads
|
||||
@report = Reports::Uploads.new(params[:min_date], params[:max_date], params[:queries])
|
||||
end
|
||||
|
||||
def similar_users
|
||||
@report = Reports::UserSimilarity.new(CurrentUser.id)
|
||||
@presenter = UserSimilarityPresenter.new(@report)
|
||||
end
|
||||
|
||||
def post_versions
|
||||
end
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
#c-reports {
|
||||
#a-similar-users {
|
||||
div.box {
|
||||
h2, h3 {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
span.accuracy {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* clearfix hacks */
|
||||
div.box:before, div.box:after {
|
||||
content: "";
|
||||
display: table;
|
||||
}
|
||||
|
||||
div.box:after {
|
||||
clear: both;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
module Reports
|
||||
class UserSimilarity
|
||||
NOT_READY_STRING = "not ready"
|
||||
|
||||
attr_reader :user_id, :result
|
||||
|
||||
def initialize(user_id)
|
||||
@user_id = user_id
|
||||
end
|
||||
|
||||
def user
|
||||
User.find(user_id)
|
||||
end
|
||||
|
||||
def prime(endpoint = "user_similarity")
|
||||
10.times do
|
||||
@result = fetch_similar_user_ids(endpoint)
|
||||
if @result == NOT_READY_STRING
|
||||
sleep(60)
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_similar_user_ids(endpoint = "user_similarity")
|
||||
raise NotImplementedError.new("the Reportbooru service isn't configured. User similarity is not available.") unless Danbooru.config.reportbooru_server
|
||||
|
||||
params = {
|
||||
"key" => Danbooru.config.reportbooru_key,
|
||||
"user_id" => user_id
|
||||
}
|
||||
uri = URI.parse("#{Danbooru.config.reportbooru_server}/reports/#{endpoint}")
|
||||
uri.query = URI.encode_www_form(params)
|
||||
|
||||
resp = HTTParty.get(uri, Danbooru.config.httparty_options)
|
||||
if resp.success?
|
||||
resp.body
|
||||
else
|
||||
raise "HTTP error code: #{resp.code} #{resp.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,48 +0,0 @@
|
||||
class UserSimilarityPresenter
|
||||
attr_reader :report, :user_ids, :user_ids_with_scores, :not_ready
|
||||
|
||||
def initialize(report)
|
||||
@report = report
|
||||
fetch
|
||||
end
|
||||
|
||||
def not_ready?
|
||||
not_ready
|
||||
end
|
||||
|
||||
def insufficient_data?
|
||||
report.user.favorite_count < 200
|
||||
end
|
||||
|
||||
def fetch
|
||||
data = report.fetch_similar_user_ids
|
||||
|
||||
if data == Reports::UserSimilarity::NOT_READY_STRING
|
||||
@not_ready = true
|
||||
else
|
||||
@user_ids_with_scores = data.scan(/\S+/).in_groups_of(2)
|
||||
end
|
||||
end
|
||||
|
||||
def user_ids
|
||||
user_ids_with_scores.map(&:first)
|
||||
end
|
||||
|
||||
def scores
|
||||
user_ids_with_scores.map(&:last)
|
||||
end
|
||||
|
||||
def each_user(&block)
|
||||
user_ids_with_scores.each do |user_id, score|
|
||||
user = User.find(user_id)
|
||||
|
||||
if !user.hide_favorites?
|
||||
yield(user, 100 * score.to_f)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def each_favorite_for(user, &block)
|
||||
user.favorites.limit(18).joins(:post).reorder("favorites.id desc").map(&:post).each(&block)
|
||||
end
|
||||
end
|
@ -15,10 +15,6 @@
|
||||
<section id="related-box">
|
||||
<h1>Related</h1>
|
||||
<ul id="related-list">
|
||||
<% if CurrentUser.is_gold? %>
|
||||
<li><%= link_to "Similar users", reports_similar_users_path %></li>
|
||||
<% end %>
|
||||
|
||||
<li><%= link_to "Deleted posts", posts_path(:tags => "#{@favorite_set.tag_string} status:deleted"), :rel => "nofollow" %></li>
|
||||
|
||||
<li><%= link_to "Random post", random_posts_path(:tags => @favorite_set.tag_string), :id => "random-post", :rel => "nofollow" %></li>
|
||||
|
@ -1,34 +0,0 @@
|
||||
<div id="c-reports">
|
||||
<div id="a-similar-users">
|
||||
<h1>Similar Users</h1>
|
||||
|
||||
<% if @presenter.insufficient_data? %>
|
||||
<p>You need at least 200 favorites before Danbooru can calculate users similar to you.</p>
|
||||
|
||||
<% elsif @presenter.not_ready? %>
|
||||
<p>The report is being generated. Check back in a few minutes.</p>
|
||||
|
||||
<% else %>
|
||||
<% @presenter.each_user do |user, score| %>
|
||||
<div class="box">
|
||||
<h2><%= link_to user.pretty_name, user_path(user) %> <span class="accuracy">(<%= number_to_percentage score, :precision => 2 %>)</span></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 %>
|
||||
|
||||
<% if @presenter.not_ready? %>
|
||||
<% content_for(:html_header) do %>
|
||||
<meta http-equiv="refresh" content="60">
|
||||
<% end %>
|
||||
<% end %>
|
@ -245,7 +245,6 @@ Rails.application.routes.draw do
|
||||
resources :artist_commentary_versions, :only => [:index]
|
||||
resource :related_tag, :only => [:show, :update]
|
||||
get "reports/uploads" => "reports#uploads"
|
||||
get "reports/similar_users" => "reports#similar_users"
|
||||
get "reports/upload_tags" => "reports#upload_tags"
|
||||
get "reports/post_versions" => "reports#post_versions"
|
||||
post "reports/post_versions_create" => "reports#post_versions_create"
|
||||
|
Loading…
Reference in New Issue
Block a user