openstudio-workflow 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +72 -72
  3. data/README.md +48 -48
  4. data/Rakefile +36 -36
  5. data/lib/openstudio/workflow/adapters/input/local.rb +240 -240
  6. data/lib/openstudio/workflow/adapters/output/local.rb +95 -95
  7. data/lib/openstudio/workflow/adapters/output/socket.rb +91 -91
  8. data/lib/openstudio/workflow/adapters/output/web.rb +66 -66
  9. data/lib/openstudio/workflow/adapters/output_adapter.rb +147 -147
  10. data/lib/openstudio/workflow/job.rb +22 -22
  11. data/lib/openstudio/workflow/jobs/resources/monthly_report.idf +222 -222
  12. data/lib/openstudio/workflow/jobs/run_energyplus.rb +49 -49
  13. data/lib/openstudio/workflow/jobs/run_ep_measures.rb +55 -55
  14. data/lib/openstudio/workflow/jobs/run_initialization.rb +167 -167
  15. data/lib/openstudio/workflow/jobs/run_os_measures.rb +69 -69
  16. data/lib/openstudio/workflow/jobs/run_postprocess.rb +53 -53
  17. data/lib/openstudio/workflow/jobs/run_preprocess.rb +69 -69
  18. data/lib/openstudio/workflow/jobs/run_reporting_measures.rb +98 -98
  19. data/lib/openstudio/workflow/jobs/run_translation.rb +61 -61
  20. data/lib/openstudio/workflow/multi_delegator.rb +46 -46
  21. data/lib/openstudio/workflow/registry.rb +137 -137
  22. data/lib/openstudio/workflow/run.rb +299 -299
  23. data/lib/openstudio/workflow/time_logger.rb +53 -53
  24. data/lib/openstudio/workflow/util/energyplus.rb +564 -564
  25. data/lib/openstudio/workflow/util/io.rb +33 -33
  26. data/lib/openstudio/workflow/util/measure.rb +588 -586
  27. data/lib/openstudio/workflow/util/model.rb +100 -100
  28. data/lib/openstudio/workflow/util/post_process.rb +187 -187
  29. data/lib/openstudio/workflow/util/weather_file.rb +108 -108
  30. data/lib/openstudio/workflow/util.rb +14 -14
  31. data/lib/openstudio/workflow/version.rb +24 -24
  32. data/lib/openstudio/workflow_json.rb +426 -426
  33. data/lib/openstudio/workflow_runner.rb +215 -215
  34. data/lib/openstudio-workflow.rb +49 -49
  35. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9b4f0394bca6c06758fcaa8151bc70d06166656
4
- data.tar.gz: 9052de122a97f74fd6d4aa573f31d14ee921709d
3
+ metadata.gz: 5ceb6100a442d5a16d724f51f956162ca46b38d6
4
+ data.tar.gz: aab8fbae2a4edab82eaea83f6ebd00d330339c0e
5
5
  SHA512:
