openstudio-analysis 1.0.0.rc19 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.gitlab-ci.yml +20 -0
  4. data/.rubocop.yml +2 -133
  5. data/.travis.yml +2 -2
  6. data/CHANGELOG.md +26 -32
  7. data/Gemfile +5 -6
  8. data/LICENSE.md +28 -0
  9. data/README.md +16 -8
  10. data/Rakefile +38 -3
  11. data/lib/openstudio-analysis.rb +35 -0
  12. data/lib/openstudio/analysis.rb +57 -26
  13. data/lib/openstudio/analysis/algorithm_attributes.rb +36 -1
  14. data/lib/openstudio/analysis/formulation.rb +41 -6
  15. data/lib/openstudio/analysis/server_api.rb +53 -36
  16. data/lib/openstudio/analysis/support_files.rb +40 -0
  17. data/lib/openstudio/analysis/translator/datapoints.rb +39 -4
  18. data/lib/openstudio/analysis/translator/excel.rb +43 -8
  19. data/lib/openstudio/analysis/translator/workflow.rb +54 -14
  20. data/lib/openstudio/analysis/version.rb +36 -1
  21. data/lib/openstudio/analysis/workflow.rb +37 -2
  22. data/lib/openstudio/analysis/workflow_step.rb +97 -70
  23. data/lib/openstudio/helpers/hash.rb +35 -0
  24. data/lib/openstudio/helpers/string.rb +36 -2
  25. data/lib/openstudio/weather/epw.rb +32 -17
  26. data/openstudio-analysis.gemspec +21 -18
  27. data/update_license.rb +120 -0
  28. metadata +62 -200
  29. data/LGPL-2.1.txt +0 -502
  30. data/LICENSE.txt +0 -65
  31. data/rubocop-todo.yml +0 -246
  32. data/spec/files/0_1_09_no_variables.xlsx +0 -0
  33. data/spec/files/0_1_09_outputvars.xlsx +0 -0
  34. data/spec/files/0_1_09_setup_version_2.xlsx +0 -0
  35. data/spec/files/0_1_09_small_list.xlsx +0 -0
  36. data/spec/files/0_1_09_small_list_incomplete.xlsx +0 -0
  37. data/spec/files/0_1_09_small_list_repeat_vars.xlsx +0 -0
  38. data/spec/files/0_1_09_small_list_validation_errors.xlsx +0 -0
  39. data/spec/files/0_1_10_proxy.xlsx +0 -0
  40. data/spec/files/0_1_10_proxy_user.xlsx +0 -0
  41. data/spec/files/0_1_10_template_input.xlsx +0 -0
  42. data/spec/files/0_1_11_discrete_variables.xlsx +0 -0
  43. data/spec/files/0_1_12_discrete_dynamic_columns.xlsx +0 -0
  44. data/spec/files/0_2_0_template.xlsx +0 -0
  45. data/spec/files/0_2_0_template_simpletest.xlsx +0 -0
  46. data/spec/files/0_3_0_dynamic_uuids.xlsx +0 -0
  47. data/spec/files/0_3_0_measure_existence.xlsx +0 -0
  48. data/spec/files/0_3_0_outputs.xlsx +0 -0
  49. data/spec/files/0_3_3_short_names.xlsx +0 -0
  50. data/spec/files/0_3_5_multiple_measure_paths.xlsx +0 -0
  51. data/spec/files/0_3_7_unique_measure_names.xlsx +0 -0
  52. data/spec/files/0_3_7_worker_init_final.xlsx +0 -0
  53. data/spec/files/0_4_0_lhs_discrete_continuous.xlsx +0 -0
  54. data/spec/files/0_4_0_multiple_seeds.xlsx +0 -0
  55. data/spec/files/0_4_0_pivot_test.xlsx +0 -0
  56. data/spec/files/analysis/examples/discrete_lhs_example.json +0 -809
  57. data/spec/files/analysis/examples/medium_office_example.json +0 -1673
  58. data/spec/files/analysis/examples/medium_office_workflow.json +0 -1298
  59. data/spec/files/measures/ActualMeasureNoJson/measure.rb +0 -80
  60. data/spec/files/measures/ActualMeasureNoJson/measure.xml +0 -2
  61. data/spec/files/measures/ExampleMeasure/measure.json +0 -3
  62. data/spec/files/measures/ExampleMeasure/measure.rb +0 -5
  63. data/spec/files/measures/ExampleMeasure/measure.xml +0 -1
  64. data/spec/files/measures/IncreaseInsulationRValueForRoofs/measure.json +0 -36
  65. data/spec/files/measures/IncreaseInsulationRValueForRoofs/measure.rb +0 -22
  66. data/spec/files/measures/IncreaseInsulationRValueForRoofs/measure.xml +0 -5
  67. data/spec/files/measures/NoMeasureRbFile/.gitkeep +0 -0
  68. data/spec/files/measures/ReduceLightingLoadsByPercentage/measure.json +0 -3
  69. data/spec/files/measures/ReduceLightingLoadsByPercentage/measure.rb +0 -5
  70. data/spec/files/measures/ReduceLightingLoadsByPercentage/measure.xml +0 -1
  71. data/spec/files/measures/SetThermostatSchedules/measure.json +0 -63
  72. data/spec/files/measures/SetThermostatSchedules/measure.rb +0 -254
  73. data/spec/files/measures/SetThermostatSchedules/measure.xml +0 -2
  74. data/spec/files/measures/example_measure_auto_directory_name/measure.json +0 -3
  75. data/spec/files/measures/example_measure_auto_directory_name/measure.rb +0 -5
  76. data/spec/files/measures/example_measure_auto_directory_name/measure.xml +0 -1
  77. data/spec/files/measures/reduce_lighting_loads_by_percentage/measure.json +0 -3
  78. data/spec/files/measures/reduce_lighting_loads_by_percentage/measure.rb +0 -5
  79. data/spec/files/measures/reduce_lighting_loads_by_percentage/measure.xml +0 -1
  80. data/spec/files/measures/reduce_space_infiltration_by_percentage/measure.rb +0 -5
  81. data/spec/files/measures/reduce_space_infiltration_by_percentage/measure.xml +0 -1
  82. data/spec/files/measures/rotate_building/measure.rb +0 -5
  83. data/spec/files/measures/rotate_building/measure.xml +0 -1
  84. data/spec/files/measures/set_window_to_wall_ratio_by_facade/measure.rb +0 -5
  85. data/spec/files/measures/set_window_to_wall_ratio_by_facade/measure.xml +0 -1
  86. data/spec/files/measures_second_path/measure_in_another_dir/measure.json +0 -3
  87. data/spec/files/measures_second_path/measure_in_another_dir/measure.rb +0 -5
  88. data/spec/files/measures_second_path/measure_in_another_dir/measure.xml +0 -1
  89. data/spec/files/partial_weather.epw +0 -32
  90. data/spec/files/partial_weather_2.epw +0 -32
  91. data/spec/files/small_seed.osm +0 -4622
  92. data/spec/files/worker_init/first_file.rb +0 -15
  93. data/spec/files/worker_init/second_file.rb +0 -15
  94. data/spec/files/workflow/analysis.osa +0 -1334
  95. data/spec/files/workflow/datapoint_0.osd +0 -65
  96. data/spec/files/workflow/datapoint_1.osd +0 -65
  97. data/spec/files/workflow/datapoint_2.osd +0 -65
  98. data/spec/files/workflow/datapoint_wrong_osa_id.osd +0 -65
  99. data/spec/integration/server_api_spec.rb +0 -48
  100. data/spec/openstudio/excel_spec.rb +0 -571
  101. data/spec/openstudio/formulation_spec.rb +0 -157
  102. data/spec/openstudio/hash_spec.rb +0 -21
  103. data/spec/openstudio/osw_spec.rb +0 -94
  104. data/spec/openstudio/server_api_spec.rb +0 -25
  105. data/spec/openstudio/string_spec.rb +0 -0
  106. data/spec/openstudio/support_files_spec.rb +0 -54
  107. data/spec/openstudio/weather_spec.rb +0 -45
  108. data/spec/openstudio/workflow_spec.rb +0 -91
  109. data/spec/openstudio/workflow_step_spec.rb +0 -118
  110. data/spec/schema/osa.json +0 -613
  111. data/spec/schema/osa.png +0 -0
  112. data/spec/schema/osd.json +0 -110
  113. data/spec/schema/osd.png +0 -0
  114. data/spec/spec_helper.rb +0 -19
