Class: WorkflowJSON_Shim
- Inherits:
- 
      Object
      
        - Object
- WorkflowJSON_Shim
 
- Defined in:
- lib/openstudio/workflow_json.rb
Overview
WorkflowJSON_Shim provides a shim interface to the WorkflowJSON class in OpenStudio 2.X when running in OpenStudio 1.X
Instance Method Summary collapse
- #absoluteFilePaths ⇒ Object
- #absoluteMeasurePaths ⇒ Object
- #absoluteOutPath ⇒ Object
- #absoluteRootDir ⇒ Object
- #absoluteRunDir ⇒ Object
- #addFilePath(path) ⇒ Object
- #completedStatus ⇒ Object
- 
  
    
      #currentStep  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Get the current step. 
- 
  
    
      #currentStepIndex  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Get the current step index. 
- 
  
    
      #filePaths  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the paths that will be searched in order for files, default value is ‘./files/’. 
- 
  
    
      #findFile(file)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Attempts to find a file by name, searches through filePaths in order and returns first match. 
- 
  
    
      #findMeasure(measureDir)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Attempts to find a measure by name, searches through measurePaths in order and returns first match. 
- 
  
    
      #incrementStep  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Increments current step, returns true if there is another step. 
- 
  
    
      #initialize(workflow, osw_dir)  ⇒ WorkflowJSON_Shim 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of WorkflowJSON_Shim. 
- 
  
    
      #measurePaths  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the paths that will be searched in order for measures, default value is ‘./measures/’. 
- 
  
    
      #oswDir  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the absolute path to the directory this workflow was loaded from or saved to. 
- #outPath ⇒ Object
- #resetFilePaths ⇒ Object
- 
  
    
      #rootDir  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the root directory, default value is ‘.’. 
- 
  
    
      #runDir  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the run directory, default value is ‘./run’. 
- 
  
    
      #runOptions  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    return empty optional. 
- #saveAs(path) ⇒ Object
- 
  
    
      #seedFile  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the seed file path. 
- #setCompletedStatus(status) ⇒ Object
- #setEplusoutErr(eplusout_err) ⇒ Object
- 
  
    
      #start  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Sets the started at time. 
- 
  
    
      #string  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    std::string string(bool includeHash=true) const;. 
- #timeString ⇒ Object
- 
  
    
      #weatherFile  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the weather file path. 
- 
  
    
      #workflowSteps  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the workflow steps. 
