Skip to content

Commit 88358e8

Browse files
committed
テストが通らない問題を解消するため origin/main の変更をマージ
2 parents c5e4b24 + 13a1d44 commit 88358e8

File tree

15 files changed

+444
-106
lines changed

15 files changed

+444
-106
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# or operating system, you probably want to add a global ignore instead:
55
# git config --global core.excludesfile '~/.gitignore_global'
66

7+
# Ignore CLAUDE.md for now
8+
CLAUDE.md
9+
710
# Ignore text file to write news article with internal API:
811
# https://github.com/coderdojo-japan/coderdojo.jp/pull/1433
912
get_dojo_list.txt

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ We use `SCRIVITO_TENANT` and `SCRIVITO_API_KEY` keys in production, but they are
209209

210210
開発に関する資料は [/docs](https://github.com/coderdojo-japan/coderdojo.jp/tree/main/docs) や下記サイトにまとめてあります (最新順)。必要に応じて適宜ご参照ください。
211211

212+
- [[EN] Inside Web Development of coderdojo.jp](https://www.youtube.com/watch?v=7WR2ulUJwvQ&list=PL94GDfaSQTmKxMzXVMzzdl-zCmzgitQFP&index=8) (English Talk on YouTube by [@nanophate](https://github.com/nanophate))
212213
- [DojoCast を Jekyll から Rails に移行しました](https://yasslab.jp/ja/posts/migrate-dojocast-from-jekyll-to-rails)
213214
- [新規 Dojo の追加方法 - GitHub](https://github.com/coderdojo-japan/coderdojo.jp/blob/main/docs/how_to_add_dojo.md)
214215
- [子どものためのプログラミング道場『CoderDojo』の Ruby/Rails 活用事例](https://speakerdeck.com/yasulab/case-study-of-how-coderdojo-japan-uses-ruby)

app/controllers/stats_controller.rb

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ class StatsController < ApplicationController
22

33
# GET /stats[.json]
44
def show
5+
# 言語設定
6+
@lang = params[:lang] || 'ja'
7+
58
# 2012年1月1日〜2024年12月31日までの集計結果
69
@period_start = 2012
710
@period_end = 2024
@@ -10,9 +13,9 @@ def show
1013

1114
# 推移グラフ
1215
@high_charts_globals = HighChartsBuilder.global_options
13-
@annual_dojos_chart = stats.annual_dojos_chart
14-
@annual_event_histories_chart = stats.annual_event_histories_chart
15-
@annual_participants_chart = stats.annual_participants_chart
16+
@annual_dojos_chart = stats.annual_dojos_chart(@lang)
17+
@annual_event_histories_chart = stats.annual_event_histories_chart(@lang)
18+
@annual_participants_chart = stats.annual_participants_chart(@lang)
1619

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

2933
# Use 'tally' method when using Ruby 2.7.0 or higher
3034
# cf. https://twitter.com/yasulab/status/1154566199511941120
@@ -37,10 +41,17 @@ def show
3741
end
3842
tags = tags.sort_by{|key, value| value}.reverse.to_h
3943

40-
f.xAxis categories: tags.keys.take(number_of_tags).reverse
44+
# タグ名を言語に応じて翻訳
45+
tag_labels = if @lang == 'en'
46+
tags.keys.take(number_of_tags).map { |tag| helpers.translate_dojo_tag(tag) }.reverse
47+
else
48+
tags.keys.take(number_of_tags).reverse
49+
end
50+
51+
f.xAxis categories: tag_labels
4152
f.yAxis title: { text: '' }, showInLegend: false, opposite: true,
4253
tickInterval: 40, max: 240
43-
f.series type: 'column', name: "対応道場数", yAxis: 0, showInLegend: false,
54+
f.series type: 'column', name: @lang == 'en' ? "Number of Dojos" : "対応道場数", yAxis: 0, showInLegend: false,
4455
data: tags.values.take(number_of_tags).reverse,
4556
dataLabels: {
4657
enabled: true,
@@ -90,9 +101,27 @@ def show
90101
@data_by_region = []
91102
@regions_and_dojos = Dojo.group_by_region_on_active
92103
@regions_and_dojos.each_with_index do |(region, dojos), index|
104+
# 地域名の英語化
105+
region_name = if @lang == 'en'
106+
case region
107+
when '北海道' then 'Hokkaido'
108+
when '東北' then 'Tohoku'
109+
when '関東' then 'Kanto'
110+
when '中部' then 'Chubu'
111+
when '近畿' then 'Kinki'
112+
when '中国' then 'Chugoku'
113+
when '四国' then 'Shikoku'
114+
when '九州' then 'Kyushu'
115+
when '沖縄' then 'Okinawa'
116+
else region
117+
end
118+
else
119+
region
120+
end
121+
93122
@data_by_region << {
94123
code: index+1,
95-
name: "#{region} (#{dojos.pluck(:counter).sum})",
124+
name: "#{region_name} (#{dojos.pluck(:counter).sum})",
96125
color: "dodgerblue", # Area Color
97126
hoverColor: "dodgerblue", # Another option: "deepskyblue"
98127
prefectures: Prefecture.where(region: region).map(&:id)
@@ -101,7 +130,8 @@ def show
101130

102131
@data_by_prefecture = {}
103132
Prefecture.order(:id).each do |p|
104-
@data_by_prefecture[p.name] = Dojo.active.where(prefecture_id: p.id).sum(:counter)
133+
prefecture_name = @lang == 'en' ? helpers.prefecture_name_in_english(p.name) : p.name
134+
@data_by_prefecture[prefecture_name] = Dojo.active.where(prefecture_id: p.id).sum(:counter)
105135
end
106136
@data_by_prefecture_count = @data_by_prefecture.select{|k,v| v>0}.count
107137

app/helpers/application_helper.rb

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,111 @@ def facebook_page_url; 'https://www.facebook.com/coderdojo.jp'; end
9494
def twitter_url; 'https://twitter.com/CoderDojoJapan'; end
9595
def youtube_url; 'https://youtube.com/CoderDojoJapan'; end
9696

97+
def prefecture_name_in_english(prefecture_name)
98+
# 都道府県名の英語表記を返す簡易マッピング
99+
# データベースには「県」「都」「府」が省略された形で保存されている
100+
prefecture_names = {
101+
'北海道' => 'Hokkaido',
102+
'青森' => 'Aomori',
103+
'岩手' => 'Iwate',
104+
'宮城' => 'Miyagi',
105+
'秋田' => 'Akita',
106+
'山形' => 'Yamagata',
107+
'福島' => 'Fukushima',
108+
'茨城' => 'Ibaraki',
109+
'栃木' => 'Tochigi',
110+
'群馬' => 'Gunma',
111+
'埼玉' => 'Saitama',
112+
'千葉' => 'Chiba',
113+
'東京' => 'Tokyo',
114+
'神奈川' => 'Kanagawa',
115+
'新潟' => 'Niigata',
116+
'富山' => 'Toyama',
117+
'石川' => 'Ishikawa',
118+
'福井' => 'Fukui',
119+
'山梨' => 'Yamanashi',
120+
'長野' => 'Nagano',
121+
'岐阜' => 'Gifu',
122+
'静岡' => 'Shizuoka',
123+
'愛知' => 'Aichi',
124+
'三重' => 'Mie',
125+
'滋賀' => 'Shiga',
126+
'京都' => 'Kyoto',
127+
'大阪' => 'Osaka',
128+
'兵庫' => 'Hyogo',
129+
'奈良' => 'Nara',
130+
'和歌山' => 'Wakayama',
131+
'鳥取' => 'Tottori',
132+
'島根' => 'Shimane',
133+
'岡山' => 'Okayama',
134+
'広島' => 'Hiroshima',
135+
'山口' => 'Yamaguchi',
136+
'徳島' => 'Tokushima',
137+
'香川' => 'Kagawa',
138+
'愛媛' => 'Ehime',
139+
'高知' => 'Kochi',
140+
'福岡' => 'Fukuoka',
141+
'佐賀' => 'Saga',
142+
'長崎' => 'Nagasaki',
143+
'熊本' => 'Kumamoto',
144+
'大分' => 'Oita',
145+
'宮崎' => 'Miyazaki',
146+
'鹿児島' => 'Kagoshima',
147+
'沖縄' => 'Okinawa'
148+
}
149+
150+
prefecture_names[prefecture_name] || prefecture_name
151+
end
152+
153+
def translate_dojo_tag(tag_name)
154+
# よくあるCoderDojoタグの英語訳
155+
tag_translations = {
156+
'ボードゲーム' => 'Board Games',
157+
'ロボット' => 'Robotics',
158+
'マインクラフト' => 'Minecraft',
159+
'タイピング' => 'Typing',
160+
'電子工作' => 'Electronics',
161+
'プログラミング' => 'Programming',
162+
'ゲーム' => 'Gaming',
163+
'パソコン' => 'Computers',
164+
'初心者歓迎' => 'Beginners Welcome',
165+
'オンライン開催あり' => 'Online Available',
166+
'オンライン' => 'Online',
167+
'女子' => 'Girls',
168+
'中高生' => 'Teens',
169+
'3Dプリンター' => '3D Printing',
170+
'AI' => 'AI',
171+
'IoT' => 'IoT',
172+
'VR' => 'VR',
173+
'AR' => 'AR',
174+
'Web' => 'Web',
175+
'アプリ' => 'Apps',
176+
'デザイン' => 'Design',
177+
'音楽' => 'Music',
178+
'動画' => 'Video',
179+
'アニメーション' => 'Animation',
180+
'ドローン' => 'Drones',
181+
'レゴ' => 'LEGO',
182+
'工作' => 'Crafts',
183+
'ラズベリーパイ' => 'Raspberry Pi',
184+
'Webサイト' => 'Web Development',
185+
'ウェブサイト' => 'Web Development',
186+
'スクラッチ' => 'Scratch',
187+
'Scratch' => 'Scratch',
188+
'Python' => 'Python',
189+
'JavaScript' => 'JavaScript',
190+
'Ruby' => 'Ruby',
191+
'Unity' => 'Unity',
192+
'micro:bit' => 'micro:bit',
193+
'マイクロビット' => 'micro:bit',
194+
'レーザーカッター' => 'Laser Cutting',
195+
'ビスケット' => 'Viscuit',
196+
'Viscuit' => 'Viscuit',
197+
'HTML' => 'HTML',
198+
'CSS' => 'CSS'
199+
}
200+
201+
tag_translations[tag_name] || tag_name
202+
end
203+
97204
end

app/models/high_charts_builder.rb

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,54 @@ def global_options
88
end
99
end
1010

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

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

28-
def build_annual_event_histories(source)
29+
def build_annual_event_histories(source, lang = 'ja')
2930
data = annual_chart_data_from(source)
31+
title_text = lang == 'en' ? 'Number of Events' : '開催回数の推移'
3032

3133
LazyHighCharts::HighChart.new('graph') do |f|
32-
f.title(text: '開催回数の推移')
34+
f.title(text: title_text)
3335
f.xAxis(categories: data[:years])
34-
f.series(type: 'column', name: '開催回数', yAxis: 0, data: data[:increase_nums])
35-
f.series(type: 'line', name: '累積合計', yAxis: 1, data: data[:cumulative_sums])
36+
f.series(type: 'column', name: lang == 'en' ? 'Events' : '開催回数', yAxis: 0, data: data[:increase_nums])
37+
f.series(type: 'line', name: lang == 'en' ? 'Total' : '累積合計', yAxis: 1, data: data[:cumulative_sums])
3638
f.yAxis [
37-
{ title: { text: '開催回数' }, tickInterval: 500, max: 2000 },
38-
{ title: { text: '累積合計' }, tickInterval: 3000, max: 12000, opposite: true }
39+
{ title: { text: lang == 'en' ? 'Events' : '開催回数' }, tickInterval: 500, max: 2000 },
40+
{ title: { text: lang == 'en' ? 'Total' : '累積合計' }, tickInterval: 3000, max: 12000, opposite: true }
3941
]
4042
f.chart(width: HIGH_CHARTS_WIDTH, alignTicks: false)
4143
f.colors(["#F4C34F", "#BD2561"])
4244
end
4345
end
4446

45-
def build_annual_participants(source)
47+
def build_annual_participants(source, lang = 'ja')
4648
data = annual_chart_data_from(source)
49+
title_text = lang == 'en' ? 'Number of Participants' : '参加者数の推移'
4750

4851
LazyHighCharts::HighChart.new('graph') do |f|
49-
f.title(text: '参加者数の推移')
52+
f.title(text: title_text)
5053
f.xAxis(categories: data[:years])
51-
f.series(type: 'column', name: '参加者数', yAxis: 0, data: data[:increase_nums])
52-
f.series(type: 'line', name: '累積合計', yAxis: 1, data: data[:cumulative_sums])
54+
f.series(type: 'column', name: lang == 'en' ? 'Participants' : '参加者数', yAxis: 0, data: data[:increase_nums])
55+
f.series(type: 'line', name: lang == 'en' ? 'Total' : '累積合計', yAxis: 1, data: data[:cumulative_sums])
5356
f.yAxis [
54-
{ title: { text: '参加者数' }, tickInterval: 2500, max: 12500 },
55-
{ title: { text: '累積合計' }, tickInterval: 14000, max: 64000, opposite: true }
57+
{ title: { text: lang == 'en' ? 'Participants' : '参加者数' }, tickInterval: 2500, max: 12500 },
58+
{ title: { text: lang == 'en' ? 'Total' : '累積合計' }, tickInterval: 14000, max: 64000, opposite: true }
5659
]
5760
f.chart(width: HIGH_CHARTS_WIDTH, alignTicks: false)
5861
f.colors(["#EF685E", "#35637D"])

app/models/stat.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ def annual_sum_of_participants
3131
@annual_sum_of_participants = year_hash_template.merge!(hash)
3232
end
3333

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

39-
def annual_event_histories_chart
40-
HighChartsBuilder.build_annual_event_histories(annual_count_of_event_histories)
39+
def annual_event_histories_chart(lang = 'ja')
40+
HighChartsBuilder.build_annual_event_histories(annual_count_of_event_histories, lang)
4141
end
4242

43-
def annual_participants_chart
44-
HighChartsBuilder.build_annual_participants(annual_sum_of_participants)
43+
def annual_participants_chart(lang = 'ja')
44+
HighChartsBuilder.build_annual_participants(annual_sum_of_participants, lang)
4545
end
4646

4747
private

0 commit comments

Comments
 (0)