@@ -1,3 +1,38 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
1
36
  # OpenStudio::Analysis Module instantiates versions of formulations
2
37
  module OpenStudio
3
38
  module Analysis
@@ -95,35 +130,31 @@ module OpenStudio
95
130
  new_wfi[:description] = wf[:description] if wf[:description]
96
131
  new_wfi[:arguments] = []
97
132
 
98
- if wf[:arguments]
99
- wf[:arguments].each do |arg|
100
- wfi_arg = {}
101
- wfi_arg[:display_name] = arg[:display_name] if arg[:display_name]
102
- wfi_arg[:display_name_short] = arg[:display_name_short] if arg[:display_name_short]
103
- wfi_arg[:name] = arg[:name] if arg[:name]
104
- wfi_arg[:data_type] = arg[:value_type] if arg[:value_type]
105
- wfi_arg[:default_value] = nil
106
- wfi_arg[:description] = ''
107
- wfi_arg[:display_units] = '' # should be haystack compatible unit strings
108
- wfi_arg[:units] = '' # should be haystack compatible unit strings
133
+ wf[:arguments]&.each do |arg|
134
+ wfi_arg = {}
135
+ wfi_arg[:display_name] = arg[:display_name] if arg[:display_name]
136
+ wfi_arg[:display_name_short] = arg[:display_name_short] if arg[:display_name_short]
137
+ wfi_arg[:name] = arg[:name] if arg[:name]
138
+ wfi_arg[:data_type] = arg[:value_type] if arg[:value_type]
139
+ wfi_arg[:default_value] = nil
140
+ wfi_arg[:description] = ''
141
+ wfi_arg[:display_units] = '' # should be haystack compatible unit strings
142
+ wfi_arg[:units] = '' # should be haystack compatible unit strings
109
143
 
