optimus-ep 0.6.91 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +13 -0
- data/{License.txt → LICENSE} +1 -1
- data/{Manifest.txt → Manifest} +23 -11
- data/{README.txt → README} +1 -1
- data/Rakefile +9 -10
- data/autotest/discover.rb +1 -0
- data/bin/eprime2tabfile +10 -10
- data/bin/extract_timings +4 -4
- data/lib/eprimetab_parser.rb +3 -3
- data/lib/excel_parser.rb +2 -2
- data/lib/expression_parser/evaluators.rb +188 -0
- data/lib/expression_parser/expressions.rb +173 -0
- data/lib/log_file_parser.rb +9 -9
- data/lib/optimus.rb +30 -0
- data/lib/{eprime_data.rb → optimus_data.rb} +12 -29
- data/lib/{eprime_reader.rb → optimus_reader.rb} +27 -13
- data/lib/parsed_calculator.rb +92 -0
- data/lib/raw_tab_parser.rb +3 -3
- data/lib/runners/generic_runner.rb +7 -7
- data/lib/runners/yaml_template/option_parser.rb +33 -0
- data/lib/runners/yaml_template/runner.rb +19 -0
- data/lib/tabfile_parser.rb +6 -6
- data/lib/tabfile_writer.rb +7 -7
- data/lib/transformers/basic_transformer.rb +35 -24
- data/lib/transformers/column_calculator.rb +131 -326
- data/lib/transformers/multipasser.rb +10 -6
- data/lib/transformers/row_filter.rb +7 -12
- data/lib/transformers/timing_extractor.rb +3 -3
- data/lib/version.rb +3 -3
- data/lib/writers/stimtimes_writer.rb +6 -6
- data/optimus-ep.gemspec +37 -0
- data/spec/eprimetab_parser_spec.rb +7 -7
- data/spec/excel_parser_spec.rb +6 -6
- data/spec/expression_parser/evaluators_spec.rb +241 -0
- data/spec/expression_parser/expressions_spec.rb +119 -0
- data/spec/log_file_parser_spec.rb +30 -30
- data/spec/{eprime_data_spec.rb → optimus_data_spec.rb} +20 -20
- data/spec/{eprime_reader_spec.rb → optimus_reader_spec.rb} +36 -24
- data/spec/parsed_calculator_spec.rb +112 -0
- data/spec/raw_tab_parser_spec.rb +26 -0
- data/spec/runners/generic_runner_spec.rb +5 -12
- data/spec/runners/yaml_template/option_parser_spec.rb +25 -0
- data/spec/runners/yaml_template/runner_spec.rb +20 -0
- data/spec/samples/optimus_log.txt +103 -103
- data/spec/samples/optimus_log_utf16le.txt +0 -0
- data/spec/samples/raw_tsv.txt +4 -0
- data/spec/spec_helper.rb +75 -12
- data/spec/tabfile_parser_spec.rb +18 -18
- data/spec/tabfile_writer_spec.rb +12 -12
- data/spec/transformers/basic_transformer_spec.rb +18 -8
- data/spec/transformers/column_calculator_spec.rb +109 -364
- data/spec/transformers/multipasser_spec.rb +14 -7
- data/spec/transformers/row_filter_spec.rb +11 -6
- data/spec/transformers/timing_extractor_spec.rb +8 -8
- data/spec/writers/stimtimes_writer_spec.rb +3 -3
- metadata +103 -50
- data/History.txt +0 -45
- data/lib/calculator.rb +0 -51
- data/lib/eprime.rb +0 -24
- data/spec/calculator_spec.rb +0 -70
data/spec/spec_helper.rb
CHANGED
@@ -1,33 +1,95 @@
|
|
1
1
|
# Part of the Optimus package for managing E-Prime data
|
2
2
|
#
|
3
|
-
# Copyright (C) 2008 Board of Regents of the University of Wisconsin System
|
3
|
+
# Copyright (C) 2008-09 Board of Regents of the University of Wisconsin System
|
4
4
|
#
|
5
5
|
# Written by Nathan Vack <njvack@wisc.edu>, at the Waisman Laborotory for Brain
|
6
6
|
# Imaging and Behavior, University of Wisconsin - Madison
|
7
7
|
|
8
|
-
module
|
8
|
+
module OptimusTestHelper
|
9
9
|
|
10
|
-
class
|
11
|
-
def initialize(expected)
|
10
|
+
class ParseAs
|
11
|
+
def initialize(parse_str, expected)
|
12
|
+
@parse_str = parse_str
|
12
13
|
@expected = expected
|
13
14
|
end
|
14
15
|
|
15
16
|
def matches?(target)
|
16
|
-
@parsed = target.parse(@
|
17
|
-
@parsed == @expected
|
17
|
+
@parsed = target.parse(@parse_str).to_s
|
18
|
+
return (@parsed == @expected)
|
18
19
|
end
|
19
20
|
|
20
21
|
def failure_message
|
21
|
-
"expected #{@
|
22
|
+
"expected #{@parse_str} to parse to #{@expected}, got #{@parsed}"
|
22
23
|
end
|
23
24
|
|
24
25
|
def negative_failure_message
|
25
|
-
"
|
26
|
+
"expected #{@parse_str} not to parse to #{@expected}."
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
30
|
+
def parse_as(parse_str, expected)
|
31
|
+
ParseAs.new(parse_str, expected)
|
32
|
+
end
|
33
|
+
|
29
34
|
def round_trip(expected)
|
30
|
-
|
35
|
+
ParseAs.new(expected, expected)
|
36
|
+
end
|
37
|
+
|
38
|
+
class ParseSuccessfully
|
39
|
+
def initialize(expected)
|
40
|
+
@expected = expected
|
41
|
+
end
|
42
|
+
|
43
|
+
def matches?(target)
|
44
|
+
begin
|
45
|
+
@parsed = target.parse(@expected)
|
46
|
+
rescue RParsec::ParserException => e
|
47
|
+
@message = e.message
|
48
|
+
return false
|
49
|
+
end
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
|
53
|
+
def failure_message
|
54
|
+
"expected #{@expected} to parse; raised #{@message}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def negative_failure_message
|
58
|
+
"expected #{@expected} not to parse"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def parse_successfully(expected)
|
63
|
+
ParseSuccessfully.new(expected)
|
64
|
+
end
|
65
|
+
|
66
|
+
class EvaluateTo
|
67
|
+
def initialize(expected)
|
68
|
+
@expected = expected
|
69
|
+
end
|
70
|
+
|
71
|
+
def matches?(target)
|
72
|
+
@target = target
|
73
|
+
@result = target.evaluate
|
74
|
+
return ((@result == @expected) or (is_NaN(@result) and is_NaN(@expected)))
|
75
|
+
end
|
76
|
+
|
77
|
+
def failure_message
|
78
|
+
"#{@target.to_s} expected to evaluate to #{@expected.inspect}; actual: #{@result.inspect}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def negative_failure_message
|
82
|
+
"#{@target.to_s} expected to NOT evaluate to #{@expected}"
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
def is_NaN(obj)
|
87
|
+
obj.respond_to? :nan? and obj.nan?
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def evaluate_to(expected)
|
92
|
+
EvaluateTo.new(expected)
|
31
93
|
end
|
32
94
|
|
33
95
|
unless constants.include?('SAMPLE_DIR')
|
@@ -40,6 +102,7 @@ module EprimeTestHelper
|
|
40
102
|
UNKNOWN_FILE = File.join(SAMPLE_DIR, 'unknown_type.txt')
|
41
103
|
UNREADABLE_FILE = File.join(SAMPLE_DIR, 'unreadable_file')
|
42
104
|
CORRUPT_LOG_FILE = File.join(SAMPLE_DIR, 'corrupt_log_file.txt')
|
105
|
+
UTF16LE_FILE = File.join(SAMPLE_DIR, 'optimus_log_utf16le.txt')
|
43
106
|
|
44
107
|
|
45
108
|
STD_COLUMNS = ["ExperimentName", "Subject", "Session", "RFP.StartTime", "BlockTitle", "PeriodA", "CarriedVal[Session]", "BlockList", "Trial",
|
@@ -75,8 +138,8 @@ module EprimeTestHelper
|
|
75
138
|
end
|
76
139
|
|
77
140
|
|
78
|
-
def
|
79
|
-
data =
|
141
|
+
def mock_optimus(col_count, row_count)
|
142
|
+
data = Optimus::Data.new()
|
80
143
|
1.upto(row_count) do |rownum|
|
81
144
|
row = data.add_row
|
82
145
|
1.upto(col_count) do |colnum|
|
@@ -90,7 +153,7 @@ module EprimeTestHelper
|
|
90
153
|
end
|
91
154
|
|
92
155
|
def mock_edata
|
93
|
-
data =
|
156
|
+
data = Optimus::Data.new()
|
94
157
|
row = data.add_row
|
95
158
|
row['stim_time'] = '3188'
|
96
159
|
row['run_start'] = '2400'
|
data/spec/tabfile_parser_spec.rb
CHANGED
@@ -1,62 +1,62 @@
|
|
1
1
|
# Part of the Optimus package for managing E-Prime data
|
2
2
|
#
|
3
|
-
# Copyright (C) 2008 Board of Regents of the University of Wisconsin System
|
3
|
+
# Copyright (C) 2008-09 Board of Regents of the University of Wisconsin System
|
4
4
|
#
|
5
5
|
# Written by Nathan Vack <njvack@wisc.edu>, at the Waisman Laborotory for Brain
|
6
6
|
# Imaging and Behavior, University of Wisconsin - Madison
|
7
7
|
|
8
8
|
require File.join(File.dirname(__FILE__),'spec_helper')
|
9
|
-
require File.join(File.dirname(__FILE__), '../lib/
|
10
|
-
include
|
9
|
+
require File.join(File.dirname(__FILE__), '../lib/optimus')
|
10
|
+
include OptimusTestHelper
|
11
11
|
|
12
12
|
|
13
|
-
shared_examples_for "
|
14
|
-
it "should generate and
|
15
|
-
@
|
13
|
+
shared_examples_for "Optimus::Reader::TabfileParser with sample data" do
|
14
|
+
it "should generate and Optimus::Data object" do
|
15
|
+
@optimus.should be_an_instance_of(Optimus::Data)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should have columns matching the test set" do
|
19
|
-
@
|
19
|
+
@optimus.columns.sort.should == STD_COLUMNS.sort
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should contain three rows" do
|
23
|
-
@
|
23
|
+
@optimus.length.should == 3
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe
|
27
|
+
describe Optimus::Reader::TabfileParser do
|
28
28
|
|
29
29
|
describe "without column order specified" do
|
30
30
|
before :each do
|
31
31
|
@file = File.open(EXCEL_FILE, 'r')
|
32
|
-
@reader =
|
33
|
-
@
|
32
|
+
@reader = Optimus::Reader::TabfileParser.new(@file, :skip_lines => 1)
|
33
|
+
@optimus = @reader.to_optimus
|
34
34
|
end
|
35
35
|
|
36
|
-
it_should_behave_like "
|
36
|
+
it_should_behave_like "Optimus::Reader::TabfileParser with sample data"
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "with column order specified" do
|
40
40
|
before :each do
|
41
41
|
@file = File.open(EXCEL_FILE, 'r')
|
42
|
-
@reader =
|
43
|
-
@
|
42
|
+
@reader = Optimus::Reader::TabfileParser.new(@file, :skip_lines => 1, :columns => SORTED_COLUMNS)
|
43
|
+
@optimus = @reader.to_optimus
|
44
44
|
end
|
45
45
|
|
46
|
-
it_should_behave_like "
|
46
|
+
it_should_behave_like "Optimus::Reader::TabfileParser with sample data"
|
47
47
|
|
48
48
|
end
|
49
49
|
|
50
50
|
describe "with data missing from some rows" do
|
51
51
|
before :each do
|
52
52
|
@file = File.open(BAD_EXCEL_FILE, 'r')
|
53
|
-
@reader =
|
53
|
+
@reader = Optimus::Reader::TabfileParser.new(@file, :skip_lines => 1)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should raise an error when parsing" do
|
57
57
|
lambda {
|
58
|
-
@reader.
|
59
|
-
}.should raise_error(
|
58
|
+
@reader.to_optimus
|
59
|
+
}.should raise_error(Optimus::DamagedFileError)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
data/spec/tabfile_writer_spec.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
# Part of the Optimus package for managing E-Prime data
|
2
2
|
#
|
3
|
-
# Copyright (C) 2008 Board of Regents of the University of Wisconsin System
|
3
|
+
# Copyright (C) 2008-09 Board of Regents of the University of Wisconsin System
|
4
4
|
#
|
5
5
|
# Written by Nathan Vack <njvack@wisc.edu>, at the Waisman Laborotory for Brain
|
6
6
|
# Imaging and Behavior, University of Wisconsin - Madison
|
7
7
|
|
8
8
|
require File.join(File.dirname(__FILE__),'spec_helper')
|
9
|
-
require File.join(File.dirname(__FILE__), '../lib/
|
9
|
+
require File.join(File.dirname(__FILE__), '../lib/optimus')
|
10
10
|
require 'stringio'
|
11
11
|
|
12
|
-
include
|
12
|
+
include OptimusTestHelper
|
13
13
|
|
14
14
|
E_ROWS = 3
|
15
15
|
E_COLS = 4
|
16
16
|
|
17
|
-
describe "
|
17
|
+
describe "Optimus::TabfileWriter" do
|
18
18
|
|
19
19
|
before :each do
|
20
|
-
@
|
20
|
+
@optimus_data = mock_optimus(E_COLS, E_ROWS)
|
21
21
|
@out_s = StringIO.new
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should succeed at writing" do
|
25
|
-
writer =
|
25
|
+
writer = Optimus::TabfileWriter.new(@optimus_data, @out_s)
|
26
26
|
writer.write
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "without filename line" do
|
30
30
|
before :each do
|
31
|
-
@writer =
|
31
|
+
@writer = Optimus::TabfileWriter.new(@optimus_data, @out_s)
|
32
32
|
@writer.write
|
33
33
|
@out_s.rewind
|
34
34
|
end
|
@@ -51,7 +51,7 @@ describe "Eprime::TabfileWriter" do
|
|
51
51
|
def @out_s.path # Redefine this so we can test the first line trick
|
52
52
|
'spec_test'
|
53
53
|
end
|
54
|
-
@writer =
|
54
|
+
@writer = Optimus::TabfileWriter.new(@optimus_data, @out_s, :write_top_line => true)
|
55
55
|
@writer.write
|
56
56
|
@out_s.rewind
|
57
57
|
end
|
@@ -68,7 +68,7 @@ describe "Eprime::TabfileWriter" do
|
|
68
68
|
|
69
69
|
describe "with good output columns specified" do
|
70
70
|
before :each do
|
71
|
-
@writer =
|
71
|
+
@writer = Optimus::TabfileWriter.new(@optimus_data, @out_s, :columns => ['col_2'])
|
72
72
|
@writer.write
|
73
73
|
@out_s.rewind
|
74
74
|
end
|
@@ -84,20 +84,20 @@ describe "Eprime::TabfileWriter" do
|
|
84
84
|
describe "with nonexistent output column specified" do
|
85
85
|
|
86
86
|
it "should raise an error when specifying a nonexistent column" do
|
87
|
-
@writer =
|
87
|
+
@writer = Optimus::TabfileWriter.new(@optimus_data, @out_s, :columns => ['KITTEH'])
|
88
88
|
lambda { @writer.write }.should raise_error(IndexError)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
describe "with column_labels set to false" do
|
93
93
|
before :each do
|
94
|
-
@writer =
|
94
|
+
@writer = Optimus::TabfileWriter.new(@optimus_data, @out_s, {:column_labels => false})
|
95
95
|
@writer.write
|
96
96
|
@out_s.rewind
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should not write a line with column labels" do
|
100
|
-
@out_s.readlines.size.should == @
|
100
|
+
@out_s.readlines.size.should == @optimus_data.size
|
101
101
|
end
|
102
102
|
|
103
103
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Part of the Optimus package for managing E-Prime data
|
2
2
|
#
|
3
|
-
# Copyright (C) 2008 Board of Regents of the University of Wisconsin System
|
3
|
+
# Copyright (C) 2008-09 Board of Regents of the University of Wisconsin System
|
4
4
|
#
|
5
5
|
# Written by Nathan Vack <njvack@wisc.edu>, at the Waisman Laborotory for Brain
|
6
6
|
# Imaging and Behavior, University of Wisconsin - Madison
|
@@ -8,12 +8,12 @@
|
|
8
8
|
# All of the complex behavior is exercised in
|
9
9
|
|
10
10
|
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
11
|
-
require File.join(File.dirname(__FILE__),'../../lib/
|
11
|
+
require File.join(File.dirname(__FILE__),'../../lib/optimus')
|
12
12
|
require File.join('transformers/basic_transformer')
|
13
|
-
include
|
14
|
-
include
|
13
|
+
include OptimusTestHelper
|
14
|
+
include Optimus::Transformers
|
15
15
|
|
16
|
-
describe
|
16
|
+
describe Optimus::Transformers::BasicTransformer do
|
17
17
|
before :each do
|
18
18
|
@data = mock_edata
|
19
19
|
@xf = BasicTransformer.new(@data)
|
@@ -33,7 +33,7 @@ describe Eprime::Transformers::BasicTransformer do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should allow copydown columns" do
|
36
|
-
@xf.copydown_column 'test',
|
36
|
+
@xf.copydown_column 'test', "sparse"
|
37
37
|
@xf.columns.should include('test')
|
38
38
|
end
|
39
39
|
|
@@ -48,8 +48,18 @@ describe Eprime::Transformers::BasicTransformer do
|
|
48
48
|
@xf.size.should == count
|
49
49
|
end
|
50
50
|
|
51
|
+
it "should allow adding simple passes without a block" do
|
52
|
+
@xf.add_pass(
|
53
|
+
'-{stim_time}',
|
54
|
+
lambda {|r| !r['sparse'].to_s.empty?},
|
55
|
+
[['test', '{stim_time}']]
|
56
|
+
)
|
57
|
+
df = @data.find_all { |r| !r['sparse'].to_s.empty? }
|
58
|
+
@xf.size.should == df.size
|
59
|
+
end
|
60
|
+
|
51
61
|
it "should allow adding passes without a block" do
|
52
|
-
@xf.add_pass('-{stim_time}', lambda {|r| !r['sparse'].to_s.empty?}, [['test', 'stim_time']])
|
62
|
+
@xf.add_pass('-{stim_time}', lambda {|r| !r['sparse'].to_s.empty?}, [['test', '{stim_time}']])
|
53
63
|
df = @data.find_all { |r| !r['sparse'].to_s.empty? }
|
54
64
|
@xf.size.should == df.size
|
55
65
|
@xf[0]['stim_time'].should == df.reverse[0]['stim_time']
|
@@ -60,7 +70,7 @@ describe Eprime::Transformers::BasicTransformer do
|
|
60
70
|
@xf.add_pass do |p|
|
61
71
|
p.sort_expression = '-{stim_time}'
|
62
72
|
p.row_filter = lambda { |r| !r['sparse'].to_s.empty?}
|
63
|
-
p.computed_column 'test', 'stim_time'
|
73
|
+
p.computed_column 'test', '{stim_time}'
|
64
74
|
end
|
65
75
|
df = @data.find_all { |r| !r['sparse'].to_s.empty? }
|
66
76
|
@xf.size.should == df.size
|