Skip to content

Commit

Permalink
fix: transponders do not fill in data if attribute is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefvaclavik committed May 8, 2024
1 parent e06ed26 commit 9611f20
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/trifle/stats/transponder/average.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def transpond(series:, path:, key: 'average', sum: 'sum', count: 'count') # rubo
count = count.to_s.split('.')
key = [path, key].compact.join('.')
series[:values] = series[:values].map do |data|
dsum = data.dig(*keys, *sum) || BigDecimal(0)
dcount = data.dig(*keys, *count) || BigDecimal(0)
dsum = data.dig(*keys, *sum)
dcount = data.dig(*keys, *count)
next data unless dsum && dcount

dres = (dsum / dcount)
signal = {
key => dres.nan? ? BigDecimal(0) : dres
Expand Down
6 changes: 4 additions & 2 deletions lib/trifle/stats/transponder/ratio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def transpond(series:, path:, key: 'ratio', sample: 'sample', total: 'total') #
total = total.to_s.split('.')
key = [path, key].compact.join('.')
series[:values] = series[:values].map do |data|
dsample = data.dig(*keys, *sample) || BigDecimal(0)
dtotal = data.dig(*keys, *total) || BigDecimal(0)
dsample = data.dig(*keys, *sample)
dtotal = data.dig(*keys, *total)
next data unless dsample && dtotal

dres = (dsample / dtotal) * 100
signal = {
key => dres.nan? ? BigDecimal(0) : dres
Expand Down
8 changes: 5 additions & 3 deletions lib/trifle/stats/transponder/standard_deviation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ def transpond(series:, path:, key: 'sd', sum: 'sum', count: 'count', square: 'sq
square = square.to_s.split('.')
key = [path, key].compact.join('.')
series[:values] = series[:values].map do |data|
dcount = data.dig(*keys, *count) || BigDecimal(0)
dsquare = data.dig(*keys, *square) || BigDecimal(0)
dsum = data.dig(*keys, *sum) || BigDecimal(0)
dcount = data.dig(*keys, *count)
dsquare = data.dig(*keys, *square)
dsum = data.dig(*keys, *sum)
next data unless dcount && dsquare && dsum

dres = Math.sqrt(
(dcount * dsquare - dsum * dsum) / (dcount * (dcount - 1)) # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
)
Expand Down

0 comments on commit 9611f20

Please sign in to comment.