110
- new_wfi[:arguments] << wfi_arg
111
- end
144
+ new_wfi[:arguments] << wfi_arg
112
145
  end
113
146
 
114
- if wf[:variables]
115
- wf[:variables].each do |arg|
116
- wfi_var = {}
117
- wfi_var[:display_name] = arg[:argument][:display_name] if arg[:argument][:display_name]
118
- wfi_var[:display_name_short] = arg[:argument][:display_name_short] if arg[:argument][:display_name_short]
119
- wfi_var[:name] = arg[:argument][:name] if arg[:argument][:name]
120
- wfi_var[:default_value] = nil
121
- wfi_var[:data_type] = arg[:argument][:value_type] if arg[:argument][:value_type]
122
- wfi_var[:description] = ''
123
- wfi_var[:display_units] = arg[:units] if arg[:units]
124
- wfi_var[:units] = '' # should be haystack compatible unit strings
125
- new_wfi[:arguments] << wfi_var
126
- end
147
+ wf[:variables]&.each do |arg|
148
+ wfi_var = {}
149
+ wfi_var[:display_name] = arg[:argument][:display_name] if arg[:argument][:display_name]
150
+ wfi_var[:display_name_short] = arg[:argument][:display_name_short] if arg[:argument][:display_name_short]
151
+ wfi_var[:name] = arg[:argument][:name] if arg[:argument][:name]
152
+ wfi_var[:default_value] = nil
153
+ wfi_var[:data_type] = arg[:argument][:value_type] if arg[:argument][:value_type]
154
+ wfi_var[:description] = ''
155
+ wfi_var[:display_units] = arg[:units] if arg[:units]
156
+ wfi_var[:units] = '' # should be haystack compatible unit strings
157
+ new_wfi[:arguments] << wfi_var
127
158
  end
128
159
 
129
160
  measure_metadata << new_wfi
@@ -1,3 +1,38 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
1
36
  # OpenStudio::Analysis::Algorithm define the algorithm parameters. The module and class names start to conflict
2
37
  # with OpenStudio's namespace. Be careful adding new classes without first making sure that the namespace conflict
3
38
  # is clear.
@@ -13,7 +48,7 @@ module OpenStudio
13
48
  def set_attribute(attribute_name, attribute_value)
14
49
  @attributes[attribute_name] = attribute_value
15
50
  begin
16
- if Float(attribute_value) != nil
51
+ unless Float(attribute_value).nil?
17
52
  if Float(attribute_value).abs >= Float('1.0e+19')
18
53
  raise "ERROR: Attribute `#{attribute_name}` is greater than 1E19. This may cause failures."
