Skip to content

Commit 1faaf3c

Browse files
committed
Add some stats data to return in /stats.json
1 parent b2a6b1d commit 1faaf3c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

app/controllers/stats_controller.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@ class StatsController < ApplicationController
22

33
# GET /stats[.json]
44
def show
5-
6-
# GET /stats.json
7-
# NOTE: Draft API that returns required-to-share data upon requests from other repos.
8-
if request.url.end_with? '.json'
9-
@stats_data = {
10-
active_dojos: Dojo.active_dojos_count,
11-
}
12-
13-
render json: @stats_data
14-
return
15-
end
16-
175
# 2012年1月1日〜2024年12月31日までの集計結果
186
@period_start = 2012
197
@period_end = 2024
@@ -116,6 +104,20 @@ def show
116104
@data_by_prefecture[p.name] = Dojo.active.where(prefecture_id: p.id).sum(:counter)
117105
end
118106
@data_by_prefecture_count = @data_by_prefecture.select{|k,v| v>0}.count
107+
108+
respond_to do |format|
109+
# No corresponding View for now.
110+
# Only for API: GET /dojos.json
111+
format.html # => app/views/stats/show.html.erb
112+
format.json { render json: {
113+
# NOTE: Add JSON data upon requests
114+
active_dojos: @sum_of_dojos, # Required by other repos
115+
total_events: @sum_of_events,
116+
total_ninjas: @sum_of_participants,
117+
active_dojos_by_region: @data_by_prefecture,
118+
}
119+
}
120+
end
119121
end
120122
end
121123

0 commit comments

Comments
 (0)