lib/openstudio/analysis/translator/workflow.rb in openstudio-analysis-1.0.0.rc19 vs lib/openstudio/analysis/translator/workflow.rb in openstudio-analysis-1.0.0

- old
+ new

@@ -1,5 +1,40 @@ +# ******************************************************************************* +# OpenStudio(R), Copyright (c) 2008-2018, Alliance for Sustainable Energy, LLC. +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# (1) Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# (2) Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# (3) Neither the name of the copyright holder nor the names of any contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission from the respective party. +# +# (4) Other than as required in clauses (1) and (2), distributions in any form +# of modifications or other derivative works may not use the "OpenStudio" +# trademark, "OS", "os", or any other confusingly similar designation without +# specific prior written permission from Alliance for Sustainable Energy, LLC. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES +# GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ******************************************************************************* + module OpenStudio module Analysis module Translator class Workflow attr_reader :osa_filename @@ -31,24 +66,25 @@ @options = options @file_paths = options[:file_paths] ? options[:file_paths] : [] @measure_paths = options[:measure_paths] ? options[:measure_paths] : [] # Initialize static inputs from the OSA - @seed_file = File.basename @osa[:seed][:path] + @seed_file = File.basename(@osa[:seed][:path]) if @options[:seed] @seed_file = @options[:seed] end - @weather_file = File.basename @osa[:weather_file][:path] + @weather_file = File.basename(@osa[:weather_file][:path]) @osa_id = @osa[:_id] @steps = [] @osa[:problem][:workflow].each_with_index do |step, i| step_hash = {} step_hash[:measure_dir_name] = File.basename(step[:measure_definition_directory]) step_hash[:arguments] = {} # Measures can have no arguments -- make sure to catch it if @osa[:problem][:workflow][i][:arguments] @osa[:problem][:workflow][i][:arguments].each do |arg| + next if arg[:value].nil? step_hash[:arguments][arg[:name].to_sym] = arg[:value] end end step_hash[:name] = step[:name] if step[:name] step_hash[:description] = step[:description] if step[:description] @@ -89,12 +125,20 @@ step[:arguments][var_name.to_sym] = var_value end end # Overwrite the seed and weather files if they are present in the datapoint.json - weather_file = osd[:weather_file] != '' ? osd[:weather_file] : @weather_file - seed_file = osd[:seed] != '' ? osd[:seed] : @seed_file + if (osd[:weather_file] != '') && !osd[:weather_file].nil? + weather_file = osd[:weather_file] + else + weather_file = @weather_file + end + if (osd[:seed] != '') && !osd[:seed].nil? + seed_file = osd[:seed] + else + seed_file = @seed_file + end # Save the OSW hash osw = {} created_at = ::Time.now osw[:seed_file] = seed_file @@ -116,10 +160,10 @@ def process_datapoints(osd_filename_array) r = [] osd_filename_array.each do |osd_file| begin r << process_datapoint(osd_file) - rescue => e + rescue StandardError => e r << nil puts "Warning: Failed to process datapoint #{osd_file} with error #{e.message} in #{e.backtrace.join('\n')}" end end