19
54
  end
@@ -1,3 +1,38 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
1
36
  # OpenStudio formulation class handles the generation of the OpenStudio Analysis format.
2
37
  module OpenStudio
3
38
  module Analysis
@@ -164,9 +199,9 @@ module OpenStudio
164
199
  wf = nil
165
200
  if @weather_file[:file]
166
201
  wf = @weather_file
167
- elsif @weather_files.size > 0
202
+ elsif !@weather_files.empty?
168
203
  # get the first EPW file (not the first file)
169
- wf = @weather_files.find { |w| File.extname(w[:file]).downcase == '.epw' }
204
+ wf = @weather_files.find { |w| File.extname(w[:file]).casecmp('.epw').zero? }
170
205
  end
171
206
 
172
207
  if wf
@@ -349,13 +384,13 @@ module OpenStudio
349
384
  @worker_inits.each_with_index do |f, index|
350
385
  ordered_file_name = "#{index.to_s.rjust(2, '0')}_#{File.basename(f[:file])}"
351
386
  puts " Adding #{f[:file]} as #{ordered_file_name}"
352
- zf.add(f[:file].sub(f[:file], "./lib/worker_initialize/#{ordered_file_name}"), f[:file])
387
+ zf.add(f[:file].sub(f[:file], "./scripts/worker_initialization//#{ordered_file_name}"), f[:file])
353
388
 
354
389
  if f[:metadata][:args]
355
390
  arg_file = "#{File.basename(ordered_file_name, '.*')}.args"
356
391
  file = Tempfile.new('arg')
357
392
  file.write(f[:metadata][:args])
358
- zf.add("./lib/worker_initialize/#{arg_file}", file)
393
+ zf.add("./scripts/worker_initialization/#{arg_file}", file)
359
394
  file.close
360
395
  end
361
396
  end
@@ -364,13 +399,13 @@ module OpenStudio
364
399
  @worker_finalizes.each_with_index do |f, index|
365
400
  ordered_file_name = "#{index.to_s.rjust(2, '0')}_#{File.basename(f[:file])}"
366
401
  puts " Adding #{f[:file]} as #{ordered_file_name}"
367
- zf.add(f[:file].sub(f[:file], "./lib/worker_finalize/#{ordered_file_name}"), f[:file])
402
+ zf.add(f[:file].sub(f[:file], "./scripts/worker_finalization/#{ordered_file_name}"), f[:file])
368
403
 
369
404
  if f[:metadata][:args]
370
405
  arg_file = "#{File.basename(ordered_file_name, '.*')}.args"
371
406
  file = Tempfile.new('arg')
372
407
  file.write(f[:metadata][:args])
373
- zf.add("./lib/worker_finalize/#{arg_file}", file)
408
+ zf.add("./scripts/worker_finalization/#{arg_file}", file)
374
409
  file.close
375
410
  end
376
411
  end
@@ -1,3 +1,38 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
1
36
  # Class manages the communication with the server.
2
37
  # Presently, this class is simple and stores all information in hashs
3
38
  module OpenStudio
@@ -6,16 +41,16 @@ module OpenStudio
6
41
  attr_reader :hostname
7
42
 
8
43
  # Define set of anlaysis methods require batch_run to be queued after them
9
- BATCH_RUN_METHODS = %w(lhs preflight single_run repeat_run doe diag baseline_perturbation batch_datapoints).freeze
44
+ BATCH_RUN_METHODS = ['lhs', 'preflight', 'single_run', 'repeat_run', 'doe', 'diag', 'baseline_perturbation', 'batch_datapoints'].freeze
10
45
 
11
46
  def initialize(options = {})
12
47
  defaults = { hostname: 'http://localhost:8080', log_path: File.expand_path('~/os_server_api.log') }
13
48
  options = defaults.merge(options)
14
- if ENV['OS_SERVER_LOG_PATH']
49
+ if ENV['OS_SERVER_LOG_PATH']
15
50
  @logger = ::Logger.new(ENV['OS_SERVER_LOG_PATH'] + '/os_server_api.log')
16
51
  else
17
52
  @logger = ::Logger.new(options[:log_path])
18
- end
53
+ end
19
54
 
20
55
  @hostname = options[:hostname]
21
56
 
@@ -117,10 +152,8 @@ module OpenStudio
117
152
  response = @conn.get "/projects/#{project_id}.json"
