Class: BuildingSync::Translator
- Inherits:
-
WorkflowMaker
- Object
- WorkflowMakerBase
- WorkflowMaker
- BuildingSync::Translator
- Includes:
- Helper
- Defined in:
- lib/buildingsync/translator.rb
Overview
Translator class
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#final_xml_prepared ⇒ Object
Returns the value of attribute final_xml_prepared.
-
#ns ⇒ Object
Returns the value of attribute ns.
-
#results_gathered ⇒ Object
Returns the value of attribute results_gathered.
Instance Method Summary collapse
-
#gather_results(year_val = Date.today.year, baseline_only = false) ⇒ Object
gather results from simulated scenarios, for all or just the baseline scenario.
-
#initialize(xml_file_path, output_dir, epw_file_path = nil, standard_to_be_used = ASHRAE90_1, validate_xml_file_against_schema = true) ⇒ Translator
constructor
load the building sync file.
-
#prepare_final_xml ⇒ Object
write parameters to xml file.
-
#run_osws(only_cb_modeled = false, runner_options = { run_simulations: true, verbose: false, num_parallel: 7, max_to_run: Float::INFINITY }) ⇒ Object
run osws - running all scenario simulations.
-
#save_xml(file_name = 'results.xml') ⇒ Object
save xml that includes the results.
- #setup_and_sizing_run(ddy_file = nil) ⇒ Object
-
#validate_xml ⇒ Object
Validate the xml file against the schema using the SelectionTool.
-
#write_osws(only_cb_modeled = false) ⇒ Object
write osws - write all workflows into osw files.
Methods included from Helper
#help_calculate_hours, #help_convert, #help_count_number_of_days, #help_element_class_type_check, #help_get_attribute_value, #help_get_default_schedule_set, #help_get_duration, #help_get_end_time, #help_get_end_time_sat, #help_get_end_time_sun, #help_get_end_time_weekday, #help_get_or_create, #help_get_schedule_rule_set_from_schedule, #help_get_start_time, #help_get_start_time_sat, #help_get_start_time_sun, #help_get_start_time_weekday, #help_get_text_value, #help_get_text_value_as_bool, #help_get_text_value_as_date, #help_get_text_value_as_datetime, #help_get_text_value_as_float, #help_get_text_value_as_integer, #help_get_zone_name_list, #help_load_doc, #help_print_all_schedules, #help_print_schedule, #help_write_profile
Methods inherited from WorkflowMaker
#cleanup_larger_files, #configure_workflow_for_scenario, #deep_copy_workflow, #get_available_measures_hash, #get_facility, #get_failed_scenarios, #get_measure_directories_array, #get_measure_type, #get_model, #get_scenarios, #get_space_types, #get_workflow, #insert_measure_into_workflow, #measures_exist?, #purge_skipped_from_workflow, #read_xml, #set_argument_detail, #write_osw
Methods inherited from WorkflowMakerBase
#add_measure_path, #add_new_measure, #clear_all_measures, #get_prefix, #set_measure_argument, #set_measure_path, #set_measure_paths
Constructor Details
#initialize(xml_file_path, output_dir, epw_file_path = nil, standard_to_be_used = ASHRAE90_1, validate_xml_file_against_schema = true) ⇒ Translator
load the building sync file
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/buildingsync/translator.rb', line 58 def initialize(xml_file_path, output_dir, epw_file_path = nil, standard_to_be_used = ASHRAE90_1, validate_xml_file_against_schema = true) @schema_version = nil @xml_file_path = xml_file_path @output_dir = output_dir @standard_to_be_used = standard_to_be_used @epw_path = epw_file_path @results_gathered = false @final_xml_prepared = false # to further reduce the log messages we can change the log level with this command # OpenStudio::Logger.instance.standardOutLogger.setLogLevel(OpenStudio::Error) # Open a log for the library log_file = OpenStudio::FileLogSink.new(OpenStudio::Path.new("#{output_dir}/in.log")) log_file.setLogLevel(OpenStudio::Info) # parse the xml if !File.exist?(xml_file_path) OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Translator.initialize', "File '#{xml_file_path}' does not exist") raise "File '#{xml_file_path}' does not exist" unless File.exist?(xml_file_path) end doc = help_load_doc(xml_file_path) @schema_version = doc.root.attributes['version'] if @schema_version.nil? @schema_version = '2.4.0' end # test for the namespace ns = 'auc' doc.root.namespaces.each_pair do |k, v| ns = k if /bedes-auc/.match(v) end if validate_xml_file_against_schema validate_xml else OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Translator.initialize', "File '#{xml_file_path}' was not validated against the BuildingSync schema version #{@schema_version}") puts "File '#{xml_file_path}' was not validated against the BuildingSync schema version #{@schema_version}" end super(doc, ns) end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
167 168 169 |
# File 'lib/buildingsync/translator.rb', line 167 def doc @doc end |
#final_xml_prepared ⇒ Object
Returns the value of attribute final_xml_prepared.
167 168 169 |
# File 'lib/buildingsync/translator.rb', line 167 def final_xml_prepared @final_xml_prepared end |
#ns ⇒ Object
Returns the value of attribute ns.
167 168 169 |
# File 'lib/buildingsync/translator.rb', line 167 def ns @ns end |
#results_gathered ⇒ Object
Returns the value of attribute results_gathered.
167 168 169 |
# File 'lib/buildingsync/translator.rb', line 167 def results_gathered @results_gathered end |
Instance Method Details
#gather_results(year_val = Date.today.year, baseline_only = false) ⇒ Object
gather results from simulated scenarios, for all or just the baseline scenario
134 135 136 137 |
# File 'lib/buildingsync/translator.rb', line 134 def gather_results(year_val = Date.today.year, baseline_only = false) @results_gathered = true return super(year_val, baseline_only) end |
#prepare_final_xml ⇒ Object
write parameters to xml file
146 147 148 149 150 151 152 153 154 |
# File 'lib/buildingsync/translator.rb', line 146 def prepare_final_xml if @results_gathered super else OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Translator.prepare_final_xml', 'All results have not yet been gathered.') super end @final_xml_prepared = true end |
#run_osws(only_cb_modeled = false, runner_options = { run_simulations: true, verbose: false, num_parallel: 7, max_to_run: Float::INFINITY }) ⇒ Object
run osws - running all scenario simulations
141 142 143 |
# File 'lib/buildingsync/translator.rb', line 141 def run_osws(only_cb_modeled = false, = { run_simulations: true, verbose: false, num_parallel: 7, max_to_run: Float::INFINITY }) super(@output_dir, only_cb_modeled, ) end |
#save_xml(file_name = 'results.xml') ⇒ Object
save xml that includes the results
158 159 160 161 162 163 164 165 |
# File 'lib/buildingsync/translator.rb', line 158 def save_xml(file_name = 'results.xml') output_file = File.join(@output_dir, file_name) if @final_xml_prepared super(output_file) else puts 'Prepare final file before attempting to save (translator.prepare_final_xml)' end end |
#setup_and_sizing_run(ddy_file = nil) ⇒ Object
122 123 124 |
# File 'lib/buildingsync/translator.rb', line 122 def setup_and_sizing_run(ddy_file = nil) super(@output_dir, @epw_path, @standard_to_be_used, ddy_file) end |
#validate_xml ⇒ Object
Validate the xml file against the schema using the SelectionTool
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/buildingsync/translator.rb', line 105 def validate_xml # we wil try to validate the file, but if it fails, we will not cancel the process, but log an error selection_tool = BuildingSync::SelectionTool.new(@xml_file_path, @schema_version) if !selection_tool.validate_schema raise "File '#{@xml_file_path}' does not valid against the BuildingSync schema" else OpenStudio.logFree(OpenStudio::Info, 'BuildingSync.Translator.initialize', "File '#{@xml_file_path}' is valid against the BuildingSync schema version #{@schema_version}") puts "File '#{@xml_file_path}' is valid against the BuildingSync schema" end rescue StandardError => error puts "ERROR: #{error}" OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Translator.initialize', "File '#{@xml_file_path}' does not validate against the BuildingSync schema version #{@schema_version}") end |
#write_osws(only_cb_modeled = false) ⇒ Object
write osws - write all workflows into osw files
127 128 129 |
# File 'lib/buildingsync/translator.rb', line 127 def write_osws(only_cb_modeled = false) super(@output_dir, only_cb_modeled) end |