nera 0.0.2 → 0.0.3

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/nera_addsim CHANGED
@@ -18,13 +18,23 @@ parser = OptionParser.new do |opts|
18
18
  opts.parse!(ARGV)
19
19
  end
20
20
 
21
- unless ARGV.size == 1
22
- raise "\n\nUsage:\n nera_addsim 'nera_db_folder'"
21
+ unless ARGV.size < 2
22
+ raise "\n\nUsage:\n nera_addsim 'nera_db_folder' or nera_addsim"
23
23
  end
24
- folder_path = ARGV[0]+'/Simulator_classes/'
25
- unless FileTest.directory?( folder_path)
26
- raise "Folder #{folder_path} does not exist."
24
+
25
+ folder_path = ""
26
+ if ARGV.size == 0
27
+ unless FileTest.exists?("Jobs") and FileTest.exists?("Tables") and FileTest.exists?("simulators.yml")
28
+ raise "\n\nCurrent directory is not a valid database.\nThis command performs in your database directory.\n\n"
29
+ end
30
+ folder_path = '.'
31
+ else
32
+ folder_path = ARGV[0]
33
+ end
34
+
35
+ unless FileTest.directory?( folder_path + '/Simulator_classes/')
36
+ raise "Folder #{folder_path}/Simulator_classes does not exist."
27
37
  end
28
38
 
29
39
  require File.expand_path(File.dirname(__FILE__) + "/../lib/nera_addsim/make_simulator")
30
- NERA::CUI_Simulator_Adder.new(ARGV[0])
40
+ NERA::CUI_Simulator_Adder.new(folder_path)
data/lib/nera/nera_cui.rb CHANGED
@@ -95,6 +95,13 @@ HEADER
95
95
 
96
96
  # --- selection of a parameter set
97
97
  def param_layer_action
98
+
99
+ plc = NERA::ParameterLayerController.new( @path_db_folder, @simulator_class)
100
+ unless plc
101
+ Dialog::message("Specified simulator does not exist #{@path_db_folder}/#{@simulator_class.to_s}")
102
+ return :simulator_layer
103
+ end
104
+
98
105
  $stdout.puts <<"HEADER"
99
106
  ===============================================
100
107
  --- in parameter layer ------------------------
@@ -102,12 +109,6 @@ HEADER
102
109
  ===============================================
103
110
  HEADER
104
111
 
105
- plc = NERA::ParameterLayerController.new( @path_db_folder, @simulator_class)
106
- unless plc
107
- Dialog::message("Specified simulator does not exist #{@path_db_folder}/#{@simulator_class.to_s}")
108
- return :simulator_layer
109
- end
110
-
111
112
  header,list = plc.parameters_list_in_csv
112
113
  list.unshift( "Menu")
113
114
  selected = 0
@@ -208,6 +209,13 @@ HEADER
208
209
 
209
210
  # --- action at run layer
210
211
  def run_layer_action
212
+
213
+ rlc = NERA::RunLayerController.new( @path_db_folder, @simulator_class, @parameter_id)
214
+ unless rlc
215
+ Dialog::message("Table #{@path_db_folder}/#{@simulator_class.to_s}/#{@parameter_id} is not found.")
216
+ return :parameter_layer
217
+ end
218
+
211
219
  $stdout.puts <<"HEADER"
212
220
  ===============================================
213
221
  --- in run layer ------------------------------
@@ -223,12 +231,6 @@ HEADER
223
231
  "Cancel jobs",
224
232
  "Analyze data",
225
233
  "Exit"]
226
- rlc = NERA::RunLayerController.new( @path_db_folder, @simulator_class, @parameter_id)
227
- unless rlc
228
- Dialog::message("Table #{@path_db_folder}/#{@simulator_class.to_s}/#{@parameter_id} is not found.")
229
- return :parameter_layer
230
- end
231
-
232
234
  selected = 0