118
153
  if response.status == 200
119
154
  analyses = JSON.parse(response.body, symbolize_names: true, max_nesting: false)
120
- if analyses[:analyses]
121
- analyses[:analyses].each do |analysis|
122
- analysis_ids << analysis[:_id]
123
- end
155
+ analyses[:analyses]&.each do |analysis|
156
+ analysis_ids << analysis[:_id]
124
157
  end
125
158
  end
126
159
 
@@ -209,11 +242,8 @@ module OpenStudio
209
242
  j = JSON.parse resp.body, symbolize_names: true
210
243
  status = j if j
211
244
  end
212
-
213
245
  rescue Faraday::ConnectionFailed
214
-
215
246
  rescue Net::ReadTimeout
216
-
217
247
  end
218
248
 
219
249
  status
@@ -340,11 +370,12 @@ module OpenStudio
340
370
  [downloaded, file_path_and_name]
341
371
  end
342
372
 
343
- def download_datapoint_reports(datapoint_id, save_directory = '.')
373
+ # http://localhost:3000/data_points/ff857845-a4c6-4eb9-a52b-cbc6a41976d5/download_result_file?filename=
374
+ def download_datapoint_report(datapoint_id, report_name, save_directory = '.')
344
375
  downloaded = false
345
376
  file_path_and_name = nil
346
377
 
347
- response = @conn.get "/data_points/#{datapoint_id}/download_reports"
378
+ response = @conn.get "/data_points/#{datapoint_id}/download_result_file?filename=#{report_name}"
348
379
  if response.status == 200
