lib/openstudio/analysis/translator/excel.rb in openstudio-analysis-0.1.1 vs lib/openstudio/analysis/translator/excel.rb in openstudio-analysis-0.1.2

- old
+ new

@@ -85,11 +85,11 @@ # helper method for ERB def get_binding binding end - + # TODO: move this into a new class that helps construct this file def translate_to_analysis_json # Load in the templates for constructing the JSON file template_root = File.join(File.dirname(__FILE__), "../../templates") analysis_template = ERB.new(File.open("#{template_root}/analysis.json.erb", 'r').read) @@ -123,16 +123,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' + if !@variable['distribution']['static_value'] + raise "can not 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'] + 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 + else + raise "Unknown variable type of #{@variable['type']}" + end ag = JSON.parse(argument_template.result(get_binding)) - elsif raise "can not have an argument without having a static value defined in which to set the argument" end wf['arguments'] << ag - else + else # must be a vriable vr = nil if @variable['method'] == 'static' # add this as an argument vr = JSON.parse(static_variable_template.result(get_binding)) elsif @variable['method'] == 'lhs' @@ -193,12 +212,17 @@ # This is the path that will be seen on the server when this runs analysis_json['analysis']['seed']['path'] = "./seed/#{File.basename(model[:path])}" # Set the weather file as the first in the list -- this is optional # TODO: check if epw or if zip file + analysis_json['analysis']['weather_file']['file_type'] = 'EPW' - analysis_json['analysis']['weather_file']['path'] = "./weather/#{File.basename(@weather_files.first, '.zip')}.epw" + if File.extname(@weather_files.first) =~ /.zip/i + analysis_json['analysis']['weather_file']['path'] = "./weather/#{File.basename(@weather_files.first, '.zip')}.epw" + else + analysis_json['analysis']['weather_file']['path'] = "./weather/#{File.basename(@weather_files.first)}" + end json_file_name = "#{@export_path}/#{model[:name]}.json" FileUtils.rm_f(json_file_name) if File.exists?(json_file_name) File.open("#{@export_path}/#{model[:name]}.json", "w") { |f| f << JSON.pretty_generate(analysis_json) } @@ -346,9 +370,11 @@ data['data'][measure_index]['display_name'] = display_name data['data'][measure_index]['name'] = measure_name data['data'][measure_index]['enabled'] = row[0] == "TRUE" ? true : false data['data'][measure_index]['measure_file_name'] = row[2] data['data'][measure_index]['measure_file_name_directory'] = row[2].underscore + data['data'][measure_index]['measure_type'] = row[3] + data['data'][measure_index]['version'] = @version_id data['data'][measure_index]['variables'] = [] end