Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ class StatsController < ApplicationController

# GET /stats[.json]
def show
# 言語設定
@lang = params[:lang] || 'ja'

# 2012年1月1日〜2024年12月31日までの集計結果
@period_start = 2012
@period_end = 2024
Expand All @@ -10,9 +13,9 @@ def show

# 推移グラフ
@high_charts_globals = HighChartsBuilder.global_options
@annual_dojos_chart = stats.annual_dojos_chart
@annual_event_histories_chart = stats.annual_event_histories_chart
@annual_participants_chart = stats.annual_participants_chart
@annual_dojos_chart = stats.annual_dojos_chart(@lang)
@annual_event_histories_chart = stats.annual_event_histories_chart(@lang)
@annual_participants_chart = stats.annual_participants_chart(@lang)

# 最新データ
@sum_of_dojos = Dojo.active_dojos_count
Expand All @@ -24,7 +27,8 @@ def show
# 道場タグ分布
@dojo_tag_chart = LazyHighCharts::HighChart.new('graph') do |f|
number_of_tags = 10
f.title(text: "CoderDojo タグ分布 (上位 #{number_of_tags})")
title_text = @lang == 'en' ? "CoderDojo Tag Distribution (Top #{number_of_tags})" : "CoderDojo タグ分布 (上位 #{number_of_tags})"
f.title(text: title_text)

# Use 'tally' method when using Ruby 2.7.0 or higher
# cf. https://twitter.com/yasulab/status/1154566199511941120
Expand Down
56 changes: 56 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,60 @@ def facebook_page_url; 'https://www.facebook.com/coderdojo.jp'; end
def twitter_url; 'https://twitter.com/CoderDojoJapan'; end
def youtube_url; 'https://youtube.com/CoderDojoJapan'; end

def prefecture_name_in_english(prefecture_name)
# 都道府県名の英語表記を返す簡易マッピング
# データベースには「県」「都」「府」が省略された形で保存されている
prefecture_names = {
'北海道' => 'Hokkaido',
'青森' => 'Aomori',
'岩手' => 'Iwate',
'宮城' => 'Miyagi',
'秋田' => 'Akita',
'山形' => 'Yamagata',
'福島' => 'Fukushima',
'茨城' => 'Ibaraki',
'栃木' => 'Tochigi',
'群馬' => 'Gunma',
'埼玉' => 'Saitama',
'千葉' => 'Chiba',
'東京' => 'Tokyo',
'神奈川' => 'Kanagawa',
'新潟' => 'Niigata',
'富山' => 'Toyama',
'石川' => 'Ishikawa',
'福井' => 'Fukui',
'山梨' => 'Yamanashi',
'長野' => 'Nagano',
'岐阜' => 'Gifu',
'静岡' => 'Shizuoka',
'愛知' => 'Aichi',
'三重' => 'Mie',
'滋賀' => 'Shiga',
'京都' => 'Kyoto',
'大阪' => 'Osaka',
'兵庫' => 'Hyogo',
'奈良' => 'Nara',
'和歌山' => 'Wakayama',
'鳥取' => 'Tottori',
'島根' => 'Shimane',
'岡山' => 'Okayama',
'広島' => 'Hiroshima',
'山口' => 'Yamaguchi',
'徳島' => 'Tokushima',
'香川' => 'Kagawa',
'愛媛' => 'Ehime',
'高知' => 'Kochi',
'福岡' => 'Fukuoka',
'佐賀' => 'Saga',
'長崎' => 'Nagasaki',
'熊本' => 'Kumamoto',
'大分' => 'Oita',
'宮崎' => 'Miyazaki',
'鹿児島' => 'Kagoshima',
'沖縄' => 'Okinawa'
}

prefecture_names[prefecture_name] || prefecture_name
end

end
39 changes: 21 additions & 18 deletions app/models/high_charts_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,54 @@ def global_options
end
end

def build_annual_dojos(source)
def build_annual_dojos(source, lang = 'ja')
data = annual_chart_data_from(source)
title_text = lang == 'en' ? 'Number of Dojos' : '道場数の推移'

