openstudio-analysis 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -235,7 +235,7 @@ module OpenStudio
235
235
  end
236
236
 
237
237
  @worker_inits.each do |w|
238
- a.worker_inits.add(w[:path], args: w[:args])
238
+ a.worker_inits.add(w[:path], args: w[:args])
239
239
  end
240
240
 
241
241
  @worker_finals.each do |w|
@@ -701,7 +701,7 @@ module OpenStudio
701
701
  # parse the choices/enums
702
702
  if var['type'] == 'enum' || var['type'] == 'choice' # this is now a choice
703
703
  if row[:enums]
704
- var['distribution']['enumerations'] = row[:enums].gsub('|', '').split(',').map(&:strip)
704
+ var['distribution']['enumerations'] = row[:enums].delete('|').split(',').map(&:strip)
705
705
  end
706
706
  elsif var['type'] == 'bool'
707
707
  var['distribution']['enumerations'] = []
@@ -758,7 +758,7 @@ module OpenStudio
758
758
  # generate name id
759
759
  # TODO: put this into a logger. puts "Parsing measure #{row[1]}"
760
760
  display_name = row[:measure_name_or_var_type]
761
- measure_name = display_name.downcase.strip.gsub('-', '_').gsub(' ', '_').gsub('__', '_')
761
+ measure_name = display_name.downcase.strip.tr('-', '_').tr(' ', '_').gsub('__', '_')
762
762
  data['data'][measure_index]['display_name'] = display_name
763
763
  data['data'][measure_index]['name'] = measure_name
764
764
  data['data'][measure_index]['enabled'] = row[:enabled] == 'TRUE' ? true : false
@@ -1,5 +1,5 @@
1
1
  module OpenStudio
2
2
  module Analysis
3
- VERSION = '0.4.4'
3
+ VERSION = '0.4.5'
4
4
  end
5
5
  end
@@ -140,10 +140,45 @@ module OpenStudio
140
140
  end
141
141
  end
142
142
 
143
+ # Add a measure from the format that CSV parses into. This is a helper method to map the csv data to the new
144
+ # programmatic interface format
145
+ #
146
+ # @params measure [Hash] The measure in the format of the CSV translator
147
+ # @return [Object] Returns the measure that was added as an OpenStudio::AnalysisWorkflowStep object
148
+ def add_measure_from_csv(measure)
149
+ hash = {}
150
+ hash[:classname] = measure[:measure_data][:classname]
151
+ hash[:name] = measure[:measure_data][:name]
152
+ hash[:display_name] = measure[:measure_data][:display_name]
153
+ hash[:measure_type] = measure[:measure_data][:measure_type]
154
+ hash[:uid] = measure[:measure_data][:uid] ? measure[:measure_data][:uid] : SecureRandom.uuid
155
+ hash[:version_id] = measure[:measure_data][:version_id] ? measure[:measure_data][:version_id] : SecureRandom.uuid
156
+
157
+ # map the arguments - this can be a variable or argument, add them all as arguments first,
158
+ # the make_variable will remove from arg and place into variables
159
+ hash[:arguments] = measure[:args]
160
+
161
+ m = add_measure(measure[:measure_data][:name], measure[:measure_data][:display_name], measure[:measure_data][:local_path_to_measure], hash)
162
+
163
+ measure[:vars].each do |variable|
164
+ next unless %w(variable pivot).include? variable[:variable_type]
165
+
166
+ dist = variable[:distribution]
167
+ opt = {
168
+ variable_type: variable[:variable_type],
169
+ variable_display_name_short: variable[:display_name_short],
170
+ static_value: variable[:distribution][:mode]
171
+ }
172
+
173
+ m.make_variable(variable[:name], variable[:display_name], dist, opt)
174
+ end
175
+ end
176
+
143
177
  # Iterate over all the WorkflowItems
144
178
  def each
145
179
  @items.each { |i| yield i }
146
180
  end
181
+
147
182
  # Find the measure by its instance name
148
183
  #
149
184
  # @params instance_name [String] instance name of the measure
@@ -132,7 +132,6 @@ module OpenStudio
132
132
  v[:values] = distribution[:values] if distribution[:values]
133
133
  v[:standard_deviation] = distribution[:standard_deviation] if distribution[:standard_deviation]
134
134
  v[:step_size] = distribution[:step_size] ? distribution[:step_size] : nil
135
- v[:step_size] = distribution[:step_size] ? distribution[:step_size] : nil
136
135
 
137
136
  # assign uuid and version id to the variable
138
137
  v[:uuid] = SecureRandom.uuid
