Class: Trifle::Stats::Transponder::Ratio
- Inherits:
-
Object
- Object
- Trifle::Stats::Transponder::Ratio
- Includes:
- Mixins::Packer
- Defined in:
- lib/trifle/stats/transponder/ratio.rb
Instance Method Summary collapse
-
#transpond(series:, path:, key: 'ratio', sample: 'sample', total: 'total') ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
Methods included from Mixins::Packer
Instance Method Details
#transpond(series:, path:, key: 'ratio', sample: 'sample', total: 'total') ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/trifle/stats/transponder/ratio.rb', line 10 def transpond(series:, path:, key: 'ratio', sample: 'sample', total: 'total') # rubocop:disable Metrics/AbcSize, Metrics/MethodLength keys = path.to_s.split('.') sample = sample.to_s.split('.') total = total.to_s.split('.') key = path.to_s.empty? ? key : [path, key].join('.') series[:values] = series[:values].map do |data| 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 } self.class.deep_merge(data, self.class.unpack(hash: signal)) end series end |