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

読み込み終了日時



153
154
155
156
157
158
159
# File 'lib/jiji/collector.rb', line 153

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



196
197
198
# File 'lib/jiji/collector.rb', line 196

def dao
  @dao
end

Instance Method Details

#collectObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/jiji/collector.rb', line 160

def collect
  JIJI::Util.log_if_error_and_throw( @logger ) {
    callback( :on_progress_changed, @progress )
    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) )
      else
        @start_date = @start_date || 0
        @end_date = @end_date || Time.now
      end
      @now = @start_date.to_i
      @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
      }
      callback( :on_progress_changed, @progress )
    end
  }
end

#progressObject



189
190
191
192
193
# File 'lib/jiji/collector.rb', line 189

def progress
  @state_mutex.synchronize {
    @progress
  }
end