lib/transformers/timing_extractor.rb in optimus-ep-0.5.6 vs lib/transformers/timing_extractor.rb in optimus-ep-0.6.0
- old
+ new
@@ -14,16 +14,59 @@
# presented, and the time the presentation stopped.
#
# In an experiment, this will take, as an argument, a template written in ruby
# that will be eval'd in the context of this instance -- that will contain
# the guts of the logic to extract stimuli.
+require 'transformers/basic_transformer'
module Eprime
- class TimingExtractor
- def initialize(argv)
+ module Transformers
+ class TimingExtractor < BasicTransformer
+ def initialize(data)
+ super(data)
+ @stim_schemas = []
+ @extracted_data = nil
+ end
- end
-
- def extract
+ def extract_stimulus(
+ name_column,
+ onset_column,
+ offset_column,
+ row_filter = (lambda { |r| true })
+ )
+ @stim_schemas << {
+ 'name_column' => name_column,
+ 'onset_column' => onset_column,
+ 'offset_column' => offset_column,
+ 'row_filter' => row_filter
+ }
+ @extracted_data = nil
+ end
+
+ def extracted_data
+ extract!
+ return @extracted_data
+ end
+
+ private
+ def extract_reset!
+ @extracted_data = nil
+ end
+
+ def extract!
+ return if @extracted_data
+ @extracted_data = Eprime::Data.new
+ @stim_schemas.each do |ss|
+ matches = processed.find_all(&ss['row_filter'])
+ matches.each do |row|
+ nr = @extracted_data.add_row
+ nr['presented'] = row[ss['name_column']]
+ nr['onset'] = row[ss['onset_column']]
+ nr['offset'] = row[ss['offset_column']]
+ nr.sort_value = nr['onset'].to_f
+ end
+ end
+ @extracted_data.sort!
+ end
end
end
end
\ No newline at end of file