lib/openstudio/analysis/translator/excel.rb in openstudio-analysis-0.2.1 vs lib/openstudio/analysis/translator/excel.rb in openstudio-analysis-0.2.2
- old
+ new
@@ -220,30 +220,35 @@
# Determine if row is suppose to be an argument or a variable to be perturbed.
if @variable['variable_type'] == 'argument'
ag = nil
if @variable['method'] == 'static'
- unless @variable['distribution']['static_value']
- fail 'can not have an argument that is not a static value defined in which to set the argument'
+ if @variable['distribution']['static_value'].nil? || @variable['distribution']['static_value'] == 'null'
+ puts " Warning: '#{measure['name']}:#{@variable['name']}' static value was empty or null, assuming optional and skipping"
+ next
end
+ # unless @variable['distribution']['static_value']
+ # fail 'Cannot have an argument that is not a static value defined in which to set the argument'
+ # end
# add this as an argument
case @variable['type'].downcase
- when 'double'
- @static_value = @variable['distribution']['static_value'].to_f
- when 'integer'
- @static_value = @variable['distribution']['static_value'].to_i
- when 'string', 'choice'
- @static_value = @variable['distribution']['static_value'].inspect
- when 'bool'
- if @variable['distribution']['static_value'].downcase == 'true'
- @static_value = true
- else
- @static_value = false
- end
+ when 'double'
+ @static_value = @variable['distribution']['static_value'].to_f
+ when 'integer'
+ @static_value = @variable['distribution']['static_value'].to_i
+ # TODO: update openstudio export to write only Strings
+ when 'string', 'choice'
+ @static_value = @variable['distribution']['static_value'].inspect
+ when 'bool'
+ if @variable['distribution']['static_value'].downcase == 'true'
+ @static_value = true
else
- fail "Unknown variable type of #{@variable['type']}"
+ @static_value = false
+ end
+ else
+ fail "Unknown variable type of '#{@variable['type']}'"
end
ag = JSON.parse(argument_template.result(get_binding))
end
fail "Argument '#{@variable['name']}' did not process. Most likely it did not have all parameters defined." if ag.nil?
wf['arguments'] << ag
@@ -271,11 +276,11 @@
else
values = eval(@variable['distribution']['discrete_values'])
end
if weights
- fail "Discrete variable #{@variable['name']} does not have equal length of values and weights" if values.size != weights.size
+ fail "Discrete variable '#{@variable['name']}' does not have equal length of values and weights" if values.size != weights.size
@values_and_weights = values.zip(weights).map { |v, w| { value: v, weight: w } }.to_json
else
@values_and_weights = values.map { |v| { value: v } }.to_json
end
@@ -309,21 +314,21 @@
# helper method for ERB
def get_binding
binding
end
- def add_directory_to_zip(zipfile, local_directory, relative_zip_directory)
- # pp "Add Directory #{local_directory}"
- Dir[File.join("#{local_directory}", '**', '**')].each do |file|
- # pp "Adding File #{file}"
- zipfile.add(file.sub(local_directory, relative_zip_directory), file)
- end
- zipfile
- end
-
# Package up the seed, weather files, and measures
def save_analysis_zip(model)
+ def add_directory_to_zip(zipfile, local_directory, relative_zip_directory)
+ # pp "Add Directory #{local_directory}"
+ Dir[File.join("#{local_directory}", '**', '**')].each do |file|
+ # pp "Adding File #{file}"
+ zipfile.add(file.sub(local_directory, relative_zip_directory), file)
+ end
+ zipfile
+ end
+
zipfile_name = "#{@export_path}/#{model[:name]}.zip"
FileUtils.rm_f(zipfile_name) if File.exist?(zipfile_name)
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
@weather_files.each do |filename|
@@ -672,11 +677,11 @@
# parse the choices/enums
if var['type'] == 'enum' || var['type'] == 'choice' # this is now a choice
var['distribution']['enumerations'] = row[:enums].gsub('|', '').split(',').map { |v| v.strip }
elsif var['type'] == 'bool'
var['distribution']['enumerations'] = []
- var['distribution']['enumerations'] << 'true' # todo: should this be a real bool?
+ var['distribution']['enumerations'] << 'true' # TODO: should this be a real bool?
var['distribution']['enumerations'] << 'false'
end
if var['method'] == 'lhs'
var['distribution']['min'] = row[:min]
@@ -700,18 +705,21 @@
measure_index += 1
variable_index = 0
data['data'][measure_index] = {}
# generate name id
- # todo: put this into a logger. puts "Parsing measure #{row[1]}"
+ # TODO: put this into a logger. puts "Parsing measure #{row[1]}"
display_name = row[:measure_name_or_var_type]
measure_name = display_name.downcase.strip.gsub('-', '_').gsub(' ', '_')
data['data'][measure_index]['display_name'] = display_name
data['data'][measure_index]['name'] = measure_name
data['data'][measure_index]['enabled'] = row[:enabled] == 'TRUE' ? true : false
data['data'][measure_index]['measure_file_name'] = row[:measure_file_name_or_var_display_name]
- data['data'][measure_index]['measure_file_name_directory'] = row[:measure_file_name_directory] ?
- row[:measure_file_name_directory] : row[:measure_file_name_or_var_display_name].underscore
+ if row[:measure_file_name_directory]
+ data['data'][measure_index]['measure_file_name_directory'] = row[:measure_file_name_directory]
+ else
+ data['data'][measure_index]['measure_file_name_directory'] = row[:measure_file_name_or_var_display_name].underscore
+ end
data['data'][measure_index]['measure_type'] = row[:measure_type_or_parameter_name_in_measure]
data['data'][measure_index]['version'] = @version_id
data['data'][measure_index]['variables'] = []
end