Skip to content

Commit

Permalink
fix: sometimes avg needs to handle 0s
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefvaclavik committed May 9, 2024
1 parent 9611f20 commit f1b6b1d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/trifle/stats/aggregator/avg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def aggregate(series:, path:, slices: 1)

def sliced(result:, slices:)
result[(result.count - (result.count / slices * slices))..].each_slice(result.count / slices).map do |slice|
slice.compact.sum / slice.compact.count
sum = slice.compact.sum
count = slice.compact.count

count.zero? ? 0 : sum / count
end
end
end
Expand Down

0 comments on commit f1b6b1d

Please sign in to comment.