Skip to content

Commit

Permalink
Removing conversions to int
Browse files Browse the repository at this point in the history
Allow for other sorts of numeric types (like float).

Signed-off-by: Scott Chacon <schacon@gmail.com>
  • Loading branch information
eric authored and schacon committed Dec 29, 2008
1 parent 2156b36 commit c6a3ede
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/munger/data.rb
Expand Up @@ -132,12 +132,12 @@ def group(groups, agg_hash = {})
newcol = key.to_s + '_' + col.to_s
case key
when :average
sum = data[:cells][col].inject(0) { |sum, a| sum + a.to_i }
sum = data[:cells][col].inject { |sum, a| sum + a }
new_row[newcol] = (sum / data[:count])
when :count
new_row[newcol] = data[:count]
else
new_row[newcol] = data[:cells][col].inject(0) { |sum, a| sum + a.to_i }
new_row[newcol] = data[:cells][col].inject { |sum, a| sum + a }
end
end
new_keys << newcol
Expand All @@ -161,7 +161,7 @@ def pivot(columns, rows, value, aggregation = :sum)
focus = data_hash[row_key][column_key]
focus[:data] = clean_data(row)
focus[:count] += 1
focus[:sum] += row[value].to_i
focus[:sum] += row[value]
end

new_data = []
Expand Down
6 changes: 3 additions & 3 deletions lib/munger/report.rb
Expand Up @@ -234,10 +234,10 @@ def calculate_aggregate(type, data)
when :count
data.size
when :average
sum = data.inject(0) {|sum, n| sum + n.to_i }
(sum / data.size).to_i rescue 0
sum = data.inject {|sum, n| sum + n }
(sum / data.size) rescue 0
else
data.inject(0) {|sum, n| sum + n.to_i }
data.inject {|sum, n| sum + n }
end
end
end
Expand Down

0 comments on commit c6a3ede

Please sign in to comment.