From b1ca2ac9a4aac71362c49a2e967b8af062ea876b Mon Sep 17 00:00:00 2001 From: Kanikashrivastav Date: Sat, 13 Oct 2018 04:12:33 +0530 Subject: [PATCH 1/4] added total contributors for all time --- app/controllers/stats_controller.rb | 2 ++ app/models/user.rb | 9 +++++++++ app/views/stats/index.html.erb | 2 ++ config/locales/views/notes/stats/en.yml | 1 + 4 files changed, 14 insertions(+) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 52c7a69b35..ae60a30b6d 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -81,5 +81,7 @@ def index @all_notes = nids.uniq.length @all_contributors = users.uniq.length + # TODO Caching + @all_time_contributors = User.count_all_time_contributor end end diff --git a/app/models/user.rb b/app/models/user.rb index 222a82540d..694007810a 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..863c08fbf1 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" 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" From db0c8566fd9033886da5186b017a5275734ab4a8 Mon Sep 17 00:00:00 2001 From: Kanikashrivastav Date: Sat, 13 Oct 2018 08:04:25 +0530 Subject: [PATCH 2/4] fixes linting issues --- app/controllers/stats_controller.rb | 1 - app/models/user.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index ae60a30b6d..03056763ed 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -81,7 +81,6 @@ def index @all_notes = nids.uniq.length @all_contributors = users.uniq.length - # TODO Caching @all_time_contributors = User.count_all_time_contributor end end diff --git a/app/models/user.rb b/app/models/user.rb index 694007810a..cc19153ff8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -454,6 +454,7 @@ 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) @@ -461,6 +462,5 @@ def self.count_all_time_contributor comments = Comment.pluck(:uid) revisions = Revision.where(status: 1).pluck(:uid) contributors = (notes + answers + questions + comments + revisions).compact.uniq.length - end end From 90a08129620803db77ebc1fb6e65b7f13d75626c Mon Sep 17 00:00:00 2001 From: Kanikashrivastav Date: Thu, 25 Oct 2018 08:43:06 +0530 Subject: [PATCH 3/4] Added Cache to all time contributors --- app/controllers/stats_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 03056763ed..369b48923a 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -81,6 +81,8 @@ def index @all_notes = nids.uniq.length @all_contributors = users.uniq.length - @all_time_contributors = User.count_all_time_contributor + Rails.cache.fetch("total-contributors-all-time", expires_in: 1.weeks) do + @all_time_contributors = User.count_all_time_contributor + end end end From a397c9d6e261d86ad97c8fe458cb54502a75d210 Mon Sep 17 00:00:00 2001 From: Kanikashrivastav Date: Thu, 25 Oct 2018 08:51:27 +0530 Subject: [PATCH 4/4] Changed the stats view template --- config/locales/views/notes/stats/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/views/notes/stats/en.yml b/config/locales/views/notes/stats/en.yml index 863c08fbf1..ac1a1645e5 100644 --- a/config/locales/views/notes/stats/en.yml +++ b/config/locales/views/notes/stats/en.yml @@ -24,7 +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" + 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"