Skip to content

Commit

Permalink
make per week frequency dynamic (#5000)
Browse files Browse the repository at this point in the history
  • Loading branch information
cesswairimu authored and jywarren committed Mar 22, 2019
1 parent f8f136f commit 64b0207
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def index
@monthly_questions = Node.questions.past_month.count(:all).count
@monthly_answers = Answer.past_month.count

@notes_per_week_past_year = Node.past_year.select(:type).where(type: 'note').count(:all) / 52.0
@edits_per_week_past_year = Revision.past_year.count / 52.0
@notes_per_week_period = Node.frequency('note', @start, @end).round(2)
@edits_per_week_period = Revision.frequency(@start, @end).round(2)

@graph_notes = Node.contribution_graph_making('note', @start, @end)
@graph_wikis = Node.contribution_graph_making('page', @start, @end)
Expand Down
7 changes: 7 additions & 0 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ def self.contribution_graph_making(type = 'note', start = Time.now - 1.year, fin
date_hash
end

def self.frequency(type, starting, ending)
weeks = (ending.to_date - starting.to_date).to_i / 7.0
Node.published.select(%i(created type))
.where(type: type, created: starting.to_i..ending.to_i)
.count(:all) / weeks
end

def notify
if status == 4
AdminMailer.notify_node_moderators(self).deliver_now
Expand Down
7 changes: 7 additions & 0 deletions app/models/revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,11 @@ def body_extras(content)
content = content.gsub('[unfold]', '</div>')
content
end

def self.frequency(starting, ending)
weeks = (ending.to_date - starting.to_date).to_i / 7.0
Revision.select(:timestamp)
.where(timestamp: starting.to_i..ending.to_i)
.count / weeks
end
end
4 changes: 2 additions & 2 deletions app/views/stats/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<h4 align="center"> <u> Notes, Wikis and Comments Statistics between <%= @start.to_date%> to <%= @end.to_date%> </u></h4>
<br>
<div id="timeline"></div>
<p><b><%= raw t('notes.stats.edits_per_week', :count => @edits_per_week_past_year.round(2)) %></b></p>
<p><b><%= raw t('notes.stats.notes_per_week_past_year', :note_count => @notes_per_week_past_year.round(2)) %></b></p>
<p><b><%= raw t('notes.stats.edits_per_week', :count => @edits_per_week_period) %></b></p>
<p><b><%= raw t('notes.stats.notes_per_week', :note_count => @notes_per_week_period) %></b></p>
<br>
<i> Member registration may include spam accounts </i>
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
Expand Down
4 changes: 2 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ en:
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."
edits_per_week: "%{count} edits per week over the past year."
notes_per_week: "%{note_count} notes per week over this period."
edits_per_week: "%{count} edits per week over this period."
notes_wikis_comments: |
<b>%{notes_count} notes</b> and <b>%{wikis_count} wiki edits and</b>
and <b>%{comments_count} comments </b> posted in this period.
Expand Down

0 comments on commit 64b0207

Please sign in to comment.