optimus-ep 0.9.1 → 0.10.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 +2 -0
- data/Manifest +1 -0
- data/README.textile +74 -0
- data/lib/optimus.rb +4 -1
- data/lib/optimus_reader.rb +12 -3
- data/lib/parsed_calculator.rb +3 -4
- data/lib/tabfile_writer.rb +6 -1
- data/lib/transformers/column_calculator.rb +21 -10
- data/lib/transformers/row_filter.rb +4 -2
- data/lib/version.rb +2 -2
- data/optimus-ep.gemspec +4 -4
- data/spec/parsed_calculator_spec.rb +4 -0
- data/spec/transformers/column_calculator_spec.rb +9 -2
- data.tar.gz.sig +0 -0
- metadata +8 -6
- metadata.gz.sig +0 -0
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/README.textile
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
h1. Optimus
|
2
|
+
|
3
|
+
h5. Turning data into results
|
4
|
+
|
5
|
+
Optimus is a set of libraries designed to process behavioral data for use in statistical analysis packages. Think of it as the ultimate scriptable spreadsheet.
|
6
|
+
|
7
|
+
Currently, it's geared towards processing files generated by "E-Prime":http://www.pstnet.com/eprime.cfm, but really works with anything that produces spreadsheet-like data.
|
8
|
+
|
9
|
+
h2. Installing
|
10
|
+
|
11
|
+
We're all set in "RubyGems":http://rubygems.org, so:
|
12
|
+
|
13
|
+
<pre>
|
14
|
+
sudo gem install optimus-ep
|
15
|
+
</pre>
|
16
|
+
|
17
|
+
should get you set up with Optimus and the required "RParsec":http://docs.codehaus.org/display/JPARSEC/rparsec+overview. I've developed and tested with Ruby 1.8.7, but suspect 1.9.x will work, too.
|
18
|
+
|
19
|
+
h2. Command-line tools:
|
20
|
+
|
21
|
+
Right now, there's one program recommended for general use:
|
22
|
+
|
23
|
+
h3. eprime2tabfile
|
24
|
+
|
25
|
+
Turns the text file written by E-Prime (or, really, any file we can read) into a tab-delimited file. It prints to stdout, and should be redirected if you want to save the output.
|
26
|
+
|
27
|
+
Usage:
|
28
|
+
|
29
|
+
<pre>
|
30
|
+
Usage: eprime2tabfile [options] INPUT_FILES
|
31
|
+
|
32
|
+
-o, --outfile=OUTFILE The name of the file to create. If this
|
33
|
+
isn't specified, print to the standard
|
34
|
+
output.
|
35
|
+
|
36
|
+
-c, --columns=COLUMN_FILE A tab-separated file containing the columns
|
37
|
+
in the order you want your output.
|
38
|
+
|
39
|
+
--filter-columns Write out only the columns in COLUMN_FILE.
|
40
|
+
Requires the use of --columns
|
41
|
+
|
42
|
+
-a, --add-filename-line Print the filename as the first line of
|
43
|
+
your output, just like E-DataAid.
|
44
|
+
|
45
|
+
-f, --force Continue processing even there are errors.
|
46
|
+
|
47
|
+
-h, --help Print this message.
|
48
|
+
</pre>
|
49
|
+
|
50
|
+
h2. API Usage
|
51
|
+
|
52
|
+
Coming very soon.
|
53
|
+
|
54
|
+
h2. License
|
55
|
+
|
56
|
+
(The GNU Public License, Version 2)
|
57
|
+
|
58
|
+
Optimus: Libraries and utilities for interacting with E-Prime data files
|
59
|
+
Copyright (C) 2008-09 Board of Regents of the University of Wisconsin System
|
60
|
+
|
61
|
+
This program is free software; you can redistribute it and/or
|
62
|
+
modify it under the terms of version 2 of the GNU General Public
|
63
|
+
License as published by the Free Software Foundation.
|
64
|
+
|
65
|
+
This program is distributed in the hope that it will be useful,
|
66
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
67
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
68
|
+
GNU General Public License for more details.
|
69
|
+
|
70
|
+
You should have received a copy of the GNU General Public License
|
71
|
+
along with this program; if not, write to the Free Software
|
72
|
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
73
|
+
|
74
|
+
E-Prime is a registered trademark of Psychology Software Tools, Inc.
|
data/lib/optimus.rb
CHANGED
@@ -23,8 +23,11 @@ module Optimus
|
|
23
23
|
# Raised whenever an input file seems to be damaged
|
24
24
|
class DamagedFileError < Error; end
|
25
25
|
|
26
|
+
class ParseError < Error; end
|
27
|
+
|
26
28
|
# Raised when a parse fails due to loops
|
27
|
-
class EvaluationLoopError <
|
29
|
+
class EvaluationLoopError < ParseError; end
|
28
30
|
|
29
31
|
class DuplicateColumnError < Error; end
|
32
|
+
|
30
33
|
end
|
data/lib/optimus_reader.rb
CHANGED
@@ -6,7 +6,6 @@
|
|
6
6
|
# Imaging and Behavior, University of Wisconsin - Madison
|
7
7
|
|
8
8
|
require 'stringio'
|
9
|
-
require 'iconv'
|
10
9
|
|
11
10
|
require 'log_file_parser'
|
12
11
|
require 'excel_parser'
|
@@ -58,11 +57,21 @@ module Optimus
|
|
58
57
|
end
|
59
58
|
|
60
59
|
def set_file_with_encoding(file)
|
60
|
+
converted_f = nil
|
61
61
|
file.rewind
|
62
62
|
datas = file.read(2)
|
63
63
|
if datas == "\377\376"
|
64
|
-
|
65
|
-
|
64
|
+
file_data = file.read
|
65
|
+
if file_data.respond_to? :encode
|
66
|
+
# Ruby 1.9.x -- iconv is deprecated here
|
67
|
+
converted_f = StringIO.new(
|
68
|
+
file_data.encode("UTF-8", "UTF-16LE"))
|
69
|
+
else
|
70
|
+
# Ruby 1.8.x -- no String#encode()
|
71
|
+
require 'iconv'
|
72
|
+
converted_f = StringIO.new(
|
73
|
+
Iconv.conv("UTF-8", "UTF-16LE", file_data))
|
74
|
+
end
|
66
75
|
else
|
67
76
|
converted_f = file
|
68
77
|
converted_f.rewind
|
data/lib/parsed_calculator.rb
CHANGED
data/lib/tabfile_writer.rb
CHANGED
@@ -35,7 +35,12 @@ module Optimus
|
|
35
35
|
|
36
36
|
# Write to the output stream.
|
37
37
|
def write
|
38
|
-
tsv =
|
38
|
+
tsv = nil
|
39
|
+
begin
|
40
|
+
tsv = CSV::Writer.create(@outstream, col_sep="\t")
|
41
|
+
rescue
|
42
|
+
tsv = CSV.new(@outstream, {:col_sep => "\t"})
|
43
|
+
end
|
39
44
|
if @write_top_line
|
40
45
|
name = @outstream.respond_to?(:path) ? File.expand_path(@outstream.path.to_s) : ''
|
41
46
|
tsv << [name]
|
@@ -47,7 +47,7 @@ module Optimus
|
|
47
47
|
@sort_expression = Evaluatable.new(value, @parser)
|
48
48
|
end
|
49
49
|
|
50
|
-
def computed_column(name, start_val, options
|
50
|
+
def computed_column(name, start_val, options={})
|
51
51
|
if columns.include?(name)
|
52
52
|
raise DuplicateColumnError.new("Can't add duplicate column name #{name}")
|
53
53
|
end
|
@@ -55,11 +55,13 @@ module Optimus
|
|
55
55
|
@computed_column_names << name
|
56
56
|
new_opts = DEFAULT_COL_OPTS.merge(options)
|
57
57
|
DEFAULT_COL_OPTS.keys.each do |key|
|
58
|
-
|
58
|
+
begin
|
59
|
+
new_opts[key] = Evaluatable.new(new_opts[key], @parser)
|
60
|
+
rescue Exception => e
|
61
|
+
raise ParseError.new("Did not understand #{name}: #{e}")
|
62
|
+
end
|
59
63
|
end
|
60
|
-
@computed_columns[name] = ComputedColumn.new(
|
61
|
-
name, sve, new_opts
|
62
|
-
)
|
64
|
+
@computed_columns[name] = ComputedColumn.new(name, sve, new_opts)
|
63
65
|
reset!
|
64
66
|
end
|
65
67
|
|
@@ -67,8 +69,11 @@ module Optimus
|
|
67
69
|
computed_column(new_name, "{#{old_name}}", :reset_when => "{#{old_name}}")
|
68
70
|
end
|
69
71
|
|
70
|
-
def counter_column(name,
|
71
|
-
|
72
|
+
def counter_column(name, options = {})
|
73
|
+
start_val = options[:start_val] || 1
|
74
|
+
options[:reset_when] ||= :once
|
75
|
+
options[:count_when] ||= true
|
76
|
+
computed_column(name, start_val, options)
|
72
77
|
end
|
73
78
|
|
74
79
|
def columns
|
@@ -127,11 +132,13 @@ module Optimus
|
|
127
132
|
end
|
128
133
|
|
129
134
|
def evaluate(*args)
|
130
|
-
|
135
|
+
should_reset = @reset_when.bool_eval(*args)
|
136
|
+
if should_reset
|
131
137
|
@current_value = @reset_exp.evaluate(*args)
|
132
138
|
end
|
133
|
-
|
134
|
-
|
139
|
+
should_count = @count_when.bool_eval(*args)
|
140
|
+
next_val! if should_count
|
141
|
+
@current_value
|
135
142
|
end
|
136
143
|
|
137
144
|
private
|
@@ -156,6 +163,10 @@ module Optimus
|
|
156
163
|
end
|
157
164
|
end
|
158
165
|
|
166
|
+
def to_s
|
167
|
+
"Evaluatable (#{@target})"
|
168
|
+
end
|
169
|
+
|
159
170
|
def evaluate(*args)
|
160
171
|
# Check for magicality
|
161
172
|
if @target == :once
|
@@ -9,8 +9,6 @@ module Optimus
|
|
9
9
|
module Transformers
|
10
10
|
|
11
11
|
# Implements a row-wise filter for optimus data.
|
12
|
-
# Right now it requires a proc; I'll do something better with a little
|
13
|
-
# DSL later.
|
14
12
|
class RowFilter
|
15
13
|
include Enumerable
|
16
14
|
|
@@ -24,6 +22,10 @@ module Optimus
|
|
24
22
|
computed
|
25
23
|
end
|
26
24
|
|
25
|
+
def each
|
26
|
+
computed.each {|row| yield row }
|
27
|
+
end
|
28
|
+
|
27
29
|
def method_missing(method, *args, &block)
|
28
30
|
computed.send method, *args, &block
|
29
31
|
end
|
data/lib/version.rb
CHANGED
data/optimus-ep.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "optimus-ep"
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.10.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Nate Vack"]
|
9
9
|
s.cert_chain = ["/Users/njvack/.gem/cert/gem-public_cert.pem"]
|
10
|
-
s.date = "2012-02-
|
10
|
+
s.date = "2012-02-17"
|
11
11
|
s.description = "Utilities to process behavioral data generated by E-Prime"
|
12
12
|
s.email = "njvack@wisc.edu"
|
13
13
|
s.executables = ["eprime2tabfile", "extract_timings"]
|
14
|
-
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "bin/eprime2tabfile", "bin/extract_timings", "lib/eprimetab_parser.rb", "lib/excel_parser.rb", "lib/expression_parser/evaluators.rb", "lib/expression_parser/expressions.rb", "lib/log_file_parser.rb", "lib/optimus.rb", "lib/optimus_data.rb", "lib/optimus_reader.rb", "lib/parsed_calculator.rb", "lib/raw_tab_parser.rb", "lib/runners/generic_runner.rb", "lib/runners/yaml_template/option_parser.rb", "lib/runners/yaml_template/runner.rb", "lib/tabfile_parser.rb", "lib/tabfile_writer.rb", "lib/transformers/basic_transformer.rb", "lib/transformers/column_calculator.rb", "lib/transformers/multipasser.rb", "lib/transformers/row_filter.rb", "lib/transformers/timing_extractor.rb", "lib/version.rb", "lib/writers/stimtimes_writer.rb"]
|
15
|
-
s.files = ["CHANGELOG", "GPL.txt", "LICENSE", "Manifest", "README", "Rakefile", "autotest/discover.rb", "bin/eprime2tabfile", "bin/extract_timings", "lib/eprimetab_parser.rb", "lib/excel_parser.rb", "lib/expression_parser/evaluators.rb", "lib/expression_parser/expressions.rb", "lib/log_file_parser.rb", "lib/optimus.rb", "lib/optimus_data.rb", "lib/optimus_reader.rb", "lib/parsed_calculator.rb", "lib/raw_tab_parser.rb", "lib/runners/generic_runner.rb", "lib/runners/yaml_template/option_parser.rb", "lib/runners/yaml_template/runner.rb", "lib/tabfile_parser.rb", "lib/tabfile_writer.rb", "lib/transformers/basic_transformer.rb", "lib/transformers/column_calculator.rb", "lib/transformers/multipasser.rb", "lib/transformers/row_filter.rb", "lib/transformers/timing_extractor.rb", "lib/version.rb", "lib/writers/stimtimes_writer.rb", "spec/eprimetab_parser_spec.rb", "spec/excel_parser_spec.rb", "spec/expression_parser/evaluators_spec.rb", "spec/expression_parser/expressions_spec.rb", "spec/log_file_parser_spec.rb", "spec/optimus_data_spec.rb", "spec/optimus_reader_spec.rb", "spec/parsed_calculator_spec.rb", "spec/raw_tab_parser_spec.rb", "spec/runners/generic_runner_spec.rb", "spec/runners/yaml_template/option_parser_spec.rb", "spec/runners/yaml_template/runner_spec.rb", "spec/samples/bad_excel_tsv.txt", "spec/samples/corrupt_log_file.txt", "spec/samples/eprime_tsv.txt", "spec/samples/excel_tsv.txt", "spec/samples/optimus_log.txt", "spec/samples/optimus_log_utf16le.txt", "spec/samples/raw_tsv.txt", "spec/samples/short_columns.txt", "spec/samples/sorted_columns.txt", "spec/samples/std_columns.txt", "spec/samples/unknown_type.txt", "spec/samples/unreadable_file", "spec/spec_helper.rb", "spec/tabfile_parser_spec.rb", "spec/tabfile_writer_spec.rb", "spec/transformers/basic_transformer_spec.rb", "spec/transformers/column_calculator_spec.rb", "spec/transformers/multipasser_spec.rb", "spec/transformers/row_filter_spec.rb", "spec/transformers/timing_extractor_spec.rb", "spec/writers/stimtimes_writer_spec.rb", "optimus-ep.gemspec"]
|
14
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "README.textile", "bin/eprime2tabfile", "bin/extract_timings", "lib/eprimetab_parser.rb", "lib/excel_parser.rb", "lib/expression_parser/evaluators.rb", "lib/expression_parser/expressions.rb", "lib/log_file_parser.rb", "lib/optimus.rb", "lib/optimus_data.rb", "lib/optimus_reader.rb", "lib/parsed_calculator.rb", "lib/raw_tab_parser.rb", "lib/runners/generic_runner.rb", "lib/runners/yaml_template/option_parser.rb", "lib/runners/yaml_template/runner.rb", "lib/tabfile_parser.rb", "lib/tabfile_writer.rb", "lib/transformers/basic_transformer.rb", "lib/transformers/column_calculator.rb", "lib/transformers/multipasser.rb", "lib/transformers/row_filter.rb", "lib/transformers/timing_extractor.rb", "lib/version.rb", "lib/writers/stimtimes_writer.rb"]
|
15
|
+
s.files = ["CHANGELOG", "GPL.txt", "LICENSE", "Manifest", "README", "README.textile", "Rakefile", "autotest/discover.rb", "bin/eprime2tabfile", "bin/extract_timings", "lib/eprimetab_parser.rb", "lib/excel_parser.rb", "lib/expression_parser/evaluators.rb", "lib/expression_parser/expressions.rb", "lib/log_file_parser.rb", "lib/optimus.rb", "lib/optimus_data.rb", "lib/optimus_reader.rb", "lib/parsed_calculator.rb", "lib/raw_tab_parser.rb", "lib/runners/generic_runner.rb", "lib/runners/yaml_template/option_parser.rb", "lib/runners/yaml_template/runner.rb", "lib/tabfile_parser.rb", "lib/tabfile_writer.rb", "lib/transformers/basic_transformer.rb", "lib/transformers/column_calculator.rb", "lib/transformers/multipasser.rb", "lib/transformers/row_filter.rb", "lib/transformers/timing_extractor.rb", "lib/version.rb", "lib/writers/stimtimes_writer.rb", "spec/eprimetab_parser_spec.rb", "spec/excel_parser_spec.rb", "spec/expression_parser/evaluators_spec.rb", "spec/expression_parser/expressions_spec.rb", "spec/log_file_parser_spec.rb", "spec/optimus_data_spec.rb", "spec/optimus_reader_spec.rb", "spec/parsed_calculator_spec.rb", "spec/raw_tab_parser_spec.rb", "spec/runners/generic_runner_spec.rb", "spec/runners/yaml_template/option_parser_spec.rb", "spec/runners/yaml_template/runner_spec.rb", "spec/samples/bad_excel_tsv.txt", "spec/samples/corrupt_log_file.txt", "spec/samples/eprime_tsv.txt", "spec/samples/excel_tsv.txt", "spec/samples/optimus_log.txt", "spec/samples/optimus_log_utf16le.txt", "spec/samples/raw_tsv.txt", "spec/samples/short_columns.txt", "spec/samples/sorted_columns.txt", "spec/samples/std_columns.txt", "spec/samples/unknown_type.txt", "spec/samples/unreadable_file", "spec/spec_helper.rb", "spec/tabfile_parser_spec.rb", "spec/tabfile_writer_spec.rb", "spec/transformers/basic_transformer_spec.rb", "spec/transformers/column_calculator_spec.rb", "spec/transformers/multipasser_spec.rb", "spec/transformers/row_filter_spec.rb", "spec/transformers/timing_extractor_spec.rb", "spec/writers/stimtimes_writer_spec.rb", "optimus-ep.gemspec"]
|
16
16
|
s.homepage = "http://github.com/njvack/optimus-ep"
|
17
17
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Optimus-ep", "--main", "README"]
|
18
18
|
s.require_paths = ["lib"]
|
@@ -16,6 +16,10 @@ describe Optimus::ParsedCalculator::ExpressionParser do
|
|
16
16
|
@exp = Optimus::ParsedCalculator::ExpressionParser.new
|
17
17
|
end
|
18
18
|
|
19
|
+
it "should allow empty expressions" do
|
20
|
+
@exp.should round_trip("")
|
21
|
+
end
|
22
|
+
|
19
23
|
it "should parse positive integers" do
|
20
24
|
@exp.should round_trip("1")
|
21
25
|
end
|
@@ -40,6 +40,11 @@ describe Optimus::Transformers::ColumnCalculator do
|
|
40
40
|
@pc.columns.should include(NEW_COLUMN)
|
41
41
|
end
|
42
42
|
|
43
|
+
it "should allow empty columns" do
|
44
|
+
@pc.computed_column NEW_COLUMN, ""
|
45
|
+
@pc.columns.should include(NEW_COLUMN)
|
46
|
+
end
|
47
|
+
|
43
48
|
it "should raise an error when adding bad columns" do
|
44
49
|
lambda {
|
45
50
|
@pc.computed_column NEW_COLUMN, "FIAL"
|
@@ -59,7 +64,9 @@ describe Optimus::Transformers::ColumnCalculator do
|
|
59
64
|
end
|
60
65
|
|
61
66
|
it "should return values for columns based on lambdas" do
|
62
|
-
@pc.computed_column NEW_COLUMN, lambda {|row|
|
67
|
+
@pc.computed_column NEW_COLUMN, lambda {|row|
|
68
|
+
row['stim_time']
|
69
|
+
}
|
63
70
|
@pc.computed_column "NEW_COL2", lambda {|row| 1}
|
64
71
|
@pc.each do |row|
|
65
72
|
row[NEW_COLUMN].should == row['stim_time']
|
@@ -131,7 +138,7 @@ describe Optimus::Transformers::ColumnCalculator do
|
|
131
138
|
it "should never update when false condition" do
|
132
139
|
@pc.computed_column NEW_COLUMN, "{stim_time}", :reset_when => "''"
|
133
140
|
@pc.each do |row|
|
134
|
-
row[NEW_COLUMN].should
|
141
|
+
row[NEW_COLUMN].to_s.should == ''
|
135
142
|
end
|
136
143
|
end
|
137
144
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optimus-ep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -50,11 +50,11 @@ cert_chain:
|
|
50
50
|
-----END CERTIFICATE-----
|
51
51
|
|
52
52
|
'
|
53
|
-
date: 2012-02-
|
53
|
+
date: 2012-02-17 00:00:00.000000000 Z
|
54
54
|
dependencies:
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rparsec-ruby19
|
57
|
-
requirement: &
|
57
|
+
requirement: &2157389960 !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
59
59
|
requirements:
|
60
60
|
- - ! '>='
|
@@ -62,10 +62,10 @@ dependencies:
|
|
62
62
|
version: '1.0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
|
-
version_requirements: *
|
65
|
+
version_requirements: *2157389960
|
66
66
|
- !ruby/object:Gem::Dependency
|
67
67
|
name: rspec
|
68
|
-
requirement: &
|
68
|
+
requirement: &2157389400 !ruby/object:Gem::Requirement
|
69
69
|
none: false
|
70
70
|
requirements:
|
71
71
|
- - ! '>='
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
version: '0'
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
|
-
version_requirements: *
|
76
|
+
version_requirements: *2157389400
|
77
77
|
description: Utilities to process behavioral data generated by E-Prime
|
78
78
|
email: njvack@wisc.edu
|
79
79
|
executables:
|
@@ -84,6 +84,7 @@ extra_rdoc_files:
|
|
84
84
|
- CHANGELOG
|
85
85
|
- LICENSE
|
86
86
|
- README
|
87
|
+
- README.textile
|
87
88
|
- bin/eprime2tabfile
|
88
89
|
- bin/extract_timings
|
89
90
|
- lib/eprimetab_parser.rb
|
@@ -114,6 +115,7 @@ files:
|
|
114
115
|
- LICENSE
|
115
116
|
- Manifest
|
116
117
|
- README
|
118
|
+
- README.textile
|
117
119
|
- Rakefile
|
118
120
|
- autotest/discover.rb
|
119
121
|
- bin/eprime2tabfile
|
metadata.gz.sig
CHANGED
Binary file
|