349
380
  filename = response['content-disposition'].match(/filename=(\"?)(.+)\1/)[2]
350
381
  downloaded = true
@@ -356,16 +387,6 @@ module OpenStudio
356
387
  [downloaded, file_path_and_name]
357
388
  end
358
389
 
359
- def download_datapoints_reports(analysis_id, save_directory = '.')
360
- # get the list of all the datapoints
361
- dps = get_datapoint_status(analysis_id)
362
- dps.each do |dp|
363
- if dp[:status] == 'completed'
364
- download_datapoint_reports(dp[:_id], save_directory)
365
- end
366
- end
367
- end
368
-
369
390
  def download_datapoint_jsons(analysis_id, save_directory = '.')
370
391
  # get the list of all the datapoints
371
392
  dps = get_datapoint_status(analysis_id)
@@ -444,16 +465,12 @@ module OpenStudio
444
465
 
445
466
  formulation_json[:analysis][:problem][:workflow].each do |wf|
446
467
  wf[:uuid] = SecureRandom.uuid
447
- if wf[:arguments]
448
- wf[:arguments].each do |arg|
449
- arg[:uuid] = SecureRandom.uuid
450
- end
468
+ wf[:arguments]&.each do |arg|
469
+ arg[:uuid] = SecureRandom.uuid
451
470
  end
452
- if wf[:variables]
453
- wf[:variables].each do |var|
454
- var[:uuid] = SecureRandom.uuid
455
- var[:argument][:uuid] = SecureRandom.uuid if var[:argument]
456
- end
471
+ wf[:variables]&.each do |var|
472
+ var[:uuid] = SecureRandom.uuid
473
+ var[:argument][:uuid] = SecureRandom.uuid if var[:argument]
457
474
  end
458
475
  end
459
476
  else
@@ -555,7 +572,7 @@ module OpenStudio
555
572
  upload = conn.load_analysis 'dencity_analysis.json'
556
573
  begin
557
574
  upload_response = upload.push
558
- rescue => e
575
+ rescue StandardError => e
559
576
  runner.registerError("Upload failure: #{e.message} in #{e.backtrace.join('/n')}")
560
577
  else
561
578
  if NoMethodError == upload_response.class
@@ -762,12 +779,12 @@ module OpenStudio
762
779
  # @option options [String] :run_data_point_filename Name of ruby file that the server runs -- will be deprecated
763
780
  # @option options [String] :push_to_dencity Whether or not to push to DEnCity
764
781
  # @option options [String] :batch_run_method Which batch run method to use (batch_run or batch_run_local [no R])
765
- def run(formulation_filename, analysis_zip_filename, analysis_type,
766
- options = {})
782
+ def run(formulation_filename, analysis_zip_filename, analysis_type, options = {})
767
783
  defaults = {
768
784
  run_data_point_filename: 'run_openstudio_workflow_monthly.rb',
769
785
  push_to_dencity: false,
770
- batch_run_method: 'batch_run'
786
+ batch_run_method: 'batch_run',
787
+ without_delay: false
771
788
  }
772
789
  options = defaults.merge(options)
773
790
 
@@ -785,7 +802,7 @@ module OpenStudio
785
802
 
786
803
  run_options = {
787
804
  analysis_action: 'start',
788
- without_delay: false,
805
+ without_delay: options[:without_delay],
789
806
  analysis_type: analysis_type,
790
807
  simulate_data_point_filename: 'simulate_data_point.rb', # TODO: remove these from server?
791
808
  run_data_point_filename: options[:run_data_point_filename]
@@ -1,3 +1,38 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
1
36
  # OpenStudio::Analysis::SupportFiles is a container to hold other analysis files that may need to be packaged.
2
37
  # The most common use of support files are weather files, design day files, multiple seed files, worker initialization
3
38
  # scripts, worker finalization scripts, and general libraries
@@ -12,6 +47,11 @@ module OpenStudio
12
47
  @files = []
13
48
  end
14
49
 
50
+ # Check if the array is empty
51
+ def empty?
52
+ @files.empty?
53
+ end
54
+
15
55
  # Add a file to the support file list
16
56
  #
17
57
  # @param path_or_filename [String] Full path of the file to be added.
@@ -1,3 +1,38 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
1
36
  module OpenStudio
2
37
  module Analysis
3
38
  module Translator
@@ -155,7 +190,7 @@ module OpenStudio
155
190
  # @append_model_name [Boolean] Append the name of the seed model to the display name
156
191
  # @return [Object] An OpenStudio::Analysis
157
192
  def analysis(seed_model = nil, append_model_name = false)
158
- raise 'There are no seed models defined in the excel file. Please add one.' if @models.size == 0
193
+ raise 'There are no seed models defined in the excel file. Please add one.' if @models.empty?
159
194
  raise 'There are more than one seed models defined in the excel file. This is not supported by the CSV Translator.' if @models.size > 1 && seed_model.nil?
160
195
 
161
196
  seed_model = @models.first if seed_model.nil?
@@ -315,7 +350,7 @@ module OpenStudio
315
350
 
316
351
  def parse_csv_measures(measure_rows)
317
352
  # Build metadata required for parsing
318
- measures = measure_rows[0].uniq.select { |measure| !measure.nil? }.map(&:to_sym)
353
+ measures = measure_rows[0].uniq.reject(&:nil?).map(&:to_sym)
319
354
  measure_map = {}
320
355
  measure_var_list = []
321
356
  measures.each do |measure|
@@ -383,12 +418,12 @@ module OpenStudio
383
418
  var_hash[:distribution] = {}
384
419
  case var_hash[:type].downcase
385
420
  when 'bool', 'boolean'
386
- var_hash[:distribution][:values] = (3..(measure_rows.length - 1)).map { |value| measure_rows[value.to_i][measure_map[measure][var]].to_s.downcase == 'true' }
421
+ var_hash[:distribution][:values] = (3..(measure_rows.length - 1)).map { |value| measure_rows[value.to_i][measure_map[measure][var]].to_s.casecmp('true').zero? }
387
422
  var_hash[:distribution][:maximum] = true
388
423
  var_hash[:distribution][:minimum] = false
389
424
  var_hash[:distribution][:mode] = var_hash[:distribution][:values].group_by { |i| i }.max { |x, y| x[1].length <=> y[1].length }[0]
390
425
  when 'choice', 'string'
391
- var_hash[:distribution][:values] = (3..(measure_rows.length) - 1).map { |value| measure_rows[value.to_i][measure_map[measure][var]].to_s }
426
+ var_hash[:distribution][:values] = (3..measure_rows.length - 1).map { |value| measure_rows[value.to_i][measure_map[measure][var]].to_s }
392
427
  var_hash[:distribution][:minimum] = var_hash[:distribution][:values].min
393
428
  var_hash[:distribution][:maximum] = var_hash[:distribution][:values].max
394
429
  var_hash[:distribution][:mode] = var_hash[:distribution][:values].group_by { |i| i }.max { |x, y| x[1].length <=> y[1].length }[0]