Constructor Details
#initialize(workflow, osw_dir) ⇒ WorkflowJSON_Shim
Returns a new instance of WorkflowJSON_Shim.
| 201 202 203 204 205 | # File 'lib/openstudio/workflow_json.rb', line 201 def initialize(workflow, osw_dir) @workflow = workflow @osw_dir = osw_dir @current_step_index = 0 end | 
Instance Method Details
#absoluteFilePaths ⇒ Object
| 330 331 332 333 334 335 336 | # File 'lib/openstudio/workflow_json.rb', line 330 def absoluteFilePaths result = OpenStudio::PathVector.new filePaths.each do |file_path| result << OpenStudio.toPath(File.absolute_path(file_path.to_s, rootDir.to_s)) end result end | 
#absoluteMeasurePaths ⇒ Object
| 391 392 393 394 395 396 397 | # File 'lib/openstudio/workflow_json.rb', line 391 def absoluteMeasurePaths result = OpenStudio::PathVector.new measurePaths.each do |measure_path| result << OpenStudio.toPath(File.absolute_path(measure_path.to_s, rootDir.to_s)) end result end | 
#absoluteOutPath ⇒ Object
| 307 308 309 | # File 'lib/openstudio/workflow_json.rb', line 307 def absoluteOutPath OpenStudio.toPath(File.absolute_path(outPath.to_s, oswDir.to_s)) end | 
#absoluteRootDir ⇒ Object
| 280 281 282 | # File 'lib/openstudio/workflow_json.rb', line 280 def absoluteRootDir OpenStudio.toPath(File.absolute_path(rootDir.to_s, @osw_dir.to_s)) end | 
#absoluteRunDir ⇒ Object
| 295 296 297 | # File 'lib/openstudio/workflow_json.rb', line 295 def absoluteRunDir OpenStudio.toPath(File.absolute_path(runDir.to_s, rootDir.to_s)) end | 
#addFilePath(path) ⇒ Object
| 338 339 340 341 342 343 | # File 'lib/openstudio/workflow_json.rb', line 338 def addFilePath(path) if !@workflow[:file_paths] @workflow[:file_paths] = [] end @workflow[:file_paths] << path end | 
#completedStatus ⇒ Object
| 454 455 456 457 458 459 460 | # File 'lib/openstudio/workflow_json.rb', line 454 def completedStatus if @workflow[:completed_status] Optional_Shim.new(@workflow[:completed_status]) else Optional_Shim.new(nil) end end | 
#currentStep ⇒ Object
Get the current step. boost::optional<WorkflowStep> currentStep() const;
| 246 247 248 249 250 251 252 253 254 | # File 'lib/openstudio/workflow_json.rb', line 246 def currentStep steps = @workflow[:steps] step = nil if @current_step_index < steps.size step = WorkflowStep_Shim.new(steps[@current_step_index]) end return Optional_Shim.new(step) end | 
#currentStepIndex ⇒ Object
Get the current step index.
| 240 241 242 | # File 'lib/openstudio/workflow_json.rb', line 240 def currentStepIndex @current_step_index end | 
#filePaths ⇒ Object
Returns the paths that will be searched in order for files, default value is ‘./files/’. Evaluated relative to rootDir if not absolute. std::vector<openstudio::path> filePaths() const; std::vector<openstudio::path> absoluteFilePaths() const;
| 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | # File 'lib/openstudio/workflow_json.rb', line 314 def filePaths result = OpenStudio::PathVector.new if @workflow[:file_paths] @workflow[:file_paths].each do |file_path| result << OpenStudio.toPath(file_path) end else result << OpenStudio.toPath('./files') result << OpenStudio.toPath('./weather') result << OpenStudio.toPath('../../files') result << OpenStudio.toPath('../../weather') result << OpenStudio.toPath('./') end result end | 
#findFile(file) ⇒ Object
Attempts to find a file by name, searches through filePaths in order and returns first match. boost::optional<openstudio::path> findFile(const openstudio::path& file); boost::optional<openstudio::path> findFile(const std::string& fileName);
| 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | # File 'lib/openstudio/workflow_json.rb', line 352 def findFile(file) file = file.to_s # check if absolute and exists if Pathname.new(file).absolute? if File.exist?(file) return OpenStudio::OptionalPath.new(OpenStudio.toPath(file)) end # absolute path does not exist return OpenStudio::OptionalPath.new end absoluteFilePaths.each do |file_path| result = File.join(file_path.to_s, file) if File.exist?(result) return OpenStudio::OptionalPath.new(OpenStudio.toPath(result)) end end OpenStudio::OptionalPath.new end | 
#findMeasure(measureDir) ⇒ Object
Attempts to find a measure by name, searches through measurePaths in order and returns first match. */ boost::optional<openstudio::path> findMeasure(const openstudio::path& measureDir); boost::optional<openstudio::path> findMeasure(const std::string& measureDirName);
| 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | # File 'lib/openstudio/workflow_json.rb', line 402 def findMeasure(measureDir) measureDir = measureDir.to_s # check if absolute and exists if Pathname.new(measureDir).absolute? if File.exist?(measureDir) return OpenStudio::OptionalPath.new(OpenStudio.toPath(measureDir)) end # absolute path does not exist return OpenStudio::OptionalPath.new end absoluteMeasurePaths.each do |measure_path| result = File.join(measure_path.to_s, measureDir) if File.exist?(result) return OpenStudio::OptionalPath.new(OpenStudio.toPath(result)) end end OpenStudio::OptionalPath.new end | 
#incrementStep ⇒ Object
Increments current step, returns true if there is another step. bool incrementStep();
| 258 259 260 261 262 263 264 265 266 267 | # File 'lib/openstudio/workflow_json.rb', line 258 def incrementStep @current_step_index += 1 @workflow[:current_step] = @current_step_index if @current_step_index < @workflow[:steps].size return true end return false end | 
#measurePaths ⇒ Object
Returns the paths that will be searched in order for measures, default value is ‘./measures/’. Evaluated relative to rootDir if not absolute. std::vector<openstudio::path> measurePaths() const; std::vector<openstudio::path> absoluteMeasurePaths() const;
| 377 378 379 380 381 382 383 384 385 386 387 388 389 | # File 'lib/openstudio/workflow_json.rb', line 377 def measurePaths result = OpenStudio::PathVector.new if @workflow[:measure_paths] @workflow[:measure_paths].each do |measure_path| result << OpenStudio.toPath(measure_path) end else result << OpenStudio.toPath('./measures') result << OpenStudio.toPath('../../measures') result << OpenStudio.toPath('./') end result end | 
#oswDir ⇒ Object
Returns the absolute path to the directory this workflow was loaded from or saved to. Returns current working dir for new WorkflowJSON. openstudio::path oswDir() const;
| 218 219 220 | # File 'lib/openstudio/workflow_json.rb', line 218 def oswDir OpenStudio.toPath(@osw_dir) end | 
#outPath ⇒ Object
| 299 300 301 302 303 304 305 | # File 'lib/openstudio/workflow_json.rb', line 299 def outPath if @workflow[:out_name] OpenStudio.toPath(@workflow[:out_name]) else OpenStudio.toPath('./out.osw') end end | 
#resetFilePaths ⇒ Object
| 345 346 347 | # File 'lib/openstudio/workflow_json.rb', line 345 def resetFilePaths @workflow[:file_paths] = [] end | 
#rootDir ⇒ Object
Returns the root directory, default value is ‘.’. Evaluated relative to oswDir if not absolute. openstudio::path rootDir() const; openstudio::path absoluteRootDir() const;
| 272 273 274 275 276 277 278 | # File 'lib/openstudio/workflow_json.rb', line 272 def rootDir if @workflow[:root_dir] OpenStudio.toPath(@workflow[:root_dir]) else OpenStudio.toPath(@osw_dir) end end | 
#runDir ⇒ Object
Returns the run directory, default value is ‘./run’. Evaluated relative to rootDir if not absolute. openstudio::path runDir() const; openstudio::path absoluteRunDir() const;
| 287 288 289 290 291 292 293 | # File 'lib/openstudio/workflow_json.rb', line 287 def runDir if @workflow[:run_directory] OpenStudio.toPath(@workflow[:run_directory]) else OpenStudio.toPath('./run') end end | 
#runOptions ⇒ Object
return empty optional
| 472 473 474 | # File 'lib/openstudio/workflow_json.rb', line 472 def runOptions return Optional_Shim.new(nil) end | 
#saveAs(path) ⇒ Object
| 222 223 224 225 226 227 228 229 230 231 232 | # File 'lib/openstudio/workflow_json.rb', line 222 def saveAs(path) File.open(path.to_s, 'w') do |f| f << JSON.pretty_generate(@workflow) # make sure data is written to the disk one way or the other begin f.fsync rescue StandardError f.flush end end end | 
#seedFile ⇒ Object
Returns the seed file path. Evaluated relative to filePaths if not absolute. boost::optional<openstudio::path> seedFile() const;
| 426 427 428 429 430 431 432 | # File 'lib/openstudio/workflow_json.rb', line 426 def seedFile result = OpenStudio::OptionalPath.new if @workflow[:seed_file] result = OpenStudio::OptionalPath.new(OpenStudio.toPath(@workflow[:seed_file])) end result end | 
#setCompletedStatus(status) ⇒ Object
| 462 463 464 465 | # File 'lib/openstudio/workflow_json.rb', line 462 def setCompletedStatus(status) @workflow[:completed_status] = status @workflow[:completed_at] = timeString end | 
#setEplusoutErr(eplusout_err) ⇒ Object
| 467 468 469 | # File 'lib/openstudio/workflow_json.rb', line 467 def setEplusoutErr(eplusout_err) @workflow[:eplusout_err] = eplusout_err end | 
#start ⇒ Object
Sets the started at time.
| 235 236 237 | # File 'lib/openstudio/workflow_json.rb', line 235 def start @workflow[:started_at] = timeString end | 
#string ⇒ Object
std::string string(bool includeHash=true) const;
| 208 209 210 | # File 'lib/openstudio/workflow_json.rb', line 208 def string JSON.fast_generate(@workflow) end | 
#timeString ⇒ Object
| 212 213 214 | # File 'lib/openstudio/workflow_json.rb', line 212 def timeString ::Time.now.utc.strftime('%Y%m%dT%H%M%SZ') end | 
#weatherFile ⇒ Object
Returns the weather file path. Evaluated relative to filePaths if not absolute. boost::optional<openstudio::path> weatherFile() const;
| 436 437 438 439 440 441 442 | # File 'lib/openstudio/workflow_json.rb', line 436 def weatherFile result = OpenStudio::OptionalPath.new if @workflow[:weather_file] result = OpenStudio::OptionalPath.new(OpenStudio.toPath(@workflow[:weather_file])) end result end | 
#workflowSteps ⇒ Object
Returns the workflow steps. */ std::vector<WorkflowStep> workflowSteps() const;
| 446 447 448 449 450 451 452 | # File 'lib/openstudio/workflow_json.rb', line 446 def workflowSteps result = [] @workflow[:steps].each do |step| result << WorkflowStep_Shim.new(step) end result end |