openstudio-analysis 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openstudio/analysis/server_api.rb +59 -62
  3. data/lib/openstudio/analysis/translator/excel.rb +186 -189
  4. data/lib/openstudio/analysis/version.rb +1 -1
  5. data/lib/openstudio/helpers/string.rb +4 -5
  6. data/spec/files/analysis/medium_office.json +192 -192
  7. data/spec/files/analysis/medium_office.zip +0 -0
  8. data/spec/files/export/analysis/Kats model v2.json +16 -16
  9. data/spec/files/export/analysis/Kats model v2.zip +0 -0
  10. data/spec/files/export/analysis/discrete_dynamic_seed.json +16 -16
  11. data/spec/files/export/analysis/discrete_dynamic_seed.zip +0 -0
  12. data/spec/files/export/analysis/discrete_seed.json +91 -91
  13. data/spec/files/export/analysis/discrete_seed.zip +0 -0
  14. data/spec/files/export/analysis/output_vars.json +83 -83
  15. data/spec/files/export/analysis/output_vars.zip +0 -0
  16. data/spec/files/export/analysis/small_seed.json +83 -83
  17. data/spec/files/export/analysis/small_seed.zip +0 -0
  18. data/spec/files/measures/IncreaseInsulationRValueForRoofs/measure.rb +372 -375
  19. data/spec/openstudio/analysis/server_api_spec.rb +6 -6
  20. data/spec/openstudio/analysis/translator/excel_spec.rb +182 -188
  21. data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-create-a-new-localhost-instance.65.xml +9 -0
  22. data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-create-a-new-localhost-instance.66.xml +9 -0
  23. data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-create-a-new-localhost-instance.67.xml +9 -0
  24. data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-test-not-localhost.65.xml +9 -0
  25. data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-test-not-localhost.66.xml +9 -0
  26. data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-test-not-localhost.67.xml +9 -0
  27. data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi.65.xml +7 -0
  28. data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi.66.xml +7 -0
  29. data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi.67.xml +7 -0
  30. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-variables.23.xml +18 -0
  31. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-variables.24.xml +18 -0
  32. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-variables.25.xml +18 -0
  33. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-with-dynamic-columns.7.xml +17 -0
  34. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-with-dynamic-columns.8.xml +17 -0
  35. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-with-dynamic-columns.9.xml +17 -0
  36. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-no-variables-defined.65.xml +20 -0
  37. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-no-variables-defined.66.xml +20 -0
  38. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-no-variables-defined.67.xml +20 -0
  39. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup-with-user.31.xml +9 -0
  40. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup-with-user.32.xml +9 -0
  41. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup-with-user.33.xml +9 -0
  42. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup.37.xml +9 -0
  43. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup.38.xml +9 -0
  44. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup.39.xml +9 -0
  45. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-output-variables.17.xml +36 -0
  46. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-output-variables.18.xml +36 -0
  47. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-output-variables.19.xml +36 -0
  48. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-version-0-1-9.14.xml +21 -0
  49. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-version-0-1-9.15.xml +21 -0
  50. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-version-0-1-9.16.xml +21 -0
  51. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-incomplete-variables.65.xml +9 -0
  52. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-incomplete-variables.66.xml +9 -0
  53. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-incomplete-variables.67.xml +9 -0
  54. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables-should-not-validate.65.xml +9 -0
  55. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables-should-not-validate.66.xml +9 -0
  56. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables-should-not-validate.67.xml +9 -0
  57. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables.65.xml +23 -0
  58. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables.66.xml +23 -0
  59. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables.67.xml +23 -0
  60. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-with-with-repeated-variable-names.65.xml +9 -0
  61. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-with-with-repeated-variable-names.66.xml +9 -0
  62. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-with-with-repeated-variable-names.67.xml +9 -0
  63. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-1-10.14.xml +13 -0
  64. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-1-10.15.xml +13 -0
  65. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-1-10.16.xml +13 -0
  66. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0-simple.0.xml +19 -0
  67. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0-simple.1.xml +19 -0
  68. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0-simple.xml +19 -0
  69. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0.0.xml +32 -0
  70. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0.1.xml +32 -0
  71. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0.2.xml +32 -0
  72. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel.65.xml +7 -0
  73. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel.66.xml +7 -0
  74. data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel.67.xml +7 -0
  75. data/spec/spec_helper.rb +1 -3
  76. metadata +127 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d469b01b41e34a2532d51c4fee63d0b8d9ed2f48
