Permalink
Browse files

avoid NaN bug in victory_rate calc

  • Loading branch information...
1 parent bd9d98d commit 3e8e79f81e4514a8a6f8d2c5eec7184c2e06a6ff @jrochkind committed Aug 23, 2012
Showing with 5 additions and 1 deletion.
  1. +5 −1 app/controllers/report_controller.rb
@@ -18,7 +18,11 @@ def index
# calc the 'victory rate': wins / (wins + losses), disregarding ties,
# expressed as a percentage
def victory_rate(row)
- 100 * row["wins"].to_f / ( row["wins"] + row["losses"] )
+ if rows["wins"].to_i == 0
+ 0
+ else
+ 100 * row["wins"].to_f / ( row["wins"] + row["losses"] )
+ end
end
helper_method :victory_rate

0 comments on commit 3e8e79f

Please sign in to comment.