-
Notifications
You must be signed in to change notification settings - Fork 16
/
os_lib_reporting.rb
4801 lines (4130 loc) · 199 KB
/
os_lib_reporting.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
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
351
352
353
354
355
356
357
358
359
360
361
362
363
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
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
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
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
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
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# *******************************************************************************
# OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
# See also https://openstudio.net/license
# *******************************************************************************
require 'json'
require 'openstudio-standards'
module OsLib_Reporting
# setup - get model, sql, and setup web assets path
def self.setup(runner)
results = {}
# get the last model
model = runner.lastOpenStudioModel
if model.empty?
runner.registerError('Cannot find last model.')
return false
end
model = model.get
# get the last idf
workspace = runner.lastEnergyPlusWorkspace
if workspace.empty?
runner.registerError('Cannot find last idf file.')
return false
end
workspace = workspace.get
# get the last sql file
sqlFile = runner.lastEnergyPlusSqlFile
if sqlFile.empty?
runner.registerError('Cannot find last sql file.')
return false
end
sqlFile = sqlFile.get
model.setSqlFile(sqlFile)
# populate hash to pass to measure
results[:model] = model
# results[:workspace] = workspace
results[:sqlFile] = sqlFile
return results
end
def self.ann_env_pd(sqlFile)
# get the weather file run period (as opposed to design day run period)
ann_env_pd = nil
sqlFile.availableEnvPeriods.each do |env_pd|
env_type = sqlFile.environmentType(env_pd)
if env_type.is_initialized
if env_type.get == OpenStudio::EnvironmentType.new('WeatherRunPeriod')
ann_env_pd = env_pd
end
end
end
return ann_env_pd
end
def self.create_xls
require 'rubyXL'
book = ::RubyXL::Workbook.new
# delete initial worksheet
return book
end
def self.save_xls(book)
file = book.write 'excel-file.xlsx'
return file
end
# write an Excel file from table data
# the Excel Functions are not currently being used, left in as example
# Requires ruby Gem which isn't currently supported in OpenStudio GUIs.
# Current setup is simple, creates new workbook for each table
# Could be updated to have one section per workbook
def self.write_xls(table_data, book)
worksheet = book.add_worksheet table_data[:title]
row_cnt = 0
# write the header row
header = table_data[:header]
header.each_with_index do |h, i|
worksheet.add_cell(row_cnt, i, h)
end
worksheet.change_row_fill(row_cnt, '0ba53d')
# loop over data rows
data = table_data[:data]
data.each do |d|
row_cnt += 1
d.each_with_index do |c, i|
worksheet.add_cell(row_cnt, i, c)
end
end
return book
end
# cleanup - prep html and close sql
def self.cleanup(html_in_path)
# TODO: - would like to move code here, but couldn't get it working. May look at it again later on.
return html_out_path
end
# clean up unkown strings used for runner.registerValue names
def self.reg_val_string_prep(string)
# replace non alpha-numberic characters with an underscore
string = string.gsub(/[^0-9a-z]/i, '_')
# snake case string
string = OpenStudio.toUnderscoreCase(string)
return string
end
# hard code fuel types (for E+ 9.4 shouldn't have it twice, should eventually come form OS)
def self.fuel_type_names(extended = false)
# get short or extended list (not using now)
fuel_types = []
OpenStudio::EndUseFuelType.getValues.each do |fuel_type|
# convert integer to string
fuel_name = OpenStudio::EndUseFuelType.new(fuel_type).valueDescription
next if fuel_name == 'Water'
fuel_types << fuel_name
end
return fuel_types
end
# create template section
def self.template_section(model, sqlFile, runner, name_only = false, is_ip_units = true)
# array to hold tables
template_tables = []
# gather data for section
@template_section = {}
@template_section[:title] = 'Tasty Treats'
@template_section[:tables] = template_tables
# stop here if only name is requested this is used to populate display name for arguments
if name_only == true
return @template_section
end
# notes:
# The data below would typically come from the model or simulation results
# You can loop through objects to make a table for each item of that type, such as air loops
# If a section will only have one table you can leave the table title blank and just rely on the section title
# these will be updated later to support graphs
# create table
template_table_01 = {}
template_table_01[:title] = 'Fruit'
template_table_01[:header] = ['Definition', 'Value']
template_table_01[:units] = ['', '$/pound']
template_table_01[:data] = []
# add rows to table
template_table_01[:data] << ['Banana', 0.23]
template_table_01[:data] << ['Apple', 0.75]
template_table_01[:data] << ['Orange', 0.50]
# add table to array of tables
template_tables << template_table_01
# using helper method that generates table for second example
template_tables << OsLib_Reporting.template_table(model, sqlFile, runner, is_ip_units = true)
return @template_section
end
# create template section
def self.template_table(model, sqlFile, runner, is_ip_units = true)
# create a second table
template_table = {}
template_table[:title] = 'Ice Cream'
template_table[:header] = ['Definition', 'Base Flavor', 'Toppings', 'Value']
template_table[:units] = ['', '', '', 'scoop']
template_table[:data] = []
# add rows to table
template_table[:data] << ['Vanilla', 'Vanilla', 'NA', 1.5]
template_table[:data] << ['Rocky Road', 'Chocolate', 'Nuts', 1.5]
template_table[:data] << ['Mint Chip', 'Mint', 'Chocolate Chips', 1.5]
return template_table
end
# building_summary section
def self.building_summary_section(model, sqlFile, runner, name_only = false, is_ip_units = true)
# array to hold tables
general_tables = []
# gather data for section
@building_summary_section = {}
@building_summary_section[:title] = 'Model Summary'
@building_summary_section[:tables] = general_tables
# stop here if only name is requested this is used to populate display name for arguments
if name_only == true
return @building_summary_section
end
# add in general information from method
general_tables << OsLib_Reporting.general_building_information_table(model, sqlFile, runner, is_ip_units)
general_tables << OsLib_Reporting.weather_summary_table(model, sqlFile, runner, is_ip_units)
general_tables << OsLib_Reporting.design_day_table(model, sqlFile, runner, is_ip_units)
general_tables << OsLib_Reporting.setpoint_not_met_summary_table(model, sqlFile, runner, is_ip_units)
general_tables << OsLib_Reporting.setpoint_not_met_criteria_table(model, sqlFile, runner, is_ip_units)
# general_tables << OsLib_Reporting.site_performance_table(model,sqlFile,runner)
site_power_generation_table = OsLib_Reporting.site_power_generation_table(model, sqlFile, runner, is_ip_units)
if site_power_generation_table
general_tables << OsLib_Reporting.site_power_generation_table(model, sqlFile, runner, is_ip_units)
end
return @building_summary_section
end
# annual_overview section
def self.annual_overview_section(model, sqlFile, runner, name_only = false, is_ip_units = true)
# array to hold tables
annual_tables = []
# gather data for section
@annual_overview_section = {}
@annual_overview_section[:title] = 'Annual Overview'
@annual_overview_section[:tables] = annual_tables
# stop here if only name is requested this is used to populate display name for arguments
if name_only == true
return @annual_overview_section
end
# add in annual overview from method
annual_tables << OsLib_Reporting.output_data_end_use_table(model, sqlFile, runner, is_ip_units)
annual_tables << OsLib_Reporting.output_data_energy_use_table(model, sqlFile, runner, is_ip_units)
annual_tables << OsLib_Reporting.output_data_end_use_electricity_table(model, sqlFile, runner, is_ip_units)
annual_tables << OsLib_Reporting.output_data_end_use_gas_table(model, sqlFile, runner, is_ip_units)
return @annual_overview_section
end
# create table with general building information
# this just makes a table, and not a full section. It feeds into another method that makes a full section
def self.general_building_information_table(model, sqlFile, runner, is_ip_units = true)
# general building information type data output
general_building_information = {}
general_building_information[:title] = 'Building Summary' # name will be with section
general_building_information[:header] = ['Data', 'Value']
general_building_information[:units] = [] # won't populate for this table since each row has different units
general_building_information[:data] = []
# structure ID / building name
display = 'Building Name'
target_units = 'n/a'
value = model.getBuilding.name.to_s
general_building_information[:data] << [display, value]
runner.registerValue(OsLib_Reporting.reg_val_string_prep(display), value, target_units)
# total site energy
display = 'Total Site Energy'
source_units = 'GJ'
if is_ip_units
target_units = 'kBtu'
else
target_units = 'kWh'
end
value = OpenStudio.convert(sqlFile.totalSiteEnergy.get, source_units, target_units).get
value_neat = "#{OpenStudio.toNeatString(value, 0, true)} #{target_units}"
runner.registerValue(OsLib_Reporting.reg_val_string_prep(display), value, target_units)
general_building_information[:data] << [display, value_neat]
# net site energy
display = 'Net Site Energy'
source_units = 'GJ'
if is_ip_units
target_units = 'kBtu'
else
target_units = 'kWh'
end
value = OpenStudio.convert(sqlFile.netSiteEnergy.get, source_units, target_units).get
value_neat = "#{OpenStudio.toNeatString(value, 0, true)} #{target_units}"
runner.registerValue(OsLib_Reporting.reg_val_string_prep(display), value, target_units)
# always register value, but only add to table if net is different than total
if sqlFile.totalSiteEnergy.get != sqlFile.netSiteEnergy.get
general_building_information[:data] << [display, value_neat]
end
# total building area
query = 'SELECT Value FROM tabulardatawithstrings WHERE '
query << "ReportName='AnnualBuildingUtilityPerformanceSummary' and "
query << "ReportForString='Entire Facility' and "
query << "TableName='Building Area' and "
query << "RowName='Total Building Area' and "
query << "ColumnName='Area' and "
query << "Units='m2';"
query_results = sqlFile.execAndReturnFirstDouble(query)
if query_results.empty?
runner.registerWarning('Did not find value for total building area.')
return false
else
display = 'Total Building Area'
source_units = 'm^2'
if is_ip_units
target_units = 'ft^2'
else
target_units = source_units
end
value = OpenStudio.convert(query_results.get, source_units, target_units).get
value_neat = "#{OpenStudio.toNeatString(value, 0, true)} #{target_units}"
general_building_information[:data] << [display, value_neat]
runner.registerValue(OsLib_Reporting.reg_val_string_prep(display), value, target_units)
end
# code to check OS vs. E+ area
energy_plus_area = query_results.get
open_studio_area = model.getBuilding.floorArea
if (energy_plus_area - open_studio_area).abs >= 1.0
runner.registerWarning("EnergyPlus reported area is #{query_results.get.round} (m^2). OpenStudio reported area is #{model.getBuilding.floorArea.round} (m^2).")
end
# total EUI
eui = sqlFile.totalSiteEnergy.get / energy_plus_area
display = 'Total Site EUI'
source_units = 'GJ/m^2'
if is_ip_units
target_units = 'kBtu/ft^2'
else
target_units = 'kWh/m^2'
end
if query_results.get > 0.0 # don't calculate EUI if building doesn't have any area
value = OpenStudio.convert(eui, source_units, target_units).get
value_neat = "#{OpenStudio.toNeatString(value, 2, true)} #{target_units}"
runner.registerValue(OsLib_Reporting.reg_val_string_prep(display), value, target_units) # is it ok not to calc EUI if no area in model
else
value_neat = "can't calculate Total EUI."
end
general_building_information[:data] << [display.to_s, value_neat]
# net EUI
eui = sqlFile.netSiteEnergy.get / energy_plus_area
display = 'EUI'
if query_results.get > 0.0 # don't calculate EUI if building doesn't have any area
value = OpenStudio.convert(eui, source_units, target_units).get
value_neat = "#{OpenStudio.toNeatString(value, 2, true)} #{target_units}"
runner.registerValue(OsLib_Reporting.reg_val_string_prep(display), value, target_units) # is it ok not to calc EUI if no area in model
else
value_neat = 'Net EUI could not be calculated.'
end
# always register value, but only add to table if net is different than total
if sqlFile.totalSiteEnergy.get != sqlFile.netSiteEnergy.get
general_building_information[:data] << ['Net Site EUI', value_neat]
end
# TODO: - add total EUI for conditioned floor area if not the same as total. Doesn't seem necessary to also calculate net conditioned EUI if it exists as a unique value.
# conditioned building area
query = 'SELECT Value FROM tabulardatawithstrings WHERE '
query << "ReportName='AnnualBuildingUtilityPerformanceSummary' and "
query << "ReportForString='Entire Facility' and "
query << "TableName='Building Area' and "
query << "RowName='Net Conditioned Building Area' and "
query << "ColumnName='Area' and "
query << "Units='m2';"
query_results = sqlFile.execAndReturnFirstDouble(query)
if query_results.empty?
runner.registerWarning('Did not find value for net conditioned building area.')
return false
elsif query_results.get == 0.0
display_a = 'Conditioned Building Area'
source_units_a = 'm^2'
if is_ip_units
target_units_a = 'ft^2'
else
target_units_a = source_units_a
end
value_a = OpenStudio.convert(query_results.get, source_units_a, target_units_a).get
value_neat_a = "#{OpenStudio.toNeatString(value_a, 0, true)} #{target_units_a}"
runner.registerValue(OsLib_Reporting.reg_val_string_prep(display_a), value_a, target_units_a)
# conditioned EUI
eui = sqlFile.totalSiteEnergy.get / energy_plus_area
display_e = 'Conditioned Site EUI'
source_units_e = 'GJ/m^2'
if is_ip_units
target_units_e = 'kBtu/ft^2'
else
target_units_e = 'kWh/m^2'
end
value_e = OpenStudio.convert(eui, source_units_e, target_units_e).get
value_neat_e = "#{OpenStudio.toNeatString(value_e, 2, true)} #{target_units_e}"
runner.registerValue(OsLib_Reporting.reg_val_string_prep(display_e), value_e, target_units_e)
# always register value, but only add to table if net is different than total
if energy_plus_area - query_results.get >= 1.0
general_building_information[:data] << [display_a, value_neat_a]
general_building_information[:data] << [display_e, value_neat_e]
end
end
# get standards building type
building_type = 'n/a'
if model.getBuilding.standardsBuildingType.is_initialized
building_type = model.getBuilding.standardsBuildingType.get
end
general_building_information[:data] << ['OpenStudio Standards Building Type', building_type]
return general_building_information
end
# create table of space type breakdown
def self.space_type_breakdown_section(model, sqlFile, runner, name_only = false, is_ip_units = true)
# space type data output
output_data_space_type_breakdown = {}
output_data_space_type_breakdown[:title] = ''
output_data_space_type_breakdown[:header] = ['Space Type Name', 'Floor Area', 'Standards Building Type', 'Standards Space Type']
if is_ip_units
target_units = 'ft^2'
else
target_units = 'm^2'
end
output_data_space_type_breakdown[:units] = ['', target_units, '', '']
output_data_space_type_breakdown[:data] = []
output_data_space_type_breakdown[:chart_type] = 'simple_pie'
output_data_space_type_breakdown[:chart] = []
# gather data for section
@output_data_space_type_breakdown_section = {}
@output_data_space_type_breakdown_section[:title] = 'Space Type Breakdown'
@output_data_space_type_breakdown_section[:tables] = [output_data_space_type_breakdown] # only one table for this section
# stop here if only name is requested this is used to populate display name for arguments
if name_only == true
return @output_data_space_type_breakdown_section
end
space_types = model.getSpaceTypes
space_types.sort.each do |spaceType|
next if spaceType.floorArea == 0
# get color
color = spaceType.renderingColor
if !color.empty?
color = color.get
red = color.renderingRedValue
green = color.renderingGreenValue
blue = color.renderingBlueValue
color = "rgb(#{red},#{green},#{blue})"
else
# TODO: - this should set red green and blue as separate values
color = 'rgb(20,20,20)' # maybe do random or let d3 pick color instead of this?
end
# data for space type breakdown
display = spaceType.name.get
floor_area_si = spaceType.floorArea
floor_area_si = 0
# loop through spaces so I can skip if not included in floor area
spaceType.spaces.each do |space|
next if !space.partofTotalFloorArea
floor_area_si += space.floorArea * space.multiplier
end
# julien
source_units = 'm^2'
if is_ip_units
target_units = 'ft^2'
else
target_units = source_units
end
value = OpenStudio.convert(floor_area_si, 'm^2', target_units).get
num_people = nil
value_neat = OpenStudio.toNeatString(value, 0, true)
# get standards information
if spaceType.standardsBuildingType.is_initialized
standards_building_type = spaceType.standardsBuildingType.get
else
standards_building_type = ''
end
if spaceType.standardsSpaceType.is_initialized
standards_space_type = spaceType.standardsSpaceType.get
else
standards_space_type = ''
end
output_data_space_type_breakdown[:data] << [display, value_neat, standards_building_type, standards_space_type]
runner.registerValue("space_type_#{OsLib_Reporting.reg_val_string_prep(display)}", value, target_units)
# data for graph
output_data_space_type_breakdown[:chart] << JSON.generate(label: display, value: value, color: color)
end
spaces = model.getSpaces
# count area of spaces that have no space type
no_space_type_area_counter = 0
spaces.each do |space|
if space.spaceType.empty?
next if !space.partofTotalFloorArea
no_space_type_area_counter += space.floorArea * space.multiplier
end
end
if no_space_type_area_counter > 0
display = 'No Space Type'
# julien
source_units = 'm^2'
if is_ip_units
target_units = 'ft^2'
else
target_units = source_units
end
value = OpenStudio.convert(no_space_type_area_counter, 'm^2', target_units).get
value_neat = OpenStudio.toNeatString(value, 0, true)
output_data_space_type_breakdown[:data] << [display, value_neat]
runner.registerValue("space_type_#{OsLib_Reporting.reg_val_string_prep(display)}", value, target_units)
# data for graph
color = 'rgb(20,20,20)' # maybe do random or let d3 pick color instead of this?
output_data_space_type_breakdown[:chart] << JSON.generate(label: 'No SpaceType Assigned',
value: OpenStudio.convert(no_space_type_area_counter, 'm^2', target_units),
color: color)
end
return @output_data_space_type_breakdown_section
end
# create table with general building information
# this just makes a table, and not a full section. It feeds into another method that makes a full section
def self.output_data_end_use_table(model, sqlFile, runner, is_ip_units = true)
# end use data output
output_data_end_use = {}
output_data_end_use[:title] = 'End Use'
output_data_end_use[:header] = ['End Use', 'Consumption']
if is_ip_units
target_units = 'kBtu'
else
target_units = 'kWh'
end
output_data_end_use[:units] = ['', target_units]
output_data_end_use[:data] = []
output_data_end_use[:chart_type] = 'simple_pie'
output_data_end_use[:chart] = []
end_use_colors = ['#EF1C21', '#0071BD', '#F7DF10', '#DEC310', '#4A4D4A', '#B5B2B5', '#FF79AD', '#632C94', '#F75921', '#293094', '#CE5921', '#FFB239', '#29AAE7', '#8CC739']
# loop through fuels for consumption tables
counter = 0
OpenStudio::EndUseCategoryType.getValues.each do |end_use|
# get end uses
end_use = OpenStudio::EndUseCategoryType.new(end_use).valueDescription
# loop through fuels
total_end_use = 0.0
fuel_type_names.each do |fuel_type|
query_fuel = "SELECT Value FROM tabulardatawithstrings WHERE ReportName='AnnualBuildingUtilityPerformanceSummary' and TableName='End Uses' and RowName= '#{end_use}' and ColumnName= '#{fuel_type}'"
results_fuel = sqlFile.execAndReturnFirstDouble(query_fuel).get
total_end_use += results_fuel
end
# convert value and populate table
value = OpenStudio.convert(total_end_use, 'GJ', target_units).get
value_neat = OpenStudio.toNeatString(value, 0, true)
output_data_end_use[:data] << [end_use, value_neat]
runner.registerValue("end_use_#{end_use.downcase.tr(' ', '_')}", value, target_units)
if value > 0
output_data_end_use[:chart] << JSON.generate(label: end_use, value: value, color: end_use_colors[counter])
end
counter += 1
end
return output_data_end_use
end
# create table with general building information
# this just makes a table, and not a full section. It feeds into another method that makes a full section
def self.output_data_end_use_electricity_table(model, sqlFile, runner, is_ip_units = true)
# end use data output
output_data_end_use_electricity = {}
output_data_end_use_electricity[:title] = 'EUI - Electricity'
output_data_end_use_electricity[:header] = ['End Use', 'Consumption']
target_units = 'kWh'
output_data_end_use_electricity[:units] = ['', target_units]
output_data_end_use_electricity[:data] = []
output_data_end_use_electricity[:chart_type] = 'simple_pie'
output_data_end_use_electricity[:chart] = []
end_use_colors = ['#EF1C21', '#0071BD', '#F7DF10', '#DEC310', '#4A4D4A', '#B5B2B5', '#FF79AD', '#632C94', '#F75921', '#293094', '#CE5921', '#FFB239', '#29AAE7', '#8CC739']
# loop through fuels for consumption tables
counter = 0
OpenStudio::EndUseCategoryType.getValues.each do |end_use|
# get end uses
end_use = OpenStudio::EndUseCategoryType.new(end_use).valueDescription
query = "SELECT Value FROM tabulardatawithstrings WHERE ReportName='AnnualBuildingUtilityPerformanceSummary' and TableName='End Uses' and RowName= '#{end_use}' and ColumnName= 'Electricity'"
results = sqlFile.execAndReturnFirstDouble(query)
value = OpenStudio.convert(results.get, 'GJ', target_units).get
value_neat = OpenStudio.toNeatString(value, 0, true)
output_data_end_use_electricity[:data] << [end_use, value_neat]
runner.registerValue("end_use_electricity_#{end_use.downcase.tr(' ', '_')}", value, target_units)
if value > 0
output_data_end_use_electricity[:chart] << JSON.generate(label: end_use, value: value, color: end_use_colors[counter])
end
counter += 1
end
return output_data_end_use_electricity
end
# create table with general building information
# this just makes a table, and not a full section. It feeds into another method that makes a full section
def self.output_data_end_use_gas_table(model, sqlFile, runner, is_ip_units = true)
# end use data output
output_data_end_use_gas = {}
output_data_end_use_gas[:title] = 'EUI - Gas'
output_data_end_use_gas[:header] = ['End Use', 'Consumption']
if is_ip_units
target_units = 'therm'
target_display_unit = 'therms'
else
target_units = 'kWh'
target_display_unit = 'kWh'
end
output_data_end_use_gas[:units] = ['', target_display_unit]
output_data_end_use_gas[:data] = []
output_data_end_use_gas[:chart_type] = 'simple_pie'
output_data_end_use_gas[:chart] = []
output_data_end_use_gas[:chart_type] = 'simple_pie'
output_data_end_use_gas[:chart] = []
end_use_colors = ['#EF1C21', '#0071BD', '#F7DF10', '#DEC310', '#4A4D4A', '#B5B2B5', '#FF79AD', '#632C94', '#F75921', '#293094', '#CE5921', '#FFB239', '#29AAE7', '#8CC739']
# loop through fuels for consumption tables
counter = 0
OpenStudio::EndUseCategoryType.getValues.each do |end_use|
# get end uses
end_use = OpenStudio::EndUseCategoryType.new(end_use).valueDescription
query = "SELECT Value FROM tabulardatawithstrings WHERE ReportName='AnnualBuildingUtilityPerformanceSummary' and TableName='End Uses' and RowName= '#{end_use}' and ColumnName= 'Natural Gas'"
results = sqlFile.execAndReturnFirstDouble(query)
value = OpenStudio.convert(results.get, 'GJ', target_units).get
value_neat = OpenStudio.toNeatString(value, 0, true)
output_data_end_use_gas[:data] << [end_use, value_neat]
runner.registerValue("end_use_natural_gas_#{end_use.downcase.tr(' ', '_')}", value, target_units)
if value > 0
output_data_end_use_gas[:chart] << JSON.generate(label: end_use, value: value, color: end_use_colors[counter])
end
counter += 1
end
return output_data_end_use_gas
end
# create table with general building information
# this just makes a table, and not a full section. It feeds into another method that makes a full section
def self.output_data_energy_use_table(model, sqlFile, runner, is_ip_units = true)
# energy use data output
output_data_energy_use = {}
output_data_energy_use[:title] = 'Energy Use'
output_data_energy_use[:header] = ['Fuel', 'Consumption']
if is_ip_units
target_units = 'kBtu'
else
target_units = 'kWh'
end
output_data_energy_use[:units] = ['', target_units]
output_data_energy_use[:data] = []
output_data_energy_use[:chart_type] = 'simple_pie'
output_data_energy_use[:chart] = []
# list of colors for fuel. Also used for cash flow chart
color = []
color << '#DDCC77' # Electricity
color << '#999933' # Natural Gas
# not used for 9.4
# color << '#AA4499' # Additional Fuel
# TODO: - new colors to add for 9.4 (for nwo using color of Additional Fuel)
color << '#AA4499'
color << '#AA4499'
color << '#AA4499'
color << '#AA4499'
color << '#AA4499'
color << '#AA4499'
color << '#AA4499'
color << '#88CCEE' # District Cooling
color << '#CC6677' # District Heating
# color << "#332288" # Water (not used here but is in cash flow chart)
# color << "#117733" # Capital and O&M (not used here but is in cash flow chart)
# loop through fuels for consumption tables
counter = 0
fuel_type_names.each do |fuel_type| # OpenStudio::EndUseFuelType.getValues
# get fuel type and units
# fuel_type = OpenStudio::EndUseFuelType.new(fuel_type).valueDescription
next if fuel_type == 'Water'
query = "SELECT Value FROM tabulardatawithstrings WHERE ReportName='AnnualBuildingUtilityPerformanceSummary' and TableName='End Uses' and RowName= 'Total End Uses' and ColumnName= '#{fuel_type}'"
results = sqlFile.execAndReturnFirstDouble(query)
# julien
source_units = 'kWh'
if is_ip_units
target_units = 'kBtu'
else
target_units = source_units
end
value = OpenStudio.convert(results.get, 'GJ', target_units).get
value_neat = OpenStudio.toNeatString(value, 0, true)
output_data_energy_use[:data] << [fuel_type, value_neat]
runner.registerValue("fuel_#{fuel_type.downcase.tr(' ', '_')}", value, target_units)
if value > 0
output_data_energy_use[:chart] << JSON.generate(label: fuel_type, value: value, color: color[counter])
end
counter += 1
end
return output_data_energy_use
end
# create table for advisory messages
def self.setpoint_not_met_summary_table(model, sqlFile, runner, is_ip_units = true)
# unmet hours data output
setpoint_not_met_summary = {}
setpoint_not_met_summary[:title] = 'Unmet Hours Summary'
setpoint_not_met_summary[:header] = ['Time Setpoint Not Met', 'Time']
target_units = 'hr'
setpoint_not_met_summary[:units] = ['', target_units]
setpoint_not_met_summary[:data] = []
# create string for rows (transposing from what is in tabular data)
setpoint_not_met_cat = []
setpoint_not_met_cat << 'During Heating'
setpoint_not_met_cat << 'During Cooling'
setpoint_not_met_cat << 'During Occupied Heating'
setpoint_not_met_cat << 'During Occupied Cooling'
# loop through messages
setpoint_not_met_cat.each do |cat|
# Retrieve end use percentages from table
query = "SELECT Value FROM tabulardatawithstrings WHERE ReportName='SystemSummary' and TableName = 'Time Setpoint Not Met' and RowName= 'Facility' and ColumnName='#{cat}';"
setpoint_not_met_cat_value = sqlFile.execAndReturnFirstDouble(query)
if setpoint_not_met_cat_value.empty?
runner.registerWarning("Did not find value for #{cat}.")
return false
else
# net site energy
display = cat
source_units = 'hr'
value = setpoint_not_met_cat_value.get
value_neat = value # OpenStudio::toNeatString(value,0,true)
setpoint_not_met_summary[:data] << [display, value_neat]
runner.registerValue("unmet_hours_#{OsLib_Reporting.reg_val_string_prep(display)}", value, target_units)
end
end # setpoint_not_met_cat.each do
return setpoint_not_met_summary
end
# create table for setpoint_not_met_criteria
def self.setpoint_not_met_criteria_table(model, sqlFile, runner, is_ip_units = true)
# unmet hours data output
tolerance_summary = {}
tolerance_summary[:title] = 'Unmet Hours Tolerance'
tolerance_summary[:header] = ['Tolerance for Time Setpoint Not Met', 'Temperature']
# julien
source_units = 'C'
if is_ip_units
target_units = 'F'
else
target_units = source_units
end
tolerance_summary[:units] = ['', target_units]
tolerance_summary[:data] = []
# create string for rows (transposing from what is in tabular data)
setpoint_not_met_cat = []
setpoint_not_met_cat << 'Heating'
setpoint_not_met_cat << 'Cooling'
# loop through messages
setpoint_not_met_cat.each do |cat|
# Retrieve end use percentages from table
query = "SELECT Value FROM tabulardatawithstrings WHERE ReportName='AnnualBuildingUtilityPerformanceSummary' and TableName = 'Setpoint Not Met Criteria' and RowName= 'Tolerance for Zone #{cat} Setpoint Not Met Time' and ColumnName='Degrees';"
setpoint_not_met_cat_value = sqlFile.execAndReturnFirstDouble(query)
if setpoint_not_met_cat_value.empty?
runner.registerWarning("Did not find value for #{cat}.")
return false
else
# net site energy
display = cat
# julien
source_units = 'K'
if is_ip_units
target_units = 'R'
else
target_units = source_units
end
value = OpenStudio.convert(setpoint_not_met_cat_value.get.to_f, source_units, target_units).get
value_neat = value.round(2)
tolerance_summary[:data] << [display, value_neat]
runner.registerValue("unmet_hours_tolerance_#{cat.downcase}", value, target_units)
end
end # setpoint_not_met_cat.each do
return tolerance_summary
end
# Generalized method for getting component performance characteristics
def self.general_component_summary_logic(component, is_ip_units)
data_arrays = []
# Convert to HVAC Component
component = component.to_HVACComponent
return data_arrays if component.empty?
component = component.get
# Skip object types that are not informative
types_to_skip = ['SetpointManager:MixedAir', 'Node']
idd_obj_type = component.iddObject.name.gsub('OS:', '')
return data_arrays if types_to_skip.include?(idd_obj_type)
# Only report the component type once
comp_name_used = false
# Airflow, heating and cooling capacity, and water flow
summary_types = []
summary_types << ['Air Flow Rate', 'maxAirFlowRate', 'm^3/s', 4, 'cfm', 0]
summary_types << ['Heating Capacity', 'maxHeatingCapacity', 'W', 1, 'Btu/hr', 1]
summary_types << ['Cooling Capacity', 'maxCoolingCapacity', 'W', 1, 'ton', 1]
summary_types << ['Water Flow Rate', 'maxWaterFlowRate', 'm^3/s', 4, 'gal/min', 2]
summary_types << ['Rated Power', 'ratedPower', 'W', 1, 'W', 1]
summary_types.each do |s|
val_name = s[0]
val_method = s[1]
units_si = s[2]
decimal_places_si = s[3]
units_ip = s[4]
decimal_places_ip = s[5]
# Get the value and skip if not available
val_si = component.public_send(val_method)
next if val_si.empty?
# Determine if the value was autosized or hard sized
siz = 'Hard Sized'
if component.public_send("#{val_method}Autosized").is_initialized
if component.public_send("#{val_method}Autosized").get
siz = 'Autosized'
end
end
# Convert and report the value
source_units = units_si
if is_ip_units
target_units = units_ip
decimal_places = decimal_places_ip
else
target_units = source_units
decimal_places = decimal_places_si
end
val_ip = OpenStudio.convert(val_si.get, source_units, target_units).get
val_ip_neat = OpenStudio.toNeatString(val_ip, decimal_places, true)
if is_ip_units
data_arrays << ['', val_name, "#{val_ip_neat} #{units_ip}", siz, '']
else
data_arrays << ['', val_name, "#{val_ip_neat} #{units_si}", siz, '']
end
end
# Performance characteristics (specific to each component type)
perf_chars = component.performanceCharacteristics.each do |char|
perf_val = char[0].to_s.to_f
perf_name = char[1]
display_units = '' # For Display
# Unit conversion for pressure rise and pump head
if perf_name.downcase.include?('pressure rise')
source_units = 'Pa'
if is_ip_units
target_units = 'inH_{2}O'
display_units = 'in w.g.'
else
target_units = source_units
display_units = source_units
end
perf_val = OpenStudio.convert(perf_val, source_units, target_units).get
perf_val = OpenStudio.toNeatString(perf_val, 2, true)
elsif perf_name.downcase.include?('pump head')
source_units = 'Pa'
if is_ip_units
target_units = 'ftH_{2}O'
display_units = 'ft H2O'
n_decimals = 1
else
target_units = source_units
display_units = source_units
n_decimals = 0
end
perf_val = OpenStudio.convert(perf_val, source_units, target_units).get
perf_val = OpenStudio.toNeatString(perf_val, n_decimals, true)
elsif perf_name.downcase.include?('efficiency') || perf_name.downcase.include?('effectiveness')
display_units = '%'
perf_val *= 100
perf_val = OpenStudio.toNeatString(perf_val, 1, true)
elsif perf_name.downcase.include?('cop')
perf_val = OpenStudio.toNeatString(perf_val, 2, true)
end
# Report the value
data_arrays << ['', perf_name, "#{perf_val} #{display_units}", '', '']
end
return data_arrays
end
# Gives the Plant Loop connection information for an HVAC Component
def self.water_component_logic(component, is_ip_units)
data_arrays = []
component = component.to_HVACComponent
return data_arrays if component.empty?
component = component.get
# Only deal with plant-connected components
return data_arrays unless component.respond_to?('plantLoop')
# Report the plant loop name
if component.plantLoop.is_initialized
data_arrays << ['', 'Plant Loop', component.plantLoop.get.name, '', '']
end
return data_arrays
end
# Shows the calculated brake horsepower for fans and pumps
def self.motor_component_logic(component, is_ip_units)
data_arrays = []
# Skip exhaust fans for now because of bug in openstudio-standards
return data_arrays if component.to_FanZoneExhaust.is_initialized
concrete_comp = component.cast_to_concrete_type
component = concrete_comp unless component.nil?
# Only deal with plant-connected components
return data_arrays unless component.respond_to?('brake_horsepower')
# Report the plant loop name
bhp = component.brake_horsepower
bhp_neat = OpenStudio.toNeatString(bhp, 2, true)
data_arrays << ['', 'Brake Horsepower', "#{bhp_neat} HP", '', '']
return data_arrays
end
# Shows the setpoint manager details depending on type
def self.spm_logic(component, is_ip_units)
data_arrays = []
case component.iddObject.name
when 'OS:SetpointManager:Scheduled'
# Constrol type and temperature range
setpoint = component.to_SetpointManagerScheduled.get
supply_air_temp_schedule = setpoint.schedule
schedule_values = OpenstudioStandards::Schedules.schedule_get_min_max(supply_air_temp_schedule)
if schedule_values.nil?
schedule_values_pretty = "can't inspect schedule"
target_units = ''
else
if setpoint.controlVariable.to_s == 'Temperature'
# julien
source_units = 'C'
if is_ip_units
target_units = 'F'
else
target_units = source_units
end
schedule_values_pretty = "#{OpenStudio.convert(schedule_values['min'], source_units, target_units).get.round(1)} to #{OpenStudio.convert(schedule_values['max'], source_units, target_units).get.round(1)}"