Skip to content

Commit 070a671

Browse files
committed
Chart of participants
1 parent ad9fed4 commit 070a671

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

app/controllers/static_pages_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def stats
3535

3636
@annual_dojos_chart = HighChartsBuilder.build_annual_dojos
3737
@annual_event_histories_chart = HighChartsBuilder.build_annual_event_histories
38+
@annual_participants_chart = HighChartsBuilder.build_annual_participants
3839
end
3940

4041
def letsencrypt

app/models/high_charts_builder.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ def build_annual_event_histories
3636
end
3737
end
3838

39+
def build_annual_participants
40+
source = EventHistory.where('evented_at < ?', Time.current.beginning_of_year).group("DATE_TRUNC('year', evented_at)").sum(:participants)
41+
data = annual_chart_data_from(source)
42+
43+
LazyHighCharts::HighChart.new('graph') do |f|
44+
f.title(text: '参加者数の推移')
45+
f.xAxis(categories: data[:years])
46+
f.series(type: 'column', name: '参加者数', yAxis: 0, data: data[:increase_nums])
47+
f.series(type: 'line', name: '累積合計', yAxis: 1, data: data[:cumulative_sums])
48+
f.yAxis [
49+
{ title: { text: '参加者数' } },
50+
{ title: { text: '累積合計' }, opposite: true }
51+
]
52+
f.chart(width: 600)
53+
f.colors(["#8085e9", "#f7a35c"])
54+
end
55+
end
56+
3957
private
4058

4159
def annual_chart_data_from(source)

app/views/static_pages/stats.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
%td= @participants.values.inject(:+)
6363
= high_chart("annual_dojos", @annual_dojos_chart)
6464
= high_chart("annual_event_histories", @annual_event_histories_chart)
65+
= high_chart("annual_participants", @annual_participants_chart)
6566

6667
%h3 関連リンク
6768
%ul{:style => "list-style: none; margin-left: -40px;"}

0 commit comments

Comments
 (0)