@@ -241,7 +240,7 @@ module OpenStudio
241
240
  fail "Could not find measure '#{instance_name}' in '#{path_to_measure}'" unless options[:ignore_not_found]
242
241
  end
243
242
 
244
- # Extract the directo
243
+ # Extract the directory
245
244
  path_to_measure_local = path_to_measure
246
245
  path_to_measure = "./measures/#{File.basename(path_to_measure)}"
247
246
 
@@ -389,7 +388,7 @@ module OpenStudio
389
388
  var_options[:variable_type] = variable[:variable_type]
390
389
  var_options[:variable_display_name_short] = variable[:display_name_short]
391
390
  var_options[:static_value] = variable[:static_value]
392
- distribution = variable[:uncertainty_description]
391
+ distribution = variable[:uncertainty_description]
393
392
  distribution[:minimum] = variable[:minimum]
394
393
  distribution[:mean] = distribution[:attributes].find { |a| a[:name] == 'modes' }[:value]
395
394
  distribution[:maximum] = variable[:maximum]
@@ -168,7 +168,7 @@ module OpenStudio
168
168
  if row_count == 1
169
169
  @valid = true
170
170
 
171
- @city = row[1].gsub('/', '-')
171
+ @city = row[1].tr('/', '-')
172
172
  @state = row[2]
173
173
  @country = row[3]
174
174
  @data_type = row[4]
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.description = 'Basic classes for generating the files needed for OpenStudio-Server'
15
15
  s.license = 'LGPL'
16
16
 
17
- s.required_ruby_version = '>= 1.9.3'
17
+ s.required_ruby_version = '>= 2.0'
18
18
  s.required_rubygems_version = '>= 1.3.6'
19
19
 
20
20
  s.files = `git ls-files -z`.split("\x0")
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.require_paths = ['lib']
24
24
 
25
25
  s.add_dependency 'faraday', '~> 0.8'
26
+ s.add_dependency 'nokogiri', '~> 1.6'
26
27
  s.add_dependency 'roo', '~> 1.12'
27
28
  s.add_dependency 'rubyzip', '~> 1.0' # don't update because of jruby
28
29
  s.add_dependency 'semantic', '~> 1.4'
