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
@@ -1,437 +1,182 @@
|
|
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
|
|
11
11
|
require 'transformers/column_calculator'
|
12
|
-
require 'transformers/row_filter'
|
13
12
|
|
14
|
-
include
|
13
|
+
include OptimusTestHelper
|
15
14
|
|
16
15
|
NEW_COLUMN = 'NEW_COLUMN'
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
@
|
21
|
-
|
22
|
-
|
23
|
-
it "should not be nil" do
|
24
|
-
@calc[0].should_not be_nil
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should allow accessing rows" do
|
28
|
-
@calc[0].should be_a_kind_of(Eprime::Data::Row)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should return data" do
|
32
|
-
@calc[0]['stim_time'].should == @edata[0]['stim_time']
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should compute column indexes for data column names" do
|
36
|
-
@calc.column_index('stim_time').should == 0
|
37
|
-
@calc.column_index('run_start').should == 1
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should find column indexes for data columns" do
|
41
|
-
@calc.column_index(0).should == 0
|
42
|
-
@calc.column_index(1).should == 1
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should return nil when searching for out-of-bound named indexes" do
|
46
|
-
@calc.column_index('not_present').should be_nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should return nil when searching for out-of-bound numeric indexes" do
|
50
|
-
@calc.column_index(@calc.columns.size).should be_nil
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should allow setting a computed column" do
|
54
|
-
lambda {
|
55
|
-
@calc.computed_column NEW_COLUMN, "1"
|
56
|
-
}.should_not raise_error
|
17
|
+
describe Optimus::Transformers::ColumnCalculator do
|
18
|
+
before :each do
|
19
|
+
@edata = mock_edata
|
20
|
+
@pc = Optimus::Transformers::ColumnCalculator.new
|
21
|
+
@pc.data = @edata
|
57
22
|
end
|
58
23
|
|
59
|
-
it "should allow
|
24
|
+
it "should allow adding a computed column" do
|
60
25
|
lambda {
|
61
|
-
@
|
26
|
+
@pc.computed_column NEW_COLUMN, "1+1"
|
62
27
|
}.should_not raise_error
|
63
28
|
end
|
64
29
|
|
65
|
-
it "should
|
66
|
-
@
|
67
|
-
@calc.columns.should include(NEW_COLUMN)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should contain the new name when setting copydown column" do
|
71
|
-
@calc.copydown_column 'sparse_copy', 'sparse'
|
72
|
-
@calc.columns.should include('sparse_copy')
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should increse in column size when setting computed column" do
|
76
|
-
s1 = @calc.columns.size
|
77
|
-
@calc.computed_column NEW_COLUMN, "1"
|
78
|
-
s2 = @calc.columns.size
|
79
|
-
s2.should == s1+1
|
30
|
+
it "should be enumerable" do
|
31
|
+
@pc.should be_a_kind_of(Enumerable)
|
80
32
|
end
|
81
33
|
|
82
|
-
it "should
|
83
|
-
|
84
|
-
@calc.computed_column NEW_COLUMN, "1"
|
85
|
-
@calc.column_index(NEW_COLUMN).should == prev_max_index+1
|
34
|
+
it "should have columns" do
|
35
|
+
@pc.columns.sort.should == @edata.columns.sort
|
86
36
|
end
|
87
37
|
|
88
|
-
it "should
|
89
|
-
|
90
|
-
@
|
91
|
-
@calc.column_index(get_index).should == get_index
|
38
|
+
it "should add new columns" do
|
39
|
+
@pc.computed_column NEW_COLUMN, "1"
|
40
|
+
@pc.columns.should include(NEW_COLUMN)
|
92
41
|
end
|
93
42
|
|
94
|
-
it "should
|
95
|
-
@calc.computed_column NEW_COLUMN, "1"
|
43
|
+
it "should raise an error when adding bad columns" do
|
96
44
|
lambda {
|
97
|
-
@
|
98
|
-
}.
|
45
|
+
@pc.computed_column NEW_COLUMN, "FIAL"
|
46
|
+
}.should raise_error(RParsec::ParserException)
|
99
47
|
end
|
100
48
|
|
101
|
-
it "should
|
102
|
-
@
|
103
|
-
|
104
|
-
@calc[0][NEW_COLUMN]
|
105
|
-
}.should_not raise_error
|
49
|
+
it "should bring forth existing data" do
|
50
|
+
col = @edata.columns[0]
|
51
|
+
@pc.map {|row| row[col]}.should == @edata.map {|row| row[col]}
|
106
52
|
end
|
107
53
|
|
108
|
-
it "should
|
109
|
-
|
110
|
-
|
111
|
-
|
54
|
+
it "should return values for columns based on literals" do
|
55
|
+
@pc.computed_column NEW_COLUMN, "1"
|
56
|
+
@pc.each do |row|
|
57
|
+
row[NEW_COLUMN].should == 1
|
58
|
+
end
|
112
59
|
end
|
113
60
|
|
114
|
-
it "should
|
115
|
-
lambda {
|
116
|
-
|
117
|
-
|
61
|
+
it "should return values for columns based on lambdas" do
|
62
|
+
@pc.computed_column NEW_COLUMN, lambda {|row| row['stim_time'] }
|
63
|
+
@pc.computed_column "NEW_COL2", lambda {|row| 1}
|
64
|
+
@pc.each do |row|
|
65
|
+
row[NEW_COLUMN].should == row['stim_time']
|
66
|
+
row["NEW_COL2"].should == 1
|
67
|
+
end
|
118
68
|
end
|
119
69
|
|
120
|
-
it "should
|
121
|
-
|
122
|
-
|
123
|
-
|
70
|
+
it "should return computed columns based on literal columns" do
|
71
|
+
@pc.computed_column NEW_COLUMN, "{stim_time}"
|
72
|
+
@pc.each do |row|
|
73
|
+
row[NEW_COLUMN].should == row['stim_time'].to_f
|
74
|
+
end
|
124
75
|
end
|
125
76
|
|
126
|
-
it "should
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
filtered = Eprime::Transformers::RowFilter.new(cc, lambda {|r| true})
|
132
|
-
filtered.each do |r|
|
133
|
-
r.should_not be_nil
|
77
|
+
it "should return computed columns based on other computed columns" do
|
78
|
+
@pc.computed_column "FOO2", "{#{NEW_COLUMN}}"
|
79
|
+
@pc.computed_column NEW_COLUMN, "{stim_time}"
|
80
|
+
@pc.each do |row|
|
81
|
+
row["FOO2"].should == row['stim_time'].to_f
|
134
82
|
end
|
135
83
|
end
|
136
84
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
@calc.data = @edata
|
85
|
+
it "should raise a loop error when detecting a loop" do
|
86
|
+
@pc.computed_column "nc1", "{nc2}"
|
87
|
+
@pc.computed_column "nc2", "{nc1}"
|
88
|
+
lambda {
|
89
|
+
@pc[0]
|
90
|
+
}.should raise_error(Optimus::EvaluationLoopError)
|
144
91
|
end
|
145
92
|
|
146
|
-
|
147
|
-
|
148
|
-
|
93
|
+
it "should pass a somewhat arbitrary test" do
|
94
|
+
@pc.computed_column "result", "({stim_time} - {run_start})+ 100 / 2"
|
95
|
+
@pc.each do |row|
|
96
|
+
row['result'].should == (
|
97
|
+
(row['stim_time'].to_f - row['run_start'].to_f)+100/2)
|
149
98
|
end
|
150
|
-
|
151
|
-
it_should_behave_like "Eprime::Transformers::ColumnCalculator with edata"
|
152
99
|
end
|
153
100
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
@calc[0]['stim_time'].should == @edata[0]['stim_time']
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should compute static columns on single rows" do
|
162
|
-
@calc.computed_column "always_1", "1"
|
163
|
-
@calc[0]["always_1"].should == "1"
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should compute on single rows with some math" do
|
167
|
-
@calc.computed_column "test", "(3+2)*4"
|
168
|
-
@calc[0]["test"].should == ((3+2)*4).to_s
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should allow adding two columns" do
|
172
|
-
@calc.computed_column "always_1", "1"
|
173
|
-
@calc.computed_column "test", "(3+2)*4"
|
174
|
-
@calc[0]["always_1"].should == "1"
|
175
|
-
@calc[0]["test"].should == ((3+2)*4).to_s
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should raise when computing nonexistent column" do
|
179
|
-
lambda {
|
180
|
-
@calc[0]['nonexistent']
|
181
|
-
}.should raise_error(IndexError)
|
182
|
-
end
|
183
|
-
|
184
|
-
it "should allow computing via lambda" do
|
185
|
-
@calc.computed_column "always_1", lambda {|r| "1"}
|
186
|
-
@calc[0]["always_1"].should == "1"
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should compute constants via indexing" do
|
190
|
-
@calc.computed_column "always_1", "1"
|
191
|
-
@calc[0]["always_1"].should == "1"
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should compute with add, mul, and grouping via indexing" do
|
195
|
-
# See calculator_spec.rb for exhaustive testing of the parser
|
196
|
-
@calc.computed_column "add_mul", "5*(6+2)"
|
197
|
-
@calc.each do |row|
|
198
|
-
row["add_mul"].should == (5*(6+2)).to_s
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should work with multiple computed columns via indexing" do
|
203
|
-
@calc.computed_column "always_1", "1"
|
204
|
-
@calc.computed_column "add_mul", "5*(6+2)"
|
205
|
-
|
206
|
-
@calc.each do |row|
|
207
|
-
row["always_1"].should == "1"
|
208
|
-
row["add_mul"].should == (5*(6+2)).to_s
|
209
|
-
end
|
210
|
-
end
|
101
|
+
it "should not allow adding a column with an existing name" do
|
102
|
+
lambda {
|
103
|
+
@pc.computed_column "stim_time", "1"
|
104
|
+
}.should raise_error(Optimus::DuplicateColumnError)
|
211
105
|
end
|
212
106
|
|
213
|
-
describe "
|
214
|
-
|
215
|
-
it "should compute based on data columns" do
|
216
|
-
@calc.computed_column "stim_time_s", "{stim_time}/1000"
|
217
|
-
@calc.each do |row|
|
218
|
-
row["stim_time_s"].should == (row["stim_time"].to_f/1000.0).to_s
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should compute based on data columns by lambda" do
|
223
|
-
@calc.computed_column "stim_time_s", lambda { |row|
|
224
|
-
row['stim_time'].to_f/1000
|
225
|
-
}
|
226
|
-
@calc.columns.should include('stim_time_s')
|
227
|
-
@calc.each do |row|
|
228
|
-
row['stim_time_s'].should == row['stim_time'].to_f/1000
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
it "should allow math between two columns" do
|
233
|
-
@calc.computed_column "stim_from_run", "{stim_time}-{run_start}"
|
234
|
-
@calc.each do |row|
|
235
|
-
row['stim_from_run'].should == (row['stim_time'].to_i - row['run_start'].to_i).to_s
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should allow columns based on other computed columns" do
|
240
|
-
@calc.computed_column "stim_from_run", "{stim_time}-{run_start}"
|
241
|
-
@calc.computed_column "stim_run_s", "{stim_from_run} / 1000"
|
242
|
-
@calc.each do |row|
|
243
|
-
row['stim_run_s'].should == ((row['stim_time'].to_f - row['run_start'].to_f)/1000.0).to_s
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
it "should fail to compute with nonexistent columns" do
|
248
|
-
@calc.computed_column "borked", "{stim_time} - {not_there}"
|
107
|
+
describe "with reset logic" do
|
108
|
+
it "should allow setting a column with reset_when logic" do
|
249
109
|
lambda {
|
250
|
-
@
|
251
|
-
}.should raise_error(IndexError)
|
252
|
-
end
|
253
|
-
|
254
|
-
it "should assume zero when a column has blank values" do
|
255
|
-
@calc.computed_column "sparse_plus_0", "{sparse} + 0"
|
256
|
-
@calc.each do |row|
|
257
|
-
row["sparse"].to_f.should == row["sparse_plus_0"].to_f
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
it "should detect loops in column computation" do
|
262
|
-
@calc.computed_column "loop1", "{stim_time} - {run_start} - {loop3}"
|
263
|
-
@calc.computed_column "loop2", "{loop1}"
|
264
|
-
@calc.computed_column "loop3", "{loop2}"
|
265
|
-
@calc.computed_column "loop4", "{loop3}"
|
266
|
-
lambda {
|
267
|
-
@calc[0]['loop4']
|
268
|
-
}.should raise_error(Eprime::Transformers::ColumnCalculator::ComputationError)
|
269
|
-
end
|
270
|
-
|
271
|
-
it "should compute columns when there are two paths to a node" do
|
272
|
-
@calc.computed_column "c1", "{stim_time} - {run_start}"
|
273
|
-
@calc.computed_column "c2", "{c1}"
|
274
|
-
@calc.computed_column "c3", "{c1} - {c2}"
|
275
|
-
lambda {
|
276
|
-
@calc[0]["c3"]
|
110
|
+
@pc.computed_column NEW_COLUMN, "{stim_time}", :reset_when => "1"
|
277
111
|
}.should_not raise_error
|
278
112
|
end
|
279
113
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
@
|
285
|
-
|
286
|
-
|
114
|
+
it "should reset only when condition passes" do
|
115
|
+
@pc.computed_column NEW_COLUMN, "{stim_time}",
|
116
|
+
:reset_when => "{sparse}"
|
117
|
+
val = ''
|
118
|
+
@pc.each do |row|
|
119
|
+
val = row['stim_time'] if row['sparse'].to_s != ''
|
120
|
+
row[NEW_COLUMN].to_f.should == val.to_f
|
287
121
|
end
|
288
122
|
end
|
289
123
|
|
290
|
-
it "should
|
291
|
-
|
292
|
-
@
|
293
|
-
|
294
|
-
sorted.each_index do |row_index|
|
295
|
-
sorted[row_index]['stim_time'].should == flipped[row_index]['stim_time']
|
124
|
+
it "should reset with an always true condition" do
|
125
|
+
@pc.computed_column NEW_COLUMN, "{stim_time}", :reset_when => "1"
|
126
|
+
@pc.each do |row|
|
127
|
+
row[NEW_COLUMN].to_f.should == row['stim_time'].to_f
|
296
128
|
end
|
297
129
|
end
|
298
130
|
|
299
|
-
it "should
|
300
|
-
@
|
301
|
-
|
302
|
-
|
303
|
-
ed[i].sort_value.should == @calc[i].sort_value
|
131
|
+
it "should never update when false condition" do
|
132
|
+
@pc.computed_column NEW_COLUMN, "{stim_time}", :reset_when => "''"
|
133
|
+
@pc.each do |row|
|
134
|
+
row[NEW_COLUMN].should be_nil
|
304
135
|
end
|
305
136
|
end
|
306
|
-
end
|
307
|
-
|
308
|
-
describe "(with copydown columns)" do
|
309
|
-
before :each do
|
310
|
-
@calc.copydown_column 'sparse_copy', 'sparse'
|
311
|
-
end
|
312
137
|
|
313
|
-
it "should
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
end
|
319
|
-
row['sparse_copy'].should == last_val
|
138
|
+
it "should accept :once as a reset condition" do
|
139
|
+
@pc.computed_column NEW_COLUMN, "{stim_time}", :reset_when => :once
|
140
|
+
val = @pc[0]['stim_time']
|
141
|
+
@pc.each do |row|
|
142
|
+
row[NEW_COLUMN].to_f.should == val.to_f
|
320
143
|
end
|
321
144
|
end
|
322
145
|
end
|
323
146
|
|
324
|
-
describe "
|
325
|
-
it "should count
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
end
|
333
|
-
|
334
|
-
it "should count from 1 when :start_value is set" do
|
335
|
-
@calc.counter_column "count_up", :start_value => 1
|
336
|
-
i = 1
|
337
|
-
@calc.each do |row|
|
338
|
-
i += 1
|
339
|
-
row["count_up"].should == i
|
147
|
+
describe "with counting logic" do
|
148
|
+
it "should count" do
|
149
|
+
init = 0
|
150
|
+
@pc.computed_column NEW_COLUMN, init, :count_when => "1",
|
151
|
+
:count_by => :next, :reset_when => :once
|
152
|
+
@pc.each do |row|
|
153
|
+
init += 1
|
154
|
+
row[NEW_COLUMN].to_f.should == init.to_f
|
340
155
|
end
|
341
156
|
end
|
342
157
|
|
343
|
-
it "should count
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
i -= 1
|
348
|
-
row['count_down'].should == i
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
it "should count by a proc when specified" do
|
353
|
-
@calc.counter_column "count_succ", :count_by => lambda {|val| val.succ}
|
354
|
-
i = 0
|
355
|
-
@calc.each do |row|
|
356
|
-
i = i.succ
|
357
|
-
row["count_succ"].should == i
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
it "should count by a symbol when specified" do
|
362
|
-
@calc.counter_column "count_succ", :count_by => :succ
|
363
|
-
i = 0
|
364
|
-
@calc.each do |row|
|
365
|
-
i = i.succ
|
366
|
-
row['count_succ'].should == i
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
it "count by a string when specified" do
|
371
|
-
@calc.counter_column "count_succ", :count_by => 'succ'
|
372
|
-
i = 0
|
373
|
-
@calc.each do |row|
|
374
|
-
i = i.succ
|
375
|
-
row['count_succ'].should == i
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
it "should count only when :count_when is true" do
|
380
|
-
@calc.counter_column "count_on_sparse", :count_when => lambda {|row| !row['sparse'].to_s.empty? }
|
158
|
+
it "should count sometimes" do
|
159
|
+
init= 0
|
160
|
+
@pc.computed_column NEW_COLUMN, init, :count_when => "{sparse}",
|
161
|
+
:reset_when => :once, :count_by => :next
|
381
162
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
it "should reset when :reset_when is true" do
|
390
|
-
@calc.counter_column "reset_on_sparse", :reset_when => lambda {|row| !row['sparse'].to_s.empty? }
|
391
|
-
i = 0
|
392
|
-
@calc.each do |row|
|
393
|
-
i = 0 if !row['sparse'].to_s.empty?
|
394
|
-
i += 1
|
395
|
-
row['reset_on_sparse'].should == i
|
163
|
+
@pc.each do |row|
|
164
|
+
if row['sparse'].to_s != ''
|
165
|
+
init += 1
|
166
|
+
end
|
167
|
+
|
168
|
+
row[NEW_COLUMN].to_f.should == init.to_f
|
396
169
|
end
|
397
170
|
end
|
398
171
|
|
399
|
-
it "should
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
row['scan_delay'].should == sd+i
|
407
|
-
i += 1
|
172
|
+
it "should reset sometimes" do
|
173
|
+
init = 0
|
174
|
+
@pc.computed_column NEW_COLUMN, init, :count_when => "1",
|
175
|
+
:count_by => :next, :reset_when => "{sparse}"
|
176
|
+
|
177
|
+
@pc.each do |row|
|
178
|
+
|
408
179
|
end
|
409
180
|
end
|
410
181
|
end
|
411
|
-
end
|
412
|
-
|
413
|
-
describe Eprime::Transformers::ColumnCalculator::Expression do
|
414
|
-
before :each do
|
415
|
-
@expr_str = "({stim_time}-{run_start}) / 1000"
|
416
|
-
@expr = Eprime::Transformers::ColumnCalculator::Expression.new(@expr_str)
|
417
|
-
end
|
418
|
-
|
419
|
-
it "should find two columns" do
|
420
|
-
@expr.columns.size.should == 2
|
421
|
-
end
|
422
|
-
|
423
|
-
it "should split into stim_time and run_start" do
|
424
|
-
@expr.columns.sort.should == %w(stim_time run_start).sort
|
425
|
-
end
|
426
|
-
|
427
|
-
it "should not allow changing columns" do
|
428
|
-
lambda {
|
429
|
-
@expr.columns << 'wakka'
|
430
|
-
}.should raise_error(TypeError)
|
431
|
-
end
|
432
|
-
|
433
|
-
it "should convert to a string" do
|
434
|
-
@expr.to_s.should == @expr_str
|
435
|
-
end
|
436
|
-
end
|
437
|
-
|
182
|
+
end
|
@@ -1,18 +1,18 @@
|
|
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 'transformers/multipasser'
|
11
11
|
|
12
|
-
include
|
13
|
-
include
|
12
|
+
include Optimus::Transformers
|
13
|
+
include OptimusTestHelper
|
14
14
|
|
15
|
-
describe
|
15
|
+
describe Optimus::Transformers::Multipasser do
|
16
16
|
before :each do
|
17
17
|
@mpass = Multipasser.new(mock_edata)
|
18
18
|
end
|
@@ -62,13 +62,20 @@ describe Eprime::Transformers::Multipasser do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
it "should allow multiple passes" do
|
66
|
+
pass = @mpass.add_pass("{fix_time}")
|
67
|
+
pass.computed_column "presented_time", "{fix_time}"
|
68
|
+
pass.computed_column "presented_name", "'fixation'"
|
69
|
+
@mpass.to_a.size.should == @data.size
|
70
|
+
end
|
71
|
+
|
65
72
|
it "should sort multiple passes together" do
|
66
73
|
pass = @mpass.add_pass("{fix_time}")
|
67
74
|
pass.computed_column "presented_time", "{fix_time}"
|
68
|
-
pass.computed_column "presented_name", "fixation"
|
75
|
+
pass.computed_column "presented_name", "'fixation'"
|
69
76
|
pass = @mpass.add_pass("{stim_time}")
|
70
77
|
pass.computed_column "presented_time", "{stim_time}"
|
71
|
-
pass.computed_column "presented_name", "stimulus"
|
78
|
+
pass.computed_column "presented_name", "'stimulus'"
|
72
79
|
@mpass.to_a.size.should == @data.size*2
|
73
80
|
ps = @mpass.to_a.sort_by{|row| row['presented_time'].to_f}
|
74
81
|
@mpass.to_a.each_index do |i|
|
@@ -1,29 +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 'transformers/row_filter'
|
11
|
-
|
11
|
+
require 'parsed_calculator'
|
12
|
+
include OptimusTestHelper
|
12
13
|
|
13
|
-
describe
|
14
|
+
describe Optimus::Transformers::RowFilter do
|
15
|
+
before :all do
|
16
|
+
@parser = Optimus::ParsedCalculator::ExpressionParser.new
|
17
|
+
end
|
14
18
|
before :each do
|
15
19
|
@edata = mock_edata
|
16
20
|
end
|
17
21
|
|
18
22
|
it "should allow filtering based on a proc" do
|
19
|
-
filter =
|
23
|
+
filter = Optimus::Transformers::RowFilter.new(@edata, lambda { |row| !row['sparse'].to_s.empty? })
|
20
24
|
filter.each do |row|
|
21
25
|
row['sparse'].to_s.should_not be_empty
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
29
|
it "should filter based on column equal test" do
|
26
|
-
|
30
|
+
exp = @parser.parse("{run_start} = 2400")
|
31
|
+
filter = Optimus::Transformers::RowFilter.new(@edata, exp)
|
27
32
|
filter.to_a.size.should_not == 0
|
28
33
|
filter.each do |row|
|
29
34
|
row['run_start'].should == '2400'
|