From 4f028aad99913a8e995246d890228cc6478497f1 Mon Sep 17 00:00:00 2001 From: Kanika Shrivastav Date: Sat, 27 Oct 2018 04:09:14 +0530 Subject: [PATCH] added total contributors for all time (#3695) * added total contributors for all time * fixes linting issues * Added Cache to all time contributors * Changed the stats view template --- app/controllers/stats_controller.rb | 3 +++ app/models/user.rb | 9 +++++++++ app/views/stats/index.html.erb | 2 ++ config/locales/views/notes/stats/en.yml | 1 + 4 files changed, 15 insertions(+) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 52c7a69b35..369b48923a 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -81,5 +81,8 @@ def index @all_notes = nids.uniq.length @all_contributors = users.uniq.length + Rails.cache.fetch("total-contributors-all-time", expires_in: 1.weeks) do + @all_time_contributors = User.count_all_time_contributor + end end end diff --git a/app/models/user.rb b/app/models/user.rb index 222a82540d..cc19153ff8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -454,4 +454,13 @@ def self.create_with_omniauth(auth) user.save! end end + + def self.count_all_time_contributor + notes = Node.where(type: 'note', status: 1).pluck(:uid) + answers = Answer.pluck(:uid) + questions = Node.questions.where(status: 1).pluck(:uid) + comments = Comment.pluck(:uid) + revisions = Revision.where(status: 1).pluck(:uid) + contributors = (notes + answers + questions + comments + revisions).compact.uniq.length + end end diff --git a/app/views/stats/index.html.erb b/app/views/stats/index.html.erb index eaec3e44a8..5a10d34406 100644 --- a/app/views/stats/index.html.erb +++ b/app/views/stats/index.html.erb @@ -43,6 +43,8 @@

<%= raw t('notes.stats.research_notes_posted_by_contributors', :note_count => @all_notes, :contributors_count => @all_contributors, :time => time_ago_in_words(Node.find_by(type: 'note', status: 1).created_at)) %>

+

<%= raw t('notes.stats.total_contributors', :all_contributors_count => @all_time_contributors) %>

+

<%= raw t('notes.stats.notes_per_week_past_year', :note_count => @notes_per_week_past_year.round(2)) %>

<%= t('notes.stats.note_posting_52_weeks') %>

diff --git a/config/locales/views/notes/stats/en.yml b/config/locales/views/notes/stats/en.yml index 5999dee4cc..ac1a1645e5 100644 --- a/config/locales/views/notes/stats/en.yml +++ b/config/locales/views/notes/stats/en.yml @@ -24,6 +24,7 @@ en: and %{wiki_count} wiki edits posted in the past month. people_joined_past_month: "%{people_count} people joined in the past month." research_notes_posted_by_contributors: "%{note_count} research notes have been posted by %{contributors_count} contributors since %{time} ago" + total_contributors: "%{all_contributors_count} Total Contributors (Tallied weekly)" notes_per_week_past_year: "%{note_count} notes per week over the past year." note_posting_52_weeks: "Note posting for the past 52 weeks:" wiki_pages_posted: "%{count} wiki pages have been posted, total"