experiment 0.3.0 → 0.3.1
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/bin/experiment +3 -3
- data/lib/experiment.rb +1 -1
- data/lib/experiment/config.rb +3 -5
- data/lib/experiment/notify.rb +14 -13
- data/lib/experiment/runner.rb +10 -9
- metadata +3 -3
data/bin/experiment
CHANGED
@@ -8,7 +8,7 @@ require "rdoc/rdoc"
|
|
8
8
|
require File.dirname(__FILE__) + "/../lib/experiment/runner"
|
9
9
|
|
10
10
|
class App
|
11
|
-
VERSION = '0.
|
11
|
+
VERSION = '0.3.1'
|
12
12
|
|
13
13
|
attr_reader :options
|
14
14
|
|
@@ -55,7 +55,7 @@ class App
|
|
55
55
|
@opts = OptionParser.new
|
56
56
|
@opts.on('-v', '--version') { output_version ; exit 0 }
|
57
57
|
@opts.on('-h', '--help') { output_help }
|
58
|
-
@opts.on('-V', '--verbose') { @options.verbose = true }
|
58
|
+
@opts.on('-V', '--verbose') { @options.verbose = true; @options.summary = true }
|
59
59
|
@opts.on('-q', '--quiet') { @options.quiet = true }
|
60
60
|
@opts.on('-e', '--env [ENV]', [:development, :compute], "Sets the environment to run in.") { |v| @options.env = v }
|
61
61
|
|
@@ -65,7 +65,7 @@ class App
|
|
65
65
|
@opts.on('-m', '--description M', String, "Description or hypothesis for the condition being generated.") { |v| @options.description = v }
|
66
66
|
end
|
67
67
|
|
68
|
-
if ARGV.first == 'run' || ARGV.first == "-h"
|
68
|
+
if ARGV.first == 'run' || ARGV.first == "-h" || ARGV.first == 'console'
|
69
69
|
@opts.separator ""
|
70
70
|
@opts.separator "Options for `run`:"
|
71
71
|
@opts.on('-c', '--cv CV', Integer, "The number of cross validations to run.") { |v| @options.cv = v }
|
data/lib/experiment.rb
CHANGED
data/lib/experiment/config.rb
CHANGED
@@ -62,6 +62,7 @@ module Experiment
|
|
62
62
|
exp = YAML::load_file(expath)
|
63
63
|
@config.merge! exp["experiment"][env.to_s] if exp["experiment"][env.to_s].is_a? Hash
|
64
64
|
end
|
65
|
+
@config.merge! @override_options if @override_options
|
65
66
|
@config.merge! parse(options)
|
66
67
|
end
|
67
68
|
|
@@ -176,11 +177,8 @@ module Experiment
|
|
176
177
|
num += 1
|
177
178
|
cl = value.class == Fixnum ? Integer : value.class;
|
178
179
|
o.on("--#{key} VALUE", cl, "Default value #{value.inspect}") do |v|
|
179
|
-
|
180
|
-
|
181
|
-
else
|
182
|
-
options.opts += ", #{key}: #{v}"
|
183
|
-
end
|
180
|
+
@override_options ||= {}
|
181
|
+
@override_options[key] = v
|
184
182
|
end
|
185
183
|
end
|
186
184
|
end
|
data/lib/experiment/notify.rb
CHANGED
@@ -24,7 +24,7 @@ module Experiment
|
|
24
24
|
@previous_time = @start_time
|
25
25
|
@growl = growl
|
26
26
|
@mode = mode
|
27
|
-
show if @mode == :normal
|
27
|
+
show if @mode == :normal && @out
|
28
28
|
end
|
29
29
|
|
30
30
|
# Called when starting work on a particular experiment
|
@@ -95,6 +95,7 @@ module Experiment
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def show_if_needed
|
98
|
+
return unless @out
|
98
99
|
if @total.zero?
|
99
100
|
cur_percentage = 100
|
100
101
|
prev_percentage = 0
|
@@ -113,22 +114,22 @@ module Experiment
|
|
113
114
|
|
114
115
|
|
115
116
|
def show
|
116
|
-
percent = @current * 100 / @total
|
117
|
-
bar_width = percent * @terminal_width / 100
|
118
|
-
line = sprintf "%3d%% |%s%s| %s", percent, "=" * bar_width, "-" * (@terminal_width - bar_width), stat
|
117
|
+
percent = @current * 100.0 / @total
|
118
|
+
bar_width = percent * @terminal_width / 100.0
|
119
|
+
line = sprintf "%3d%% |%s%s| %s", percent, "=" * bar_width.floor, "-" * (@terminal_width - bar_width.ceil), stat
|
119
120
|
|
120
121
|
|
121
|
-
width = get_width
|
122
|
-
if line.length == width - 1
|
122
|
+
#width = get_width
|
123
|
+
#if line.length == width - 1
|
123
124
|
@out.print(line + (@finished_p ? "\n" : "\r"))
|
124
125
|
@out.flush
|
125
|
-
elsif line.length >= width
|
126
|
-
|
127
|
-
|
128
|
-
else # line.length < width - 1
|
129
|
-
|
130
|
-
|
131
|
-
end
|
126
|
+
#elsif line.length >= width
|
127
|
+
# @terminal_width = [@terminal_width - (line.length - width + 1), 0].max
|
128
|
+
# if @terminal_width == 0 then @out.print(line + (@finished_p ? "\n" : "\r")) else show end
|
129
|
+
#else # line.length < width - 1
|
130
|
+
# @terminal_width += width - line.length + 1
|
131
|
+
# show
|
132
|
+
#end
|
132
133
|
@previous_time = Time.now
|
133
134
|
end
|
134
135
|
|
data/lib/experiment/runner.rb
CHANGED
@@ -33,9 +33,10 @@ module Experiment
|
|
33
33
|
req_file.puts "# The first contious block of comment will be included in your report."
|
34
34
|
req_file.puts "# This includes the reference implementation."
|
35
35
|
req_file.puts "# Override any desired files in this directory."
|
36
|
-
Dir["./app/**/*.rb"].each do |f|
|
37
|
-
|
38
|
-
|
36
|
+
Dir["./app/**/*.{rb,o,dll,so,bundle}"].each do |f|
|
37
|
+
next if File.basename(f) == 'extconfig.rb'
|
38
|
+
p = File.expand_path(f).split("/") - File.expand_path(".").split("/")
|
39
|
+
req_file.puts "require \"#{p.join("/").gsub(/\.(rb|o|dll|so|bundle)$/, "")}\""
|
39
40
|
end
|
40
41
|
req_file.puts "\nclass #{as_class_name @arguments.first} < MyExperiment\n\t\nend"
|
41
42
|
end
|
@@ -125,6 +126,7 @@ module Experiment
|
|
125
126
|
require File.dirname(__FILE__) + "/base"
|
126
127
|
|
127
128
|
require "./experiments/experiment"
|
129
|
+
$: << "./"
|
128
130
|
Experiment::Config::init @options.env
|
129
131
|
@options.cv = Experiment::Config.get :cross_validations, 5 if @options.cv.nil?
|
130
132
|
if @options.distributed
|
@@ -136,7 +138,7 @@ module Experiment
|
|
136
138
|
Notify::done
|
137
139
|
return true
|
138
140
|
else
|
139
|
-
Notify::init @arguments.length * @options.cv,
|
141
|
+
Notify::init @arguments.length * @options.cv, @options.quiet ? false : STDERR, Experiment::Config::get(:growl_notifications, !@options.quiet)
|
140
142
|
@arguments.each do |exp|
|
141
143
|
require "./experiments/#{exp}/#{exp}"
|
142
144
|
cla = eval(as_class_name(exp))
|
@@ -152,17 +154,17 @@ module Experiment
|
|
152
154
|
def console
|
153
155
|
cla = as_class_name(@arguments.first) if @arguments.length == 1
|
154
156
|
File.open("./tmp/irb-setup.rb", 'w') do |f|
|
157
|
+
f.puts "# Initializes the environment for IRb."
|
155
158
|
f.puts "Experiment::Config::init #{@options.env.inspect}"
|
156
|
-
f.puts "
|
157
|
-
f.puts " "
|
158
|
-
f.puts "end"
|
159
|
+
f.puts "$: << '#{File.expand_path(".")}/'"
|
159
160
|
if @arguments.length == 1
|
161
|
+
f.puts "require 'experiments/#{@arguments.first}/#{@arguments.first}'"
|
160
162
|
f.puts "def experiment"
|
161
163
|
f.puts " @experiment ||= #{cla}.new :normal, #{@arguments.first.inspect}, OpenStruct.new(#{@options.marshal_dump})"
|
162
164
|
f.puts "end"
|
163
165
|
f.puts "experiment #load up the configs"
|
164
166
|
else
|
165
|
-
f.puts 'Dir["./app
|
167
|
+
f.puts 'Dir["./app/**/*.{rb,o,so,dll,bundle}"].each{|e| require e.gsub(/\.(rb|so|o|dll|bundle)$/, "") }'
|
166
168
|
f.puts "Experiment::Config::load '', #{options.opts.inspect}"
|
167
169
|
end
|
168
170
|
|
@@ -171,7 +173,6 @@ module Experiment
|
|
171
173
|
libs = " -r irb/completion"
|
172
174
|
libs << " -r #{File.dirname(__FILE__) + "/base"}"
|
173
175
|
libs << " -r./experiments/experiment"
|
174
|
-
libs << " -r ./experiments/#{@arguments.first}/#{@arguments.first}" if @arguments.length == 1
|
175
176
|
libs << " -r ./tmp/irb-setup.rb"
|
176
177
|
puts "Loading #{@options.env} environment..."
|
177
178
|
exec "#{irb} #{libs} --simple-prompt"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jakub Hampl
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-11 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|