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.
- checksums.yaml +4 -4
- data/lib/openstudio/analysis/server_api.rb +59 -62
- data/lib/openstudio/analysis/translator/excel.rb +186 -189
- data/lib/openstudio/analysis/version.rb +1 -1
- data/lib/openstudio/helpers/string.rb +4 -5
- data/spec/files/analysis/medium_office.json +192 -192
- data/spec/files/analysis/medium_office.zip +0 -0
- data/spec/files/export/analysis/Kats model v2.json +16 -16
- data/spec/files/export/analysis/Kats model v2.zip +0 -0
- data/spec/files/export/analysis/discrete_dynamic_seed.json +16 -16
- data/spec/files/export/analysis/discrete_dynamic_seed.zip +0 -0
- data/spec/files/export/analysis/discrete_seed.json +91 -91
- data/spec/files/export/analysis/discrete_seed.zip +0 -0
- data/spec/files/export/analysis/output_vars.json +83 -83
- data/spec/files/export/analysis/output_vars.zip +0 -0
- data/spec/files/export/analysis/small_seed.json +83 -83
- data/spec/files/export/analysis/small_seed.zip +0 -0
- data/spec/files/measures/IncreaseInsulationRValueForRoofs/measure.rb +372 -375
- data/spec/openstudio/analysis/server_api_spec.rb +6 -6
- data/spec/openstudio/analysis/translator/excel_spec.rb +182 -188
- data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-create-a-new-localhost-instance.65.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-create-a-new-localhost-instance.66.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-create-a-new-localhost-instance.67.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-test-not-localhost.65.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-test-not-localhost.66.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi-test-not-localhost.67.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi.65.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi.66.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-ServerApi.67.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-variables.23.xml +18 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-variables.24.xml +18 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-variables.25.xml +18 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-with-dynamic-columns.7.xml +17 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-with-dynamic-columns.8.xml +17 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-discrete-with-dynamic-columns.9.xml +17 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-no-variables-defined.65.xml +20 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-no-variables-defined.66.xml +20 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-no-variables-defined.67.xml +20 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup-with-user.31.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup-with-user.32.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup-with-user.33.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup.37.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup.38.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-proxy-setup.39.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-output-variables.17.xml +36 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-output-variables.18.xml +36 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-output-variables.19.xml +36 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-version-0-1-9.14.xml +21 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-version-0-1-9.15.xml +21 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-setup-version-0-1-9.16.xml +21 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-incomplete-variables.65.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-incomplete-variables.66.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-incomplete-variables.67.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables-should-not-validate.65.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables-should-not-validate.66.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables-should-not-validate.67.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables.65.xml +23 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables.66.xml +23 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-of-variables.67.xml +23 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-with-with-repeated-variable-names.65.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-with-with-repeated-variable-names.66.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-small-list-with-with-repeated-variable-names.67.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-1-10.14.xml +13 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-1-10.15.xml +13 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-1-10.16.xml +13 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0-simple.0.xml +19 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0-simple.1.xml +19 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0-simple.xml +19 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0.0.xml +32 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0.1.xml +32 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel-version-0-2-0.2.xml +32 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel.65.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel.66.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Analysis-Translator-Excel.67.xml +7 -0
- data/spec/spec_helper.rb +1 -3
- metadata +127 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15a5a8290b759332184a73846a76ece6de4f90f3
|
4
|
+
data.tar.gz: cd308376243524a8e739758f137859d3cb7d1f85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 = {:
|
9
|
+
defaults = { hostname: 'http://localhost:8080' }
|
10
10
|
options = defaults.merge(options)
|
11
|
-
@logger = Logger.new(
|
12
|
-
|
11
|
+
@logger = Logger.new('faraday.log')
|
12
|
+
|
13
13
|
@hostname = options[:hostname]
|
14
14
|
|
15
|
-
|
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(:
|
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(:
|
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, :
|
42
|
+
projects_json = JSON.parse(response.body, symbolize_names: true, max_nesting: false)
|
43
43
|
else
|
44
|
-
|
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: "
|
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
|
-
|
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
|
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)[
|
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
|
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
|
99
|
+
puts 'received the list of analyses for the project'
|
99
100
|
|
100
|
-
analyses = JSON.parse(response.body, :
|
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
|
-
|
116
|
-
|
117
|
-
|
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]), :
|
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
|
-
|
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)[
|
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
|
-
|
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
|
-
|
173
|
+
fail "upload file does not exist #{options[:upload_file]}" unless File.exist?(options[:upload_file])
|
173
174
|
|
174
|
-
payload = {:
|
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
|
179
|
+
puts 'Successfully uploaded ZIP file'
|
179
180
|
else
|
180
|
-
|
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
|
-
|
192
|
-
|
193
|
-
|
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, :
|
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
|
-
|
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
|
-
|
221
|
-
|
222
|
-
|
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, :
|
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
|
-
|
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:
|
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
|
-
|
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:
|
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
|
-
|
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",
|
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
|