4
- data.tar.gz: 4826616b6e98102ecbaba4643189a919d2722f3d
3
+ metadata.gz: 15a5a8290b759332184a73846a76ece6de4f90f3
4
+ data.tar.gz: cd308376243524a8e739758f137859d3cb7d1f85
5
5
  SHA512:
6
- metadata.gz: d4c0ec3e4fd6f679aca4f3dc2ea5b8f573e1bbe47c42077b3281da349893f97bbbefce73b1121ceaee3ac798fad6bde2b9e1104ba729a0c93fd414258dbf0ac5
7
- data.tar.gz: d429af8696a0284fff428f1af84894c95690395af39cbceb6bddb11ef40bf3ccdebe22d1387508aafbb94d807e0f6ef83a7f7fa9f59397e2abd54006ae124834
6
+ metadata.gz: 4312b0092d6c882efeb3b51036af00b391c4d4f1433749a89415574fc0c0b4ee20bcc8999631364e148ab667e684d443faaef67fe00bc2926a75890b798884a3
7
+ data.tar.gz: ebf2b276c50fbd32b5fffc6fb8809fc1f21059724fecb32a9372754d234f972d386c4cf55b7a4b530ee6202dee802d22a9a492376c9d2e62f695d5b03671386e
@@ -1,4 +1,4 @@
1
- # Class manages the communication with the server.
1
+ # Class manages the communication with the server.
2
2
  # Presently, this class is simple and stores all information in hashs
3
3
  module OpenStudio
4
4
  module Analysis
@@ -6,54 +6,54 @@ module OpenStudio
6
6
  attr_reader :hostname
7
7
 
8
8
  def initialize(options = {})
9
- defaults = {:hostname => "http://localhost:8080"}
9
+ defaults = { hostname: 'http://localhost:8080' }
10
10
  options = defaults.merge(options)
11
- @logger = Logger.new("faraday.log")
12
-
11
+ @logger = Logger.new('faraday.log')
12
+
13
13
  @hostname = options[:hostname]
14
14
 
15
- raise "no host defined for server api class" if @hostname.nil?
15
+ fail 'no host defined for server api class' if @hostname.nil?
16
16
 
17
17
  # todo: add support for the proxy
18
-
18
+
19
19
  # create connection with basic capabilities
20
- @conn = Faraday.new(:url => @hostname) do |faraday|
20
+ @conn = Faraday.new(url: @hostname) do |faraday|
21
21
  faraday.request :url_encoded # form-encode POST params
22
22
  faraday.use Faraday::Response::Logger, @logger
23
- #faraday.response @logger # log requests to STDOUT
23
+ # faraday.response @logger # log requests to STDOUT
24
24
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
25
25
  end
26
26
 
27
27
  # create connection to server api with multipart capabilities
28
- @conn_multipart = Faraday.new(:url => @hostname) do |faraday|
28
+ @conn_multipart = Faraday.new(url: @hostname) do |faraday|
29
29
  faraday.request :multipart
30
30
  faraday.request :url_encoded # form-encode POST params
31
31
  faraday.use Faraday::Response::Logger, @logger
32
- #faraday.response :logger # log requests to STDOUT
32
+ # faraday.response :logger # log requests to STDOUT
33
33
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
34
34
  end
35
35
  end
36
36
 
37
- def get_projects()
37
+ def get_projects
38
38
  response = @conn.get '/projects.json'
39
39
 
40
40
  projects_json = nil
41
41
  if response.status == 200
