Class: JIJI::Dao::AvgAggregator
- Inherits:
-
AbstractAggregator
- Object
- Aggregator
- AbstractAggregator
- JIJI::Dao::AvgAggregator
- Defined in:
- lib/jiji/dao/timed_data_dao.rb
Overview
平均を取るAggregator
Instance Attribute Summary
Attributes inherited from AbstractAggregator
Attributes inherited from Aggregator
Instance Method Summary collapse
Methods inherited from AbstractAggregator
#flush, #initialize, #next, #next_date
Methods inherited from Aggregator
Constructor Details
This class inherits a constructor from JIJI::Dao::AbstractAggregator
Instance Method Details
#aggregate(timed_data) ⇒ Object
309 310 311 312 313 314 315 |
# File 'lib/jiji/dao/timed_data_dao.rb', line 309 def aggregate( timed_data ) @values = [] unless @values timed_data.values.each_index {|i| @values[i] = [] unless @values[i] @values[i] << timed_data.values[i] } end |
#aggregated ⇒ Object
316 317 318 319 320 321 322 |
# File 'lib/jiji/dao/timed_data_dao.rb', line 316 def aggregated avgs = @values.map{|vs| vs.inject(0){|t,v| t+=v }/vs.length } @values = [] BasicTimedData.new(avgs + [@start.to_i, @end.to_i], @end) end |