nera 0.3.1 → 0.4.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/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.4.0
2
+ * 1 major enhancement:
3
+ * A new format is adopted in parameters_table.
4
+ * The conversion routine from old format to new format is implemented.
5
+ * 2 bug fixes:
6
+
1
7
  == 0.3.1
2
8
  * 1 major enhancement:
3
9
  * A new API function is added.
data/Manifest.txt CHANGED
@@ -5,6 +5,8 @@ Rakefile
5
5
  bin/nera
6
6
  bin/nera_addhost
7
7
  bin/nera_addsim
8
+ config/website.yml
9
+ config/website.yml.sample
8
10
  lib/nera.rb
9
11
  lib/nera/nera_cui.rb
10
12
  lib/nera/nera_database.rb
@@ -23,10 +25,11 @@ lib/nera/nera_simulator_layer_controller.rb
23
25
  lib/nera/nera_simulator_records.rb
24
26
  lib/nera_addhost/add_hosts.rb
25
27
  lib/nera_addsim/make_simulator.rb
26
- scripts/console
27
- scripts/destroy
28
- scripts/generate
29
- scripts/make_manifest.rb
28
+ script/console
29
+ script/destroy
30
+ script/generate
31
+ script/make_manifest.rb
32
+ script/txt2html
30
33
  test/runner.rb
31
34
  test/test_helper.rb
32
35
  test/test_nera_database.rb
@@ -42,3 +45,10 @@ test/test_nera_run_records.rb
42
45
  test/test_nera_simulator.rb
43
46
  test/test_nera_simulator_layer_controller.rb
44
47
  test/test_nera_simulator_records.rb
48
+ website/index.html
49
+ website/index.txt
50
+ website/javascripts/rounded_corners_lite.inc.js
51
+ website/stylesheets/screen.css
52
+ website/template.html.erb
53
+ website/temporary/temp.html
54
+ website/temporary/temp.txt
data/Rakefile CHANGED
@@ -1,28 +1,30 @@
1
- %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
- require File.dirname(__FILE__) + '/lib/nera'
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/nera'
6
+
7
+ Hoe.plugin :newgem
8
+ Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
3
10
 
4
11
  # Generate all the Rake tasks
5
12
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
- $hoe = Hoe.new('nera', NERA::VERSION) do |p|
7
- p.developer('Yohsuke Murase', 'murase@serow.t.u-tokyo.ac.jp')
8
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
- p.rubyforge_name = p.name # TODO this is default value
10
- p.extra_deps = [
13
+ $hoe = Hoe.spec 'nera' do
14
+ self.developer 'Yohsuke Murase', 'murase@serow.t.u-tokyo.ac.jp'
15
+ # self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ self.extra_deps = [
11
18
  ['net-ssh','>= 2.0.11'],
12
19
  ['net-sftp','>= 2.0.2']
13
20
  ]
14
- p.extra_dev_deps = [
15
- ['newgem', "= #{::Newgem::VERSION}"]
16
- ]
17
-
18
- p.clean_globs |= %w[**/.DS_Store tmp *.log]
19
- path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
20
- p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
- p.rsync_args = '-av --delete --ignore-errors'
21
+
22
22
  end
23
23
 
24
- require 'newgem/tasks' # load /tasks/*.rake
24
+ require 'newgem/tasks'
25
25
  Dir['tasks/**/*.rake'].each { |t| load t }
26
26
 
27
+
27
28
  # TODO - want other tests/tasks run by default? Add them to the list
29
+ # remove_task :default
28
30
  # task :default => [:spec, :features]
@@ -0,0 +1,2 @@
1
+ host: murase@rubyforge.org
2
+ remote_dir: /var/www/gforge-projects/nera
@@ -0,0 +1,2 @@
1
+ host: unknown@rubyforge.org
2
+ remote_dir: /var/www/gforge-projects/nera
@@ -82,6 +82,7 @@ module NERA
82
82
  @filename = path_to_file
83
83
  @in_transaction = nil