42
- projects_json = JSON.parse(response.body, :symbolize_names => true, :max_nesting => false)
42
+ projects_json = JSON.parse(response.body, symbolize_names: true, max_nesting: false)
43
43
  else
44
- raise "did not receive a 200 in get_projects"
44
+ fail 'did not receive a 200 in get_projects'
45
45
  end
46
46
 
47
47
  projects_json
48
48
  end
49
49
 
50
- def get_project_ids()
51
- ids = get_projects()
50
+ def get_project_ids
51
+ ids = get_projects
52
52
  ids.map { |project| project[:uuid] }
53
53
  end
54
54
 
55
- def delete_all()
56
- ids = get_project_ids()
55
+ def delete_all
56
+ ids = get_project_ids
57
57
  puts "Deleting Projects #{ids}"
58
58
  ids.each do |id|
59
59
  response = @conn.delete "/projects/#{id}.json"
@@ -66,25 +66,26 @@ module OpenStudio
66
66
  end
67
67
 
68
68
  def new_project(options = {})
69
- defaults = {project_name: "project #{(rand()*1000).round}"}
69
+ defaults = { project_name: "Project #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}" }
70
70
  options = defaults.merge(options)
71
71
  project_id = nil
72
72
 
73
- project_hash = {project: {name: "#{options[:project_name]}"}}
73
+ # TODO: make this a display name and a machine name
74
+ project_hash = { project: { name: "#{options[:project_name]}" } }
74
75
 
75
76
  response = @conn.post do |req|
76
- req.url "/projects.json"
77
+ req.url '/projects.json'
77
78
  req.headers['Content-Type'] = 'application/json'
78
79
  req.body = project_hash.to_json
79
80
  end
80
81
 
81
82
  if response.status == 201
82
- project_id = JSON.parse(response.body)["_id"]
83
+ project_id = JSON.parse(response.body)['_id']
83
84
 
84
85
  puts "new project created with ID: #{project_id}"
85
- #grab the project id
86
+ # grab the project id
86
87
  elsif response.status == 500
87
- puts "500 Error"
88
+ puts '500 Error'
88
89
  puts response.inspect
89
90
  end
90
91
 
@@ -95,9 +96,9 @@ module OpenStudio
95
96
  analysis_ids = []
96
97
  response = @conn.get "/projects/#{project_id}.json"
97
98
  if response.status == 200
98
- puts "received the list of analyses for the project"
99
+ puts 'received the list of analyses for the project'
99
100
 
100
- analyses = JSON.parse(response.body, :symbolize_names => true, :max_nesting => false)
101
+ analyses = JSON.parse(response.body, symbolize_names: true, max_nesting: false)
101
102
  if analyses[:analyses]
102
103
  analyses[:analyses].each do |analysis|
103
104
  analysis_ids << analysis[:_id]
@@ -109,14 +110,14 @@ module OpenStudio
109
110
  end
110
111
 
111
112
  def new_analysis(project_id, options)
112
- defaults = {analysis_name: nil, reset_uuids: false}
113
+ defaults = { analysis_name: nil, reset_uuids: false }
113
114
  options = defaults.merge(options)
114
115
 
115
- raise "No project id passed" if project_id.nil?
116
- raise "no formulation passed to new_analysis" if !options[:formulation_file]
117
- raise "No formation exists #{options[:formulation_file]}" if !File.exists?(options[:formulation_file])
116
+ fail 'No project id passed' if project_id.nil?
117
+ fail 'no formulation passed to new_analysis' unless options[:formulation_file]
118
+ fail "No formation exists #{options[:formulation_file]}" unless File.exist?(options[:formulation_file])
118
119
 
119
- formulation_json = JSON.parse(File.read(options[:formulation_file]), :symbolize_names => true)
120
+ formulation_json = JSON.parse(File.read(options[:formulation_file]), symbolize_names: true)
120
121
 
121
122
  # read in the analysis id from the analysis.json file
122
123
  analysis_id = nil
@@ -143,13 +144,13 @@ module OpenStudio
143
144
  else