LazyHighCharts::HighChart.new('graph') do |f|
f.title(text: '道場数の推移')
f.title(text: title_text)
f.xAxis(categories: data[:years])
f.series(type: 'column', name: '増加数', yAxis: 0, data: data[:increase_nums])
f.series(type: 'line', name: '累積合計', yAxis: 1, data: data[:cumulative_sums])
f.series(type: 'column', name: lang == 'en' ? 'New' : '増加数', yAxis: 0, data: data[:increase_nums])
f.series(type: 'line', name: lang == 'en' ? 'Total' : '累積合計', yAxis: 1, data: data[:cumulative_sums])
f.yAxis [
{ title: { text: '増加数' }, tickInterval: 15, max: 75 },
{ title: { text: '累積合計' }, tickInterval: 50, max: 250, opposite: true }
{ title: { text: lang == 'en' ? 'New' : '増加数' }, tickInterval: 15, max: 75 },
{ title: { text: lang == 'en' ? 'Total' : '累積合計' }, tickInterval: 50, max: 250, opposite: true }
]
f.chart(width: HIGH_CHARTS_WIDTH, alignTicks: false)
f.colors(["#A0D3B5", "#505D6B"])
end
end

def build_annual_event_histories(source)
def build_annual_event_histories(source, lang = 'ja')
data = annual_chart_data_from(source)
title_text = lang == 'en' ? 'Number of Events' : '開催回数の推移'

LazyHighCharts::HighChart.new('graph') do |f|
f.title(text: '開催回数の推移')
f.title(text: title_text)
f.xAxis(categories: data[:years])
f.series(type: 'column', name: '開催回数', yAxis: 0, data: data[:increase_nums])
f.series(type: 'line', name: '累積合計', yAxis: 1, data: data[:cumulative_sums])
f.series(type: 'column', name: lang == 'en' ? 'Events' : '開催回数', yAxis: 0, data: data[:increase_nums])
f.series(type: 'line', name: lang == 'en' ? 'Total' : '累積合計', yAxis: 1, data: data[:cumulative_sums])
f.yAxis [
{ title: { text: '開催回数' }, tickInterval: 500, max: 2000 },
{ title: { text: '累積合計' }, tickInterval: 3000, max: 12000, opposite: true }
{ title: { text: lang == 'en' ? 'Events' : '開催回数' }, tickInterval: 500, max: 2000 },
{ title: { text: lang == 'en' ? 'Total' : '累積合計' }, tickInterval: 3000, max: 12000, opposite: true }
]
f.chart(width: HIGH_CHARTS_WIDTH, alignTicks: false)
f.colors(["#F4C34F", "#BD2561"])
end
end

def build_annual_participants(source)
def build_annual_participants(source, lang = 'ja')
data = annual_chart_data_from(source)
title_text = lang == 'en' ? 'Number of Participants' : '参加者数の推移'

LazyHighCharts::HighChart.new('graph') do |f|
f.title(text: '参加者数の推移')
f.title(text: title_text)
f.xAxis(categories: data[:years])
f.series(type: 'column', name: '参加者数', yAxis: 0, data: data[:increase_nums])
f.series(type: 'line', name: '累積合計', yAxis: 1, data: data[:cumulative_sums])
f.series(type: 'column', name: lang == 'en' ? 'Participants' : '参加者数', yAxis: 0, data: data[:increase_nums])
f.series(type: 'line', name: lang == 'en' ? 'Total' : '累積合計', yAxis: 1, data: data[:cumulative_sums])
f.yAxis [
{ title: { text: '参加者数' }, tickInterval: 2500, max: 12500 },
{ title: { text: '累積合計' }, tickInterval: 14000, max: 64000, opposite: true }
{ title: { text: lang == 'en' ? 'Participants' : '参加者数' }, tickInterval: 2500, max: 12500 },
{ title: { text: lang == 'en' ? 'Total' : '累積合計' }, tickInterval: 14000, max: 64000, opposite: true }
]
f.chart(width: HIGH_CHARTS_WIDTH, alignTicks: false)
f.colors(["#EF685E", "#35637D"])
Expand Down
12 changes: 6 additions & 6 deletions app/models/stat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ def annual_sum_of_participants
@annual_sum_of_participants = year_hash_template.merge!(hash)
end

def annual_dojos_chart
def annual_dojos_chart(lang = 'ja')
# MEMO: トップページの道場数と一致するように Active Dojo を集計対象としている
HighChartsBuilder.build_annual_dojos(Dojo.active.annual_count(@period))
HighChartsBuilder.build_annual_dojos(Dojo.active.annual_count(@period), lang)
end

def annual_event_histories_chart
HighChartsBuilder.build_annual_event_histories(annual_count_of_event_histories)
def annual_event_histories_chart(lang = 'ja')
HighChartsBuilder.build_annual_event_histories(annual_count_of_event_histories, lang)
end

def annual_participants_chart
HighChartsBuilder.build_annual_participants(annual_sum_of_participants)
def annual_participants_chart(lang = 'ja')
HighChartsBuilder.build_annual_participants(annual_sum_of_participants, lang)
end

private
Expand Down
Loading