Skip to content

Commit

Permalink
added total contributors for all time (#3695)
Browse files Browse the repository at this point in the history
* added total contributors for all time

* fixes linting issues

* Added Cache to all time contributors

* Changed the stats view template
  • Loading branch information
Kanika Shrivastav authored and jywarren committed Oct 26, 2018
1 parent 3de151d commit 4f028aa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions app/views/stats/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

<h4><%= 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)) %></h4>
<h4><%= raw t('notes.stats.total_contributors', :all_contributors_count => @all_time_contributors) %></h4>

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

<p><i><%= t('notes.stats.note_posting_52_weeks') %></i></p>
Expand Down
1 change: 1 addition & 0 deletions config/locales/views/notes/stats/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ en:
and <a href='%{url2}'>%{wiki_count} wiki edits</a> posted in the past month.
people_joined_past_month: "<b>%{people_count} people</b> 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"
Expand Down

0 comments on commit 4f028aa

Please sign in to comment.