@@ -0,0 +1,550 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "description": "JSON Schema for the OpenStudioAnalysis File Type",
4
+ "type": "object",
5
+ "properties": {
6
+ "analysis": {
7
+ "$ref": "#/definitions/Analysis"
8
+ }
9
+ },
10
+ "required": [
11
+ "analysis"
12
+ ],
13
+ "additionalProperties": false,
14
+ "definitions": {
15
+ "Output": {
16
+ "description": "Hash",
17
+ "type": "object",
18
+ "properties": {
19
+ "units": {
20
+ "description": "Haystack complient unit string, or empty string if not applicable",
21
+ "type": "string"
22
+ },
23
+ "objective_function": {
24
+ "description": "Determines if output is part of an objective function",
25
+ "type": "boolean"
26
+ },
27
+ "objective_function_index": {
28
+ "description": "Key used to define multi-objective functions, null if not applicale",
29
+ "type": "number"
30
+ },
31
+ "objective_function_target": {
32
+ "description": "Key used to define target of the objective function, null if not applicable",
33
+ "type": [
34
+ "number",
35
+ "null"
36
+ ]
37
+ },
38
+ "objective_function_group": {
39
+ "description": "Optional key used to define multi-objective functions",
40
+ "type": "number"
41
+ },
42
+ "scaling_factor": {
43
+ "description": "????",
44
+ "type": "null"
45
+ },
46
+ "display_name": {
47
+ "description": "User facing name of objective which must be unique",
48
+ "type": "string"
49
+ },
50
+ "display_name_short": {
51
+ "description": "User facing name less that 20 chareters",
52
+ "type": "string"
53
+ },
54
+ "metadata_id": {
55
+ "description": "??????",
56
+ "type": [
57
+ "string",
58
+ "null"
59
+ ]
60
+ },
61
+ "name": {
62
+ "description": "Snake cased output machine name",
63
+ "type": "string"
64
+ },
65
+ "visualize": {
66
+ "description": "Determines if variable will be include in plots on the server",
67
+ "type": "boolean"
68
+ },
69
+ "export": {
70
+ "description": "?????",
71
+ "type": "boolean"
72
+ },
73
+ "variable_type": {
74
+ "description": "Allowed values of 'string', 'bool', or 'number'",
75
+ "type": "string"
76
+ }
77
+ },
78
+ "required": [
79
+ "units",
80
+ "objective_function",
81
+ "objective_function_index",
82
+ "objective_function_target",
83
+ "scaling_factor",
84
+ "display_name",
85
+ "metadata_id",
86
+ "name"
87
+ ],
88
+ "additionalProperties": false
89
+ },
90
+ "Algorithm Attributes": {
91
+ "title": "algorithm",
92
+ "description": "Hash of ttributes associated with the analysis_type",
93
+ "type": "object",
94
+ "additionalProperties": {
95
+ "description": "Attibutes defined by analysis type"
96
+ }
97
+ },
98
+ "Argument": {
99
+ "title": "argument",
100
+ "description": "Indivigual argument instance",
101
+ "type": "object",
102
+ "properties": {
103
+ "display_name": {
104
+ "description": "User-facing display name which must be unique",
105
+ "type": "string"
106
+ },
107
+ "display_name_short": {
108
+ "description": "Optional user-facing display name under 20 charecters",
109
+ "type": "string"
110
+ },
111
+ "name": {
112
+ "description": "Machine readable snake-cased name of agrument as defined in the measure.xml",
113
+ "type": "string"
114
+ },
115
+ "value_type": {
116
+ "description": "Accepts inputs of 'string', 'bool', and 'number'",
117
+ "type": "string"
118
+ },
119
+ "default_value": {
120
+ "description": "Default value for argument, if defined in the measure.xml file",
121
+ "type": [
122
+ "string",
123
+ "number",
124
+ "boolean"
125
+ ]
126
+ },
127
+ "value": {
128
+ "description": "Value to set argument to in analysis",
129
+ "type": [
130
+ "string",
131
+ "number",
132
+ "boolean"
133
+ ]
134
+ },
135
+ "machine_name": {
136
+ "description": "????",
137
+ "type": "string"
138
+ },
139
+ "uuid": {
140
+ "description": "UUID for the measure from the measure.xml",
141
+ "type": "string"
142
+ },
143
+ "version_uuid": {
144
+ "description": "UUID for the measure version form the measure.xml",
145
+ "type": "string"
146
+ }
147
+ },
148
+ "required": [
149
+ "display_name",
150
+ "name",
151
+ "value",
152
+ "machine_name",
153
+ "uuid",
154
+ "version_uuid"
155
+ ],
156
+ "additionalProperties": false
157
+ },
158
+ "Workflow Step": {
159
+ "description": "Indivigual measure definition",
160
+ "type": "object",
161
+ "properties": {
162
+ "name": {
163
+ "description": "Snake-cased machine readable measure name which must be unique",
164
+ "type": "string"
165
+ },
166
+ "display_name": {
167
+ "description": "User facing measure name whcih must also be unique",
168
+ "type": "string"
169
+ },
170
+ "measure_type": {
171
+ "description": "Accepts values of 'Ruby' 'EnergyPlus' and 'Reporting'",
172
+ "type": "string"
173
+ },
174
+ "measure_definition_class_name": {
175
+ "description": "Class name of measure.rb file",
176
+ "type": "string"
177
+ },
178
+ "measure_definition_directory": {
179
+ "description": "??",
180
+ "type": "string"
181
+ },
182
+ "measure_definition_directory_local": {
183
+ "description": "Local path to the measure directory",
184
+ "type": "string"
185
+ },
186
+ "measure_definition_display_name": {
187
+ "description": "?????",
188
+ "type": "string"
189
+ },
190
+ "measure_definition_name": {
191
+ "description": "?????",
192
+ "type": "string"
193
+ },
194
+ "measure_definition_name_xml": {
195
+ "description": "?????",
196
+ "type": "null"
197
+ },
198
+ "measure_definition_uuid": {
199
+ "description": "UUID of measure in measure.xml",
200
+ "type": "string"
201
+ },
202
+ "measure_definition_version_uuid": {
203
+ "description": "UUID of measure version in measure.xml",
204
+ "type": "string"
205
+ },
206
+ "arguments": {
207
+ "$ref": "#/definitions/Argument Array"
208
+ },
209
+ "variables": {
210
+ "$ref": "#/definitions/Variable Array"
211
+ },
212
+ "workflow_index": {
213
+ "description": "Index in workflow array, indexing from 0",
214
+ "type": "number"
215
+ },
216
+ "workflow_step_type": {
217
+ "description": "???????",
218
+ "type": "string"
219
+ },
220
+ "version_uuid": {
221
+ "description": "UUID of measure version from the measure.xml",
222
+ "type": "string"
223
+ },
224
+ "uuid": {
225
+ "description": "UUID of measure from the measure.xml",
226
+ "type": "string"
227
+ }
228
+ },
229
+ "required": [
230
+ "name",
231
+ "display_name",
232
+ "measure_type",
233
+ "measure_definition_class_name",
234
+ "measure_definition_directory",
235
+ "measure_definition_uuid",
236
+ "measure_definition_version_uuid",
237
+ "arguments",
238
+ "variables",
239
+ "workflow_index",
240
+ "workflow_step_type",
241
+ "version_uuid",
242
+ "uuid"
243
+ ],
244
+ "additionalProperties": false
245
+ },
246
+ "Uncertainty Definition": {
247
+ "title": "uncertainty_description",
248
+ "description": "Set of attributes defining the variablity of the input",
249
+ "type": "object",
250
+ "properties": {
251
+ "type": {
252
+ "description": "Uncertainty type, accepting values of 'triangle', 'uniform', 'discrete', and 'normal'",
253
+ "type": "string",
254
+ "oneof": [
255
+ "triangle",
256
+ "uniform",
257
+ "normal",
258
+ "discrete"
259
+ ]
260
+ },
261
+ "attributes": {
262
+ "$ref": "#/definitions/Distribution Definition"
263
+ }
264
+ },
265
+ "required": [
266
+ "type",
267
+ "attributes"
268
+ ],
269
+ "additionalProperties": false
270
+ },
271
+ "Variable": {
272
+ "description": "Inidivigual variable instance",
273
+ "type": "object",
274
+ "properties": {
275
+ "argument": {
276
+ "$ref": "#/definitions/Argument"
277
+ },
278
+ "display_name": {
279
+ "description": "User-facing display name which must be unique",
280
+ "type": "string"
281
+ },
282
+ "display_name_short": {
283
+ "description": "Optional user-facing name under 20 charecters",
284
+ "type": "string"
285
+ },
286
+ "variable_type": {
287
+ "description": "Definition of variable type",
288
+ "type": "string",
289
+ "oneof": [
290
+ "variable",
291
+ "pivot"
292
+ ]
293
+ },
294
+ "units": {
295
+ "description": "Haystack complient units with an empty string if not defined.",
296
+ "type": "null"
297
+ },
298
+ "minimum": {
299
+ "description": "????",
300
+ "type": "number"
301
+ },
302
+ "maximum": {
303
+ "description": "????",
304
+ "type": "number"
305
+ },
306
+ "relation_to_output": {
307
+ "description": "????",
308
+ "type": "null"
309
+ },
310
+ "static_value": {
311
+ "description": "Value to defalut to in the case of this variable not being perturbed in a datapoint",
312
+ "type": "number"
313
+ },
314
+ "uuid": {
315
+ "description": "Variable UUID to link against in the .osd file",
316
+ "type": "string"
317
+ },
318
+ "version_uuid": {
319
+ "description": "???",
320
+ "type": "string"
321
+ },
322
+ "variable": {
323
+ "description": "????",
324
+ "type": "boolean"
325
+ },
326
+ "uncertainty_description": {
327
+ "$ref": "#/definitions/Uncertainty Definition"
328
+ },
329
+ "workflow_index": {
330
+ "description": "???????",
331
+ "type": "number"
332
+ },
333
+ "machine_name": {
334
+ "description": "???????",
335
+ "type": "string"
336
+ }
337
+ },
338
+ "required": [
339
+ "argument",
340
+ "display_name",
341
+ "variable_type",
342
+ "units",
343
+ "static_value",
344
+ "uuid",
345
+ "version_uuid",
346
+ "uncertainty_description",
347
+ "machine_name"
348
+ ],
349
+ "additionalProperties": false
350
+ },
351
+ "Problem": {
352
+ "title": "problem",
353
+ "description": "Defines procedure for running the analysis",
354
+ "type": "object",
355
+ "properties": {
356
+ "analysis_type": {
357
+ "description": "Type of analysis to be run, e.g. LHS or nsga2",
358
+ "type": "string",
359
+ "oneof": [
360
+ "morris",
361
+ "lhs",
362
+ "rgenound",
363
+ "nsga_nrel",
364
+ "spea",
365
+ "sequential_search",
366
+ "single_run",
367
+ "batch_run",
368
+ "doe",
369
+ "repeat_run",
370
+ "optim",
371
+ "baseline_purturbation",
372
+ "preflight"
373
+ ]
374
+ },
375
+ "algorithm": {
376
+ "$ref": "#/definitions/Algorithm Attributes"
377
+ },
378
+ "workflow": {
379
+ "$ref": "#/definitions/Workflow"
380
+ },
381
+ "random_seed": {
382
+ "description": "Random seed to set server to for the execution of the OSA file",
383
+ "type": "number"
384
+ },
385
+ "name": {
386
+ "description": "??????",
387
+ "type": "string"
388
+ }
389
+ },
390
+ "required": [
391
+ "analysis_type",
392
+ "algorithm",
393
+ "workflow",
394
+ "random_seed"
395
+ ],
396
+ "additionalProperties": false
397
+ },
398
+ "Output Array": {
399
+ "description": "Array of objects which define user-desired outputs from the analysis ",
400
+ "type": "array",
401
+ "items": {
402
+ "$ref": "#/definitions/Output"
403
+ }
404
+ },
405
+ "Workflow": {
406
+ "description": "Definintion of measures to be applied in the analysis",
407
+ "type": "array",
408
+ "items": {
409
+ "$ref": "#/definitions/Workflow Step"
410
+ }
411
+ },
412
+ "Seed Object": {
413
+ "title": "seed",
414
+ "description": "Seed osm or idf file for default use",
415
+ "type": "object",
416
+ "properties": {
417
+ "file_type": {
418
+ "description": "Accepted values of 'osm' and 'idf'",
419
+ "type": "string",
420
+ "oneonf": [
421
+ "osm",
422
+ "idf"
423
+ ]
424
+ },
425
+ "path": {
426
+ "description": "Path to the seed file from the project directory",
427
+ "type": "string"
428
+ }
429
+ },
430
+ "required": [
431
+ "file_type"
432
+ ],
433
+ "additionalProperties": false
434
+ },
435
+ "Weather File": {
436
+ "title": "weather_file",
437
+ "description": "Weather file for default use in the simulation",
438
+ "type": "object",
439
+ "properties": {
440
+ "file_type": {
441
+ "description": "Weather file type, e.g. TMY3",
442
+ "type": "string"
443
+ },
444
+ "path": {
445
+ "description": "Path to weather file from the project directory",
446
+ "type": "string"
447
+ }
448
+ },
449
+ "required": [
450
+ "file_type",
451
+ "path"
452
+ ],
453
+ "additionalProperties": false
454
+ },
455
+ "Analysis": {
456
+ "title": "analysis",
457
+ "description": "Analysis object",
458
+ "type": "object",
459
+ "properties": {
460
+ "display_name": {
461
+ "description": "User facing string, spaces & capitals allowed",
462
+ "type": "string"
463
+ },
464
+ "name": {
465
+ "description": "snake_cassed machine name",
466
+ "type": "string"
467
+ },
468
+ "output_variables": {
469
+ "$ref": "#/definitions/Output Array"
470
+ },
471
+ "problem": {
472
+ "$ref": "#/definitions/Problem"
473
+ },
474
+ "seed": {
475
+ "$ref": "#/definitions/Seed Object"
476
+ },
477
+ "weather_file": {
478
+ "$ref": "#/definitions/Weather File"
479
+ },
480
+ "file_format_version": {
481
+ "description": "1.0",
482
+ "type": "number"
483
+ },
484
+ "_id": {
485
+ "description": "UUID of the OSA file",
486
+ "type": "string"
487
+ },
488
+ "uuid": {
489
+ "description": "UUID of the OSA file",
490
+ "type": "string"
491
+ },
492
+ "project_id": {
493
+ "description": "?????",
494
+ "type": "string"
495
+ }
496
+ },
497
+ "required": [
498
+ "output_variables",
499
+ "problem",
500
+ "seed",
501
+ "weather_file",
502
+ "_id",
503
+ "uuid",
504
+ "project_id"
505
+ ],
506
+ "additionalProperties": false
507
+ },
508
+ "Argument Array": {
509
+ "description": "Array of fixed inputs for the masure",
510
+ "type": "array",
511
+ "items": {
512
+ "$ref": "#/definitions/Argument"
513
+ }
514
+ },
515
+ "Variable Array": {
516
+ "description": "Array of variable inputs for the measure",
517
+ "type": "array",
518
+ "items": {
519
+ "$ref": "#/definitions/Variable"
520
+ }
521
+ },
522
+ "Distribution Definition": {
523
+ "title": "attributes",
524
+ "description": "Array of attributes defining the distribution type properties",
525
+ "type": "array",
526
+ "items": {
527
+ "title": "Distribution Attributes",
528
+ "type": "object",
529
+ "properties": {
530
+ "name": {
531
+ "type": "string"
532
+ },
533
+ "value": {
534
+ "type": [
535
+ "array",
536
+ "string",
537
+ "number",
538
+ "boolean"
539
+ ]
540
+ }
541
+ },
542
+ "required": [
543
+ "name",
544
+ "value"
545
+ ],
546
+ "additionalProperties": false
547
+ }
548
+ }
549
+ }
550
+ }