Class: JIJI::Dao::AbstractAggregator

Inherits:
Aggregator show all
Defined in:
lib/jiji/dao/timed_data_dao.rb

Overview

一定期間のデータを集約するクラス

Instance Attribute Summary collapse

Attributes inherited from Aggregator

#scale

Instance Method Summary collapse

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

#startObject (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

#aggregatedObject



299
300
# File 'lib/jiji/dao/timed_data_dao.rb', line 299

def aggregated
end

#flush(time) {|aggregated| ... } ⇒ Object

Yields:



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_dateObject



301
302
303
# File 'lib/jiji/dao/timed_data_dao.rb', line 301

def next_date
  @next
end