Class: JIJI::BackTestCollector

Inherits:
Collector show all
Defined in:
lib/jiji/collector.rb

Overview

指定された期間のログからレート一覧を取得し、JIJI::ObserverManagerに通知するクラス

Instance Attribute Summary collapse

Attributes inherited from Collector

#client, #conf, #error, #listeners, #logger, #observer_manager, #wait_time

Instance Method Summary collapse

Methods inherited from Collector

#start, #state, #stop

Constructor Details

#initialize(rate_dao, start_date, end_date) ⇒ BackTestCollector

コンストラクタ

rate_dao

レート情報の取得先とするJIJI::RateDao

start_date

読み込み開始日時

end_date

読み込み終了日時



150
151
152
153
154
155
156
# File 'lib/jiji/collector.rb', line 150

def initialize( rate_dao, start_date, end_date )
  super()
  @dao = rate_dao
  @start_date = start_date
  @end_date  =  end_date
  @progress = 0
end

Instance Attribute Details

#daoObject (readonly)

レートDAO



187
188
189
# File 'lib/jiji/collector.rb', line 187

def dao
  @dao
end

Instance Method Details

#collectObject



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/jiji/collector.rb', line 157

def collect
  JIJI::Util.log_if_error_and_throw( @logger ) {
    begin
      pairs =  @dao.list_pairs
      if pairs.length > 0
        @start_date = @start_date || Time.at( @dao.dao(pairs[0]).first_time(:raw) )
        @end_date = @end_date || Time.at( @dao.dao(pairs[0]).last_time(:raw) )
      end
      @dao.each_all_pair_rates(:raw, @start_date, @end_date ) {|rates|
        each_rate(rates)
        # キャンセルチェック

        if ( !@end_mutex.synchronize { @alive } )
          @logger.info( "collector canceled" )
          break
        end
      }
    ensure
      @state_mutex.synchronize {
        @progress = 100
      }
    end
  }
end

#progressObject



180
181
182
183
184
# File 'lib/jiji/collector.rb', line 180

def progress
  @state_mutex.synchronize {
    @progress
  }
end