233
235
  Dir.chdir( rlc.path_to_run_layer) {
234
236
  selected = Dialog::select_one_or_return_string( action_list, "Select one")
data/lib/nera.rb CHANGED
@@ -21,5 +21,5 @@ require 'nera_simulator_layer_controller'
21
21
  require 'nera_simulator_records'
22
22
 
23
23
  module NERA
24
- VERSION = '0.0.2'
24
+ VERSION = '0.0.3'
25
25
  end
@@ -7,6 +7,7 @@ module NERA
7
7
  def script_body(sim_info)
8
8
  params=[]
9
9
  sim_info[:params].each do | param |
10
+ next if param[0] == "seed"
10
11
  params << " [#{param[0]},#{param[1]},#{param[2]}]"
11
12
  end
12
13
  params_str = params.join(",\n\t\t")
@@ -32,13 +33,16 @@ BODY
32
33
  while true
33
34
  $stdout.puts
34
35
  $stdout.puts "+++Input parameter name+++"
36
+ $stdout.puts " If you need a seed of random number, please just input \"seed\""
35
37
  name = Readline.readline(">").chomp.strip
36
38
  break if name =~ /^[a-z]/ or name =~ /^[A-Z]/
37
39
  $stdout.puts "Input is not valid"
38
40
  $stdout.puts
39
41
  $stdout.puts "Input the simulator name again."
40
42
  end
41
- array << ":#{name}"
43
+ return ["seed",nil,nil] if name == "seed"
44
+ #array << ":#{name}"
45
+ array << name.to_sym.inspect
42
46
  $stdout.puts
43
47
  num = Dialog.select_one(type, "++Select parameter type+++")
44
48
  array << type[num]
@@ -53,6 +57,8 @@ BODY
53
57
  end
54
58
  if type[num] == Integer or type[num] == Float
55
59
  if /[-+]?(?:[0-9]+(\.[0-9]*)?|(\.[0-9]+))([eE][-+]?[0-9]+)?/ =~ default
60
+ default = "#{default.to_i}" if type[num] == Integer
61
+ default = "#{default.to_f}" if type[num] == Float
56
62
  break
57
63
  end
58
64
  else
@@ -84,11 +90,16 @@ BODY
84
90
 
85
91
  case num
86
92
  when 0
93
+ if param[0] == "seed"
94
+ return ["seed",nil,nil]
95
+ end
87
96
  if param[1] == Integer or param[1] == Float
88
97
  unless /[-+]?(?:[0-9]+(\.[0-9]*)?|(\.[0-9]+))([eE][-+]?[0-9]+)?/ =~ param[2]
89
98
  $stdout.puts "! Default value must be #{param[1]}"
90
99
  next
91
100
  end
101
+ param[2] = "#{param[2].to_i}" if param[1] == Integer
102
+ param[2] = "#{param[2].to_f}" if param[1] == Float
92
103
  end
93
104
  return param
94
105
  when 1
@@ -96,12 +107,14 @@ BODY
96
107
  while true
97
108
  $stdout.puts
98
109
  $stdout.puts "+++Input parameter name+++"
110
+ $stdout.puts " If you need a seed of random number, please just input \"seed\""
99
111
  name = Readline.readline(">").chomp.strip
100
112
  break if name =~ /^[a-z]/ or name =~ /^[A-Z]/
101
113
  $stdout.puts "Input is not valid"
102
114
  $stdout.puts
103
115
  $stdout.puts "Input the simulator name again."
104
116
  end
117
+ return ["seed",nil,nil] if name == "seed"
105
118
  param[0] = ":#{name}"
106
119
  when 2
107
120
  $stdout.puts
@@ -115,7 +128,8 @@ BODY
115
128
  # p param[1]
116
129
  if param[1] == Integer or param[1] == Float
117
130
  if /[-+]?(?:[0-9]+(\.[0-9]*)?|(\.[0-9]+))([eE][-+]?[0-9]+)?/ =~ default
118
- param[2] = default
131
+ param[2] = "#{default.to_i}" if param[1] == Integer
132
+ param[2] = "#{default.to_f}" if param[1] == Float
119
133
  break
120
134
  end
121
135
  else
@@ -173,7 +187,7 @@ BODY
173
187
  return nil
174
188
  end
175
189
 
176
- $stdout.print "Would you create a new simulator \"#{name}\" ?(y/n): "
190
+ $stdout.print "Will you create a new simulator \"#{name}\" ?(y/n): "
177
191
  if Readline.readline("").chomp.strip == "y"
178
192
  sim_info[:name]=name
179
193
  break
@@ -194,17 +208,17 @@ BODY
194
208
  path_file = Readline.readline("> ~/").chomp.strip
195
209
  unless File.file?(home+path_file)
196
210
  $stdout.puts "File \"~/#{path_file}\" is not found."
197
- $stdout.print "Would you abort this registration\" ?(y/n): "
211
+ $stdout.print "Will you abort this registration\" ?(y/n): "
198
212
  return nil if Readline.readline("").chomp.strip == "y"
199
213
  else
200
214
  if (File.stat(home+path_file).mode & 2**6 ) != 2**6
201
215
  $stdout.puts "File ~/#{path_file} is not executable."
202
- $stdout.print "Would you abort this registration\" ?(y/n): "
216
+ $stdout.print "Will you abort this registration\" ?(y/n): "
203
217
  return nil if Readline.readline("").chomp.strip == "y"
204
218
  end
205
219
  end
206
220
 
207
- $stdout.print "Would you use \"~/#{path_file}\" ?(y/n): "
221
+ $stdout.print "Will you use \"~/#{path_file}\" ?(y/n): "
208
222
  if Readline.readline("").chomp.strip == "y"
209
223
  sim_info[:path]="~/"+path_file
210
224
  break
@@ -229,25 +243,33 @@ BODY
229
243
  $stdout.puts "Execute command :"
230
244
  params_str = ""
231
245
  params.each do | name, type, default |
232
- params_str += " (#{name.sub(':','')})"
246
+ if name == "seed"
247
+ params_str += " (seed)"
248
+ else
249
+ params_str += " (#{name.sub(':','')})"
250
+ end
251
+
233
252
  end
234
- exec = "#{path}#{params_str} (seed)"
253
+ exec = "#{path}#{params_str}"
235
254
  $stdout.puts " $ #{exec}"
236
255
  $stdout.puts "------------------------------"
237
256
  menu =["add"]
238
257
  params.each do | name, type, default |
239
- menu += ["#{name.sub(':','')} : #{type} (default #{default})"]
258
+ if name == "seed"
259
+ menu += ["seed"]
260
+ else
261
+ menu += ["#{name.sub(':','')} : #{type} (default #{default})"]
262
+ end
240
263
  end
241
264
  menu += ["exit"]
242
265
  num = Dialog.select_one(menu)
243
- # p menu[num]
244
266
  case menu[num]
245
267
  when "add"
246
268
  params << add_param()
247
269
  next
248
270
  when "exit"
249
271
  if params.length==0
250
- $stdout.print "Any parameters don't exist. Would you continue this registration?(y/n): "
272
+ $stdout.print "Any parameters don't exist. Will you continue this registration?(y/n): "
251
273
  next if Readline.readline("").chomp.strip != "y"
252
274
  end
253
275
  break
@@ -280,9 +302,7 @@ BODY
280
302
  $stdout.puts " No parameter"
281
303
  else
282
304
  index = 1
283
- cmd = []
284
305
  sim_info[:params].each do |name, type, default|
285
- cmd << name.sub(':','')
286
306
  $stdout.puts " #{index}-> #{name.sub(':','')} : #{type} (default #{default}) "
287
307
  index += 1
288
308
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nera
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yohsuke Murase
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-27 00:00:00 +09:00
12
+ date: 2009-03-30 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency