Skip to content

Commit 8e9b9e1

Browse files
authored
Merge pull request #229 from coderdojo-japan/add-yearly-stats
Add year-by-year table to Stats page
2 parents d8f35dc + 9259ace commit 8e9b9e1

File tree

4 files changed

+154
-1
lines changed

4 files changed

+154
-1
lines changed

app/controllers/static_pages_controller.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ def stats
1818
@sum_of_dojos = DojoEventService.count('DISTINCT dojo_id') +
1919
4 # TODO: 同上。上記の道場数を静的に足しています
2020
@sum_of_participants = EventHistory.sum(:participants)
21+
22+
# 2012年1月1日〜2017年12月31日までの集計結果
23+
@dojos, @events, @participants = {}, {}, {}
24+
@range = (2012..2017)
25+
@range.each do |year|
26+
@dojos[year] =
27+
Dojo.where(created_at:
28+
Time.zone.local(year).beginning_of_year..Time.zone.local(year).end_of_year).count
29+
@events[year] =
30+
EventHistory.where(evented_at:
31+
Time.zone.local(year).beginning_of_year..Time.zone.local(year).end_of_year).count
32+
@participants[year] =
33+
EventHistory.where(evented_at:
34+
Time.zone.local(year).beginning_of_year..Time.zone.local(year).end_of_year).sum(:participants)
35+
end
2136
end
2237

2338
def letsencrypt

app/views/static_pages/stats.html.haml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@
3030
\/ #{@dojo_count} Dojos
3131
%h3 計測間隔
3232
毎週月曜日
33+
34+
%h3 各統計の推移
35+
%div{align: 'center'}
36+
%table
37+
%thead
38+
%tr
39+
%th
40+
- @range.each do |year|
41+
%td{style: 'padding: 0 5px; font-weight: bold;'} #{year}年
42+
%tbody{align: 'center'}
43+
%tr
44+
%td 新規道場数
45+
- @range.each do |year|
46+
%td #{@dojos[year]}
47+
%tr
48+
%td 開催回数
49+
- @range.each do |year|
50+
%td #{@events[year]}
51+
%tr
52+
%td 参加者数
53+
- @range.each do |year|
54+
%td #{@participants[year]}
55+
3356
%h3 関連リンク
3457
%ul{:style => "list-style: none; margin-left: -40px;"}
3558
%li

0 commit comments

Comments
 (0)