openstudio-analysis 1.3.6 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/openstudio-analysis.yml +65 -40
- data/.gitignore +21 -21
- data/.rubocop.yml +9 -9
- data/CHANGELOG.md +278 -269
- data/Gemfile +14 -14
- data/README.md +102 -102
- data/Rakefile +40 -40
- data/lib/openstudio/analysis/algorithm_attributes.rb +47 -47
- data/lib/openstudio/analysis/formulation.rb +881 -857
- data/lib/openstudio/analysis/server_api.rb +862 -862
- data/lib/openstudio/analysis/server_scripts.rb +108 -108
- data/lib/openstudio/analysis/support_files.rb +104 -104
- data/lib/openstudio/analysis/translator/datapoints.rb +454 -454
- data/lib/openstudio/analysis/translator/excel.rb +893 -893
- data/lib/openstudio/analysis/translator/workflow.rb +143 -143
- data/lib/openstudio/analysis/version.rb +12 -12
- data/lib/openstudio/analysis/workflow.rb +302 -279
- data/lib/openstudio/analysis/workflow_step.rb +523 -523
- data/lib/openstudio/analysis.rb +144 -144
- data/lib/openstudio/helpers/hash.rb +10 -10
- data/lib/openstudio/helpers/string.rb +36 -36
- data/lib/openstudio/helpers/utils.rb +36 -36
- data/lib/openstudio/weather/epw.rb +178 -178
- data/lib/openstudio-analysis.rb +47 -47
- data/openstudio-analysis.gemspec +38 -38
- data/update_license.rb +60 -60
- metadata +18 -18
@@ -1,857 +1,881 @@
|
|
1
|
-
# *******************************************************************************
|
2
|
-
# OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
|
3
|
-
# See also https://openstudio.net/license
|
4
|
-
# *******************************************************************************
|
5
|
-
|
6
|
-
# OpenStudio formulation class handles the generation of the OpenStudio Analysis format.
|
7
|
-
module OpenStudio
|
8
|
-
module Analysis
|
9
|
-
SeedModel = Struct.new(:file)
|
10
|
-
WeatherFile = Struct.new(:file)
|
11
|
-
|
12
|
-
@@measure_paths = ['./measures']
|
13
|
-
# List of paths to look for measures when adding them. This currently only is used when loading an
|
14
|
-
# analysis hash file. It looks in the order of the measure_paths. As soon as it finds one, it stops.
|
15
|
-
def self.measure_paths
|
16
|
-
@@measure_paths
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.measure_paths=(new_array)
|
20
|
-
@@measure_paths = new_array
|
21
|
-
end
|
22
|
-
|
23
|
-
class Formulation
|
24
|
-
attr_reader :seed_model
|
25
|
-
attr_reader :weather_file
|
26
|
-
attr_reader :analysis_type
|
27
|
-
attr_reader :outputs
|
28
|
-
attr_accessor :display_name
|
29
|
-
attr_accessor :workflow
|
30
|
-
attr_accessor :algorithm
|
31
|
-
attr_accessor :osw_path
|
32
|
-
attr_accessor :download_zip
|
33
|
-
attr_accessor :download_reports
|
34
|
-
attr_accessor :download_osw
|
35
|
-
attr_accessor :download_osm
|
36
|
-
attr_accessor :cli_debug
|
37
|
-
attr_accessor :cli_verbose
|
38
|
-
attr_accessor :initialize_worker_timeout
|
39
|
-
attr_accessor :run_workflow_timeout
|
40
|
-
attr_accessor :upload_results_timeout
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
attr_reader :
|
45
|
-
attr_reader :
|
46
|
-
attr_reader :
|
47
|
-
attr_reader :
|
48
|
-
attr_reader :
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
#
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
@
|
58
|
-
@
|
59
|
-
|
60
|
-
@
|
61
|
-
|
62
|
-
@
|
63
|
-
@
|
64
|
-
@
|
65
|
-
@
|
66
|
-
@
|
67
|
-
@
|
68
|
-
@
|
69
|
-
@
|
70
|
-
@
|
71
|
-
@
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
@
|
77
|
-
@
|
78
|
-
@
|
79
|
-
@
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
#
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
#
|
206
|
-
#
|
207
|
-
# @
|
208
|
-
# @option output_hash [String] :
|
209
|
-
# @option output_hash [String] :
|
210
|
-
# @option output_hash [String] :
|
211
|
-
# @option output_hash [String] :
|
212
|
-
# @option output_hash [String] :
|
213
|
-
# @option output_hash [
|
214
|
-
# @option output_hash [
|
215
|
-
# @option output_hash [
|
216
|
-
# @option output_hash [
|
217
|
-
# @option output_hash [Integer] :
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
if
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
output =
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
#set default to
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
#
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
#
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
wf = @
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
h[:analysis][:
|
318
|
-
h[:analysis][:
|
319
|
-
h[:analysis][:
|
320
|
-
h[:analysis][:
|
321
|
-
h[:analysis][:
|
322
|
-
h[:analysis][:
|
323
|
-
h[:analysis][:
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
#
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
h
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
o.
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
}
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
#
|
412
|
-
#
|
413
|
-
# @
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
filename
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
#
|
426
|
-
#
|
427
|
-
# @
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
end
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
#
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
#
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
#
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
added_measures
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
@
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
if
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
file.
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
@
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
end
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
1
|
+
# *******************************************************************************
|
2
|
+
# OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
|
3
|
+
# See also https://openstudio.net/license
|
4
|
+
# *******************************************************************************
|
5
|
+
|
6
|
+
# OpenStudio formulation class handles the generation of the OpenStudio Analysis format.
|
7
|
+
module OpenStudio
|
8
|
+
module Analysis
|
9
|
+
SeedModel = Struct.new(:file)
|
10
|
+
WeatherFile = Struct.new(:file)
|
11
|
+
|
12
|
+
@@measure_paths = ['./measures']
|
13
|
+
# List of paths to look for measures when adding them. This currently only is used when loading an
|
14
|
+
# analysis hash file. It looks in the order of the measure_paths. As soon as it finds one, it stops.
|
15
|
+
def self.measure_paths
|
16
|
+
@@measure_paths
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.measure_paths=(new_array)
|
20
|
+
@@measure_paths = new_array
|
21
|
+
end
|
22
|
+
|
23
|
+
class Formulation
|
24
|
+
attr_reader :seed_model
|
25
|
+
attr_reader :weather_file
|
26
|
+
attr_reader :analysis_type
|
27
|
+
attr_reader :outputs
|
28
|
+
attr_accessor :display_name
|
29
|
+
attr_accessor :workflow
|
30
|
+
attr_accessor :algorithm
|
31
|
+
attr_accessor :osw_path
|
32
|
+
attr_accessor :download_zip
|
33
|
+
attr_accessor :download_reports
|
34
|
+
attr_accessor :download_osw
|
35
|
+
attr_accessor :download_osm
|
36
|
+
attr_accessor :cli_debug
|
37
|
+
attr_accessor :cli_verbose
|
38
|
+
attr_accessor :initialize_worker_timeout
|
39
|
+
attr_accessor :run_workflow_timeout
|
40
|
+
attr_accessor :upload_results_timeout
|
41
|
+
|
42
|
+
|
43
|
+
# the attributes below are used for packaging data into the analysis zip file
|
44
|
+
attr_reader :weather_files
|
45
|
+
attr_reader :seed_models
|
46
|
+
attr_reader :worker_inits
|
47
|
+
attr_reader :worker_finalizes
|
48
|
+
attr_reader :libraries
|
49
|
+
attr_reader :server_scripts
|
50
|
+
attr_reader :gem_files
|
51
|
+
|
52
|
+
# Create an instance of the OpenStudio::Analysis::Formulation
|
53
|
+
#
|
54
|
+
# @param display_name [String] Display name of the project.
|
55
|
+
# @return [Object] An OpenStudio::Analysis::Formulation object
|
56
|
+
def initialize(display_name)
|
57
|
+
@display_name = display_name
|
58
|
+
@analysis_type = nil
|
59
|
+
@outputs = []
|
60
|
+
@workflow = OpenStudio::Analysis::Workflow.new
|
61
|
+
# Initialize child objects (expect workflow)
|
62
|
+
@weather_file = WeatherFile.new
|
63
|
+
@seed_model = SeedModel.new
|
64
|
+
@algorithm = OpenStudio::Analysis::AlgorithmAttributes.new
|
65
|
+
@download_zip = true
|
66
|
+
@download_reports = true
|
67
|
+
@download_osw = true
|
68
|
+
@download_osm = true
|
69
|
+
@cli_debug = "--debug"
|
70
|
+
@cli_verbose = "--verbose"
|
71
|
+
@initialize_worker_timeout = 28800
|
72
|
+
@run_workflow_timeout = 28800
|
73
|
+
@upload_results_timeout = 28800
|
74
|
+
|
75
|
+
# Analysis Zip attributes
|
76
|
+
@weather_files = SupportFiles.new
|
77
|
+
@gem_files = SupportFiles.new
|
78
|
+
@seed_models = SupportFiles.new
|
79
|
+
@worker_inits = SupportFiles.new
|
80
|
+
@worker_finalizes = SupportFiles.new
|
81
|
+
@libraries = SupportFiles.new
|
82
|
+
@server_scripts = ServerScripts.new
|
83
|
+
end
|
84
|
+
|
85
|
+
# Define the type of analysis which is going to be running
|
86
|
+
#
|
87
|
+
# @param name [String] Name of the algorithm/analysis. (e.g. rgenoud, lhs, single_run)
|
88
|
+
# allowed values are ANALYSIS_TYPES = ['spea_nrel', 'rgenoud', 'nsga_nrel', 'lhs', 'preflight',
|
89
|
+
# 'morris', 'sobol', 'doe', 'fast99', 'ga', 'gaisl',
|
90
|
+
# 'single_run', 'repeat_run', 'batch_run']
|
91
|
+
def analysis_type=(value)
|
92
|
+
if OpenStudio::Analysis::AlgorithmAttributes::ANALYSIS_TYPES.include?(value)
|
93
|
+
@analysis_type = value
|
94
|
+
else
|
95
|
+
raise "Invalid analysis type. Allowed types: #{OpenStudio::Analysis::AlgorithmAttributes::ANALYSIS_TYPES}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Path to the seed model
|
100
|
+
#
|
101
|
+
# @param path [String] Path to the seed model. This should be relative.
|
102
|
+
def seed_model=(file)
|
103
|
+
@seed_model[:file] = file
|
104
|
+
end
|
105
|
+
|
106
|
+
# Path to the weather file (or folder). If it is a folder, then the measures will look for the weather file
|
107
|
+
# by name in that folder.
|
108
|
+
#
|
109
|
+
# @param path [String] Path to the weather file or folder.
|
110
|
+
def weather_file=(file)
|
111
|
+
@weather_file[:file] = file
|
112
|
+
end
|
113
|
+
|
114
|
+
# Set the value for 'download_zip'
|
115
|
+
#
|
116
|
+
# @param value [Boolean] The value for 'download_zip'
|
117
|
+
def download_zip=(value)
|
118
|
+
if [true, false].include?(value)
|
119
|
+
@download_zip = value
|
120
|
+
else
|
121
|
+
raise ArgumentError, "Invalid value for 'download_zip'. Only true or false allowed."
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Set the value for 'download_reports'
|
126
|
+
#
|
127
|
+
# @param value [Boolean] The value for 'download_reports'
|
128
|
+
def download_reports=(value)
|
129
|
+
if [true, false].include?(value)
|
130
|
+
@download_reports = value
|
131
|
+
else
|
132
|
+
raise ArgumentError, "Invalid value for 'download_reports'. Only true or false allowed."
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Set the value for 'download_osw'
|
137
|
+
#
|
138
|
+
# @param value [Boolean] The value for 'download_osw'
|
139
|
+
def download_osw=(value)
|
140
|
+
if [true, false].include?(value)
|
141
|
+
@download_osw = value
|
142
|
+
else
|
143
|
+
raise ArgumentError, "Invalid value for 'download_osw'. Only true or false allowed."
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Set the value for 'download_osm'
|
148
|
+
#
|
149
|
+
# @param value [Boolean] The value for 'download_osm'
|
150
|
+
def download_osm=(value)
|
151
|
+
if [true, false].include?(value)
|
152
|
+
@download_osm = value
|
153
|
+
else
|
154
|
+
raise ArgumentError, "Invalid value for 'download_osm'. Only true or false allowed."
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Set the value for 'cli_debug'
|
159
|
+
#
|
160
|
+
# @param value [Boolean] The value for 'cli_debug'
|
161
|
+
def cli_debug=(value)
|
162
|
+
@cli_debug = value
|
163
|
+
end
|
164
|
+
|
165
|
+
# Set the value for 'cli_verbose'
|
166
|
+
#
|
167
|
+
# @param value [Boolean] The value for 'cli_verbose'
|
168
|
+
def cli_verbose=(value)
|
169
|
+
@cli_verbose = value
|
170
|
+
end
|
171
|
+
|
172
|
+
# Set the value for 'run_workflow_timeout'
|
173
|
+
#
|
174
|
+
# @param value [Integer] The value for 'run_workflow_timeout'
|
175
|
+
def run_workflow_timeout=(value)
|
176
|
+
if value.is_a?(Integer)
|
177
|
+
@run_workflow_timeout = value
|
178
|
+
else
|
179
|
+
raise ArgumentError, "Invalid value for 'run_workflow_timeout'. Only integer values allowed."
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# Set the value for 'initialize_worker_timeout'
|
184
|
+
#
|
185
|
+
# @param value [Integer] The value for 'initialize_worker_timeout'
|
186
|
+
def initialize_worker_timeout=(value)
|
187
|
+
if value.is_a?(Integer)
|
188
|
+
@initialize_worker_timeout = value
|
189
|
+
else
|
190
|
+
raise ArgumentError, "Invalid value for 'initialize_worker_timeout'. Only integer values allowed."
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# Set the value for 'upload_results_timeout'
|
195
|
+
#
|
196
|
+
# @param value [Integer] The value for 'upload_results_timeout'
|
197
|
+
def upload_results_timeout=(value)
|
198
|
+
if value.is_a?(Integer)
|
199
|
+
@upload_results_timeout = value
|
200
|
+
else
|
201
|
+
raise ArgumentError, "Invalid value for 'upload_results_timeout'. Only integer values allowed."
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# Add an output of interest to the problem formulation
|
206
|
+
#
|
207
|
+
# @param output_hash [Hash] Hash of the output variable in the legacy format
|
208
|
+
# @option output_hash [String] :display_name Name to display
|
209
|
+
# @option output_hash [String] :display_name_short A shorter display name
|
210
|
+
# @option output_hash [String] :metadata_id Link to DEnCity ID in which this output corresponds
|
211
|
+
# @option output_hash [String] :name Unique machine name of the variable. Typically this is measure.attribute
|
212
|
+
# @option output_hash [String] :export Export the variable to CSV and dataframes from OpenStudio-server
|
213
|
+
# @option output_hash [String] :visualize Visualize the variable in the plots on OpenStudio-server
|
214
|
+
# @option output_hash [String] :units Units of the variable as a string
|
215
|
+
# @option output_hash [String] :variable_type Data type of the variable
|
216
|
+
# @option output_hash [Boolean] :objective_function Whether or not this output is an objective function. Default: false
|
217
|
+
# @option output_hash [Integer] :objective_function_index Index of the objective function. Default: nil
|
218
|
+
# @option output_hash [Float] :objective_function_target Target for the objective function to reach (if defined). Default: nil
|
219
|
+
# @option output_hash [Float] :scaling_factor How to scale the objective function(s). Default: nil
|
220
|
+
# @option output_hash [Integer] :objective_function_group If grouping objective functions, then group ID. Default: nil
|
221
|
+
def add_output(output_hash)
|
222
|
+
# Check if the name is already been added.
|
223
|
+
exist = @outputs.find_index { |o| o[:name] == output_hash[:name] }
|
224
|
+
# if so, update the fields but keep objective_function_index the same
|
225
|
+
if exist
|
226
|
+
original = @outputs[exist]
|
227
|
+
if original[:objective_function] && !output_hash[:objective_function]
|
228
|
+
return @outputs
|
229
|
+
end
|
230
|
+
output = original.merge(output_hash)
|
231
|
+
output[:objective_function_index] = original[:objective_function_index]
|
232
|
+
@outputs[exist] = output
|
233
|
+
else
|
234
|
+
output = {
|
235
|
+
units: '',
|
236
|
+
objective_function: false,
|
237
|
+
objective_function_index: nil,
|
238
|
+
objective_function_target: nil,
|
239
|
+
#set default to nil or 1 if objective_function is true and this is not set
|
240
|
+
objective_function_group: (output_hash[:objective_function] ? 1 : nil),
|
241
|
+
scaling_factor: nil,
|
242
|
+
#set default to false or true if objective_function is true and this is not set
|
243
|
+
visualize: (output_hash[:objective_function] ? true : false),
|
244
|
+
metadata_id: nil,
|
245
|
+
export: true,
|
246
|
+
}.merge(output_hash)
|
247
|
+
#set display_name default to be name if its not set
|
248
|
+
output[:display_name] = output_hash[:display_name] ? output_hash[:display_name] : output_hash[:name]
|
249
|
+
#set display_name_short default to be display_name if its not set, this can be null if :display_name not set
|
250
|
+
output[:display_name_short] = output_hash[:display_name_short] ? output_hash[:display_name_short] : output_hash[:display_name]
|
251
|
+
# if the variable is an objective_function, then increment and
|
252
|
+
# assign and objective function index
|
253
|
+
if output[:objective_function]
|
254
|
+
values = @outputs.select { |o| o[:objective_function] }
|
255
|
+
output[:objective_function_index] = values.size
|
256
|
+
end
|
257
|
+
|
258
|
+
@outputs << output
|
259
|
+
end
|
260
|
+
|
261
|
+
@outputs
|
262
|
+
end
|
263
|
+
|
264
|
+
# return the machine name of the analysis
|
265
|
+
def name
|
266
|
+
@display_name.to_underscore
|
267
|
+
end
|
268
|
+
|
269
|
+
# return a hash.
|
270
|
+
#
|
271
|
+
# @param version [Integer] Version of the format to return
|
272
|
+
# @return [Hash]
|
273
|
+
def to_hash(version = 1)
|
274
|
+
# fail 'Must define an analysis type' unless @analysis_type
|
275
|
+
if version == 1
|
276
|
+
h = {
|
277
|
+
analysis: {
|
278
|
+
display_name: @display_name,
|
279
|
+
name: name,
|
280
|
+
output_variables: @outputs,
|
281
|
+
problem: {
|
282
|
+
analysis_type: @analysis_type,
|
283
|
+
algorithm: algorithm.to_hash(version),
|
284
|
+
workflow: workflow.to_hash(version)
|
285
|
+
}
|
286
|
+
}
|
287
|
+
}
|
288
|
+
|
289
|
+
if @seed_model[:file]
|
290
|
+
h[:analysis][:seed] = {
|
291
|
+
file_type: File.extname(@seed_model[:file]).delete('.').upcase,
|
292
|
+
path: "./seed/#{File.basename(@seed_model[:file])}"
|
293
|
+
}
|
294
|
+
else
|
295
|
+
h[:analysis][:seed] = nil
|
296
|
+
end
|
297
|
+
|
298
|
+
# silly catch for if weather_file is not set
|
299
|
+
wf = nil
|
300
|
+
if @weather_file[:file]
|
301
|
+
wf = @weather_file
|
302
|
+
elsif !@weather_files.empty?
|
303
|
+
# get the first EPW file (not the first file)
|
304
|
+
wf = @weather_files.find { |w| File.extname(w[:file]).casecmp('.epw').zero? }
|
305
|
+
end
|
306
|
+
|
307
|
+
if wf
|
308
|
+
h[:analysis][:weather_file] = {
|
309
|
+
file_type: File.extname(wf[:file]).delete('.').upcase,
|
310
|
+
path: "./weather/#{File.basename(wf[:file])}"
|
311
|
+
}
|
312
|
+
else
|
313
|
+
# log: could not find weather file
|
314
|
+
warn 'Could not resolve a valid weather file. Check paths to weather files'
|
315
|
+
end
|
316
|
+
|
317
|
+
h[:analysis][:file_format_version] = version
|
318
|
+
h[:analysis][:cli_debug] = @cli_debug
|
319
|
+
h[:analysis][:cli_verbose] = @cli_verbose
|
320
|
+
h[:analysis][:run_workflow_timeout] = @run_workflow_timeout
|
321
|
+
h[:analysis][:upload_results_timeout] = @upload_results_timeout
|
322
|
+
h[:analysis][:initialize_worker_timeout] = @initialize_worker_timeout
|
323
|
+
h[:analysis][:download_zip] = @download_zip
|
324
|
+
h[:analysis][:download_reports] = @download_reports
|
325
|
+
h[:analysis][:download_osw] = @download_osw
|
326
|
+
h[:analysis][:download_osm] = @download_osm
|
327
|
+
|
328
|
+
# If there are Gemfiles, then set the hash to use the :gemfile. The zip file method will
|
329
|
+
# add them to the root of the zip file.
|
330
|
+
if @gem_files.size.positive?
|
331
|
+
h[:analysis][:gemfile] = true
|
332
|
+
else
|
333
|
+
h[:analysis][:gemfile] = false
|
334
|
+
end
|
335
|
+
|
336
|
+
#-BLB I dont think this does anything. server_scripts are run if they are in
|
337
|
+
#the /scripts/analysis or /scripts/data_point directories
|
338
|
+
#but nothing is ever checked in the OSA.
|
339
|
+
h[:analysis][:server_scripts] = {}
|
340
|
+
|
341
|
+
# This is a hack right now, but after the initial hash is created go back and add in the objective functions
|
342
|
+
# to the the algorithm as defined in the output_variables list
|
343
|
+
ofs = @outputs.map { |i| i[:name] if i[:objective_function] }.compact
|
344
|
+
if h[:analysis][:problem][:algorithm]
|
345
|
+
h[:analysis][:problem][:algorithm][:objective_functions] = ofs
|
346
|
+
end
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
h
|
351
|
+
else
|
352
|
+
raise "Version #{version} not defined for #{self.class} and #{__method__}"
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
# Load the analysis JSON from a hash (with symbolized keys)
|
357
|
+
def self.from_hash(h, seed_dir = nil, weather_dir = nil)
|
358
|
+
o = OpenStudio::Analysis::Formulation.new(h[:analysis][:display_name])
|
359
|
+
|
360
|
+
version = 1
|
361
|
+
if version == 1
|
362
|
+
h[:analysis][:output_variables].each do |ov|
|
363
|
+
o.add_output(ov)
|
364
|
+
end
|
365
|
+
|
366
|
+
o.workflow = OpenStudio::Analysis::Workflow.load(workflow: h[:analysis][:problem][:workflow])
|
367
|
+
|
368
|
+
if weather_dir
|
369
|
+
o.weather_file "#{weather_path}/#{File.basename(h[:analysis][:weather_file][:path])}"
|
370
|
+
else
|
371
|
+
o.weather_file = h[:analysis][:weather_file][:path]
|
372
|
+
end
|
373
|
+
|
374
|
+
if seed_dir
|
375
|
+
o.seed_model "#{weather_path}/#{File.basename(h[:analysis][:seed][:path])}"
|
376
|
+
else
|
377
|
+
o.seed_model = h[:analysis][:seed][:path]
|
378
|
+
end
|
379
|
+
else
|
380
|
+
raise "Version #{version} not defined for #{self.class} and #{__method__}"
|
381
|
+
end
|
382
|
+
|
383
|
+
o
|
384
|
+
end
|
385
|
+
|
386
|
+
# return a hash of the data point with the static variables set
|
387
|
+
#
|
388
|
+
# @param version [Integer] Version of the format to return
|
389
|
+
# @return [Hash]
|
390
|
+
def to_static_data_point_hash(version = 1)
|
391
|
+
if version == 1
|
392
|
+
static_hash = {}
|
393
|
+
# TODO: this method should be on the workflow step and bubbled up to this interface
|
394
|
+
@workflow.items.map do |item|
|
395
|
+
item.variables.map { |v| static_hash[v[:uuid]] = v[:static_value] }
|
396
|
+
end
|
397
|
+
|
398
|
+
h = {
|
399
|
+
data_point: {
|
400
|
+
set_variable_values: static_hash,
|
401
|
+
status: 'na',
|
402
|
+
uuid: SecureRandom.uuid
|
403
|
+
}
|
404
|
+
}
|
405
|
+
h
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
# save the file to JSON. Will overwrite the file if it already exists
|
410
|
+
#
|
411
|
+
# @param filename [String] Name of file to create. It will create the directory and override the file if it exists. If no file extension is given, then it will use .json.
|
412
|
+
# @param version [Integer] Version of the format to return
|
413
|
+
# @return [Boolean]
|
414
|
+
def save(filename, version = 1)
|
415
|
+
filename += '.json' if File.extname(filename) == ''
|
416
|
+
|
417
|
+
FileUtils.mkdir_p File.dirname(filename) unless Dir.exist? File.dirname(filename)
|
418
|
+
File.open(filename, 'w') { |f| f << JSON.pretty_generate(to_hash(version)) }
|
419
|
+
|
420
|
+
true
|
421
|
+
end
|
422
|
+
|
423
|
+
# save the data point JSON with the variables set to the static values. Will overwrite the file if it already exists
|
424
|
+
#
|
425
|
+
# @param filename [String] Name of file to create. It will create the directory and override the file if it exists. If no file extension is given, then it will use .json.
|
426
|
+
# @param version [Integer] Version of the format to return
|
427
|
+
# @return [Boolean]
|
428
|
+
def save_static_data_point(filename, version = 1)
|
429
|
+
filename += '.json' if File.extname(filename) == ''
|
430
|
+
|
431
|
+
FileUtils.mkdir_p File.dirname(filename) unless Dir.exist? File.dirname(filename)
|
432
|
+
File.open(filename, 'w') { |f| f << JSON.pretty_generate(to_static_data_point_hash(version)) }
|
433
|
+
|
434
|
+
true
|
435
|
+
end
|
436
|
+
|
437
|
+
# save the analysis zip file which contains the measures, seed model, weather file, and init/final scripts
|
438
|
+
#
|
439
|
+
# @param filename [String] Name of file to create. It will create the directory and override the file if it exists. If no file extension is given, then it will use .json.
|
440
|
+
# @return [Boolean]
|
441
|
+
def save_zip(filename)
|
442
|
+
filename += '.zip' if File.extname(filename) == ''
|
443
|
+
|
444
|
+
FileUtils.mkdir_p File.dirname(filename) unless Dir.exist? File.dirname(filename)
|
445
|
+
|
446
|
+
save_analysis_zip(filename)
|
447
|
+
end
|
448
|
+
|
449
|
+
|
450
|
+
def save_osa_zip(filename, all_weather_files = false, all_seed_files = false)
|
451
|
+
filename += '.zip' if File.extname(filename) == ''
|
452
|
+
|
453
|
+
FileUtils.mkdir_p File.dirname(filename) unless Dir.exist? File.dirname(filename)
|
454
|
+
|
455
|
+
save_analysis_zip_osa(filename, all_weather_files, all_seed_files)
|
456
|
+
end
|
457
|
+
|
458
|
+
# convert an OSW to an OSA
|
459
|
+
# osw_filename is the full path to the OSW file
|
460
|
+
# assumes the associated files and directories are in the same location
|
461
|
+
# /example.osw
|
462
|
+
# /measures
|
463
|
+
# /seeds
|
464
|
+
# /weather
|
465
|
+
#
|
466
|
+
def convert_osw(osw_filename, *measure_paths)
|
467
|
+
# load OSW so we can loop over [:steps]
|
468
|
+
if File.exist? osw_filename #will this work for both rel and abs paths?
|
469
|
+
osw = JSON.parse(File.read(osw_filename), symbolize_names: true)
|
470
|
+
@osw_path = File.expand_path(osw_filename)
|
471
|
+
else
|
472
|
+
raise "Could not find workflow file #{osw_filename}"
|
473
|
+
end
|
474
|
+
|
475
|
+
# set the weather and seed files if set in OSW
|
476
|
+
# use :file_paths and look for files to set
|
477
|
+
if osw[:file_paths]
|
478
|
+
# seed_model, check if in OSW and not found in path search already
|
479
|
+
if osw[:seed_file]
|
480
|
+
osw[:file_paths].each do |path|
|
481
|
+
puts "searching for seed at: #{File.join(File.expand_path(path), osw[:seed_file])}"
|
482
|
+
if File.exist?(File.join(File.expand_path(path), osw[:seed_file]))
|
483
|
+
puts "found seed_file: #{osw[:seed_file]}"
|
484
|
+
self.seed_model = File.join(File.expand_path(path), osw[:seed_file])
|
485
|
+
break
|
486
|
+
end
|
487
|
+
end
|
488
|
+
else
|
489
|
+
warn "osw[:seed_file] is not defined"
|
490
|
+
end
|
491
|
+
|
492
|
+
# weather_file, check if in OSW and not found in path search already
|
493
|
+
if osw[:weather_file]
|
494
|
+
osw[:file_paths].each do |path|
|
495
|
+
puts "searching for weather at: #{File.join(File.expand_path(path), osw[:weather_file])}"
|
496
|
+
if File.exist?(File.join(File.expand_path(path), osw[:weather_file]))
|
497
|
+
puts "found weather_file: #{osw[:weather_file]}"
|
498
|
+
self.weather_file = File.join(File.expand_path(path), osw[:weather_file])
|
499
|
+
break
|
500
|
+
end
|
501
|
+
end
|
502
|
+
else
|
503
|
+
warn "osw[:weather_file] is not defined"
|
504
|
+
end
|
505
|
+
|
506
|
+
# file_paths is not defined in OSW, so warn and try to set
|
507
|
+
else
|
508
|
+
warn ":file_paths is not defined in the OSW."
|
509
|
+
self.weather_file = osw[:weather_file] ? osw[:weather_file] : nil
|
510
|
+
self.seed_model = osw[:seed_file] ? osw[:seed_file] : nil
|
511
|
+
end
|
512
|
+
|
513
|
+
#set analysis_type default to Single_Run
|
514
|
+
self.analysis_type = 'single_run'
|
515
|
+
|
516
|
+
#loop over OSW 'steps' and map over measures
|
517
|
+
#there is no name/display name in the OSW. Just measure directory name
|
518
|
+
#read measure.XML from directory to get name / display name
|
519
|
+
#increment name by +_1 if there are duplicates
|
520
|
+
#add measure
|
521
|
+
#change default args to osw arg values
|
522
|
+
|
523
|
+
osw[:steps].each do |step|
|
524
|
+
#get measure directory
|
525
|
+
measure_dir = step[:measure_dir_name]
|
526
|
+
measure_name = measure_dir.split("measures/").last
|
527
|
+
puts "measure_dir_name: #{measure_name}"
|
528
|
+
#get XML
|
529
|
+
# Loop over possible user defined *measure_paths, including the dir of the osw_filename path and :measure_paths, to find the measure,
|
530
|
+
# then set measure_dir_abs_path to that path
|
531
|
+
measure_dir_abs_path = ''
|
532
|
+
paths_to_parse = [File.dirname(osw_filename), osw[:measure_paths], *measure_paths].flatten.compact.map { |path| File.join(File.expand_path(path), measure_dir, 'measure.xml') }
|
533
|
+
puts "searching for xml's in: #{paths_to_parse}"
|
534
|
+
xml = {}
|
535
|
+
paths_to_parse.each do |path|
|
536
|
+
if File.exist?(path)
|
537
|
+
puts "found xml: #{path}"
|
538
|
+
xml = parse_measure_xml(path)
|
539
|
+
if !xml.empty?
|
540
|
+
measure_dir_abs_path = path
|
541
|
+
break
|
542
|
+
end
|
543
|
+
end
|
544
|
+
end
|
545
|
+
raise "measure #{measure_name} not found" if xml.empty?
|
546
|
+
puts ""
|
547
|
+
#add check for previous names _+1
|
548
|
+
count = 1
|
549
|
+
name = xml[:name]
|
550
|
+
display_name = xml[:display_name]
|
551
|
+
loop do
|
552
|
+
measure = @workflow.find_measure(name)
|
553
|
+
break if measure.nil?
|
554
|
+
|
555
|
+
count += 1
|
556
|
+
name = "#{xml[:name]}_#{count}"
|
557
|
+
display_name = "#{xml[:display_name]} #{count}"
|
558
|
+
end
|
559
|
+
#Add Measure to workflow
|
560
|
+
@workflow.add_measure_from_path(name, display_name, measure_dir_abs_path) #this forces to an absolute path which seems constent with PAT
|
561
|
+
#@workflow.add_measure_from_path(name, display_name, measure_dir) #this uses the path in the OSW which could be relative
|
562
|
+
|
563
|
+
#Change the default argument values to the osw values
|
564
|
+
#1. find measure in @workflow
|
565
|
+
m = @workflow.find_measure(name)
|
566
|
+
#2. loop thru osw args
|
567
|
+
#check if the :argument is missing from the measure step, it shouldnt be but just in case give a clean message
|
568
|
+
if step[:arguments].nil?
|
569
|
+
raise "measure #{name} step has no arguments: #{step}"
|
570
|
+
else
|
571
|
+
step[:arguments].each do |k,v|
|
572
|
+
#check if argument is in measure, otherwise setting argument_value will crash
|
573
|
+
raise "OSW arg: #{k} is not in Measure: #{name}" if m.arguments.find_all { |a| a[:name] == k.to_s }.empty?
|
574
|
+
#set measure arg to match osw arg
|
575
|
+
m.argument_value(k.to_s, v)
|
576
|
+
end
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
private
|
582
|
+
|
583
|
+
# New format for OSAs. Package up the seed, weather files, and measures
|
584
|
+
# filename is the name of the file to be saved. ex: analysis.zip
|
585
|
+
# it will parse the OSA and zip up all the files defined in the workflow
|
586
|
+
def save_analysis_zip_osa(filename, all_weather_files = false, all_seed_files = false)
|
587
|
+
def add_directory_to_zip_osa(zipfile, local_directory, relative_zip_directory)
|
588
|
+
puts "Add Directory #{local_directory}"
|
589
|
+
Dir[File.join(local_directory.to_s, '**', '**')].each do |file|
|
590
|
+
puts "Adding File #{file}"
|
591
|
+
zipfile.add(file.sub(local_directory, relative_zip_directory), file)
|
592
|
+
end
|
593
|
+
zipfile
|
594
|
+
end
|
595
|
+
#delete file if exists
|
596
|
+
FileUtils.rm_f(filename) if File.exist?(filename)
|
597
|
+
#get the full path to the OSW, since all Files/Dirs should be in same directory as the OSW
|
598
|
+
puts "osw_path: #{@osw_path}"
|
599
|
+
osw_full_path = File.dirname(File.expand_path(@osw_path))
|
600
|
+
puts "osw_full_path: #{osw_full_path}"
|
601
|
+
|
602
|
+
Zip::File.open(filename, create: true) do |zf|
|
603
|
+
## Weather files
|
604
|
+
puts 'Adding Support Files: Weather'
|
605
|
+
# check if weather file exists. use abs path. remove leading ./ from @weather_file path if there.
|
606
|
+
# check if path is already absolute
|
607
|
+
if @weather_file[:file]
|
608
|
+
if File.exist?(@weather_file[:file])
|
609
|
+
puts " Adding #{@weather_file[:file]}"
|
610
|
+
#zf.add("weather/#{File.basename(@weather_file[:file])}", @weather_file[:file])
|
611
|
+
base_name = File.basename(@weather_file[:file], ".*")
|
612
|
+
puts "base_name: #{base_name}"
|
613
|
+
# convert backslash on windows to forward slash so Dir.glob will work (in case user uses \)
|
614
|
+
weather_dirname = File.dirname(@weather_file[:file]).gsub("\\", "/")
|
615
|
+
puts "weather_dirname: #{weather_dirname}"
|
616
|
+
# If all_weather_files is true, add all files in the directory to the zip.
|
617
|
+
# Otherwise, add only files that match the base name.
|
618
|
+
file_pattern = all_weather_files ? "*" : "#{base_name}.*"
|
619
|
+
Dir.glob(File.join(weather_dirname, file_pattern)) do |file_path|
|
620
|
+
puts "file_path: #{file_path}"
|
621
|
+
puts "zip path: weather/#{File.basename(file_path)}"
|
622
|
+
zf.add("weather/#{File.basename(file_path)}", file_path)
|
623
|
+
end
|
624
|
+
# make absolute path and check for file
|
625
|
+
elsif File.exist?(File.join(osw_full_path,@weather_file[:file].sub(/^\.\//, '')))
|
626
|
+
puts " Adding: #{File.join(osw_full_path,@weather_file[:file].sub(/^\.\//, ''))}"
|
627
|
+
#zf.add("weather/#{File.basename(@weather_file[:file])}", File.join(osw_full_path,@weather_file[:file].sub(/^\.\//, '')))
|
628
|
+
base_name = File.basename(@weather_file[:file].sub(/^\.\//, ''), ".*")
|
629
|
+
puts "base_name2: #{base_name}"
|
630
|
+
weather_dirname = File.dirname(File.join(osw_full_path,@weather_file[:file].sub(/^\.\//, ''))).gsub("\\", "/")
|
631
|
+
puts "weather_dirname: #{weather_dirname}"
|
632
|
+
file_pattern = all_weather_files ? "*" : "#{base_name}.*"
|
633
|
+
Dir.glob(File.join(weather_dirname, file_pattern)) do |file_path|
|
634
|
+
puts "file_path2: #{file_path}"
|
635
|
+
puts "zip path2: weather/#{File.basename(file_path)}"
|
636
|
+
zf.add("weather/#{File.basename(file_path)}", file_path)
|
637
|
+
end
|
638
|
+
else
|
639
|
+
raise "weather_file[:file] does not exist at: #{File.join(osw_full_path,@weather_file[:file].sub(/^\.\//, ''))}"
|
640
|
+
end
|
641
|
+
else
|
642
|
+
warn "weather_file[:file] is not defined"
|
643
|
+
end
|
644
|
+
|
645
|
+
## Seed files
|
646
|
+
puts 'Adding Support Files: Seed Models'
|
647
|
+
#check if seed file exists. use abs path. remove leading ./ from @seed_model path if there.
|
648
|
+
#check if path is already absolute
|
649
|
+
if @seed_model[:file]
|
650
|
+
if File.exist?(@seed_model[:file])
|
651
|
+
puts " Adding #{@seed_model[:file]}"
|
652
|
+
zf.add("seeds/#{File.basename(@seed_model[:file])}", @seed_model[:file])
|
653
|
+
if all_seed_files
|
654
|
+
seed_dirname = File.dirname(@seed_model[:file]).gsub("\\", "/")
|
655
|
+
puts "seed_dirname: #{seed_dirname}"
|
656
|
+
Dir.glob(File.join(seed_dirname, '*')) do |file_path|
|
657
|
+
next if file_path == @seed_model[:file] # Skip if the file is the same as @seed_model[:file] so not added twice
|
658
|
+
puts "file_path: #{file_path}"
|
659
|
+
puts "zip path: seeds/#{File.basename(file_path)}"
|
660
|
+
zf.add("seeds/#{File.basename(file_path)}", file_path)
|
661
|
+
end
|
662
|
+
end
|
663
|
+
#make absolute path and check for file
|
664
|
+
elsif File.exist?(File.join(osw_full_path,@seed_model[:file].sub(/^\.\//, '')))
|
665
|
+
puts " Adding #{File.join(osw_full_path,@seed_model[:file].sub(/^\.\//, ''))}"
|
666
|
+
zf.add("seeds/#{File.basename(@seed_model[:file])}", File.join(osw_full_path,@seed_model[:file].sub(/^\.\//, '')))
|
667
|
+
if all_seed_files
|
668
|
+
seed_dirname = File.dirname(File.join(osw_full_path,@seed_model[:file].sub(/^\.\//, ''))).gsub("\\", "/")
|
669
|
+
puts "seed_dirname: #{seed_dirname}"
|
670
|
+
Dir.glob(File.join(seed_dirname, '*')) do |file_path|
|
671
|
+
next if file_path == File.join(osw_full_path,@seed_model[:file].sub(/^\.\//, '')) # Skip if the file is the same as @seed_model[:file] so not added twice
|
672
|
+
puts "file_path: #{file_path}"
|
673
|
+
puts "zip path: seeds/#{File.basename(file_path)}"
|
674
|
+
zf.add("seeds/#{File.basename(file_path)}", file_path)
|
675
|
+
end
|
676
|
+
end
|
677
|
+
else
|
678
|
+
raise "seed_file[:file] does not exist at: #{File.join(osw_full_path,@seed_model[:file].sub(/^\.\//, ''))}"
|
679
|
+
end
|
680
|
+
else
|
681
|
+
warn "seed_file[:file] is not defined"
|
682
|
+
end
|
683
|
+
|
684
|
+
puts 'Adding Support Files: Libraries'
|
685
|
+
@libraries.each do |lib|
|
686
|
+
raise "Libraries must specify their 'library_name' as metadata which becomes the directory upon zip" unless lib[:metadata][:library_name]
|
687
|
+
|
688
|
+
if File.directory? lib[:file]
|
689
|
+
Dir[File.join(lib[:file], '**', '**')].each do |file|
|
690
|
+
puts " Adding #{file}"
|
691
|
+
zf.add(file.sub(lib[:file], "lib/#{lib[:metadata][:library_name]}"), file)
|
692
|
+
end
|
693
|
+
else
|
694
|
+
# just add the file to the zip
|
695
|
+
puts " Adding #{lib[:file]}"
|
696
|
+
zf.add(lib[:file], "lib/#{File.basename(lib[:file])}", lib[:file])
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
700
|
+
puts 'Adding Support Files: Server Scripts'
|
701
|
+
@server_scripts.each_with_index do |f, index|
|
702
|
+
if f[:init_or_final] == 'finalization'
|
703
|
+
file_name = 'finalization.sh'
|
704
|
+
else
|
705
|
+
file_name = 'initialization.sh'
|
706
|
+
end
|
707
|
+
if f[:server_or_data_point] == 'analysis'
|
708
|
+
new_name = "scripts/analysis/#{file_name}"
|
709
|
+
else
|
710
|
+
new_name = "scripts/data_point/#{file_name}"
|
711
|
+
end
|
712
|
+
puts " Adding #{f[:file]} as #{new_name}"
|
713
|
+
zf.add(new_name, f[:file])
|
714
|
+
|
715
|
+
if f[:arguments]
|
716
|
+
arg_file = "#{(new_name.sub(/\.sh\z/, ''))}.args"
|
717
|
+
puts " Adding arguments as #{arg_file}"
|
718
|
+
file = Tempfile.new('arg')
|
719
|
+
file.write(f[:arguments])
|
720
|
+
zf.add(arg_file, file)
|
721
|
+
file.close
|
722
|
+
end
|
723
|
+
end
|
724
|
+
|
725
|
+
puts 'Adding Gemfiles'
|
726
|
+
@gem_files.each do |f|
|
727
|
+
puts " Adding #{f[:file]}"
|
728
|
+
zf.add(File.basename(f[:file]), f[:file])
|
729
|
+
end
|
730
|
+
|
731
|
+
## Measures
|
732
|
+
puts 'Adding Measures'
|
733
|
+
added_measures = []
|
734
|
+
# The list of the measures should always be there, but make sure they are uniq
|
735
|
+
@workflow.each do |measure|
|
736
|
+
measure_dir_to_add = measure.measure_definition_directory_local
|
737
|
+
|
738
|
+
next if added_measures.include? measure_dir_to_add
|
739
|
+
|
740
|
+
puts " Adding #{File.basename(measure_dir_to_add)}"
|
741
|
+
Dir[File.join(measure_dir_to_add, '**')].each do |file|
|
742
|
+
if File.directory?(file)
|
743
|
+
if File.basename(file) == 'resources' || File.basename(file) == 'lib'
|
744
|
+
#remove leading ./ from measure_definition_directory path if there.
|
745
|
+
add_directory_to_zip_osa(zf, file, "#{measure.measure_definition_directory.sub(/^\.\//, '')}/#{File.basename(file)}")
|
746
|
+
end
|
747
|
+
else
|
748
|
+
puts " Adding File #{file}"
|
749
|
+
#remove leading ./ from measure.measure_definition_directory string with regex .sub(/^\.\//, '')
|
750
|
+
zip_path_for_measures = file.sub(measure_dir_to_add, measure.measure_definition_directory.sub(/^\.\//, ''))
|
751
|
+
#puts " zip_path_for_measures: #{zip_path_for_measures}"
|
752
|
+
zf.add(zip_path_for_measures, file)
|
753
|
+
end
|
754
|
+
end
|
755
|
+
|
756
|
+
added_measures << measure_dir_to_add
|
757
|
+
end
|
758
|
+
end
|
759
|
+
end
|
760
|
+
|
761
|
+
#keep legacy function
|
762
|
+
# Package up the seed, weather files, and measures
|
763
|
+
def save_analysis_zip(filename)
|
764
|
+
def add_directory_to_zip(zipfile, local_directory, relative_zip_directory)
|
765
|
+
# puts "Add Directory #{local_directory}"
|
766
|
+
Dir[File.join(local_directory.to_s, '**', '**')].each do |file|
|
767
|
+
# puts "Adding File #{file}"
|
768
|
+
zipfile.add(file.sub(local_directory, relative_zip_directory), file)
|
769
|
+
end
|
770
|
+
zipfile
|
771
|
+
end
|
772
|
+
|
773
|
+
FileUtils.rm_f(filename) if File.exist?(filename)
|
774
|
+
|
775
|
+
Zip::File.open(filename, Zip::File::CREATE) do |zf|
|
776
|
+
## Weather files
|
777
|
+
# TODO: eventually remove the @weather_file attribute and grab the weather file out
|
778
|
+
# of the @weather_files
|
779
|
+
puts 'Adding Support Files: Weather'
|
780
|
+
if @weather_file[:file] && !@weather_files.files.find { |f| @weather_file[:file] == f[:file] }
|
781
|
+
# manually add the weather file
|
782
|
+
puts " Adding #{@weather_file[:file]}"
|
783
|
+
zf.add("./weather/#{File.basename(@weather_file[:file])}", @weather_file[:file])
|
784
|
+
end
|
785
|
+
@weather_files.each do |f|
|
786
|
+
puts " Adding #{f[:file]}"
|
787
|
+
zf.add("./weather/#{File.basename(f[:file])}", f[:file])
|
788
|
+
end
|
789
|
+
|
790
|
+
## Seed files
|
791
|
+
puts 'Adding Support Files: Seed Models'
|
792
|
+
if @seed_model[:file] && !@seed_models.files.find { |f| @seed_model[:file] == f[:file] }
|
793
|
+
# manually add the weather file
|
794
|
+
puts " Adding #{@seed_model[:file]}"
|
795
|
+
zf.add("./seed/#{File.basename(@seed_model[:file])}", @seed_model[:file])
|
796
|
+
end
|
797
|
+
@seed_models.each do |f|
|
798
|
+
puts " Adding #{f[:file]}"
|
799
|
+
zf.add("./seed/#{File.basename(f[:file])}", f[:file])
|
800
|
+
end
|
801
|
+
|
802
|
+
puts 'Adding Support Files: Libraries'
|
803
|
+
@libraries.each do |lib|
|
804
|
+
raise "Libraries must specify their 'library_name' as metadata which becomes the directory upon zip" unless lib[:metadata][:library_name]
|
805
|
+
|
806
|
+
if File.directory? lib[:file]
|
807
|
+
Dir[File.join(lib[:file], '**', '**')].each do |file|
|
808
|
+
puts " Adding #{file}"
|
809
|
+
zf.add(file.sub(lib[:file], "./lib/#{lib[:metadata][:library_name]}/"), file)
|
810
|
+
end
|
811
|
+
else
|
812
|
+
# just add the file to the zip
|
813
|
+
puts " Adding #{lib[:file]}"
|
814
|
+
zf.add(lib[:file], "./lib/#{File.basename(lib[:file])}", lib[:file])
|
815
|
+
end
|
816
|
+
end
|
817
|
+
|
818
|
+
puts 'Adding Support Files: Worker Initialization Scripts'
|
819
|
+
@worker_inits.each_with_index do |f, index|
|
820
|
+
ordered_file_name = "#{index.to_s.rjust(2, '0')}_#{File.basename(f[:file])}"
|
821
|
+
puts " Adding #{f[:file]} as #{ordered_file_name}"
|
822
|
+
zf.add(f[:file].sub(f[:file], "./scripts/worker_initialization//#{ordered_file_name}"), f[:file])
|
823
|
+
|
824
|
+
if f[:metadata][:args]
|
825
|
+
arg_file = "#{File.basename(ordered_file_name, '.*')}.args"
|
826
|
+
file = Tempfile.new('arg')
|
827
|
+
file.write(f[:metadata][:args])
|
828
|
+
zf.add("./scripts/worker_initialization/#{arg_file}", file)
|
829
|
+
file.close
|
830
|
+
end
|
831
|
+
end
|
832
|
+
|
833
|
+
puts 'Adding Support Files: Worker Finalization Scripts'
|
834
|
+
@worker_finalizes.each_with_index do |f, index|
|
835
|
+
ordered_file_name = "#{index.to_s.rjust(2, '0')}_#{File.basename(f[:file])}"
|
836
|
+
puts " Adding #{f[:file]} as #{ordered_file_name}"
|
837
|
+
zf.add(f[:file].sub(f[:file], "scripts/worker_finalization/#{ordered_file_name}"), f[:file])
|
838
|
+
|
839
|
+
if f[:metadata][:args]
|
840
|
+
arg_file = "#{File.basename(ordered_file_name, '.*')}.args"
|
841
|
+
file = Tempfile.new('arg')
|
842
|
+
file.write(f[:metadata][:args])
|
843
|
+
zf.add("scripts/worker_finalization/#{arg_file}", file)
|
844
|
+
file.close
|
845
|
+
end
|
846
|
+
end
|
847
|
+
|
848
|
+
puts 'Adding Gemfiles'
|
849
|
+
@gem_files.each do |f|
|
850
|
+
puts " Adding #{f}"
|
851
|
+
zf.add(File.basename(f), f)
|
852
|
+
end
|
853
|
+
|
854
|
+
## Measures
|
855
|
+
puts 'Adding Measures'
|
856
|
+
added_measures = []
|
857
|
+
# The list of the measures should always be there, but make sure they are uniq
|
858
|
+
@workflow.each do |measure|
|
859
|
+
measure_dir_to_add = measure.measure_definition_directory_local
|
860
|
+
|
861
|
+
next if added_measures.include? measure_dir_to_add
|
862
|
+
|
863
|
+
puts " Adding #{File.basename(measure_dir_to_add)}"
|
864
|
+
Dir[File.join(measure_dir_to_add, '**')].each do |file|
|
865
|
+
if File.directory?(file)
|
866
|
+
if File.basename(file) == 'resources' || File.basename(file) == 'lib'
|
867
|
+
add_directory_to_zip(zf, file, "#{measure.measure_definition_directory}/#{File.basename(file)}")
|
868
|
+
end
|
869
|
+
else
|
870
|
+
# puts "Adding File #{file}"
|
871
|
+
zf.add(file.sub(measure_dir_to_add, "#{measure.measure_definition_directory}/"), file)
|
872
|
+
end
|
873
|
+
end
|
874
|
+
|
875
|
+
added_measures << measure_dir_to_add
|
876
|
+
end
|
877
|
+
end
|
878
|
+
end
|
879
|
+
end
|
880
|
+
end
|
881
|
+
end
|