From bf3101da489ea88ecaafd59fd31da3ec05443f1a Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 10 Aug 2017 21:20:10 -0500 Subject: [PATCH 1/3] upload limits: show how upload limits are calculated in profiles. * Allow mousing over the upload limit on profile pages to show the full formula for the upload limit calculation. In particular, show how the upload limit multiplier is derived from the deletion confidence. * Refactor to avoid duplicating upload limit calculations in the presenter, as much as possible. --- app/models/user.rb | 41 +++++++++++++++------------- app/presenters/user_presenter.rb | 13 +++++---- app/views/users/_statistics.html.erb | 2 +- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 3a85606b5..57ac132fb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -549,6 +549,28 @@ class User < ApplicationRecord is_moderator? || flagger_id == id end + def upload_limit + @upload_limit ||= [max_upload_limit - used_upload_slots, 0].max + end + + def used_upload_slots + uploaded_count = Post.for_user(id).where("created_at >= ?", 24.hours.ago).count + uploaded_comic_count = Post.for_user(id).tag_match("comic").where("created_at >= ?", 24.hours.ago).count / 3 + uploaded_count - uploaded_comic_count + end + + def max_upload_limit + [(base_upload_limit * upload_limit_multiplier).ceil, 10].max + end + + def upload_limit_multiplier + (1 - (adjusted_deletion_confidence / 15.0)) + end + + def adjusted_deletion_confidence + [deletion_confidence(60), 15].min + end + def base_upload_limit if created_at >= 1.month.ago 10 @@ -563,25 +585,6 @@ class User < ApplicationRecord end end - def max_upload_limit - dcon = [deletion_confidence(60), 15].min - [(base_upload_limit * (1 - (dcon / 15.0))).ceil, 10].max - end - - def upload_limit - @upload_limit ||= begin - uploaded_count = Post.for_user(id).where("created_at >= ?", 24.hours.ago).count - uploaded_comic_count = Post.for_user(id).tag_match("comic").where("created_at >= ?", 24.hours.ago).count / 3 - limit = max_upload_limit - (uploaded_count - uploaded_comic_count) - - if limit < 0 - limit = 0 - end - - limit - end - end - def tag_query_limit if is_platinum? Danbooru.config.base_tag_query_limit * 2 diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index 808da1fa0..b5bea4e0a 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -68,13 +68,14 @@ class UserPresenter return "none" end - dcon = [user.deletion_confidence(60), 15].min - multiplier = (1 - (dcon / 15.0)) - max_count = [(user.base_upload_limit * multiplier).ceil, 5].max - uploaded_count = Post.for_user(user.id).where("created_at >= ?", 24.hours.ago).count - uploaded_comic_count = Post.for_user(user.id).tag_match("comic").where("created_at >= ?", 24.hours.ago).count / 3 + limit_tooltip = <<-EOS.strip_heredoc + Base: #{user.base_upload_limit} + Del. Rate: #{"%.2f" % user.adjusted_deletion_confidence} + Multiplier: (1 - (#{"%.2f" % user.adjusted_deletion_confidence} / 15)) = #{user.upload_limit_multiplier} + Upload Limit: #{user.base_upload_limit} * #{"%.2f" % user.upload_limit_multiplier} = #{user.max_upload_limit} + EOS - "(#{user.base_upload_limit} * #{'%0.2f' % multiplier}) - #{uploaded_count - uploaded_comic_count} = #{user.upload_limit}" + %{#{user.used_upload_slots} / #{user.upload_limit}}.html_safe end def uploads diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index 25d63d60c..c5deecb12 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -31,7 +31,7 @@ Upload Limit - <%= presenter.upload_limit %> + <%= presenter.upload_limit %> (<%= link_to "help", wiki_pages_path(title: "about:upload_limits") %>) From 1ef363dd6807f25a2ffb2c662825ed3cdc886b35 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 10 Aug 2017 23:52:47 -0500 Subject: [PATCH 2/3] upload limits: add time remaining until next upload to profiles (fix #3262). --- app/models/user.rb | 4 ++++ app/presenters/user_presenter.rb | 5 +++-- app/views/users/_statistics.html.erb | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 57ac132fb..9f13de0e0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -585,6 +585,10 @@ class User < ApplicationRecord end end + def next_free_upload_slot + (posts.where("created_at >= ?", 24.hours.ago).first.try(:created_at) || 24.hours.ago) + 24.hours + end + def tag_query_limit if is_platinum? Danbooru.config.base_tag_query_limit * 2 diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index b5bea4e0a..2e01d0794 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -63,11 +63,12 @@ class UserPresenter end end - def upload_limit + def upload_limit(template) if user.can_upload_free? return "none" end + slots_tooltip = "Next free slot: #{template.time_ago_in_words(user.next_free_upload_slot)}" limit_tooltip = <<-EOS.strip_heredoc Base: #{user.base_upload_limit} Del. Rate: #{"%.2f" % user.adjusted_deletion_confidence} @@ -75,7 +76,7 @@ class UserPresenter Upload Limit: #{user.base_upload_limit} * #{"%.2f" % user.upload_limit_multiplier} = #{user.max_upload_limit} EOS - %{#{user.used_upload_slots} / #{user.upload_limit}}.html_safe + %{#{user.used_upload_slots} / #{user.max_upload_limit}}.html_safe end def uploads diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index c5deecb12..d70c0d181 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -31,7 +31,7 @@ Upload Limit - <%= presenter.upload_limit %> (<%= link_to "help", wiki_pages_path(title: "about:upload_limits") %>) + <%= presenter.upload_limit(self) %> (<%= link_to "help", wiki_pages_path(title: "about:upload_limits") %>) From 6797f8564d3d765e08862e801ed1a47c5322bded Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 10 Aug 2017 23:54:59 -0500 Subject: [PATCH 3/3] upload limits: show full upload limits on upload page. --- app/models/user.rb | 4 ++++ app/views/uploads/new.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 9f13de0e0..00a32acec 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -942,4 +942,8 @@ class User < ApplicationRecord self.enable_sequential_post_navigation = true self.enable_auto_complete = true end + + def presenter + @presenter ||= UserPresenter.new(self) + end end diff --git a/app/views/uploads/new.html.erb b/app/views/uploads/new.html.erb index a2e6d02b2..8cdfcdab1 100644 --- a/app/views/uploads/new.html.erb +++ b/app/views/uploads/new.html.erb @@ -8,7 +8,7 @@ <% unless CurrentUser.can_upload_free? %> -

You can upload <%= pluralize CurrentUser.upload_limit, "more post" %> today.

+

Upload limit: <%= CurrentUser.user.presenter.upload_limit(self) %>.

<% end %> <%= render "image" %>