6
- metadata.gz: 6d946e5188f54cedf4e8d1dd8bf9f1bfc93a3443fd34623dd51abedf432162e036e9bcf86fc2f79a9cddd0a2d94d88c91e6f6ce8f5edc5afad31345dc8fac0e1
7
- data.tar.gz: d42e9fafcbf20d01b4d74281861678593993263fe72f626681993e0a03ff2bca9106d26dca24ffc34cb8b5d7940c52e60c0b06ac75b5a6c68f24b50310c299a5
6
+ metadata.gz: a7d08630608ae324fe3b816b8af27571ee243062976c6c97780cd089670305a806ad3c81295f9ddeba84d636138c88a264557bb0f031dfd80090209b641927d2
7
+ data.tar.gz: 8bbab1896284b8bf7957b382932d83677576ae74208196622b56ce61b9d262ed225eec39078dff18217e5414f43da64f82ae41280eed0a49ff578acaa8130336
data/CHANGELOG.md CHANGED
@@ -1,72 +1,72 @@
1
- OpenStudio::Workflow Change Log
2
- ==================================
3
-
4
- Version '1.0.0-rc1' (Not released)
5
- -------------------
6
- * Use specific version of OpenStudio Analysis Gem
7
- * Fix tests
8
- * Remove to_underscore method (use OpenStudio.toUnderscoreCase(...) if needed)
9
-
10
- Version '1.0.0-alpha.0'
11
- -----------------------
12
- * Support new workflow for PAT 2.0. Many of these changes are breaking changes
13
- * Remove rake from gemspec
14
- * Update rubyzip to version 1.2
15
-
16
- Version 0.2.0
17
- ------------------
18
- * Use EnergyPlus that is packaged with OpenStudio. The branch of this repo is no longer tied to the version of EnergyPlus
19
- * Update find_energyplus to use new OpenStudio method instead of RUBYLIB env var
20
- * Update dependencies
21
- * Support tests running on Docker
22
- * Skip the PAT tests for now since they are broken
23
- * Remove snake_case method as it conflicts with another libraries method, now called to_underscore
24
- * Add test for persisting JSONs as reports. Rename reports in the form of <measure_name_underscored>_<report_name>.<ext>
25
- * Always add in Monthly Reports (Deprecate the :run_monthly_reports option)
26
- * Remove the old Standard Reports and use the version in the OpenStudio Release (along with the calibration report)
27
-
28
- Version 0.1.1
29
- ------------------
30
- * Catch exception when loading a measure file.
31
- * Enable running simulations on windows and mac
32
- * Use rubyzip gem instead of system call
33
- * Fix the double directory which caused the zip files to behave strangely on windows
34
- * New find_energyplus method which tries to use OpenStudio's version of EnergyPlus
35
- * Copy all EnergyPlus files into run directory
36
- * Better cleanup after EnergyPlus simulation
37
- * Read machine information from /etc/openstudio-server directory, if available
38
-
39
- Version 0.1.0
40
- -------------
41
- * Tests for programmatically creating the analysis.json files from the OpenStudio-analysis-gem
42
- * Upgrade to EnergyPlus 8.2. Right now the run energyplus and run runmanager job hard code these paths.
43
- * Upgrade and fix Facter facts to grab the correct ip address when running on EC2
44
-
45
- Version 0.0.4
46
- -------------
47
- * Include rubyXL gem for reading/writing MS Excel files
48
- * Remove invalid characters from OpenStudio Measure Attributes. /[|!@#\$%^&\*\(\)\{\}\\\[\]|;:'",<.>\/?\+=]+/
49
- * Fix objective functions to read from any of the results hash, not just the standard report legacy
50
- * Add time logger and reporting measure
51
-
52
- Version 0.0.3
53
- --------------
54
- * Allow measures to set weather file in a measure and have it update what EnergyPlus uses for the weather file.
55
- * OpenStudio::Workflow.run_energyplus method added to just run energyplus.
56
- * Remove AASM (act as state machine) and replace with simple tracking of the state. Interface is the same except there is now no need to pass in the States.
57
- * Catch EnergyPlus errors (non-zero exits), Fatal Errors in eplusout.err, and invalid weather files.
58
- * Force UTF-8 version upon reading the eplusout.err file
59
-
60
- Version 0.0.2
61
- --------------
62
-
63
- * Support reporting measures
64
- * Reduce logging messages
65
- * Keep IDF files
66
- * Remove mtr and eso files after simulation completes
67
- * If measure changes weather file, then use the new weather file with the analysis.json weather path
68
-
69
- Version 0.0.1
70
- --------------
71
-
72
- * Initial release with basic workflow implemented to support running OpenStudio measure-based workflows
1
+ OpenStudio::Workflow Change Log
2
+ ==================================
3
+
4
+ Version '1.0.0-rc1' (Not released)
5
+ -------------------
6
+ * Use specific version of OpenStudio Analysis Gem
7
+ * Fix tests
8
+ * Remove to_underscore method (use OpenStudio.toUnderscoreCase(...) if needed)
9
+
10
+ Version '1.0.0-alpha.0'
11
+ -----------------------
12
+ * Support new workflow for PAT 2.0. Many of these changes are breaking changes
13
+ * Remove rake from gemspec
14
+ * Update rubyzip to version 1.2
15
+
16
+ Version 0.2.0
17
+ ------------------
18
+ * Use EnergyPlus that is packaged with OpenStudio. The branch of this repo is no longer tied to the version of EnergyPlus
19
+ * Update find_energyplus to use new OpenStudio method instead of RUBYLIB env var
20
+ * Update dependencies
21
+ * Support tests running on Docker
22
+ * Skip the PAT tests for now since they are broken
23
+ * Remove snake_case method as it conflicts with another libraries method, now called to_underscore
24
+ * Add test for persisting JSONs as reports. Rename reports in the form of <measure_name_underscored>_<report_name>.<ext>
25
+ * Always add in Monthly Reports (Deprecate the :run_monthly_reports option)
26
+ * Remove the old Standard Reports and use the version in the OpenStudio Release (along with the calibration report)
27
+
28
+ Version 0.1.1
29
+ ------------------
30
+ * Catch exception when loading a measure file.
31
+ * Enable running simulations on windows and mac
32
+ * Use rubyzip gem instead of system call
33
+ * Fix the double directory which caused the zip files to behave strangely on windows
34
+ * New find_energyplus method which tries to use OpenStudio's version of EnergyPlus
35
+ * Copy all EnergyPlus files into run directory
36
+ * Better cleanup after EnergyPlus simulation
37
+ * Read machine information from /etc/openstudio-server directory, if available
38
+
39
+ Version 0.1.0
40
+ -------------
41
+ * Tests for programmatically creating the analysis.json files from the OpenStudio-analysis-gem
42
+ * Upgrade to EnergyPlus 8.2. Right now the run energyplus and run runmanager job hard code these paths.
43
+ * Upgrade and fix Facter facts to grab the correct ip address when running on EC2
44
+
45
+ Version 0.0.4
46
+ -------------
47
+ * Include rubyXL gem for reading/writing MS Excel files
48
+ * Remove invalid characters from OpenStudio Measure Attributes. /[|!@#\$%^&\*\(\)\{\}\\\[\]|;:'",<.>\/?\+=]+/
49
+ * Fix objective functions to read from any of the results hash, not just the standard report legacy
50
+ * Add time logger and reporting measure
51
+
52
+ Version 0.0.3
53
+ --------------
54
+ * Allow measures to set weather file in a measure and have it update what EnergyPlus uses for the weather file.
55
+ * OpenStudio::Workflow.run_energyplus method added to just run energyplus.
56
+ * Remove AASM (act as state machine) and replace with simple tracking of the state. Interface is the same except there is now no need to pass in the States.
57
+ * Catch EnergyPlus errors (non-zero exits), Fatal Errors in eplusout.err, and invalid weather files.
58
+ * Force UTF-8 version upon reading the eplusout.err file
59
+
60
+ Version 0.0.2
61
+ --------------
62
+
63
+ * Support reporting measures
64
+ * Reduce logging messages
65
+ * Keep IDF files
66
+ * Remove mtr and eso files after simulation completes
67
+ * If measure changes weather file, then use the new weather file with the analysis.json weather path
68
+
69
+ Version 0.0.1
70
+ --------------
71
+
72
+ * Initial release with basic workflow implemented to support running OpenStudio measure-based workflows
data/README.md CHANGED
@@ -1,48 +1,48 @@
1
- # OpenStudio::Workflow
2
- [![Circle CI](https://circleci.com/gh/NREL/OpenStudio-workflow-gem/tree/osw.svg?style=svg)](https://circleci.com/gh/NREL/OpenStudio-workflow-gem/tree/osw)
3
- [![Coverage Status](https://coveralls.io/repos/NREL/OpenStudio-workflow-gem/badge.svg?branch=osw&service=github)](https://coveralls.io/github/NREL/OpenStudio-workflow-gem?branch=osw)
4
-
5
- ## OpenStudio Workflow branch
6
-
7
- This branch is the development branch for the OpenStudio 2.0 workflow gem. This will become the primary branch when OpenStudio 2.0 is released.
8
-
9
- ## Caveats and Todos
10
-
11
- ### Todos
12
-
13
- * Find a better home for monthly_reports.idf
14
- * Fix issues around where standard reports and calibration reports run (and make them optional enabled)
15
- * Move registry into the WorkflowRunner class; this includes logging
16
- * Add a test to ensure that the models being returned contain alterations after apply_measure
17
- * Add unit tests for each util method
18
- * Clean up log messages (and code flow) for @current_state in run.rb
19
- * Define and document the complete set of options for the adapter and run classes
20
- * Implement better error handling with custom exception classes
21
- * Add a results adapter to return a string as the last call based on the source of the call. (e.g. R, command line, C++, etc).
22
-
23
- ## Testing
24
-
25
- The preferred way for testing is to run rspec either natively or via docker. The issue with natively running the tests locally is the requirement to have mongo installed and running.
26
-
27
- ### Locally
28
-
29
- ```
30
- rspec spec/
31
- ```
32
-
33
- ### Docker
34
-
35
- ```
36
- export OPENSTUDIO_VERSION=1.13.0
37
- docker run -v $(pwd):/var/simdata/openstudio \
38
- nrel/openstudio:$OPENSTUDIO_VERSION \
39
- /var/simdata/openstudio/test/bin/docker-run.sh
40
- ```
41
-
42
- ## Contributing
43
-
44
- 1. Fork it ( https://github.com/NREL/OpenStudio-workflow/fork )
45
- 2. Create your feature branch (`git checkout -b my-new-feature`)
46
- 3. Commit your changes (`git commit -am 'Add some feature'`)
47
- 4. Push to the branch (`git push origin my-new-feature`)
48
- 5. Create a new Pull Request
1
+ # OpenStudio::Workflow
2
+ [![Circle CI](https://circleci.com/gh/NREL/OpenStudio-workflow-gem/tree/osw.svg?style=svg)](https://circleci.com/gh/NREL/OpenStudio-workflow-gem/tree/osw)
3
+ [![Coverage Status](https://coveralls.io/repos/NREL/OpenStudio-workflow-gem/badge.svg?branch=osw&service=github)](https://coveralls.io/github/NREL/OpenStudio-workflow-gem?branch=osw)
4
+
5
+ ## OpenStudio Workflow branch
6
+
7
+ This branch is the development branch for the OpenStudio 2.0 workflow gem. This will become the primary branch when OpenStudio 2.0 is released.
8
+
9
+ ## Caveats and Todos
10
+
11
+ ### Todos
12
+
13
+ * Find a better home for monthly_reports.idf
14
+ * Fix issues around where standard reports and calibration reports run (and make them optional enabled)
15
+ * Move registry into the WorkflowRunner class; this includes logging
16
+ * Add a test to ensure that the models being returned contain alterations after apply_measure
17
+ * Add unit tests for each util method
18
+ * Clean up log messages (and code flow) for @current_state in run.rb
19
+ * Define and document the complete set of options for the adapter and run classes
20
+ * Implement better error handling with custom exception classes
21
+ * Add a results adapter to return a string as the last call based on the source of the call. (e.g. R, command line, C++, etc).
22
+
23
+ ## Testing
24
+
25
+ The preferred way for testing is to run rspec either natively or via docker. The issue with natively running the tests locally is the requirement to have mongo installed and running.
26
+
27
+ ### Locally
28
+
29
+ ```
30
+ rspec spec/
31
+ ```
32
+
33
+ ### Docker
34
+
35
+ ```
36
+ export OPENSTUDIO_VERSION=1.13.0
37
+ docker run -v $(pwd):/var/simdata/openstudio \
38
+ nrel/openstudio:$OPENSTUDIO_VERSION \
39
+ /var/simdata/openstudio/test/bin/docker-run.sh
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/NREL/OpenStudio-workflow/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,36 +1,36 @@
1
- require 'bundler'
2
- Bundler.setup
3
-
4
- require 'rspec/core/rake_task'
5
-
6
- # Always create spec reports
7
- require 'ci/reporter/rake/rspec'
8
-
9
- # Gem tasks
10
- require 'bundler/gem_tasks'
11
-
12
- RSpec::Core::RakeTask.new('spec:unit') do |spec|
13
- spec.rspec_opts = %w(--format progress --format CI::Reporter::RSpec)
14
- spec.pattern = FileList['spec/**/*_spec.rb']
15
- end
16
-
17
- task 'spec:unit' => 'ci:setup:rspec'
18
- task default: 'spec:unit'
19
-
20
- require 'rubocop/rake_task'
21
- desc 'Run RuboCop on the lib directory'
22
- RuboCop::RakeTask.new(:rubocop) do |task|
23
- task.options = ['--no-color', '--out=rubocop-results.xml']
24
- task.formatters = ['RuboCop::Formatter::CheckstyleFormatter']
25
- task.requires = ['rubocop/formatter/checkstyle_formatter']
26
- # don't abort rake on failure
27
- task.fail_on_error = false
28
- end
29
-
30
- require 'openstudio-workflow'
31
- desc 'test extracting zip'
32
- task :test_zip do
33
- f = File.join(File.dirname(__FILE__), 'spec/files/example_models/the_project.zip')
34
- puts "Trying to extract #{f}"
35
- OpenStudio::Workflow.extract_archive(f, 'junk_out', true)
36
- end
1
+ require 'bundler'
2
+ Bundler.setup
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ # Always create spec reports
7
+ require 'ci/reporter/rake/rspec'
8
+
9
+ # Gem tasks
10
+ require 'bundler/gem_tasks'
11
+
12
+ RSpec::Core::RakeTask.new('spec:unit') do |spec|
13
+ spec.rspec_opts = %w(--format progress --format CI::Reporter::RSpec)
14
+ spec.pattern = FileList['spec/**/*_spec.rb']
15
+ end
16
+
17
+ task 'spec:unit' => 'ci:setup:rspec'
18
+ task default: 'spec:unit'
19
+
20
+ require 'rubocop/rake_task'
21
+ desc 'Run RuboCop on the lib directory'
22
+ RuboCop::RakeTask.new(:rubocop) do |task|
23
+ task.options = ['--no-color', '--out=rubocop-results.xml']
24
+ task.formatters = ['RuboCop::Formatter::CheckstyleFormatter']
25
+ task.requires = ['rubocop/formatter/checkstyle_formatter']
26
+ # don't abort rake on failure
27
+ task.fail_on_error = false
28
+ end
29
+
30
+ require 'openstudio-workflow'
31
+ desc 'test extracting zip'
32
+ task :test_zip do
33
+ f = File.join(File.dirname(__FILE__), 'spec/files/example_models/the_project.zip')
34
+ puts "Trying to extract #{f}"
35
+ OpenStudio::Workflow.extract_archive(f, 'junk_out', true)
36
+ end
@@ -1,240 +1,240 @@
1
- ######################################################################
2
- # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
- # All rights reserved.
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- ######################################################################
19
-
20
- require 'openstudio/workflow_json'
21
-
22
- # Local file based workflow
23
- module OpenStudio
24
- module Workflow
25
- module InputAdapter
26
- class Local
27
- def initialize(osw_path = './workflow.osw')
28
- @osw_abs_path = File.absolute_path(osw_path, Dir.pwd)
29
-
30
- @workflow = nil
31
- if File.exist? @osw_abs_path
32
- @workflow = ::JSON.parse(File.read(@osw_abs_path), symbolize_names: true)
33
- end
34
-
35
- @workflow_json = nil
36
- @run_options = nil
37
- if @workflow
38
- begin
39
- # Create a temporary WorkflowJSON, will not be same one used in registry during simulation
40
- @workflow_json = OpenStudio::WorkflowJSON.new(JSON.fast_generate(workflow))
41
- @workflow_json.setOswDir(osw_dir)
42
- rescue NameError => e
43
- @workflow_json = WorkflowJSON_Shim.new(workflow, osw_dir)
44
- end
45
-
46
- begin
47
- @run_options = @workflow_json.runOptions
48
- rescue
49
- end
50
- end
51
- end
52
-
53
- # Get the OSW file from the local filesystem
54
- #
55
- def workflow
56
- raise "Could not read workflow from #{@osw_abs_path}" if @workflow.nil?
57
- @workflow
58
- end
59
-
60
- # Get the OSW path
61
- #
62
- def osw_path
63
- @osw_abs_path
64
- end
65
-
66
- # Get the OSW dir
67
- #
68
- def osw_dir
69
- File.dirname(@osw_abs_path)
70
- end
71
-
72
- # Get the run dir
73
- #
74
- def run_dir
75
- result = File.join(osw_dir, 'run')
76
- if @workflow_json
77
- begin
78
- result = @workflow_json.absoluteRunDir.to_s
79
- rescue
80
- end
81
- end
82
- result
83
- end
84
-
85
- def output_adapter(user_options, default, logger)
86
-
87
- # user option trumps all others
88
- return user_options[:output_adapter] if user_options[:output_adapter]
89
-
90
- # try to read from OSW
91
- if @run_options && !@run_options.empty?
92
- custom_adapter = @run_options.get.customOutputAdapter
93
- if !custom_adapter.empty?
94
- begin
95
- custom_file_name = custom_adapter.get.customFileName
96
- class_name = custom_adapter.get.className
97
- options = ::JSON.parse(custom_adapter.get.options, :symbolize_names => true)
98
-
99
- # merge with user options, user options will replace options loaded from OSW
100
- options.merge!(user_options)
101
-
102
- # stick output_directory in options
103
- options[:output_directory] = run_dir
104
-
105
- p = @workflow_json.findFile(custom_file_name)
106
- if !p.empty?
107
- load(p.get.to_s)
108
- output_adapter = eval("#{class_name}.new(options)")
109
- return output_adapter
110
- else
111
- log_message = "Failed to load custom adapter file '#{custom_file_name}'"
112
- logger.error log_message
113
- raise log_message
114
- end
115
- rescue
116
- log_message = "Failed to load custom adapter '#{class_name}' from file '#{custom_file_name}'"
117
- logger.error log_message
118
- raise log_message
119
- end
120
- end
121
- end
122
-
123
- return default
124
- end
125
-
126
- def jobs(user_options, default, logger)
127
-
128
- # user option trumps all others
129
- return user_options[:jobs] if user_options[:jobs]
130
-
131
- # try to read from OSW
132
- begin
133
- #log_message = "Reading custom job states from OSW is not currently supported'"
134
- #logger.info log_message
135
- rescue
136
- end
137
-
138
- return default
139
- end
140
-
141
- def debug(user_options, default)
142
-
143
- # user option trumps all others
144
- return user_options[:debug] if user_options[:debug]
145
-
146
- # try to read from OSW
147
- if @run_options && !@run_options.empty?
148
- return @run_options.get.debug
149
- end
150
-
151
- return default
152
- end
153
-
154
- def preserve_run_dir(user_options, default)
155
-
156
- # user option trumps all others
157
- return user_options[:preserve_run_dir] if user_options[:preserve_run_dir]
158
-
159
- # try to read from OSW
160
- if @run_options && !@run_options.empty?
161
- return @run_options.get.preserveRunDir
162
- end
163
-
164
- return default
165
- end
166
-
167
- def cleanup(user_options, default)
168
-
169
- # user option trumps all others
170
- return user_options[:cleanup] if user_options[:cleanup]
171
-
172
- # try to read from OSW
173
- if @run_options && !@run_options.empty?
174
- return @run_options.get.cleanup
175
- end
176
-
177
- return default
178
- end
179
-
180
- def energyplus_path(user_options, default)
181
-
182
- # user option trumps all others
183
- return user_options[:energyplus_path] if user_options[:energyplus_path]
184
-
185
- return default
186
- end
187
-
188
- def profile(user_options, default)
189
-
190
- # user option trumps all others
191
- return user_options[:profile] if user_options[:profile]
192
-
193
- return default
194
- end
195
-
196
- def verify_osw(user_options, default)
197
-
198
- # user option trumps all others
199
- return user_options[:verify_osw] if user_options[:verify_osw]
200
-
201
- return default
202
- end
203
-
204
- def weather_file(user_options, default)
205
-
206
- # user option trumps all others
207
- return user_options[:weather_file] if user_options[:weather_file]
208
-
209
- # try to read from OSW
210
- if !@workflow_json.weatherFile.empty?
211
- return @workflow_json.weatherFile.get.to_s
212
- end
213
-
214
- return default
215
- end
216
-
217
- # Get the associated OSD (datapoint) file from the local filesystem
218
- #
219
- def datapoint
220
- # DLM: should this come from the OSW? the osd id and checksum are specified there.
221
- osd_abs_path = File.join(osw_dir, 'datapoint.osd')
222
- if File.exist? osd_abs_path
223
- ::JSON.parse(File.read(osd_abs_path), symbolize_names: true)
224
- end
225
- end
226
-
227
- # Get the associated OSA (analysis) definition from the local filesystem
228
- #
229
- def analysis
230
- # DLM: should this come from the OSW? the osd id and checksum are specified there.
231
- osa_abs_path = File.join(osw_dir, '../analysis.json')
232
- if File.exist? osa_abs_path
233
- ::JSON.parse(File.read(osa_abs_path), symbolize_names: true)
234
- end
235
- end
236
-
237
- end
238
- end
239
- end
240
- end
1
+ ######################################################################
2
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
+ # All rights reserved.
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ ######################################################################
19
+
20
+ require 'openstudio/workflow_json'
21
+
22
+ # Local file based workflow
23
+ module OpenStudio
24
+ module Workflow
25
+ module InputAdapter
26
+ class Local
27
+ def initialize(osw_path = './workflow.osw')
28
+ @osw_abs_path = File.absolute_path(osw_path, Dir.pwd)
29
+
30
+ @workflow = nil
31
+ if File.exist? @osw_abs_path
32
+ @workflow = ::JSON.parse(File.read(@osw_abs_path), symbolize_names: true)
33
+ end
34
+
35
+ @workflow_json = nil
36
+ @run_options = nil
37
+ if @workflow
38
+ begin
39
+ # Create a temporary WorkflowJSON, will not be same one used in registry during simulation
40
+ @workflow_json = OpenStudio::WorkflowJSON.new(JSON.fast_generate(workflow))
41
+ @workflow_json.setOswDir(osw_dir)
42
+ rescue NameError => e
43
+ @workflow_json = WorkflowJSON_Shim.new(workflow, osw_dir)
44
+ end
45
+
46
+ begin
47
+ @run_options = @workflow_json.runOptions
48
+ rescue
49
+ end
50
+ end
51
+ end
52
+
53
+ # Get the OSW file from the local filesystem
54
+ #
55
+ def workflow
56
+ raise "Could not read workflow from #{@osw_abs_path}" if @workflow.nil?
57
+ @workflow
58
+ end
59
+
60
+ # Get the OSW path
61
+ #
62
+ def osw_path
63
+ @osw_abs_path
64
+ end
65
+
66
+ # Get the OSW dir
67
+ #
68
+ def osw_dir
69
+ File.dirname(@osw_abs_path)
70
+ end
71
+
72
+ # Get the run dir
73
+ #
74
+ def run_dir
75
+ result = File.join(osw_dir, 'run')
76
+ if @workflow_json
77
+ begin
78
+ result = @workflow_json.absoluteRunDir.to_s
79
+ rescue
80
+ end
81
+ end
82
+ result
83
+ end
84
+
85
+ def output_adapter(user_options, default, logger)
86
+
87
+ # user option trumps all others
88
+ return user_options[:output_adapter] if user_options[:output_adapter]
89
+
90
+ # try to read from OSW
91
+ if @run_options && !@run_options.empty?
92
+ custom_adapter = @run_options.get.customOutputAdapter
93
+ if !custom_adapter.empty?
94
+ begin
95
+ custom_file_name = custom_adapter.get.customFileName
96
+ class_name = custom_adapter.get.className
97
+ options = ::JSON.parse(custom_adapter.get.options, :symbolize_names => true)
98
+
99
+ # merge with user options, user options will replace options loaded from OSW
100
+ options.merge!(user_options)
101
+
102
+ # stick output_directory in options
103
+ options[:output_directory] = run_dir
104
+
105
+ p = @workflow_json.findFile(custom_file_name)
106
+ if !p.empty?
107
+ load(p.get.to_s)
108
+ output_adapter = eval("#{class_name}.new(options)")
109
+ return output_adapter
110
+ else
111
+ log_message = "Failed to load custom adapter file '#{custom_file_name}'"
112
+ logger.error log_message
113
+ raise log_message
114
+ end
115
+ rescue
116
+ log_message = "Failed to load custom adapter '#{class_name}' from file '#{custom_file_name}'"
117
+ logger.error log_message
118
+ raise log_message
119
+ end
120
+ end
121
+ end
122
+
123
+ return default
124
+ end
125
+
126
+ def jobs(user_options, default, logger)
127
+
128
+ # user option trumps all others
129
+ return user_options[:jobs] if user_options[:jobs]
130
+
131
+ # try to read from OSW
132
+ begin
133
+ #log_message = "Reading custom job states from OSW is not currently supported'"
134
+ #logger.info log_message
135
+ rescue
136
+ end
137
+
138
+ return default
139
+ end
140
+
141
+ def debug(user_options, default)
142
+
143
+ # user option trumps all others
144
+ return user_options[:debug] if user_options[:debug]
145
+
146
+ # try to read from OSW
147
+ if @run_options && !@run_options.empty?
148
+ return @run_options.get.debug
149
+ end
150
+
151
+ return default
152
+ end
153
+
154
+ def preserve_run_dir(user_options, default)
155
+
156
+ # user option trumps all others
157
+ return user_options[:preserve_run_dir] if user_options[:preserve_run_dir]
158
+
159
+ # try to read from OSW
160
+ if @run_options && !@run_options.empty?
161
+ return @run_options.get.preserveRunDir
162
+ end
163
+
164
+ return default
165
+ end
166
+
167
+ def cleanup(user_options, default)
168
+
169
+ # user option trumps all others
170
+ return user_options[:cleanup] if user_options[:cleanup]
171
+
172
+ # try to read from OSW
173
+ if @run_options && !@run_options.empty?
174
+ return @run_options.get.cleanup
175
+ end
176
+
177
+ return default
178
+ end
179
+
180
+ def energyplus_path(user_options, default)
181
+
182
+ # user option trumps all others
183
+ return user_options[:energyplus_path] if user_options[:energyplus_path]
184
+
185
+ return default
186
+ end
187
+
188
+ def profile(user_options, default)
189
+
190
+ # user option trumps all others
191
+ return user_options[:profile] if user_options[:profile]
192
+
193
+ return default
194
+ end
195
+
196
+ def verify_osw(user_options, default)
197
+
198
+ # user option trumps all others
199
+ return user_options[:verify_osw] if user_options[:verify_osw]
200
+
201
+ return default
202
+ end
203
+
204
+ def weather_file(user_options, default)
205
+
206
+ # user option trumps all others
207
+ return user_options[:weather_file] if user_options[:weather_file]
208
+
209
+ # try to read from OSW
210
+ if !@workflow_json.weatherFile.empty?
211
+ return @workflow_json.weatherFile.get.to_s
212
+ end
213
+
214
+ return default
215
+ end
216
+
217
+ # Get the associated OSD (datapoint) file from the local filesystem
218
+ #
219
+ def datapoint
220
+ # DLM: should this come from the OSW? the osd id and checksum are specified there.
221
+ osd_abs_path = File.join(osw_dir, 'datapoint.osd')
222
+ if File.exist? osd_abs_path
223
+ ::JSON.parse(File.read(osd_abs_path), symbolize_names: true)
224
+ end
225
+ end
226
+
227
+ # Get the associated OSA (analysis) definition from the local filesystem
228
+ #
229
+ def analysis
230
+ # DLM: should this come from the OSW? the osd id and checksum are specified there.
231
+ osa_abs_path = File.join(osw_dir, '../analysis.json')
232
+ if File.exist? osa_abs_path
233
+ ::JSON.parse(File.read(osa_abs_path), symbolize_names: true)
234
+ end
235
+ end
236
+
237
+ end
238
+ end
239
+ end
240
+ end