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 CHANGED
@@ -1,3 +1,5 @@
1
+ v.0.10.0. Actually make things like counter columns work again. Sorry, anyone who downloaded 0.9.x.
2
+
1
3
  v0.9.1. Change dependency from rparsec to rparsec-ruby19
2
4
 
3
5
  v0.9.0. Ruby 1.9 compatibility.
data/Manifest CHANGED
@@ -3,6 +3,7 @@ GPL.txt
3
3
  LICENSE
4
4
  Manifest
5
5
  README
6
+ README.textile
6
7
  Rakefile
7
8
  autotest/discover.rb
8
9
  bin/eprime2tabfile
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 < Error; end
29
+ class EvaluationLoopError < ParseError; end
28
30
 
29
31
  class DuplicateColumnError < Error; end
32
+
30
33
  end
@@ -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
- converted = Iconv.conv("ASCII//TRANSLIT", "UTF-16LE", file.read)
65
- converted_f = StringIO.new(converted)
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
@@ -62,11 +62,10 @@ module Optimus
62
62
  end
63
63
 
64
64
  def parse(str)
65
- begin
66
- @parser.parse(str)
67
- rescue Exception
68
- raise
65
+ if str.strip.empty?
66
+ return ''
69
67
  end
68
+ @parser.parse(str)
70
69
  end
71
70
 
72
71
  private
@@ -35,7 +35,12 @@ module Optimus
35
35
 
36
36
  # Write to the output stream.
37
37
  def write
38
- tsv = CSV.new(@outstream, {:col_sep => "\t"})
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
- new_opts[key] = Evaluatable.new(new_opts[key], @parser)
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, start_val = 1, options = {})
71
- computed_column(name, start_val, options = {})
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
- if @reset_when.bool_eval(*args)
135
+ should_reset = @reset_when.bool_eval(*args)
136
+ if should_reset
131
137
  @current_value = @reset_exp.evaluate(*args)
132
138
  end
133
- next_val! if @count_when.bool_eval(*args)
134
- return @current_value
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
@@ -1,8 +1,8 @@
1
1
  module Optimus
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 9
5
- TINY = 1
4
+ MINOR = 10
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
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.9.1"
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-09"
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| row['stim_time'] }
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 be_nil
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.9.1
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-09 00:00:00.000000000 Z
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: &2152782200 !ruby/object:Gem::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: *2152782200
65
+ version_requirements: *2157389960
66
66
  - !ruby/object:Gem::Dependency
67
67
  name: rspec
68
- requirement: &2152781580 !ruby/object:Gem::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: *2152781580
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