Skip to content

Commit 92f6aa8

Browse files
committed
Roughly render year-by-year stats table
1 parent 73c0da2 commit 92f6aa8

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

app/controllers/static_pages_controller.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,20 @@ def stats
1919
4 # TODO: 同上。上記の道場数を静的に足しています
2020
@sum_of_participants = EventHistory.sum(:participants)
2121

22-
# 2017年1月1日〜12月31日までの集計結果
23-
@events_2017 = EventHistory.where('evented_at > ?', Time.zone.local(2017).beginning_of_year).count
24-
@participants_2017 = EventHistory.where('evented_at > ?', Time.zone.local(2017).beginning_of_year).sum(:participants)
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
2536
end
2637

2738
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'} #{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)