144
145
  analysis_id = formulation_json[:analysis][:uuid]
145
146
  end
146
- raise "No analysis id defined in analyis.json #{options[:formulation_file]}" if analysis_id.nil?
147
+ fail "No analysis id defined in analyis.json #{options[:formulation_file]}" if analysis_id.nil?
147
148
 
148
149
  # set the analysis name
149
150
  formulation_json[:analysis][:name] = "#{options[:analysis_name]}" unless options[:analysis_name].nil?
150
151
 
151
152
  # save out this file to compare
152
- #File.open('formulation_merge.json', 'w') { |f| f << JSON.pretty_generate(formulation_json) }
153
+ # File.open('formulation_merge.json', 'w') { |f| f << JSON.pretty_generate(formulation_json) }
153
154
 
154
155
  response = @conn.post do |req|
155
156
  req.url "projects/#{project_id}/analyses.json"
@@ -159,25 +160,25 @@ module OpenStudio
159
160
 
160
161
  if response.status == 201
161
162
  puts "asked to create analysis with #{analysis_id}"
162
- #puts resp.inspect
163
- analysis_id = JSON.parse(response.body)["_id"]
163
+ # puts resp.inspect
164
+ analysis_id = JSON.parse(response.body)['_id']
164
165
 
165
166
  puts "new analysis created with ID: #{analysis_id}"
166
167
  else
167
- raise "Could not create new analysis"
168
+ fail 'Could not create new analysis'
168
169
  end
169
170
 
170
171
  # check if we need to upload the analysis zip file
171
172
  if options[:upload_file]
172
- raise "upload file does not exist #{options[:upload_file]}" if !File.exists?(options[:upload_file])
173
+ fail "upload file does not exist #{options[:upload_file]}" unless File.exist?(options[:upload_file])
173
174
 
174
- payload = {:file => Faraday::UploadIO.new(options[:upload_file], 'application/zip')}
175
+ payload = { file: Faraday::UploadIO.new(options[:upload_file], 'application/zip') }
175
176
  response = @conn_multipart.post "analyses/#{analysis_id}/upload.json", payload
176
177
 
177
178
  if response.status == 201
178
- puts "Successfully uploaded ZIP file"
179
+ puts 'Successfully uploaded ZIP file'
179
180
  else
180
- raise response.inspect
181
+ fail response.inspect
181
182
  end
182
183
  end
183
184
 
@@ -185,14 +186,14 @@ module OpenStudio
185
186
  end
186
187
 
187
188
  def upload_datapoint(analysis_id, options)
188
- defaults = {reset_uuids: false}
189
+ defaults = { reset_uuids: false }
189
190
  options = defaults.merge(options)
190
191
 
191
- raise "No analysis id passed" if analysis_id.nil?
192
- raise "No datapoints file passed to new_analysis" if !options[:datapoint_file]
193
- raise "No datapoints_file exists #{options[:datapoint_file]}" if !File.exists?(options[:datapoint_file])
192
+ fail 'No analysis id passed' if analysis_id.nil?
193
+ fail 'No datapoints file passed to new_analysis' unless options[:datapoint_file]
194
+ fail "No datapoints_file exists #{options[:datapoint_file]}" unless File.exist?(options[:datapoint_file])
194
195
 
195
- dp_hash = JSON.parse(File.open(options[:datapoint_file]).read, :symbolize_names => true)
196
+ dp_hash = JSON.parse(File.open(options[:datapoint_file]).read, symbolize_names: true)
196
197
 
197
198
  if options[:reset_uuids]
198
199
  dp_hash[:analysis_uuid] = analysis_id
@@ -209,7 +210,7 @@ module OpenStudio
209
210
  if response.status == 201
210
211
  puts "new datapoints created for analysis #{analysis_id}"
211
212
  else
212
- raise "could not create new datapoints #{response.body}"
213
+ fail "could not create new datapoints #{response.body}"
213
214
  end
214
215
  end
215
216
 
