urbanopt-reopt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.rakeTasks +7 -0
  4. data/.rdoc_options +37 -0
  5. data/.rspec +3 -0
  6. data/.rubocop.yml +9 -0
  7. data/.travis.yml +22 -0
  8. data/CHANGELOG.md +5 -0
  9. data/Gemfile +67 -0
  10. data/Jenkinsfile +10 -0
  11. data/LICENSE.md +27 -0
  12. data/RDOC_MAIN.md +176 -0
  13. data/README.md +177 -0
  14. data/Rakefile +30 -0
  15. data/deploy_docs.sh +5 -0
  16. data/developer_nrel_key.rb +31 -0
  17. data/doc_templates/LICENSE.md +27 -0
  18. data/doc_templates/README.md.erb +42 -0
  19. data/doc_templates/copyright_erb.txt +31 -0
  20. data/doc_templates/copyright_js.txt +4 -0
  21. data/doc_templates/copyright_ruby.txt +29 -0
  22. data/docs/.gitignore +3 -0
  23. data/docs/.vuepress/components/InnerJsonSchema.vue +78 -0
  24. data/docs/.vuepress/components/JsonSchema.vue +12 -0
  25. data/docs/.vuepress/components/ReoptInputSchema.vue +12 -0
  26. data/docs/.vuepress/components/ReoptOutputSchema.vue +12 -0
  27. data/docs/.vuepress/components/StaticLink.vue +8 -0
  28. data/docs/.vuepress/config.js +16 -0
  29. data/docs/.vuepress/highlight.js +8 -0
  30. data/docs/.vuepress/public/custom_rdoc_styles.css +58 -0
  31. data/docs/.vuepress/utils.js +17 -0
  32. data/docs/README.md +196 -0
  33. data/docs/package-lock.json +254 -0
  34. data/docs/package.json +22 -0
  35. data/docs/schemas/reopt-input-schema.md +57 -0
  36. data/docs/schemas/reopt-output-schema.md +66 -0
  37. data/index.html +1 -0
  38. data/index.md +176 -0
  39. data/lib/files/.gitkeep +0 -0
  40. data/lib/urbanopt/reopt/extension.rb +44 -0
  41. data/lib/urbanopt/reopt/feature_report_adapter.rb +364 -0
  42. data/lib/urbanopt/reopt/reopt_lite_api.rb +230 -0
  43. data/lib/urbanopt/reopt/reopt_logger.rb +42 -0
  44. data/lib/urbanopt/reopt/reopt_post_processor.rb +245 -0
  45. data/lib/urbanopt/reopt/reopt_schema/reopt_input_schema.json +1111 -0
  46. data/lib/urbanopt/reopt/reopt_schema/reopt_output_schema.json +538 -0
  47. data/lib/urbanopt/reopt/scenario/reopt_scenario_csv.rb +115 -0
  48. data/lib/urbanopt/reopt/scenario_report_adapter.rb +404 -0
  49. data/lib/urbanopt/reopt/version.rb +35 -0
  50. data/lib/urbanopt/reopt.rb +36 -0
  51. data/lib/urbanopt/reopt_scenario.rb +31 -0
  52. data/lib/urbanopt-reopt.rb +31 -0
  53. data/urbanopt-reopt.gemspec +33 -0
  54. metadata +194 -0
