reduce fav requirement to 300, show score in similar user report

This commit is contained in:
r888888888
2016-01-13 17:38:33 -08:00
parent af2167ea32
commit 01ad7f6745
3 changed files with 23 additions and 9 deletions

View File

@@ -8,6 +8,10 @@
margin-bottom: 2em;
}
span.accuracy {
color: #666;
}
/* clearfix hacks */
div.box:before, div.box:after {
content: "";

View File

@@ -1,5 +1,5 @@
class UserSimilarityPresenter
attr_reader :report, :user_ids, :not_ready
attr_reader :report, :user_ids, :user_ids_with_scores, :not_ready
def initialize(report)
@report = report
@@ -11,21 +11,31 @@ class UserSimilarityPresenter
end
def insufficient_data?
report.user.favorite_count < 500
report.user.favorite_count < 300
end
def fetch
user_ids = report.fetch_similar_user_ids
data = report.fetch_similar_user_ids
if user_ids == "not ready"
if data == "not ready"
@not_ready = true
else
@user_ids = user_ids.scan(/\d+/).slice(0, 10)
@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.where(id: user_ids).each(&block)
user_ids_with_scores.each do |user_id, score|
yield(User.find(user_id), 100 * score.to_f)
end
end
def each_favorite_for(user, &block)

View File

@@ -3,15 +3,15 @@
<h1>Similar Users</h1>
<% if @presenter.insufficient_data? %>
<p>You need at least 500 favorites before Danbooru can calculate users similar to you.</p>
<p>You need at least 300 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| %>
<% @presenter.each_user do |user, score| %>
<div class="box">
<h2><%= link_to user.pretty_name, user_path(user) %></h2>
<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}") %>