Skip to content

Commit b2af6f2

Browse files
committed
fix: 統計表示とラベルを/statsページと完全一致させる修正
- 統計ラベルを修正:「開設道場数」→「開設数」、「合計道場数」→「合計数」 - 統計計算ロジックを/statsページと同一に修正(counter合計を使用) - 現在年の表示テキストを改善:「2025年末時点」→「2025年8月8日時点」 - 変数名を統一:start_of_year/end_of_year → year_begin/year_end - if-elseブロックを削除してコードをシンプル化 この修正により、/dojos?year=XXXXの統計値が/statsページの グラフ値と完全に一致し、訪問者が数値を正確に照合できるようになった。
1 parent 79f260d commit b2af6f2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

app/controllers/dojos_controller.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def index
1313
end
1414

1515
@selected_year = year
16-
end_of_year = Time.zone.local(@selected_year).end_of_year
16+
year_end = Time.zone.local(@selected_year).end_of_year
1717

1818
# その年末時点でアクティブだった道場を取得
19-
dojos_scope = Dojo.active_at(end_of_year)
19+
dojos_scope = Dojo.active_at(year_end)
2020
@page_title = "#{@selected_year}年末時点のCoderDojo一覧"
2121
rescue ArgumentError
2222
flash[:inline_alert] = "無効な年が指定されました"
@@ -58,8 +58,20 @@ def index
5858

5959
# 年が選択されている場合、統計情報を含むメッセージを設定
6060
if @selected_year
61-
active_dojos_count = @dojos.count
62-
flash.now[:inline_info] = "#{@selected_year}年末時点のアクティブな道場を表示中<br>(開設道場数: #{active_dojos_count} / 合計道場数: #{@counter_sum})".html_safe
61+
# /statsページと同じ計算方法を使用
62+
# 開設数 = その年に新規開設されたDojoのcounter合計
63+
year_begin = Time.zone.local(@selected_year).beginning_of_year
64+
year_end = Time.zone.local(@selected_year).end_of_year
65+
new_dojos_count = Dojo.where(created_at: year_begin..year_end).sum(:counter)
66+
67+
# 合計数 = その年末時点でアクティブだったDojoのcounter合計
68+
total_dojos_count = Dojo.active_at(year_end).sum(:counter)
69+
70+
# 表示用の日付テキスト
71+
display_date = "#{@selected_year}年末"
72+
display_date = Date.current.strftime('%Y年%m月%d日') if @selected_year == Date.current.year
73+
74+
flash.now[:inline_info] = "#{display_date}時点のアクティブな道場を表示中<br>(開設数: #{new_dojos_count} / 合計数: #{total_dojos_count})".html_safe
6375
end
6476

6577
respond_to do |format|

spec/requests/dojos_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
expect(flash[:inline_alert]).to include("2012年から")
5959
end
6060

61-
it "rejects years after current year" do
61+
it "rejects future years" do
6262
future_year = Date.current.year + 1
6363
get dojos_path(year: future_year, format: :json)
6464
expect(response).to redirect_to(dojos_path(anchor: 'table'))
@@ -294,8 +294,8 @@
294294
expect(response.body).to include('2020年末時点')
295295
expect(response.body).to include('アクティブな道場を表示中')
296296
# 統計情報が含まれていることを確認(/statsページとの比較検証用)
297-
expect(response.body).to include('開設道場数:')
298-
expect(response.body).to include('合計道場数:')
297+
expect(response.body).to include('開設数:')
298+
expect(response.body).to include('合計数:')
299299
# inline_infoメッセージが表示されることを確認
300300
expect(response.body).to include('alert-info')
301301
end

0 commit comments

Comments
 (0)