Class: JIJI::Dao::AbstractAggregator
- Inherits:
-
Aggregator
- Object
- Aggregator
- JIJI::Dao::AbstractAggregator
- Defined in:
- lib/jiji/dao/timed_data_dao.rb
Overview
一定期間のデータを集約するクラス
Direct Known Subclasses
AvgAggregator, LastAggregator, RateDao::RatesAggregator, TradeResultDao::TradeAggregator
Instance Attribute Summary collapse
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Attributes inherited from Aggregator
Instance Method Summary collapse
- #aggregate(timed_data) ⇒ Object
- #aggregated ⇒ Object
- #flush(time) {|aggregated| ... } ⇒ Object
-
#initialize(scale) ⇒ AbstractAggregator
constructor
A new instance of AbstractAggregator.
-
#next(timed_data) ⇒ Object
データを受け取り、集約したデータがある場合、それを引数としてブロックを実行する。.
- #next_date ⇒ Object
Constructor Details
#initialize(scale) ⇒ AbstractAggregator
Returns a new instance of AbstractAggregator.
267 268 269 270 271 |
# File 'lib/jiji/dao/timed_data_dao.rb', line 267 def initialize( scale ) super @period = JIJI::Util.parse_scale(scale) @next = nil end |
Instance Attribute Details
#start ⇒ Object (readonly)
Returns the value of attribute start.
304 305 306 |
# File 'lib/jiji/dao/timed_data_dao.rb', line 304 def start @start end |
Instance Method Details
#aggregate(timed_data) ⇒ Object
297 298 |
# File 'lib/jiji/dao/timed_data_dao.rb', line 297 def aggregate( timed_data ) end |
#aggregated ⇒ Object
299 300 |
# File 'lib/jiji/dao/timed_data_dao.rb', line 299 def aggregated end |
#flush(time) {|aggregated| ... } ⇒ Object
288 289 290 291 292 293 294 295 296 |
# File 'lib/jiji/dao/timed_data_dao.rb', line 288 def flush( time ) return unless @next #一度もnextが呼ばれていない場合、何もしない @end = time yield aggregated @start = @next @end = nil @next += @period while @next <= time end |
#next(timed_data) ⇒ Object
データを受け取り、集約したデータがある場合、それを引数としてブロックを実行する。
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/jiji/dao/timed_data_dao.rb', line 273 def next( timed_data ) now = timed_data.time unless @next @next = Time.at(((now.to_i / @period)+1) * @period ) @start = Time.at(@next.to_i-@period) end aggregate( timed_data ) if now >= @next @end = @next yield aggregated @start = @next @end = nil @next += @period while @next <= now end end |
#next_date ⇒ Object
301 302 303 |
# File 'lib/jiji/dao/timed_data_dao.rb', line 301 def next_date @next end |