lib/openstudio/analysis/translator/excel.rb in openstudio-analysis-0.1.7 vs lib/openstudio/analysis/translator/excel.rb in openstudio-analysis-0.1.8
- old
+ new
@@ -31,11 +31,11 @@
else
raise "File #{xls_filename} does not exist"
end
# Initialize some other instance variables
- @version = nil
+ @version = '0.0.1'
@name = nil
@machine_name = nil
@settings = {}
@weather_files = []
@models = []
@@ -61,10 +61,13 @@
FileUtils.rm_f(filename) if File.exists?(filename)
File.open(filename, 'w') { |f| f << JSON.pretty_generate(@variables) }
end
def validate_analysis
+ version_test = Semantic::Version.new @version
+ raise "Spreadsheet version #{@version} is no longer supported. Please upgrade your spreadsheet to at least 0.1.9" if version_test < '0.1.9'
+
# Setup the paths and do some error checking
raise "Measures directory '#{@measure_path}' does not exist" unless Dir.exists?(@measure_path)
@models.uniq!
raise "No seed models defined in spreadsheet" if @models.empty?
@@ -133,15 +136,21 @@
# most of the checks will raise a runtime exception, so this true will never be called
true
end
- def save_analysis
+ def create_analysis_hash
# save the format in the OpenStudio analysis json format template without
# the correct weather files or models
@template_json = translate_to_analysis_json_template()
-
+
+ @template_json
+ end
+
+ def save_analysis
+ @template_json = create_analysis_hash
+
#validate_template_json
# iterate over each model and save the zip and json
@models.each do |model|
save_analysis_zip(model)
@@ -162,10 +171,15 @@
argument_template = ERB.new(File.open("#{template_root}/argument.json.erb", 'r').read)
# Templated analysis json file (this is what is returned)
puts "Analysis name is #{@name}"
openstudio_analysis_json = JSON.parse(analysis_template.result(get_binding))
+
+ openstudio_analysis_json['analysis']['problem'].merge!(@problem)
+ openstudio_analysis_json['analysis']['problem']['algorithm'].merge!(@algorithm)
+
+
@measure_index = -1
@variables['data'].each do |measure|
# With OpenStudio server we need to create the workflow with all the measure instances
if measure['enabled'] && measure['name'] != 'baseline'
@@ -252,25 +266,25 @@
zipfile_name = "#{@export_path}/#{model[:name]}.zip"
FileUtils.rm_f(zipfile_name) if File.exists?(zipfile_name)
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
@weather_files.each do |filename|
- puts " Adding #{filename}"
+ #puts " Adding #{filename}"
zipfile.add("./weather/#{File.basename(filename)}", filename)
end
Dir.glob("#{@measure_path}/**/*.rb").each do |measure|
next if measure.include?("spec") # don't include the spec folders nor files
measure_name = measure.split(File::SEPARATOR).last(2).first
- puts " Adding ./measures/#{measure_name}/#{File.basename(measure)}"
+ #puts " Adding ./measures/#{measure_name}/#{File.basename(measure)}"
zipfile.add("./measures/#{measure_name}/#{File.basename(measure)}", measure)
end
- puts "Adding #{model[:path]}"
+ #puts "Adding #{model[:path]}"
zipfile.add("./seed/#{File.basename(model[:path])}", model[:path])
- puts "Adding in other files #{@other_files.inspect}"
+ #puts "Adding in other files #{@other_files.inspect}"
@other_files.each do |others|
Dir[File.join(others[:path], '**', '**')].each do |file|
zipfile.add(file.sub(others[:path], "./lib/#{others[:lib_zip_name]}/"), file)
end
end
@@ -383,12 +397,21 @@
@name = row[1].chomp if row[0] == "Analysis Name"
@machine_name = @name.snake_case
@export_path = File.expand_path(File.join(@root_path, row[1])) if row[0] == "Export Directory"
@measure_path = File.expand_path(File.join(@root_path, row[1])) if row[0] == "Measure Directory"
elsif b_problem_setup
- @problem["#{row[0].snake_case}"] = row[1] if row[0]
+ if row[0]
+ v = row[1]
+ v.to_i if v % 1 == 0
+ @problem["#{row[0].snake_case}"] = v
+ end
+
elsif b_algorithm_setup
- @algorithm["#{row[0].snake_case}"] = row[1] if row[0]
+ if row[0]
+ v = row[1]
+ v = v.to_i if v % 1 == 0
+ @algorithm["#{row[0].snake_case}"] = v
+ end
elsif b_weather_files
if row[0] == "Weather File"
@weather_files += Dir.glob(File.expand_path(File.join(@root_path, row[1])))
end
elsif b_models