@@ -0,0 +1,538 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "description": "Data Dictionary for REopt Lite Outputs",
4
+ "type": "object",
5
+ "properties": {
6
+ "$ref": "#/definitions/Response"
7
+ },
8
+ "required": [
9
+ "Scenario"
10
+ ],
11
+ "definitions": {
12
+ "Response": {
13
+ "inputs": {
14
+ "type": "object",
15
+ "properties": {
16
+ "Scenario": {
17
+ "type": "object",
18
+ "description": "See REopt Input Schema"
19
+ }
20
+ }
21
+ },
22
+ "outputs": {
23
+ "type": "object",
24
+ "properties": {
25
+ "Scenario": {
26
+ "type": "object",
27
+ "properties": {
28
+ "run_uuid": {
29
+ "type": "str",
30
+ "description": "Unique id",
31
+ "units": "none"
32
+ },
33
+ "api_version": {
34
+ "type": "str"
35
+ },
36
+ "status": {
37
+ "type": "str",
38
+ "description": "Problem Status",
39
+ "units": "none"
40
+ },
41
+ "Profile": {
42
+ "type": "object",
43
+ "properties": {
44
+ "pre_setup_scenario_seconds": {
45
+ "type": "float",
46
+ "description": "Time spent before setting up scenario",
47
+ "units": "seconds"
48
+ },
49
+ "setup_scenario_seconds": {
50
+ "type": "float",
51
+ "description": "Time spent setting up scenario",
52
+ "units": "seconds"
53
+ },
54
+ "reopt_seconds": {
55
+ "type": "float",
56
+ "description": "Time spent solving scenario",
57
+ "units": "seconds"
58
+ },
59
+ "reopt_bau_seconds": {
60
+ "type": "float",
61
+ "description": "Time spent solving base-case scenario",
62
+ "units": "seconds"
63
+ },
64
+ "parse_run_outputs_seconds": {
65
+ "type": "float",
66
+ "description": "Time spent parsing outputs",
67
+ "units": "seconds"
68
+ }
69
+ }
70
+ },
71
+ "Site": {
72
+ "type": "object",
73
+ "properties": {
74
+ "LoadProfile": {
75
+ "type": "object",
76
+ "properties": {
77
+ "year_one_electric_load_series_kw": {
78
+ "type": "list_of_float",
79
+ "description": "Year one hourly time series of electric load",
80
+ "units": "kW"
81
+ },
82
+ "critical_load_series_kw": {
83
+ "type": "list_of_float",
84
+ "description": "Hourly critical load for outage simulator. Values are either uploaded by user, or determined from typical load (either uploaded or simulated) and critical_load_pct.",
85
+ "units": "kW"
86
+ },
87
+ "annual_calculated_kwh": {
88
+ "type": "float",
89
+ "description": "Annual energy consumption calculated by summing up 8760 load profile",
90
+ "units": "kWh"
91
+ },
92
+ "resilience_check_flag": {
93
+ "type": "boolean",
94
+ "description": "BAU resilience check status for existing system"
95
+ },
96
+ "sustain_hours": {
97
+ "type": "int",
98
+ "description": "Number of hours the existing system can sustain with resilience check",
99
+ "units": "hours"
100
+ }
101
+ }
102
+ },
103
+ "Financial": {
104
+ "type": "object",
105
+ "properties": {
106
+ "lcc_us_dollars": {
107
+ "type": "float",
108
+ "description": "Optimal lifecycle cost",
109
+ "units": "dollars"
110
+ },
111
+ "lcc_bau_us_dollars": {
112
+ "type": "float",
113
+ "description": "Business as usual lifecycle cost",
114
+ "units": "dollars"
115
+ },
116
+ "npv_us_dollars": {
117
+ "type": "float",
118
+ "description": "Net present value of savings realized by the project",
119
+ "units": "dollars"
120
+ },
121
+ "net_capital_costs_plus_om_us_dollars": {
122
+ "type": "float",
123
+ "description": "Capital cost for all technologies plus present value of operations and maintenance over anlaysis period",
124
+ "units": "$"
125
+ },
126
+ "avoided_outage_costs_us_dollars": {
127
+ "type": "float",
128
+ "description": "Avoided outage costs are determined using the Value of Lost Load [$/kWh], multiplied by the average critical load in kW (determined using critical_load_pct), the average hours that the critical load is sustained (determined by simulating outages starting at every hour of the year), and a present worth factor that accounts for cost growth with escalation_pct over the analysis_years and discounts the avoided costs to present value using offtaker_discount_pct. Note that the use of a present worth factor presumes that the outage period and the microgrid's ability to meet the critical load is the same each year in the analysis_years.If outage_is_major_event is set to true, then the present worth factor is set to 1, which assumes that only one outage occurs in the analysis_years.",
129
+ "units": "$"
130
+ },
131
+ "net_capital_costs": {
132
+ "type": "float",
133
+ "description": "Capital cost for all technologies.",
134
+ "units": "$"
135
+ },
136
+ "microgrid_upgrade_cost_us_dollars": {
137
+ "type": "float",
138
+ "description": "Cost in US dollars to make a distributed energy system islandable from the grid.Determined by multiplying the total capital costs of resultant energy systems from REopt(such as PV and Storage system) with the input valuefor microgrid_upgrade_cost_pct(which defaults to 0.30)."
139
+ }
140
+ }
141
+ },
142
+ "PV": {
143
+ "type": "object",
144
+ "properties": {
145
+ "size_kw": {
146
+ "type": "float",
147
+ "description": "Optimal PV system size",
148
+ "units": "kW"
149
+ },
150
+ "average_yearly_energy_produced_kwh": {
151
+ "type": "float",
152
+ "description": "Average annual energy produced by the PV system over one year",
153
+ "units": "kWh"
154
+ },
155
+ "average_yearly_energy_exported_kwh": {
156
+ "type": "float",
157
+ "description": "Average annual energy exported by the PV system",
158
+ "units": "kWh"
159
+ },
160
+ "year_one_energy_produced_kwh": {
161
+ "type": "float",
162
+ "description": "Year one energy produced by the PV system",
163
+ "units": "kWh"
164
+ },
165
+ "year_one_power_production_series_kw": {
166
+ "type": "list_of_float",
167
+ "description": "Year one PV power production time series",
168
+ "units": "kW"
169
+ },
170
+ "year_one_to_battery_series_kw": {
171
+ "type": "list_of_float",
172
+ "description": "Year one hourly time series of PV charging",
173
+ "units": "kW"
174
+ },
175
+ "year_one_to_load_series_kw": {
176
+ "type": "list_of_float",
177
+ "description": "Year one hourly time series of PV serving load",
178
+ "units": "kW"
179
+ },
180
+ "year_one_to_grid_series_kw": {
181
+ "type": "list_of_float",
182
+ "description": "Year one hourly time series of PV exporting to grid",
183
+ "units": "kW"
184
+ },
185
+ "existing_pv_om_cost_us_dollars": {
186
+ "type": "float",
187
+ "description": "Lifetime O & M costfor existing PV system.",
188
+ "units": "$"
189
+ },
190
+ "station_latitude": {
191
+ "type": "float",
192
+ "description": "The latitude of the station usedfor weather resource data",
193
+ "units": "degrees"
194
+ },
195
+ "station_longitude": {
196
+ "type": "float",
197
+ "description": "The longitude of the station usedfor weather resource data",
198
+ "units": "degrees"
199
+ },
200
+ "station_distance_km": {
201
+ "type": "float",
202
+ "description": "The distance from the weather resource station from the input site",
203
+ "units": "km"
204
+ }
205
+ }
206
+ },
207
+ "Wind": {
208
+ "type": "object",
209
+ "properties": {
210
+ "size_kw": {
211
+ "type": "float",
212
+ "description": "Recommended wind system size",
213
+ "units": "kW"
214
+ },
215
+ "average_yearly_energy_produced_kwh": {
216
+ "type": "float",
217
+ "description": "Average energy produced by the wind system over one year",
218
+ "units": "kWh"
219
+ },
220
+ "average_yearly_energy_exported_kwh": {
221
+ "type": "float",
222
+ "description": "Average annual energy exported by the wind system",
223
+ "units": "kWh"
224
+ },
225
+ "year_one_energy_produced_kwh": {
226
+ "type": "float",
227
+ "description": "Wind energy produced in year one",
228
+ "units": "kWh"
229
+ },
230
+ "year_one_power_production_series_kw": {
231
+ "type": "list_of_float",
232
+ "description": "Hourly wind resource",
233
+ "units": "kW"
234
+ },
235
+ "year_one_to_battery_series_kw": {
236
+ "type": "list_of_float",
237
+ "description": "Year one wind to battery time series",
238
+ "units": "kW"
239
+ },
240
+ "year_one_to_load_series_kw": {
241
+ "type": "list_of_float",
242
+ "description": "Year one wind to load time series",
243
+ "units": "kW"
244
+ },
245
+ "year_one_to_grid_series_kw": {
246
+ "type": "list_of_float",
247
+ "description": "Year one wind to grid time series",
248
+ "units": "kW"
249
+ }
250
+ }
251
+ },
252
+ "Storage": {
253
+ "type": "object",
254
+ "properties": {
255
+ "size_kw": {
256
+ "type": "float",
257
+ "description": "Optimal battery power capacity",
258
+ "units": "kW"
259
+ },
260
+ "size_kwh": {
261
+ "type": "float",
262
+ "description": "Optimal battery energy capacity",
263
+ "units": "kWh"
264
+ },
265
+ "year_one_to_load_series_kw": {
266
+ "type": "list_of_float",
267
+ "description": "Year one hourly time series of battery serving load",
268
+ "units": "kW"
269
+ },
270
+ "year_one_to_grid_series_kw": {
271
+ "type": "list_of_float",
272
+ "description": "Year one hourly time series of battery exporting to grid",
273
+ "units": "kW"
274
+ },
275
+ "year_one_soc_series_pct": {
276
+ "type": "list_of_float",
277
+ "description": "Year one hourly time series of battery state of charge",
278
+ "units": " %"
279
+ }
280
+ }
281
+ },
282
+ "ElectricTariff": {
283
+ "type": "object",
284
+ "properties": {
285
+ "year_one_energy_cost_us_dollars": {
286
+ "type": "float",
287
+ "description": "Optimal year one utility energy cost",
288
+ "units": "$"
289
+ },
290
+ "year_one_demand_cost_us_dollars": {
291
+ "type": "float",
292
+ "description": "Optimal year one utility demand cost",
293
+ "units": "$"
294
+ },
295
+ "year_one_fixed_cost_us_dollars": {
296
+ "type": "float",
297
+ "description": "Optimal year one utility fixed cost",
298
+ "units": "$"
299
+ },
300
+ "year_one_min_charge_adder_us_dollars": {
301
+ "type": "float",
302
+ "description": "Optimal year one utility minimum charge adder",
303
+ "units": "$"
304
+ },
305
+ "year_one_energy_cost_bau_us_dollars": {
306
+ "type": "float",
307
+ "description": "Business as usual year one utility energy cost",
308
+ "units": "$"
309
+ },
310
+ "year_one_demand_cost_bau_us_dollars": {
311
+ "type": "float",
312
+ "description": "Business as usual year one utility demand cost",
313
+ "units": "$"
314
+ },
315
+ "year_one_fixed_cost_bau_us_dollars": {
316
+ "type": "float",
317
+ "description": "Business as usual year one utility fixed cost",
318
+ "units": "$"
319
+ },
320
+ "year_one_min_charge_adder_bau_us_dollars": {
321
+ "type": "float",
322
+ "description": "Business as usual year one utility minimum charge adder",
323
+ "units": "$"
324
+ },
325
+ "total_energy_cost_us_dollars": {
326
+ "type": "float",
327
+ "description": "Total utility energy cost over the lifecycle,after - tax",
328
+ "units": "$"
329
+ },
330
+ "total_demand_cost_us_dollars": {
331
+ "type": "float",
332
+ "description": "Optimal total lifecycle utility demand cost over the analysis period,after - tax",
333
+ "units": "$"
334
+ },
335
+ "total_fixed_cost_us_dollars": {
336
+ "type": "float",
337
+ "description": "Total utility fixed cost over the lifecycle,after - tax",
338
+ "units": "$"
339
+ },
340
+ "total_min_charge_adder_us_dollars": {
341
+ "type": "float",
342
+ "description": "Total utility minimum charge adder",
343
+ "units": "$"
344
+ },
345
+ "total_energy_cost_bau_us_dollars": {
346
+ "type": "float",
347
+ "description": "Business as usual total utility energy cost over the lifecycle,after - tax",
348
+ "units": "$"
349
+ },
350
+ "total_demand_cost_bau_us_dollars": {
351
+ "type": "float",
352
+ "description": "Business as usual total lifecycle utility demand cost over the analysis period,after - tax",
353
+ "units": "$"
354
+ },
355
+ "total_fixed_cost_bau_us_dollars": {
356
+ "type": "float",
357
+ "description": "Business as usual total utility fixed cost over the lifecycle,after - tax",
358
+ "units": "$"
359
+ },
360
+ "total_export_benefit_us_dollars": {
361
+ "type": "float",
362
+ "description": "Totalexport benefit cost over the lifecycle,after - tax",
363
+ "units": "$"
364
+ },
365
+ "total_min_charge_adder_bau_us_dollars": {
366
+ "type": "float",
367
+ "description": "Business as usual total utility minimum charge adder",
368
+ "units": "$"
369
+ },
370
+ "year_one_bill_us_dollars": {
371
+ "type": "float",
372
+ "description": "Optimal year one total utility bill",
373
+ "units": "$"
374
+ },
375
+ "year_one_bill_bau_us_dollars": {
376
+ "type": "float",
377
+ "description": "Business as usual year one total utility bill",
378
+ "units": "$"
379
+ },
380
+ "year_one_export_benefit_us_dollars": {
381
+ "type": "float",
382
+ "description": "Optimal year one value of exported energy",
383
+ "units": "$"
384
+ },
385
+ "year_one_energy_cost_series_us_dollars_per_kwh": {
386
+ "type": "list_of_float",
387
+ "description": "Year one hourly energy costs",
388
+ "units": "$ / kWh"
389
+ },
390
+ "year_one_demand_cost_series_us_dollars_per_kw": {
391
+ "type": "list_of_float",
392
+ "description": "Year one hourly demand costs",
393
+ "units": "$ / kW"
394
+ },
395
+ "year_one_to_load_series_kw": {
396
+ "type": "list_of_float",
397
+ "description": "Year one grid to load time series",
398
+ "units": "kW"
399
+ },
400
+ "year_one_to_battery_series_kw": {
401
+ "type": "list_of_float",
402
+ "description": "Year one hourly time series of power from grid to battery",
403
+ "units": "kW"
404
+ },
405
+ "year_one_energy_supplied_kwh": {
406
+ "type": "float",
407
+ "description": "Year one hourly time series of power from grid to load",
408
+ "units": "kWh"
409
+ },
410
+ "year_one_energy_supplied_kwh_bau": {
411
+ "type": "float",
412
+ "description": "Year one hourly time series of power from grid to load in bau scenario",
413
+ "units": "kWh"
414
+ }
415
+ }
416
+ },
417
+ "Generator": {
418
+ "type": "object",
419
+ "properties": {
420
+ "size_kw": {
421
+ "type": "float",
422
+ "description": "Optimal diesel generator system size",
423
+ "units": "kW"
424
+ },
425
+ "fuel_used_gal": {
426
+ "type": "float",
427
+ "description": "Generator fuel used to meet critical load during grid outage.",
428
+ "units": "US gallons"
429
+ },
430
+ "fuel_used_gal_bau": {
431
+ "type": "float",
432
+ "description": "Generator fuel used to meet critical load during grid outage in baucase.",
433
+ "units": "US gallons"
434
+ },
435
+ "average_yearly_energy_produced_kwh": {
436
+ "type": "float",
437
+ "description": "Average annual energy produced by the diesel generator over one year",
438
+ "units": "kWh"
439
+ },
440
+ "average_yearly_energy_exported_kwh": {
441
+ "type": "float",
442
+ "description": "Average annual energy exported by the diesel generator",
443
+ "units": "kWh"
444
+ },
445
+ "year_one_energy_produced_kwh": {
446
+ "type": "float",
447
+ "description": "Year one energy produced by the diesel generator",
448
+ "units": "kWh"
449
+ },
450
+ "year_one_power_production_series_kw": {
451
+ "type": "list_of_float",
452
+ "description": "Year one diesel generator power production time series",
453
+ "units": "kW"
454
+ },
455
+ "year_one_to_battery_series_kw": {
456
+ "type": "list_of_float",
457
+ "description": "Year one hourly time series of diesel generator charging",
458
+ "units": "kW"
459
+ },
460
+ "year_one_to_load_series_kw": {
461
+ "type": "list_of_float",
462
+ "description": "Year one generator to load time series.",
463
+ "units": "kW"
464
+ },
465
+ "year_one_to_grid_series_kw": {
466
+ "type": "list_of_float",
467
+ "description": "Year one hourly time series of diesel generator exporting to grid",
468
+ "units": "kW"
469
+ },
470
+ "existing_gen_total_fixed_om_cost_us_dollars": {
471
+ "type": "float",
472
+ "description": "Lifetime fixed O & M costfor existing diesel generator system in baucase.",
473
+ "units": "$"
474
+ },
475
+ "existing_gen_total_variable_om_cost_us_dollars": {
476
+ "type": "float",
477
+ "description": "Lifetime variable(based on kwh produced) O & M costfor existing diesel generator system.",
478
+ "units": "$"
479
+ },
480
+ "existing_gen_year_one_variable_om_cost_us_dollars": {
481
+ "type": "float",
482
+ "description": "Year one variable(based on kwh produced) O & M costfor existing diesel generator system.",
483
+ "units": "$"
484
+ },
485
+ "total_variable_om_cost_us_dollars": {
486
+ "type": "float",
487
+ "description": "Total lifecycle variable(based on kwh produced) O & M costfor existing + newly recommended diesel generator system",
488
+ "units": "$"
489
+ },
490
+ "year_one_variable_om_cost_us_dollars": {
491
+ "type": "float",
492
+ "description": "Year one variable(based on kwh produced) O & M costfor existing + newly recommended diesel generator system",
493
+ "units": "$"
494
+ },
495
+ "total_fuel_cost_us_dollars": {
496
+ "type": "float",
497
+ "description": "Total lifecycle fuel costfor existing + newly recommended diesel generator system",
498
+ "units": "$"
499
+ },
500
+ "year_one_fuel_cost_us_dollars": {
501
+ "type": "float",
502
+ "description": "Year one fuel costfor existing + newly recommended diesel generator system",
503
+ "units": "$"
504
+ },
505
+ "existing_gen_total_fuel_cost_us_dollars": {
506
+ "type": "float",
507
+ "description": "Total lifecycle fuel costfor existing diesel generator system",
508
+ "units": "$"
509
+ },
510
+ "existing_gen_year_one_fuel_cost_us_dollars": {
511
+ "type": "float",
512
+ "description": "Year one fuel costfor existing diesel generator system",
513
+ "units": "$"
514
+ }
515
+ }
516
+ }
517
+ }
518
+ }
519
+ }
520
+ }
521
+ }
522
+ },
523
+ "messages": {
524
+ "type": "object",
525
+ "properties": {
526
+ "warnings": {
527
+ "type": "list_of_string",
528
+ "description": "Warnings generated by simulation"
529
+ },
530
+ "error": {
531
+ "type": "str",
532
+ "description": "Error generated by simulation"
533
+ }
534
+ }
535
+ }
536
+ }
537
+ }
538
+ }
@@ -0,0 +1,115 @@
1
+ # *********************************************************************************
2
+ # URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
3
+ # contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # Redistributions of source code must retain the above copyright notice, this list
9
+ # of conditions and the following disclaimer.
10
+ #
11
+ # Redistributions in binary form must reproduce the above copyright notice, this
12
+ # list of conditions and the following disclaimer in the documentation and/or other
13
+ # materials provided with the distribution.
14
+ #
15
+ # Neither the name of the copyright holder nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without specific
17
+ # prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
+ # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
+ # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ # *********************************************************************************
30
+
31
+ require 'urbanopt/scenario/scenario_base'
32
+ require 'urbanopt/scenario/simulation_dir_osw'
33
+
34
+ require 'csv'
35
+ require 'fileutils'
36
+
37
+ module URBANopt # nodoc:
38
+ module Scenario # nodoc:
39
+ class REoptScenarioCSV < ScenarioCSV
40
+ ##
41
+ # REoptScenarioCSV is an extension of ScenarioCSV which assigns a Simulation Mapper to each Feature in a FeatureFile using a simple CSV format.
42
+ # The a \REopt Lite enabled CSV file has four columns 1) feature_id, 2) feature_name, 3) mapper_class_name and 4) optional reopt assumptions file name. There is one row for each Feature.
43
+ # A REoptScenarioCSV can be instantiated with set of assumptions to use in \REopt Lite for an optimization at the aggregated ScenarioReport level.
44
+ # A REoptScenarioCSV is also instantiated with a +reopt_files_dir+ file directory containing all \REopt Lite assumptions files (required only if the ScenarioReport or its FeatureReports will have specified assumptions).
45
+ #
46
+ # [*parameters:*]
47
+ #
48
+ # * +name+ - _String_ - Human readable scenario name.
49
+ # * +root_dir+ - _String_ - Root directory for the scenario, contains Gemfile describing dependencies.
50
+ # * +run_dir+ - _String_ - Directory for simulation of this scenario, deleting run directory clears the scenario.
51
+ # * +feature_file+ - _URBANopt::Core::FeatureFile_ - FeatureFile containing features to simulate.
52
+ # * +mapper_files_dir+ - _String_ - Directory containing all mapper class files containing MapperBase definitions.
53
+ # * +csv_file+ - _String_ - Path to CSV file assigning a MapperBase class to each feature in feature_file.
54
+ # * +num_header_rows+ - _String_ - Number of header rows to skip in CSV file.
55
+ # * +reopt_files_dir+ - _String_ - Path to folder containing default \REopt Lite assumptions JSON's.
56
+ # * +scenario_reopt_assumptions_file_name+ - _String_ - Name of .json file in the +reopt_files_dir+ location to use in assessing the aggregated ScenarioReport in \REopt Lite.
57
+ ##
58
+ def initialize(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows, reopt_files_dir = nil, scenario_reopt_assumptions_file_name = nil)
59
+ super(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
60
+
61
+ @reopt_files_dir = reopt_files_dir
62
+ @reopt_feature_assumptions = []
63
+ @scenario_reopt_assumptions_file = nil
64
+
65
+ if !reopt_files_dir.nil? && !scenario_reopt_assumptions_file_name.nil?
66
+ @scenario_reopt_assumptions_file = File.join(@reopt_files_dir, scenario_reopt_assumptions_file_name)
67
+ end
68
+ end
69
+ # Path to json files of reopt assumptions for feature reports ordered by feature order
70
+ attr_accessor :reopt_feature_assumptions
71
+
72
+ # Path to json file of reopt assumptions for scenario report
73
+ attr_reader :scenario_reopt_assumptions_file #:nodoc:
74
+
75
+ # Gets all the simulation directories
76
+ def simulation_dirs
77
+ # DLM: TODO use HeaderConverters from CSV module
78
+ rows_skipped = 0
79
+ result = []
80
+ CSV.foreach(@csv_file).with_index do |row, idx|
81
+ if rows_skipped < @num_header_rows
82
+ rows_skipped += 1
83
+ next
84
+ end
85
+
86
+ break if row[0].nil?
87
+
88
+ # gets +feature_id+ , +feature_name+ and +mapper_class+ from csv_file
89
+ feature_id = row[0].chomp
90
+ feature_name = row[1].chomp
91
+ mapper_class = row[2].chomp
92
+ # Assume fourth columns, if exists, contains the name of the JSON file in the reopt_files_dir to use when running \REopt Lite for the feature report
93
+
94
+ if row.length > 3
95
+ if !@reopt_files_dir.nil?
96
+ @reopt_feature_assumptions[idx - 1] = File.join(@reopt_files_dir, row[3].chomp)
97
+ end
98
+ end
99
+
100
+ # gets +features+ from the feature_file.
101
+ features = []
102
+ feature = feature_file.get_feature_by_id(feature_id)
103
+ features << feature
104
+
105
+ feature_names = []
106
+ feature_names << feature_name
107
+ simulation_dir = SimulationDirOSW.new(self, features, feature_names, mapper_class)
108
+
109
+ result << simulation_dir
110
+ end
111
+ return result
112
+ end
113
+ end
114
+ end
115
+ end