Class: OpenStudio::Workflow::InputAdapter::Local
- Inherits:
-
Object
- Object
- OpenStudio::Workflow::InputAdapter::Local
- Defined in:
- lib/openstudio/workflow/adapters/input/local.rb
Instance Method Summary collapse
-
#analysis ⇒ Object
Get the associated OSA (analysis) definition from the local filesystem.
- #cleanup(user_options, default) ⇒ Object
-
#datapoint ⇒ Object
Get the associated OSD (datapoint) file from the local filesystem.
- #debug(user_options, default) ⇒ Object
- #energyplus_path(user_options, default) ⇒ Object
-
#initialize(osw_path = './workflow.osw') ⇒ Local
constructor
A new instance of Local.
- #jobs(user_options, default, logger) ⇒ Object
-
#osw_dir ⇒ Object
Get the OSW dir.
-
#osw_path ⇒ Object
Get the OSW path.
- #output_adapter(user_options, default, logger) ⇒ Object
- #preserve_run_dir(user_options, default) ⇒ Object
- #profile(user_options, default) ⇒ Object
-
#run_dir ⇒ Object
Get the run dir.
- #verify_osw(user_options, default) ⇒ Object
- #weather_file(user_options, default) ⇒ Object
-
#workflow ⇒ Object
Get the OSW file from the local filesystem.
Constructor Details
#initialize(osw_path = './workflow.osw') ⇒ Local
Returns a new instance of Local.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 27 def initialize(osw_path = './workflow.osw') @osw_abs_path = File.absolute_path(osw_path, Dir.pwd) @workflow = nil if File.exist? @osw_abs_path @workflow = ::JSON.parse(File.read(@osw_abs_path), symbolize_names: true) end @workflow_json = nil @run_options = nil if @workflow begin # Create a temporary WorkflowJSON, will not be same one used in registry during simulation @workflow_json = OpenStudio::WorkflowJSON.new(JSON.fast_generate(workflow)) @workflow_json.setOswDir(osw_dir) rescue NameError => e @workflow_json = WorkflowJSON_Shim.new(workflow, osw_dir) end begin @run_options = @workflow_json.runOptions rescue end end end |
Instance Method Details
#analysis ⇒ Object
Get the associated OSA (analysis) definition from the local filesystem
229 230 231 232 233 234 235 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 229 def analysis # DLM: should this come from the OSW? the osd id and checksum are specified there. osa_abs_path = File.join(osw_dir, '../analysis.json') if File.exist? osa_abs_path ::JSON.parse(File.read(osa_abs_path), symbolize_names: true) end end |
#cleanup(user_options, default) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 167 def cleanup(, default) # user option trumps all others return [:cleanup] if [:cleanup] # try to read from OSW if @run_options && !@run_options.empty? return @run_options.get.cleanup end return default end |
#datapoint ⇒ Object
Get the associated OSD (datapoint) file from the local filesystem
219 220 221 222 223 224 225 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 219 def datapoint # DLM: should this come from the OSW? the osd id and checksum are specified there. osd_abs_path = File.join(osw_dir, 'datapoint.osd') if File.exist? osd_abs_path ::JSON.parse(File.read(osd_abs_path), symbolize_names: true) end end |
#debug(user_options, default) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 141 def debug(, default) # user option trumps all others return [:debug] if [:debug] # try to read from OSW if @run_options && !@run_options.empty? return @run_options.get.debug end return default end |
#energyplus_path(user_options, default) ⇒ Object
180 181 182 183 184 185 186 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 180 def energyplus_path(, default) # user option trumps all others return [:energyplus_path] if [:energyplus_path] return default end |
#jobs(user_options, default, logger) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 126 def jobs(, default, logger) # user option trumps all others return [:jobs] if [:jobs] # try to read from OSW begin #log_message = "Reading custom job states from OSW is not currently supported'" #logger.info log_message rescue end return default end |
#osw_dir ⇒ Object
Get the OSW dir
68 69 70 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 68 def osw_dir File.dirname(@osw_abs_path) end |
#osw_path ⇒ Object
Get the OSW path
62 63 64 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 62 def osw_path @osw_abs_path end |
#output_adapter(user_options, default, logger) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 85 def output_adapter(, default, logger) # user option trumps all others return [:output_adapter] if [:output_adapter] # try to read from OSW if @run_options && !@run_options.empty? custom_adapter = @run_options.get.customOutputAdapter if !custom_adapter.empty? begin custom_file_name = custom_adapter.get.customFileName class_name = custom_adapter.get.className = ::JSON.parse(custom_adapter.get., :symbolize_names => true) # merge with user options, user options will replace options loaded from OSW .merge!() # stick output_directory in options [:output_directory] = run_dir p = @workflow_json.findFile(custom_file_name) if !p.empty? load(p.get.to_s) output_adapter = eval("#{class_name}.new(options)") return output_adapter else = "Failed to load custom adapter file '#{custom_file_name}'" logger.error raise end rescue = "Failed to load custom adapter '#{class_name}' from file '#{custom_file_name}'" logger.error raise end end end return default end |
#preserve_run_dir(user_options, default) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 154 def preserve_run_dir(, default) # user option trumps all others return [:preserve_run_dir] if [:preserve_run_dir] # try to read from OSW if @run_options && !@run_options.empty? return @run_options.get.preserveRunDir end return default end |
#profile(user_options, default) ⇒ Object
188 189 190 191 192 193 194 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 188 def profile(, default) # user option trumps all others return [:profile] if [:profile] return default end |
#run_dir ⇒ Object
Get the run dir
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 74 def run_dir result = File.join(osw_dir, 'run') if @workflow_json begin result = @workflow_json.absoluteRunDir.to_s rescue end end result end |
#verify_osw(user_options, default) ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 196 def verify_osw(, default) # user option trumps all others return [:verify_osw] if [:verify_osw] return default end |
#weather_file(user_options, default) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 204 def weather_file(, default) # user option trumps all others return [:weather_file] if [:weather_file] # try to read from OSW if !@workflow_json.weatherFile.empty? return @workflow_json.weatherFile.get.to_s end return default end |
#workflow ⇒ Object
Get the OSW file from the local filesystem
55 56 57 58 |
# File 'lib/openstudio/workflow/adapters/input/local.rb', line 55 def workflow raise "Could not read workflow from #{@osw_abs_path}" if @workflow.nil? @workflow end |