Skip to content

Commit

Permalink
割合を求める式でゼロ除算が実行される場合はNaNと表示させる in Stats
Browse files Browse the repository at this point in the history
  • Loading branch information
yasulab committed Feb 7, 2024
1 parent d6eb349 commit 0e89910
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 8 additions & 0 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def show
# 「集計対象となっている道場数 / 非集計対象含む道場数」の推移
@annual_dojos_table = stats.annual_sum_total_of_aggregatable_dojo
@annual_dojos_whole = stats.annual_sum_total_of_dojo_inactive_included
@annual_dojos_ratio = {}
(@period_start..@period_end).each do |year|
ratio = @annual_dojos_whole[year.to_s].zero? ?
'NaN' :
(Rational(@annual_dojos_table[year.to_s], @annual_dojos_whole[year.to_s]).to_f * 100).round(1).to_s

@annual_dojos_ratio[year.to_s] = ratio
end

# 日本各地の道場
@data_by_region = []
Expand Down
6 changes: 2 additions & 4 deletions app/views/stats/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@
%small
割合
%span{style: 'font-size: x-small'}<> [%]
- (@period_start..@period_end).each do |year|
- ratio = (Rational(@annual_dojos_table[year.to_s], @annual_dojos_whole[year.to_s]).to_f * 100).round(1)
- @annual_dojos_ratio.each_value do |num|
%td
%small
= ratio == 100 ? '100' : ratio
%small= num
%span{style: 'font-size: 10px;'} (非アクティブになった道場も含まれています)


Expand Down

0 comments on commit 0e89910

Please sign in to comment.