@@ -217,11 +218,11 @@ module OpenStudio
217
218
  defaults = {}
218
219
  options = defaults.merge(options)
219
220
 
220
- raise "No analysis id passed" if analysis_id.nil?
221
- raise "No datapoints file passed to new_analysis" if !options[:datapoints_file]
222
- raise "No datapoints_file exists #{options[:datapoints_file]}" if !File.exists?(options[:datapoints_file])
221
+ fail 'No analysis id passed' if analysis_id.nil?
222
+ fail 'No datapoints file passed to new_analysis' unless options[:datapoints_file]
223
+ fail "No datapoints_file exists #{options[:datapoints_file]}" unless File.exist?(options[:datapoints_file])
223
224
 
224
- dp_hash = JSON.parse(File.open(options[:datapoints_file]).read, :symbolize_names => true)
225
+ dp_hash = JSON.parse(File.open(options[:datapoints_file]).read, symbolize_names: true)
225
226
 
226
227
  # merge in the analysis_id as it has to be what is in the database
227
228
  response = @conn.post do |req|
@@ -233,12 +234,12 @@ module OpenStudio
233
234
  if response.status == 201
234
235
  puts "new datapoints created for analysis #{analysis_id}"
235
236
  else
236
- raise "could not create new datapoints #{response.body}"
237
+ fail "could not create new datapoints #{response.body}"
237
238
  end
238
239
  end
239
240
 
240
241
  def run_analysis(analysis_id, options)
241
- defaults = {analysis_action: "start", without_delay: false}
242
+ defaults = { analysis_action: 'start', without_delay: false }
242
243
  options = defaults.merge(options)
243
244
 
244
245
  puts "Run analysis is configured with #{options.to_json}"
@@ -246,18 +247,18 @@ module OpenStudio
246
247
  req.url "analyses/#{analysis_id}/action.json"
247
248
  req.headers['Content-Type'] = 'application/json'
248
249
  req.body = options.to_json
249
- req.options[:timeout] = 1800 #seconds
250
+ req.options[:timeout] = 1800 # seconds
250
251
  end
251
252
 
252
253
  if response.status == 200
253
254
  puts "Recieved request to run analysis #{analysis_id}"
254
255
  else
255
- raise "Could not start the analysis"
256
+ fail 'Could not start the analysis'
256
257
  end
257
258
  end
258
259
 
259
260
  def kill_analysis(analysis_id)
260
- analysis_action = {analysis_action: "stop"}
261
+ analysis_action = { analysis_action: 'stop' }
261
262
 
262
263
  response = @conn.post do |req|
263
264
  req.url "analyses/#{analysis_id}/action.json"
@@ -268,9 +269,8 @@ module OpenStudio
268
269
  if response.status == 200
269
270
  puts "Killed analysis #{analysis_id}"
270
271
  else
271
- #raise "Could not kill the analysis with response of #{response.inspect}"
272
+ # raise "Could not kill the analysis with response of #{response.inspect}"
272
273
  end
273
-
274
274
  end
275
275
 
276
276
  def kill_all_analyses
@@ -287,21 +287,18 @@ module OpenStudio
287
287
  end
288
288
  end
289
289
 
290
-
291
290
  def get_datapoint_status(analysis_id, filter = nil)
292
291
  # get the status of all the entire analysis
293
- if !analysis_id.nil?
294
- if filter.nil? || filter == ""
292
+ unless analysis_id.nil?
293
+ if filter.nil? || filter == ''
295
294
  resp = @conn.get "analyses/#{analysis_id}/status.json"
296
295
  puts "Data points (all): #{resp}"
297
296
  else
298
- resp = @conn.get "#{@hostname}/analyses/#{analysis_id}/status.json", {jobs: filter}
297
+ resp = @conn.get "#{@hostname}/analyses/#{analysis_id}/status.json", jobs: filter
299
298
  puts "Data points (#{filter}): #{resp}"
300
299
  end
301
300
  end
302
301
  end
303
-
304
302
  end
305
303
  end
306
-
307
304
  end