84
84
  @notify_observer_arg = notify_observer_arg
85
+ @yml_path = nil
85
86
  unless File.exist?(@filename)
86
87
  raise "No such database : #{@filename}"
87
88
  end
@@ -76,10 +76,13 @@ module NERA
76
76
  param_recs.set_yaml_file( @db_folders.path_to_parameters_yaml( klass) )
77
77
  run_records = NERA::RunRecords.new( @db_folders.path_to_runs_table( klass, d[:parameter_id]), param_recs, d[:parameter_id] )
78
78
  run_records.set_yaml_file( @db_folders.path_to_runs_yaml( klass, d[:parameter_id]) )
79
- run_records.transaction {
80
- a = run_records.destroy_job_id( jid)
81
- raise RuntimeError, "must not happen" unless a
82
- FileUtils.rm( @db_folders.path_to_job_script(jid) )
79
+ param_recs.transaction {
80
+ run_records.transaction {
81
+ a = run_records.destroy_job_id( jid)
82
+ raise RuntimeError, "must not happen" unless a
83
+ FileUtils.rm( @db_folders.path_to_job_script(jid) )
84
+ param_recs.update_num_runs( d[:parameter_id], run_records.list_all_finished.size, run_records.list_all.size)
85
+ }
83
86
  }
84
87
  destroyed_jobids << jid
85
88
  @db_folders.logger.info(self.class.to_s) {
@@ -139,11 +142,14 @@ module NERA
139
142
  fpath = @db_folders.path_to_include_layer + filename
140
143
  return nil unless File.exist?(fpath)
141
144
  jinfo, rinfo = expand_and_parse( fpath)
142
- run_layer_path, run_recs = check_consistency( jinfo, rinfo)
143
- run_recs.transaction {
144
- folder_path = fpath.sub(/.tar.bz2$/,'/')
145
- file_move( folder_path, run_layer_path, jinfo[:run_ids])
146
- update_tables( run_recs, jinfo, rinfo)
145
+ run_layer_path, run_recs, param_recs, param_id = check_consistency( jinfo, rinfo)
146
+ param_recs.transaction {
147
+ run_recs.transaction {
148
+ folder_path = fpath.sub(/.tar.bz2$/,'/')
149
+ file_move( folder_path, run_layer_path, jinfo[:run_ids])
150
+ update_tables( run_recs, jinfo, rinfo)
151
+ param_recs.update_num_runs( param_id, run_recs.list_all_finished.size, run_recs.list_all.size)
152
+ }
147
153
  }
148
154
  remove_files( fpath)
149
155
  @db_folders.logger.info(self.class.to_s) {
@@ -211,7 +217,7 @@ module NERA
211
217
  raise "Run info is not consistent with job info!" unless jinfo[:run_ids] == rinfo.keys.sort
212
218
 
213
219
  run_layer_path = @db_folders.path_to_run_layer( sim_class, jinfo[:param_id])
214
- return run_layer_path, run_recs
220
+ return run_layer_path, run_recs, param_records, jinfo[:param_id]
215
221
  end
216
222
 
217
223
  def conflicting
@@ -35,8 +35,29 @@ module NERA
35
35
  p_tab_path = @db_folders.path_to_parameters_table( @sim_class)
36
36
  @param_records = NERA::ParameterRecords.new( p_tab_path, sim_records, sim_id)
37
37
  @param_records.set_yaml_file( @db_folders.path_to_parameters_yaml( @sim_class) )
38
+
39
+ convert_to_recent_format
38
40
  end
39
41
 
42
+ # update the parameters table to the most recent one
43
+ private
44
+ def convert_to_recent_format
45
+ @param_records.transaction do
46
+ recs = @param_records.list_active
47
+ found = recs.find_all do |rec|
48
+ rec[:num_finished_runs] == nil or rec[:num_all_runs] == nil
49
+ end
50
+ found.each do |rec|
51
+ param_id = rec[:id]
52
+ run_records = NERA::RunRecords.new( @db_folders.path_to_runs_table( @sim_class, param_id), @param_records, param_id )
53
+ num_all_runs = run_records.list_all.size
54
+ num_finished_runs = run_records.list_all_finished.size
55
+ @param_records.update_num_runs( param_id, num_finished_runs, num_all_runs)
56
+ end
57
+ end
58
+ end
59
+
60
+ public
40
61
  def parameters_list_in_csv
41
62
  l_active = @param_records.list_active
42
63
  header = @param_records.keys.dup
@@ -54,8 +75,14 @@ module NERA
54
75
  strings << found[2].to_s
55
76
  end
56
77
  end
78
+ strings[1] = "#{strings[1]}/#{strings[2]}"
79
+ strings.delete_at(2)
57
80
  csv_list << strings.join(", ")
58
81
  end
82
+
83
+ header.delete( :num_finished_runs)
84
+ header[1] = :num_runs
85
+
59
86
  return header.join(", "), csv_list
60
87
  end
61
88
 
@@ -150,12 +177,21 @@ module NERA
150
177
  elsif p_hash[key]
151
178
  strings << p_hash[key].to_s
152
179
  elsif p_hash[key] == nil
153
- found = @sim_class::Parameters.find do |p| p[0] == key end
154
- strings << found[2].to_s
180
+ if key == :num_finished_runs or key == :num_all_runs
181
+ strings << 0
182
+ else
183
+ found = @sim_class::Parameters.find do |param| param[0] == key end
184
+ strings << found[2].to_s
185
+ end
155
186
  end
156
187
  end
188
+ strings[1] = "#{strings[1].to_i}/#{strings[2].to_i}"
189
+ strings.delete_at(2)
157
190
  csv_list << strings.join(", ")
158
191
  end
192
+
193
+ header.delete( :num_finished_runs)
194
+ header[1] = :num_runs
159
195
  return header.join(", "), csv_list
160
196
  end
161
197
 
@@ -173,6 +209,7 @@ module NERA
173
209
  @db_folders.logger.info(self.class.to_s) {
174
210
  "reverted a parameter set in the trashbox (#{@sim_class.to_s}/#{id})"
175
211
  }
212
+ convert_to_recent_format
176
213
  }
177
214
  return true
178
215
  end
@@ -8,6 +8,8 @@ module NERA
8
8
 
9
9
  # keys of the parameter table
10
10
  ATTRIBUTES_PART = [ [:id, Integer],
11
+ [:num_finished_runs, Integer],
12
+ [:num_all_runs, Integer],
11
13
  [:created_at, DateTime],
12
14
  [:updated_at, DateTime],
13
15
  [:in_trashbox?, Symbol] ] # :active or :trashbox
@@ -48,7 +50,7 @@ module NERA
48
50
  @db = NERA::Database.new( db_file, sim_id)
49
51
  @db.add_observer( sim_records)
50
52
  end
51
-
53
+
52
54
  # argument is the path to parameters.yml
53
55
  def set_yaml_file( yaml_path)
54
56
  @db.set_yaml_file( yaml_path)
@@ -74,7 +76,7 @@ module NERA
74
76
  NERA::Database.create_table( db_file)
75
77
  end
76
78
 
77
- #
79
+ # add one record
78
80
  def add( param_hash)
79
81
  # check the argument
80
82
  unless param_hash.is_a?(Hash)
@@ -117,7 +119,7 @@ module NERA
117
119
 
118
120
  # add a parameter
119
121
  d = DateTime.now
120
- h = {:created_at => d, :updated_at => d, :in_trashbox? => :active}
122
+ h = {:num_finished_runs => 0, :num_all_runs => 0, :created_at => d, :updated_at => d, :in_trashbox? => :active}
121
123
  ps = param_hash.dup
122
124
  @sim_class::Parameters.each do |p|
123
125
  ps[ p[0]] = p[3] if ps[p[0]] == nil
@@ -171,6 +173,20 @@ module NERA
171
173
  @db.update( found)
172
174
  end
173
175
 
176
+ def update_num_runs( id, num_finished, num_all)
177
+ raise ArgumentError unless id.is_a?(Integer) and num_finished.is_a?(Integer) and num_all.is_a?(Integer)
178
+ return nil if num_finished < 0 or num_all < 0
179
+ return nil if num_finished > num_all
180
+
181
+ found = @db.find_by_id(id)
182
+ return nil unless found
183
+ return nil if found[:in_trashbox?] == :trashbox
184
+
185
+ found[:num_finished_runs] = num_finished
186
+ found[:num_all_runs] = num_all
187
+ @db.update( found)
188
+ end
189
+
174
190
  def touch( id)
175
191
  raise ArgumentError unless id.is_a?(Integer)
176
192
  found = @db.find_by_id( id)
@@ -17,6 +17,8 @@ module NERA
17
17
  @sim_instance
18
18
  # id of the parameter set
19
19
  @param_id
20
+ # instance of NERA::ParameterRecords
21
+ @param_records
20
22
  # instance of NERA::RunRecords
21
23
  @run_records
22
24
 
@@ -39,9 +41,9 @@ module NERA
39
41
 
40
42
  @sim_instance = sim_class.new
41
43
  @param_id = param_id
42
- param_records = NERA::ParameterRecords.new( @db_folders.path_to_parameters_table( sim_class), sim_records, sim_id)
43
- param_records.set_yaml_file( @db_folders.path_to_parameters_yaml( sim_class) )
44
- found = param_records.find_by_id( @param_id)
44
+ @param_records = NERA::ParameterRecords.new( @db_folders.path_to_parameters_table( sim_class), sim_records, sim_id)
45
+ @param_records.set_yaml_file( @db_folders.path_to_parameters_yaml( sim_class) )
46
+ found = @param_records.find_by_id( @param_id)
45
47
  raise "No such parameter : #{param_id}." unless found
46
48
  @sim_instance.class::Parameters.each do |pa|
47
49
  key = pa[0]
@@ -52,7 +54,7 @@ module NERA
52
54
  end
53
55
  end
54
56
 
55
- @run_records = NERA::RunRecords.new( @db_folders.path_to_runs_table( sim_class, @param_id), param_records, @param_id )
57
+ @run_records = NERA::RunRecords.new( @db_folders.path_to_runs_table( sim_class, @param_id), @param_records, @param_id )
56
58
  @run_records.set_yaml_file( @db_folders.path_to_runs_yaml( @sim_instance.class, @param_id) )
57
59
  end
58
60
 
@@ -88,21 +90,24 @@ module NERA
88
90
  job_recs.set_yaml_file( @db_folders.path_to_jobs_yaml)
89
91
  js = NERA::JobScript.new( @db_folders)
90
92
  job_recs.transaction {
91
- @run_records.transaction {
92
- num_jobs.times do |j_idx|
93
- run_stat = @run_records.add( num_runs_per_job)
94
- rid = run_stat[0][:id]
95
- jid = job_recs.add( @sim_instance.class, @param_id, rid, num_runs_per_job)
96
- @run_records.set_job_id( rid, num_runs_per_job, jid)
97
- sim_records = NERA::SimulatorRecords.new( @db_folders.path_to_simulators_table)
98
- sim_records.set_yaml_file( @db_folders.path_to_simulators_yaml )
99
- found = sim_records.list.find do |rec| rec[:name] == @sim_instance.class.to_s end
100
- path_script = js.create_script( jid, found[:id], @param_id, @sim_instance, run_stat)
101
- job_ids << jid
102
- @db_folders.logger.info(self.class.to_s) {
103
- "created a job (#{@sim_instance.class.to_s}/#{@param_id}/#{rid}, #{num_runs_per_job} runs, jobid:#{jid})"
104
- }
105
- end
93
+ @param_records.transaction {
94
+ @run_records.transaction {
95
+ num_jobs.times do |j_idx|
96
+ run_stat = @run_records.add( num_runs_per_job)
97
+ rid = run_stat[0][:id]
98
+ jid = job_recs.add( @sim_instance.class, @param_id, rid, num_runs_per_job)
99
+ @run_records.set_job_id( rid, num_runs_per_job, jid)
100
+ sim_records = NERA::SimulatorRecords.new( @db_folders.path_to_simulators_table)
101
+ sim_records.set_yaml_file( @db_folders.path_to_simulators_yaml )
102
+ found = sim_records.list.find do |rec| rec[:name] == @sim_instance.class.to_s end
103
+ path_script = js.create_script( jid, found[:id], @param_id, @sim_instance, run_stat)
104
+ job_ids << jid
105
+ @db_folders.logger.info(self.class.to_s) {
106
+ "created a job (#{@sim_instance.class.to_s}/#{@param_id}/#{rid}, #{num_runs_per_job} runs, jobid:#{jid})"
107
+ }
108
+ end
109
+ @param_records.update_num_runs( @param_id, @run_records.list_all_finished.size, @run_records.list_all.size)
110
+ }
106
111
  }
107
112
  }
108
113
  return job_ids
@@ -144,18 +149,21 @@ module NERA
144
149
  job_recs.set_yaml_file( @db_folders.path_to_jobs_yaml)
145
150
  destroyed_jobids = []
146
151
  job_recs.transaction {
147
- @run_records.transaction {
148
- job_ids.each do |jid|
149
- d = job_recs.destroy(jid)
150
- next unless d
151
- a = @run_records.destroy_job_id( jid)
152
- raise "must not happen" unless a
153
- FileUtils.rm( @db_folders.path_to_job_script(jid) )
154
- destroyed_jobids << jid
155
- @db_folders.logger.info(self.class.to_s) {
156
- "canceled a job (jobid:#{jid})"
157
- }
158
- end
152
+ @param_records.transaction {
153
+ @run_records.transaction {
154
+ job_ids.each do |jid|
155
+ d = job_recs.destroy(jid)
156
+ next unless d
157
+ a = @run_records.destroy_job_id( jid)
158
+ raise "must not happen" unless a
159
+ FileUtils.rm( @db_folders.path_to_job_script(jid) )
160
+ destroyed_jobids << jid
161
+ @db_folders.logger.info(self.class.to_s) {
162
+ "canceled a job (jobid:#{jid})"
163
+ }
164
+ end
165
+ @param_records.update_num_runs( @param_id, @run_records.list_all_finished.size, @run_records.list_all.size)
166
+ }
159
167
  }
160
168
  }
161
169
  destroyed_jobids = nil if destroyed_jobids.size == 0
@@ -22,7 +22,7 @@ module NERA
22
22
  # record
23
23
  @keys
24
24
  attr_accessor :keys
25
-
25
+
26
26
  # run record
27
27
  def initialize( table_file, param_recs, param_id)
28
28
  raise ArgumentError unless param_recs.is_a?( NERA::ParameterRecords) and param_id.is_a?(Integer)
@@ -37,7 +37,6 @@ module NERA
37
37
  @db.set_yaml_file( yaml_path)
38
38
  end
39
39
 
40
-
41
40
  def self.create_table(table_file)
42
41
  NERA::Database.create_table( table_file)
43
42
  end
@@ -106,7 +105,7 @@ module NERA
106
105
  }
107
106
  return j_id
108
107
  end
109
-
108
+
110
109
  def list_all
111
110
  matched = @db.find_all do |rec|
112
111
  true
data/lib/nera.rb CHANGED
@@ -22,5 +22,5 @@ require 'nera_simulator_records'
22
22
  require 'nera_remote_connector'
23
23
 
24
24
  module NERA
25
- VERSION = '0.3.1'
25
+ VERSION = '0.4.0'
26
26
  end
@@ -5,6 +5,6 @@ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
5
5
  libs = " -r irb/completion"
6
6
  # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
7
  # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
- libs << " -r #{File.dirname(__FILE__) + '/../lib/mygem.rb'}"
9
- puts "Loading mygem gem"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/nera.rb'}"
9
+ puts "Loading nera gem"
10
10
  exec "#{irb} #{libs} --simple-prompt"
data/script/txt2html ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.dirname(__FILE__) + "/../Rakefile"
4
+ require 'rubyforge'
5
+ require 'redcloth'
6
+ require 'syntax/convertors/html'
7
+ require 'erb'
8
+
9
+ download = "http://rubyforge.org/projects/#{$hoe.rubyforge_name}"
10
+ version = $hoe.version
11
+
12
+ def rubyforge_project_id
13
+ RubyForge.new.configure.autoconfig["group_ids"][$hoe.rubyforge_name]
14
+ end
15
+
16
+ class Fixnum
17
+ def ordinal
18
+ # teens
19
+ return 'th' if (10..19).include?(self % 100)
20
+ # others
21
+ case self % 10
22
+ when 1: return 'st'
23
+ when 2: return 'nd'
24
+ when 3: return 'rd'
25
+ else return 'th'
26
+ end
27
+ end
28
+ end
29
+
30
+ class Time
31
+ def pretty
32
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
33
+ end
34
+ end
35
+
36
+ def convert_syntax(syntax, source)
37
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
38
+ end
39
+
40
+ if ARGV.length >= 1
41
+ src, template = ARGV
42
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
43
+ else
44
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
45
+ exit!
46
+ end
47
+
48
+ template = ERB.new(File.open(template).read)
49
+
50
+ title = nil
51
+ body = nil
52
+ File.open(src) do |fsrc|
53
+ title_text = fsrc.readline
54
+ body_text_template = fsrc.read
55
+ body_text = ERB.new(body_text_template).result(binding)
56
+ syntax_items = []
57
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
58
+ ident = syntax_items.length
59
+ element, syntax, source = $1, $2, $3
60
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
61
+ "syntax-temp-#{ident}"
62
+ }
63
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
64
+ body = RedCloth.new(body_text).to_html
65
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
66
+ end
67
+ stat = File.stat(src)
68
+ created = stat.ctime
69
+ modified = stat.mtime
70
+
71
+ $stdout << template.result(binding)
@@ -65,7 +65,6 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
65
65
  s2 = File.open(logp,'r').readlines.size
66
66
  assert_equal( s1+2, s2)
67
67
 
68
-
69
68
  flag = File.exist?( @dbf.path_to_job_script(1))
70
69
  assert_equal( false, flag)
71
70
  flag = File.exist?( @dbf.path_to_job_script(2))
@@ -73,6 +72,7 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
73
72
 
74
73
  h, l = @rlc.not_finished_jobs_list_in_csv
75
74
  assert_equal( 1, l.size)
75
+ assert_equal( "0/1", @plc.parameters_list_in_csv[1][0].split(',')[1].strip)
76
76
 
77
77
  f = @jlc.cancel_jobs( [1000] )
78
78
  assert_nil( f)
@@ -162,6 +162,8 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
162
162
  assert_equal( 2, l.size)
163
163
  h, l = @rlc.not_finished_jobs_list_in_csv
164
164
  assert_equal( 2, l.size)
165
+ assert_equal( "1/3", @plc.parameters_list_in_csv[1][0].split(',')[1].strip)
166
+
165
167
  end
166
168
 
167
169
  def test_include_all
@@ -174,6 +176,7 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
174
176
  assert_equal( [], a)
175
177
  h, l = @jlc.not_finished_list_in_csv
176
178
  assert_equal( [], l)
179
+ assert_equal( "3/3", @plc.parameters_list_in_csv[1][0].split(',')[1].strip)
177
180
  h, l = @rlc.not_finished_jobs_list_in_csv
178
181
  assert_equal( [], l)
179
182
  s2 = File.open(logp,'r').readlines.size
@@ -33,11 +33,59 @@ class TC_NERA_PARAM_LAYER_CONTROLLER < Test::Unit::TestCase
33
33
  x = NERA::ParameterLayerController.new( @db_folder, "Unknown")
34
34
  }
35
35
  end
36
+
37
+ def test_convert_to_recent_format
38
+ f = @plc.create_a_new_parameter_set( {:L => 96, :K => 0.25, :tmax => 128} )
39
+ io = File.open( File.join( @db_folder, "Tables", "Ising", "parameters.pstore") ,'w')
40
+ d = DateTime.now
41
+ Marshal.dump({ 1 => {:id => 1, :created_at => d, :updated_at => d, :in_trashbox? => :active, :L => 96, :K => 0.25, :tmax => 128 }, :max_id => 1} , io )
42
+ io.flush
43
+ plc = NERA::ParameterLayerController.new( @db_folder, "Ising")
44
+ loaded = YAML.load( File.open( File.join( @db_folder, "Ising", "parameters.yml") ) )
45
+ assert( loaded[0].has_key?( :num_finished_runs) )
46
+ assert( loaded[0].has_key?( :num_all_runs) )
47
+ assert_equal( 0, loaded[0][:num_all_runs])
48
+ assert_equal( 0, loaded[0][:num_finished_runs])
49
+
50
+ f = @plc.create_a_new_parameter_set( {:L => 32, :K => 0.25, :tmax => 128} )
51
+ rlc = NERA::RunLayerController.new( @db_folder, "Ising", f)
52
+ assert( rlc.create_jobs(3) )
53
+ io = File.open( File.join( @db_folder, "Tables", "Ising", "parameters.pstore") ,'w')
54
+ Marshal.dump( { 1 => {:id => 1, :created_at => d, :updated_at => d, :in_trashbox? => :active, :L => 96, :K => 0.25, :tmax => 128 },
55
+ 2 => {:id => 2, :created_at => d, :updated_at => d, :in_trashbox? => :active, :L => 32, :K => 0.25, :tmax => 128 },
56
+ :max_id => 2 } , io )
57
+ io.flush
58
+
59
+ plc = NERA::ParameterLayerController.new( @db_folder, "Ising")
60
+ loaded = YAML.load( File.open( File.join( @db_folder, "Ising", "parameters.yml") ) )
61
+ assert( loaded[1].has_key?( :num_finished_runs) )
62
+ assert( loaded[1].has_key?( :num_all_runs) )
63
+ assert_equal( 3, loaded[1][:num_all_runs])
64
+ assert_equal( 0, loaded[1][:num_finished_runs])
65
+
66
+ assert( @plc.move_a_parameter_set_into_trashbox(1) )
67
+ io = File.open( File.join( @db_folder, "Tables", "Ising", "parameters.pstore") ,'w')
68
+ Marshal.dump( { 1 => {:id => 1, :created_at => d, :updated_at => d, :in_trashbox? => :trashbox, :L => 96, :K => 0.25, :tmax => 128 },
69
+ 2 => {:id => 2, :created_at => d, :updated_at => d, :in_trashbox? => :active, :L => 32, :K => 0.25, :tmax => 128 },
70
+ :max_id => 2 } , io )
71
+ io.flush
72
+ plc = NERA::ParameterLayerController.new( @db_folder, "Ising")
73
+ loaded = YAML.load( File.open( File.join( @db_folder, "Ising", "parameters.yml") ) )
74
+ assert_equal( false, loaded[0].has_key?( :num_finished_runs) ) # only active records can be updated
75
+ assert_equal( false, loaded[0].has_key?( :num_all_runs) )
76
+ assert( loaded[1].has_key?( :num_finished_runs) ) # only active records can be updated
77
+ assert( loaded[1].has_key?( :num_all_runs) )
78
+
79
+ assert( plc.revert_a_parameter_set_in_trashbox(1) )
80
+ loaded = YAML.load( File.open( File.join( @db_folder, "Ising", "parameters.yml") ) )
81
+ assert( loaded[0].has_key?( :num_finished_runs) ) # format is converted when reverted
82
+ assert( loaded[0].has_key?( :num_all_runs) )
83
+ end
36
84
 
37
85
  def test_parameters_list_in_csv
38
86
  header, list = @plc.parameters_list_in_csv
39
87
  assert( header.is_a?(String) )
40
- assert_equal( "id, created_at, updated_at, L, K, tmax", header)
88
+ assert_equal( "id, num_runs, created_at, updated_at, L, K, tmax", header)
41
89
  assert( list.is_a?(Array) )
42
90
  assert_equal( 0, list.size)
43
91
 
@@ -45,24 +93,33 @@ class TC_NERA_PARAM_LAYER_CONTROLLER < Test::Unit::TestCase
45
93
  assert_equal( 1, f)
46
94
  header, list = @plc.parameters_list_in_csv
47
95
  assert( header.is_a?(String) )
48
- assert_equal( "id, created_at, updated_at, L, K, tmax", header)
96
+ assert_equal( "id, num_runs, created_at, updated_at, L, K, tmax", header)
49
97
  assert( list.is_a?(Array) )
50
98
  assert_equal( 1, list.size)
51
99
  dstr = DateTime.now.to_s.split('T')[0]
52
- assert_equal( "1, #{dstr}, #{dstr}, 96, 0.25, 128", list[0])
100
+ assert_equal( "1, 0/0, #{dstr}, #{dstr}, 96, 0.25, 128", list[0])
53
101
 
54
102
  f = @plc.create_a_new_parameter_set( {:L => 32} )
55
103
  assert_equal( 2, f)
56
104
  header, list = @plc.parameters_list_in_csv
57
105
  assert_equal( 2, list.size)
58
- assert_equal( "1, #{dstr}, #{dstr}, 96, 0.25, 128", list[0])
106
+ assert_equal( "1, 0/0, #{dstr}, #{dstr}, 96, 0.25, 128", list[0])
59
107
  dstr = DateTime.now.to_s.split('T')[0]
60
- assert_equal( "2, #{dstr}, #{dstr}, 32, 0.223, 512", list[1])
108
+ assert_equal( "2, 0/0, #{dstr}, #{dstr}, 32, 0.223, 512", list[1])
61
109
 
62
110
  @plc.move_a_parameter_set_into_trashbox(1)
63
111
  header, list = @plc.parameters_list_in_csv
64
112
  assert_equal( 1, list.size)
65
- assert_equal( "2, #{dstr}, #{dstr}, 32, 0.223, 512", list[0])
113
+ assert_equal( "2, 0/0, #{dstr}, #{dstr}, 32, 0.223, 512", list[0])
114
+
115
+ =begin
116
+ rlc = NERA::RunLayerController.new( @db_folder, "Ising", 2)
117
+ assert( rlc.create_jobs(3), 2 )
118
+ header, list = @plc.parameters_list_in_csv
119
+ assert_equal( "2, 0/6, #{dstr}, #{dstr}, 32, 0.223, 512", list[0])
120
+ assert( rlc.create_jobs(1) )
121
+ assert_equal( "2, 0/4, #{dstr}, #{dstr}, 32, 0.223, 512", list[0])
122
+ =end
66
123
  end
67
124
 
68
125
  def add_three
@@ -137,9 +194,9 @@ class TC_NERA_PARAM_LAYER_CONTROLLER < Test::Unit::TestCase
137
194
  }
138
195
  header, list = @plc.parameters_list_in_csv
139
196
  d = DateTime.now.to_s.split('T')[0]
140
- l = [ "1, #{d}, #{d}, 32, 0.01, 1",
141
- "2, #{d}, #{d}, 64, 0.02, 512",
142
- "3, #{d}, #{d}, 96, 0.223, 3"]
197
+ l = [ "1, 0/0, #{d}, #{d}, 32, 0.01, 1",
198
+ "2, 0/0, #{d}, #{d}, 64, 0.02, 512",
199
+ "3, 0/0, #{d}, #{d}, 96, 0.223, 3"]
143
200
  assert_equal( l, list)
144
201
  end
145
202