Module: OsLib_ReportingHeatGainLoss

Defined in:
lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb

Class Method Summary collapse

Class Method Details

.ann_env_pd(sqlFile) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb', line 47

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

.heat_gains_section(model, sqlFile, runner, name_only = false) ⇒ Object

section for heat_gains



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
# File 'lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb', line 74

def self.heat_gains_section(model, sqlFile, runner, name_only = false)
  # array to hold tables
  tables = []

  # gather data for section
  @heat_gains = {}
  @heat_gains[:title] = 'Heat Gains By Month Detailed'
  @heat_gains[:tables] = tables

  # stop here if only name is requested this is used to populate display name for arguments
  if name_only == true
    return @heat_gains
  end

  # using helper method that generates table for second example
  tables << @elec_equip_gain_table = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner, 'Electric Equipment Total Heating Energy', 'J', 'kBtu')
  tables << @gas_equip_gain_table = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner, 'Gas Equipment Total Heating Energy', 'J', 'kBtu')
  tables << @lights_gain_table = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner, 'Zone Lights Total Heating Energy', 'J', 'kBtu')
  tables << @people_gain_table = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner, 'Zone People Sensible Heating Energy', 'J', 'kBtu')

  #     # use multiple variables for ventilation
  #     temp_vent_gain_ht = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner,'Zone Mechanical Ventilation Cooling Load Increase Energy','J','kBtu')
  #     temp_vent_no_load_gain = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner,'Zone Mechanical Ventilation No Load Heat Addition Energy','J','kBtu')
  #     temp_vent_gain_clg_over_ht = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner,'Zone Mechanical Ventilation Cooling Load Increase Due to Overheating Energy','J','kBtu')
  #     temp_vent_gain_ht_decr = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner,'Zone Mechanical Ventilation Heating Load Decrease Energy','J','kBtu')
  #     temp_heat_exch_clg = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner,'Air System Heat Exchanger Total Cooling Energy','J','kBtu')
  #     temp_vent_gain_ht[:title] = 'Mechanical Ventilation Heat Gain (kBtu)'
  #     temp_vent_gain_ht[:data].each_with_index do |row,i|
  #       row.each_with_index do |column,j|
  #         next if j == 0
  #         value = column.gsub(",","").to_f + temp_vent_gain_ht_decr[:data][i][j].gsub(",","").to_f + temp_vent_no_load_gain[:data][i][j].gsub(",","").to_f + temp_vent_gain_clg_over_ht[:data][i][j].gsub(",","").to_f
  #         temp_vent_gain_ht[:data][i][j] = OpenStudio::toNeatString(value,1,true)
  #       end
  #     end
  #
  #     # deduct for heat exchangers
  #     temp_heat_exch_clg[:data].each_with_index do |row,i|
  #       new_row = []
  #       row.each_with_index do |column,j|
  #         if j == 0
  #           new_row <<  "Air System Heat Exchanger Total Cooling Energy - #{column}"
  #         else
  #           value = column.gsub(",","").to_f * -1.0
  #           if i + 1.0 == temp_heat_exch_clg[:data].size
  #             # update monthly total for column
  #             orig_value = temp_vent_gain_ht[:data].last[j].gsub(",","").to_f
  #             new_value = orig_value + value
  #             temp_vent_gain_ht[:data].last[j] =  OpenStudio::toNeatString(new_value,1,true)
  #           else
  #             new_row << OpenStudio::toNeatString(value,1,true)
  #           end
  #         end
  #       end
  #       # add new row before monthly totals adjusted for heat exchangers
  #       if new_row.size > 1
  #         temp_vent_gain_ht[:data].insert(temp_vent_gain_ht[:data].size - 1, new_row)
  #       end
  #     end
  #     tables << @ventilation_gain_table = temp_vent_gain_ht

  tables << @infiltration_gain_table = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner, 'Zone Infiltration Sensible Heat Gain Energy', 'J', 'kBtu')
  tables << @window_gain_table = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner, 'Surface Window Heat Gain Energy', 'J', 'kBtu')
  tables << @surface_gain_table = OsLib_ReportingHeatGainLoss.monthly_surface_heat_gains_table(model, sqlFile, runner)

  return @heat_gains
end

.heat_gains_summary_section(model, sqlFile, runner, name_only = false) ⇒ Object

create heat_gains_summary_section



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
# File 'lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb', line 142

def self.heat_gains_summary_section(model, sqlFile, runner, name_only = false)
  # array to hold tables
  summary_tables = []

  # gather data for section
  @template_section = {}
  @template_section[:title] = 'Heat Gains Summary'
  @template_section[:tables] = summary_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

  # gather data from previous section
  source_tables = []
  source_tables << @elec_equip_gain_table
  source_tables << @gas_equip_gain_table
  source_tables << @lights_gain_table
  source_tables << @people_gain_table
  source_tables << @infiltration_gain_table
  # source_tables << @ventilation_gain_table
  source_tables << @window_gain_table
  source_tables << @surface_gain_table

  # component order and color
  component_color = {}
  component_color['Zone Lights Total Heating Energy'] = '#F7DF10'
  component_color['Electric Equipment Total Heating Energy'] = '#4A4D4A'
  component_color['Gas Equipment Total Heating Energy'] = '#D6D6D6'
  component_color['Zone People Sensible Heating Energy'] = '#FFC0CB '
  component_color['Zone Infiltration Sensible Heat Gain Energy'] = '#5B9C31'
  # component_color['Mechanical Ventilation Heat Gain'] = '#CA8BCC'
  component_color['Ground Exposed Surfaces Heat Gain'] = '#7D8080'
  component_color['Exterior Wall Surfaces Heat Gain'] = '#CCB266' # was Surface Average Face Conduction Heat Gain
  component_color['Surface Window Heat Gain Energy'] = '#66B2CC'
  component_color['Roof Surfaces Heat Gain'] = '#994C4C'

  # create annual table
  summary_table_01 = {}
  summary_table_01[:title] = 'Heat Gains Annual Breakdown (kBtu)'
  summary_table_01[:header] = ['Type', 'Quantity']
  summary_table_01[:units] = ['', 'kBtu']
  summary_table_01[:data] = []

  # create annual chart
  summary_table_01[:chart_type] = 'simple_pie'
  summary_table_01[:chart] = []

  # loop through tables to get annual information
  source_tables.each do |table|
    title = table[:title].gsub(' (kBtu)', '')

    # use subtotal rows for surfaces, total row for everything else
    if title == 'Surface Average Face Conduction Heat Gain'

      # exterior walls subtotal
      display_value = table[:data][table[:data].size - 4].last
      sub_total_title = 'Exterior Wall Surfaces Heat Gain'
      summary_table_01[:data] << [sub_total_title, display_value]
      summary_table_01[:chart] << JSON.generate(label: sub_total_title, value: display_value.to_s.delete(',').to_f, color: component_color[sub_total_title])

      # exterior roofs subtotal
      display_value = table[:data][table[:data].size - 3].last
      sub_total_title = 'Roof Surfaces Heat Gain'
      summary_table_01[:data] << [sub_total_title, display_value]
      summary_table_01[:chart] << JSON.generate(label: sub_total_title, value: display_value.to_s.delete(',').to_f, color: component_color[sub_total_title])

      # ground subtotal
      display_value = table[:data][table[:data].size - 2].last
      sub_total_title = 'Ground Exposed Surfaces Heat Gain'
      summary_table_01[:data] << [sub_total_title, display_value]
      summary_table_01[:chart] << JSON.generate(label: sub_total_title, value: display_value.to_s.delete(',').to_f, color: component_color[sub_total_title])
    else
      display_value = table[:data].last.last
      summary_table_01[:data] << [title, display_value]
      summary_table_01[:chart] << JSON.generate(label: title, value: display_value.to_s.delete(',').to_f, color: component_color[title])
    end
  end

  # add table to array of tables
  summary_tables << summary_table_01

  # create monthly table
  summary_table_02 = {}
  summary_table_02[:title] = 'Heat Gains Monthly Breakdown (kBtu)'
  summary_table_02[:header] = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  summary_table_02[:units] = []
  summary_table_02[:data] = []

  # create monthly chart
  month_order = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  summary_table_02[:chart_type] = 'vertical_stacked_bar'
  summary_table_02[:chart_attributes] = { value: summary_table_02[:title], label_x: 'Month', sort_yaxis: component_color.keys, sort_xaxis: month_order }
  summary_table_02[:chart] = []

  # loop through tables to get annual information
  source_tables.each do |table|
    title = table[:title].gsub(' (kBtu)', '')
    if title == 'Surface Average Face Conduction Heat Gain'

      # exterior walls subtotal
      row_data = []
      sub_title = 'Exterior Wall Surfaces Heat Gain'
      target_row = table[:data][table[:data].size - 4]
      row_data << sub_title
      target_row.each_with_index do |value, i|
        ''
        next if i < 3
        next if i == target_row.size - 1 # don't want to include annual total
        row_data << value
        # update chart
        month = summary_table_02[:header][i - 2] # shifted over because of extra columns
        clean_value = value.to_s.delete(',').to_f
        summary_table_02[:chart] << JSON.generate(label: sub_title, label_x: month, value: clean_value, color: component_color[sub_title])
      end
      summary_table_02[:data] << row_data

      # exterior roofs subtotal
      row_data = []
      sub_title = 'Roof Surfaces Heat Gain'
      target_row = table[:data][table[:data].size - 3]
      row_data << sub_title
      target_row.each_with_index do |value, i|
        next if i < 3
        next if i == target_row.size - 1 # don't want to include annual total
        row_data << value
        # update chart
        month = summary_table_02[:header][i - 2] # shifted over because of extra columns
        clean_value = value.to_s.delete(',').to_f
        summary_table_02[:chart] << JSON.generate(label: sub_title, label_x: month, value: clean_value, color: component_color[sub_title])
      end
      summary_table_02[:data] << row_data

      # ground subtotal
      row_data = []
      sub_title = 'Ground Exposed Surfaces Heat Gain'
      target_row = table[:data][table[:data].size - 2]
      row_data << sub_title
      target_row.each_with_index do |value, i|
        next if i < 3
        next if i == target_row.size - 1 # don't want to include annual total
        row_data << value
        # update chart
        month = summary_table_02[:header][i - 2] # shifted over because of extra columns
        clean_value = value.to_s.delete(',').to_f
        summary_table_02[:chart] << JSON.generate(label: sub_title, label_x: month, value: clean_value, color: component_color[sub_title])
      end
      summary_table_02[:data] << row_data

    else

      row_data = []
      last_row = table[:data].last
      row_data << title
      last_row.each_with_index do |value, i|
        next if value == 'Monthly Totals'
        next if value == ''
        next if i == last_row.size - 1 # don't want to include annual total
        row_data << value

        # update chart
        month = summary_table_02[:header][i]
        clean_value = value.to_s.delete(',').to_f
        summary_table_02[:chart] << JSON.generate(label: title, label_x: month, value: clean_value, color: component_color[title])
      end
      summary_table_02[:data] << row_data

    end
  end

  # add table to array of tables
  summary_tables << summary_table_02

  return @template_section
end

.heat_loss_summary_section(model, sqlFile, runner, name_only = false) ⇒ Object

create heat_loss_summary_section



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
# File 'lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb', line 383

def self.heat_loss_summary_section(model, sqlFile, runner, name_only = false)
  # array to hold tables
  summary_tables = []

  # gather data for section
  @template_section = {}
  @template_section[:title] = 'Heat Loss Summary'
  @template_section[:tables] = summary_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

  # gather data from previous section
  source_tables = []
  source_tables << @infiltration_loss_table
  # source_tables << @ventilation_loss_table
  source_tables << @window_loss_table
  source_tables << @surface_loss_table

  # component order and color
  component_color = {}
  component_color['Zone Infiltration Sensible Heat Loss Energy'] = '#5B9C31'
  # component_color['Mechanical Ventilation Heat Loss'] = '#CA8BCC'
  component_color['Ground Exposed Surfaces Heat Loss'] = '#7D8080'
  component_color['Exterior Wall Surfaces Heat Loss'] = '#CCB266'
  component_color['Surface Window Heat Loss Energy'] = '#66B2CC'
  component_color['Roof Surfaces Heat Loss'] = '#994C4C'

  # create table
  summary_table_01 = {}
  summary_table_01[:title] = 'Heat Loss Annual Breakdown (kBtu)'
  summary_table_01[:header] = ['Type', 'Quantity']
  summary_table_01[:units] = ['', 'kBtu']
  summary_table_01[:data] = []

  # create annual chart
  summary_table_01[:chart_type] = 'simple_pie'
  summary_table_01[:chart] = []

  # loop through tables to get annual information
  source_tables.each do |table|
    title = table[:title].gsub(' (kBtu)', '')

    # use subtotal rows for surfaces, total row for everything else
    if title == 'Surface Average Face Conduction Heat Loss'

      # exterior walls subtotal
      display_value = table[:data][table[:data].size - 4].last
      sub_total_title = 'Exterior Wall Surfaces Heat Loss'
      summary_table_01[:data] << [sub_total_title, display_value]
      summary_table_01[:chart] << JSON.generate(label: sub_total_title, value: display_value.to_s.delete(',').to_f, color: component_color[sub_total_title])

      # exterior roofs subtotal
      display_value = table[:data][table[:data].size - 3].last
      sub_total_title = 'Roof Surfaces Heat Loss'
      summary_table_01[:data] << [sub_total_title, display_value]
      summary_table_01[:chart] << JSON.generate(label: sub_total_title, value: display_value.to_s.delete(',').to_f, color: component_color[sub_total_title])

      # ground subtotal
      display_value = table[:data][table[:data].size - 2].last
      sub_total_title = 'Ground Exposed Surfaces Heat Loss'
      summary_table_01[:data] << [sub_total_title, display_value]
      summary_table_01[:chart] << JSON.generate(label: sub_total_title, value: display_value.to_s.delete(',').to_f, color: component_color[sub_total_title])
    else
      display_value = table[:data].last.last
      summary_table_01[:data] << [title, display_value]
      summary_table_01[:chart] << JSON.generate(label: title, value: display_value.to_s.delete(',').to_f, color: component_color[title])
    end
  end

  # add table to array of tables
  summary_tables << summary_table_01

  # create monthly table
  summary_table_02 = {}
  summary_table_02[:title] = 'Heat Loss Monthly Breakdown (kBtu)'
  summary_table_02[:header] = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  summary_table_02[:units] = []
  summary_table_02[:data] = []

  # create annual chart
  month_order = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  summary_table_02[:chart_type] = 'vertical_stacked_bar'
  summary_table_02[:chart_attributes] = { value: summary_table_02[:title], label_x: 'Month', sort_yaxis: component_color.keys, sort_xaxis: month_order }
  summary_table_02[:chart] = []

  # loop through tables to get annual information
  source_tables.each do |table|
    title = table[:title].gsub(' (kBtu)', '')
    if title == 'Surface Average Face Conduction Heat Loss'

      # exterior walls subtotal
      row_data = []
      sub_title = 'Exterior Wall Surfaces Heat Loss'
      target_row = table[:data][table[:data].size - 4]
      row_data << sub_title
      target_row.each_with_index do |value, i|
        next if i < 3
        next if i == target_row.size - 1 # don't want to include annual total
        row_data << value
        # update chart
        month = summary_table_02[:header][i - 2] # shifted over because of extra columns
        clean_value = value.to_s.delete(',').to_f
        summary_table_02[:chart] << JSON.generate(label: sub_title, label_x: month, value: clean_value, color: component_color[sub_title])
      end
      summary_table_02[:data] << row_data

      # exterior roofs subtotal
      row_data = []
      sub_title = 'Roof Surfaces Heat Loss'
      target_row = table[:data][table[:data].size - 3]
      row_data << sub_title
      target_row.each_with_index do |value, i|
        next if i < 3
        next if i == target_row.size - 1 # don't want to include annual total
        row_data << value
        # update chart
        month = summary_table_02[:header][i - 2] # shifted over because of extra columns
        clean_value = value.to_s.delete(',').to_f
        summary_table_02[:chart] << JSON.generate(label: sub_title, label_x: month, value: clean_value, color: component_color[sub_title])
      end
      summary_table_02[:data] << row_data

      # ground subtotal
      row_data = []
      sub_title = 'Ground Exposed Surfaces Heat Loss'
      target_row = table[:data][table[:data].size - 2]
      row_data << sub_title
      target_row.each_with_index do |value, i|
        next if i < 3
        next if i == target_row.size - 1 # don't want to include annual total
        row_data << value
        # update chart
        month = summary_table_02[:header][i - 2] # shifted over because of extra columns
        clean_value = value.to_s.delete(',').to_f
        summary_table_02[:chart] << JSON.generate(label: sub_title, label_x: month, value: clean_value, color: component_color[sub_title])
      end
      summary_table_02[:data] << row_data

    else

      row_data = []
      last_row = table[:data].last
      row_data << title
      last_row.each_with_index do |value, i|
        next if value == 'Monthly Totals'
        next if value == ''
        next if i == last_row.size - 1 # don't want to include annual total
        row_data << value

        # update chart
        month = summary_table_02[:header][i]
        clean_value = value.to_s.delete(',').to_f
        summary_table_02[:chart] << JSON.generate(label: title, label_x: month, value: clean_value, color: component_color[title])
      end
      summary_table_02[:data] << row_data

    end
  end

  # add table to array of tables
  summary_tables << summary_table_02

  return @template_section
end

.heat_losses_section(model, sqlFile, runner, name_only = false) ⇒ Object

section for heat_losses



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
# File 'lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb', line 320

def self.heat_losses_section(model, sqlFile, runner, name_only = false)
  # array to hold tables
  tables = []

  # gather data for section
  @heat_losses = {}
  @heat_losses[:title] = 'Heat Losses By Month Detailed'
  @heat_losses[:tables] = tables

  # stop here if only name is requested this is used to populate display name for arguments
  if name_only == true
    return @heat_losses
  end

  #     # using helper method that generates table for second example
  #     # use multiple variables for ventilation
  #     temp_vent_loss_ht = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner,'Zone Mechanical Ventilation Heating Load Increase Energy','J','kBtu')
  #     temp_vent_no_load_loss = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner,'Zone Mechanical Ventilation No Load Heat Removal Energy','J','kBtu')
  #     temp_vent_loss_ht_over_clg = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner,'Zone Mechanical Ventilation Heating Load Increase Due to Overcooling Energy','J','kBtu')
  #     temp_vent_loss_clg_decr = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner,'Zone Mechanical Ventilation Cooling Load Decrease Energy','J','kBtu')
  #     temp_heat_exch_htg = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner,'Air System Heat Exchanger Total Heating Energy','J','kBtu')
  #     temp_vent_loss_ht[:title] = 'Mechanical Ventilation Heat Loss (kBtu)'
  #     temp_vent_loss_ht[:data].each_with_index do |row,i|
  #       row.each_with_index do |column,j|
  #         next if j == 0
  #         value = column.gsub(",","").to_f + temp_vent_loss_clg_decr[:data][i][j].gsub(",","").to_f + temp_vent_no_load_loss[:data][i][j].gsub(",","").to_f + temp_vent_loss_ht_over_clg[:data][i][j].gsub(",","").to_f
  #         temp_vent_loss_ht[:data][i][j] = OpenStudio::toNeatString(value,1,true)
  #       end
  #     end
  #
  #     # deduct for heat exchangers
  #     temp_heat_exch_htg[:data].each_with_index do |row,i|
  #       new_row = []
  #       row.each_with_index do |column,j|
  #         if j == 0
  #           new_row <<  "Air System Heat Exchanger Total Heating Energy - #{column}"
  #         else
  #           value = column.gsub(",","").to_f * -1.0
  #           if i + 1.0 == temp_heat_exch_htg[:data].size
  #             # update monthly total for column
  #             orig_value = temp_vent_loss_ht[:data].last[j].gsub(",","").to_f
  #             new_value = orig_value + value
  #             temp_vent_loss_ht[:data].last[j] =  OpenStudio::toNeatString(new_value,1,true)
  #           else
  #             new_row << OpenStudio::toNeatString(value,1,true)
  #           end
  #         end
  #       end
  #       # add new row before monthly totals adjusted for heat exchangers
  #       if new_row.size > 1
  #         temp_vent_loss_ht[:data].insert(temp_vent_loss_ht[:data].size - 1, new_row)
  #       end
  #     end
  #     tables << @ventilation_loss_table = temp_vent_loss_ht

  tables << @infiltration_loss_table = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner, 'Zone Infiltration Sensible Heat Loss Energy', 'J', 'kBtu')
  tables << @window_loss_table = OsLib_ReportingHeatGainLoss.monthly_table_with_totals(model, sqlFile, runner, 'Surface Window Heat Loss Energy', 'J', 'kBtu')
  tables << @surface_loss_table = OsLib_ReportingHeatGainLoss.monthly_surface_heat_losses_table(model, sqlFile, runner)

  return @heat_losses
end

.monthly_surface_heat_gains_table(model, sqlFile, runner) ⇒ Object

monthly_surface_heat_gains_and_losses_table rolled up from hourly values



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
# File 'lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb', line 638

def self.monthly_surface_heat_gains_table(model, sqlFile, runner)
  # variables
  frequency = 'Hourly'
  var = 'Surface Average Face Conduction Heat Transfer Energy'
  source_units = 'J'
  target_units = 'kBtu'

  # create table
  monthly_surface_heat_gains_table = {}
  monthly_surface_heat_gains_table[:title] = "Surface Average Face Conduction Heat Gain (#{target_units})" # heat losses will be in another table
  monthly_surface_heat_gains_table[:header] = ['', 'Surface Type', 'Ouside Boundary Condition', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Total']
  monthly_surface_heat_gains_table[:units] = [] # in title since all columns the same
  monthly_surface_heat_gains_table[:data] = []

  monthly_totals = {}
  model.getSurfaces.sort.each do |surface|
    next if surface.outsideBoundaryCondition == 'Surface'
    next if surface.outsideBoundaryCondition == 'Adiabatic'
    key = surface.name.to_s
    row_data = []
    row_data << surface.name.to_s
    row_data << surface.surfaceType
    row_data << surface.outsideBoundaryCondition

    # get time series hourly data
    ann_env_pd = OsLib_ReportingHeatGainLoss.ann_env_pd(sqlFile)
    if ann_env_pd

      # get timeseries data
      output_timeseries = sqlFile.timeSeries(ann_env_pd, frequency, var, key)
      if output_timeseries.is_initialized # checks to see if time_series exists
        values = output_timeseries.get.values
        date_times = output_timeseries.get.dateTimes

        # loop through hourly data
        surface_values_hash = {}
        values.size.times do |i|
          value = values[i]
          # if value negative then set to 0 (heat losses will be in their own table with reversed logic)
          if value < 0.0
            value = 0.0
          end
          month = date_times[i].date.monthOfYear.valueName
          if surface_values_hash.key?(month)
            surface_values_hash[month] += value
          else
            surface_values_hash[month] = value
          end
        end

        # loop through has to populate row for table
        annual_total_ip = 0.0
        surface_values_hash.each do |month, monthly_value_si|
          monthly_value_ip = OpenStudio.convert(monthly_value_si, source_units, target_units).get

          # update value for total column
          annual_total_ip += monthly_value_ip

          # update value for totals row
          if monthly_totals.key?(month)
            monthly_totals[month][:total] += monthly_value_ip
          else
            monthly_totals[month] = {}
            monthly_totals[month][:total] = monthly_value_ip
          end

          # add sub-totals
          if surface.outsideBoundaryCondition == 'Outdoors' && surface.surfaceType == 'Wall'
            if monthly_totals[month].key?(:ext_wall)
              monthly_totals[month][:ext_wall] += monthly_value_ip
            else
              monthly_totals[month][:ext_wall] = monthly_value_ip
            end
          elsif surface.outsideBoundaryCondition == 'Outdoors' && surface.surfaceType == 'RoofCeiling'
            if monthly_totals[month].key?(:ext_roof)
              monthly_totals[month][:ext_roof] += monthly_value_ip
            else
              monthly_totals[month][:ext_roof] = monthly_value_ip
            end
          else # assume others are ground, could also include OtherSideConditionsModel, could be floor or walls
            if monthly_totals[month].key?(:ground)
              monthly_totals[month][:ground] += monthly_value_ip
            else
              monthly_totals[month][:ground] = monthly_value_ip
            end
          end

          monthly_value_ip_neat = OpenStudio.toNeatString(monthly_value_ip, 1, true)
          row_data << monthly_value_ip_neat
        end

        # add annual total
        row_data << OpenStudio.toNeatString(annual_total_ip, 1, true)
        monthly_surface_heat_gains_table[:data] << row_data

      else
        runner.registerWarning("Didn't find data for #{var} #{key}")
      end

    else
      runner.registerWarning('An annual simulation was not run. Cannot get annual timeseries data')
      return false
    end
  end

  # add total and sub-total rows
  row_data_total = ['Monthly Totals', '', '']
  row_data_sub_ext_wall = ['Monthly SubTotals', 'Wall', 'Outdoors']
  row_data_sub_ext_roof = ['Monthly SubTotals', 'Roof', 'Outdoors']
  row_data_sub_ground = ['Monthly SubTotals', '', 'Ground']
  row_data_total_annual = 0.0
  row_data_sub_ext_wall_annual = 0.0
  row_data_sub_ext_roof_annual = 0.0
  row_data_sub_ground_annual = 0.0
  monthly_totals.each do |month, hash|
    # add 0 value if key doesn't exist for surface type
    if !hash.key?(:ext_wall) then hash[:ext_wall] = 0 end
    if !hash.key?(:ext_roof) then hash[:ext_roof] = 0 end
    if !hash.key?(:ground) then hash[:ground] = 0 end
    if !hash.key?(:total) then hash[:total] = 0 end

    row_data_sub_ext_wall << OpenStudio.toNeatString(hash[:ext_wall], 1, true)
    row_data_sub_ext_wall_annual += hash[:ext_wall]
    row_data_sub_ext_roof << OpenStudio.toNeatString(hash[:ext_roof], 1, true)
    row_data_sub_ext_roof_annual += hash[:ext_roof]
    row_data_sub_ground << OpenStudio.toNeatString(hash[:ground], 1, true)
    row_data_sub_ground_annual += hash[:ground]
    row_data_total << OpenStudio.toNeatString(hash[:total], 1, true)
    row_data_total_annual += hash[:total]
  end

  # add annual total column in total and subtotal rows
  row_data_sub_ext_wall << OpenStudio.toNeatString(row_data_sub_ext_wall_annual, 1, true)
  row_data_sub_ext_roof << OpenStudio.toNeatString(row_data_sub_ext_roof_annual, 1, true)
  row_data_sub_ground << OpenStudio.toNeatString(row_data_sub_ground_annual, 1, true)
  row_data_total << OpenStudio.toNeatString(row_data_total_annual, 1, true)

  # register values
  runner.registerValue('ext_wall_heat_gain', row_data_sub_ext_wall.last.delete(',').to_f, 'kBtu')
  runner.registerValue('ext_roof_heat_gain', row_data_sub_ext_roof.last.delete(',').to_f, 'kBtu')
  runner.registerValue('ground_heat_gain', row_data_sub_ground.last.delete(',').to_f, 'kBtu')
  runner.registerValue('surface_heat_gain', row_data_total.last.delete(',').to_f, 'kBtu')

  # add rows
  monthly_surface_heat_gains_table[:data] << row_data_sub_ext_wall
  monthly_surface_heat_gains_table[:data] << row_data_sub_ext_roof
  monthly_surface_heat_gains_table[:data] << row_data_sub_ground
  monthly_surface_heat_gains_table[:data] << row_data_total

  return monthly_surface_heat_gains_table
end

.monthly_surface_heat_losses_table(model, sqlFile, runner) ⇒ Object

monthly_surface_heat_losses_and_losses_table rolled up from hourly values



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
# File 'lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb', line 791

def self.monthly_surface_heat_losses_table(model, sqlFile, runner)
  # variables
  frequency = 'Hourly'
  var = 'Surface Average Face Conduction Heat Transfer Energy'
  source_units = 'J'
  target_units = 'kBtu'

  # create table
  monthly_surface_heat_losses_table = {}
  monthly_surface_heat_losses_table[:title] = "Surface Average Face Conduction Heat Loss (#{target_units})" # heat losses will be in another table
  monthly_surface_heat_losses_table[:header] = ['', 'Surface Type', 'Ouside Boundary Condition', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Total']
  monthly_surface_heat_losses_table[:units] = [] # in title since all columns the same
  monthly_surface_heat_losses_table[:data] = []

  monthly_totals = {}
  model.getSurfaces.sort.each do |surface|
    next if surface.outsideBoundaryCondition == 'Surface'
    next if surface.outsideBoundaryCondition == 'Adiabatic'
    key = surface.name.to_s
    row_data = []
    row_data << surface.name.to_s
    row_data << surface.surfaceType
    row_data << surface.outsideBoundaryCondition

    # get time series hourly data
    ann_env_pd = OsLib_ReportingHeatGainLoss.ann_env_pd(sqlFile)
    if ann_env_pd

      # get timeseries data
      output_timeseries = sqlFile.timeSeries(ann_env_pd, frequency, var, key)
      if output_timeseries.is_initialized # checks to see if time_series exists
        values = output_timeseries.get.values
        date_times = output_timeseries.get.dateTimes

        # loop through hourly data
        surface_values_hash = {}
        values.size.times do |i|
          value = values[i]
          # if value positive then set to 0 (heat gains will be in their own table with reversed logic)
          if value > 0.0
            value = 0.0
          else
            value = value.abs
          end
          month = date_times[i].date.monthOfYear.valueName
          if surface_values_hash.key?(month)
            surface_values_hash[month] += value
          else
            surface_values_hash[month] = value
          end
        end

        # loop through has to populate row for table
        annual_total_ip = 0.0
        surface_values_hash.each do |month, monthly_value_si|
          monthly_value_ip = OpenStudio.convert(monthly_value_si, source_units, target_units).get

          # update value for total column
          annual_total_ip += monthly_value_ip

          # update value for totals row
          if monthly_totals.key?(month)
            monthly_totals[month][:total] += monthly_value_ip
          else
            monthly_totals[month] = {}
            monthly_totals[month][:total] = monthly_value_ip
          end

          # add sub-totals
          if surface.outsideBoundaryCondition == 'Outdoors' && surface.surfaceType == 'Wall'
            if monthly_totals[month].key?(:ext_wall)
              monthly_totals[month][:ext_wall] += monthly_value_ip
            else
              monthly_totals[month][:ext_wall] = monthly_value_ip
            end
          elsif surface.outsideBoundaryCondition == 'Outdoors' && surface.surfaceType == 'RoofCeiling'
            if monthly_totals[month].key?(:ext_roof)
              monthly_totals[month][:ext_roof] += monthly_value_ip
            else
              monthly_totals[month][:ext_roof] = monthly_value_ip
            end
          else # assume others are ground, could also include OtherSideConditionsModel, could be floor or walls
            if monthly_totals[month].key?(:ground)
              monthly_totals[month][:ground] += monthly_value_ip
            else
              monthly_totals[month][:ground] = monthly_value_ip
            end
          end

          monthly_value_ip_neat = OpenStudio.toNeatString(monthly_value_ip, 1, true)
          row_data << monthly_value_ip_neat
        end

        # add annual total
        row_data << OpenStudio.toNeatString(annual_total_ip, 1, true)
        monthly_surface_heat_losses_table[:data] << row_data

      else
        runner.registerWarning("Didn't find data for #{var} #{key}")
      end

    else
      runner.registerWarning('An annual simulation was not run. Cannot get annual timeseries data')
      return false
    end
  end

  # add total and sub-total rows
  row_data_total = ['Monthly Totals', '', '']
  row_data_sub_ext_wall = ['Monthly SubTotals', 'Wall', 'Outdoors']
  row_data_sub_ext_roof = ['Monthly SubTotals', 'Roof', 'Outdoors']
  row_data_sub_ground = ['Monthly SubTotals', '', 'Ground']
  row_data_total_annual = 0.0
  row_data_sub_ext_wall_annual = 0.0
  row_data_sub_ext_roof_annual = 0.0
  row_data_sub_ground_annual = 0.0
  monthly_totals.each do |month, hash|
    # add 0 value if key doesn't exist for surface type
    if !hash.key?(:ext_wall) then hash[:ext_wall] = 0 end
    if !hash.key?(:ext_roof) then hash[:ext_roof] = 0 end
    if !hash.key?(:ground) then hash[:ground] = 0 end
    if !hash.key?(:total) then hash[:total] = 0 end

    row_data_sub_ext_wall << OpenStudio.toNeatString(hash[:ext_wall], 1, true)
    row_data_sub_ext_wall_annual += hash[:ext_wall]
    row_data_sub_ext_roof << OpenStudio.toNeatString(hash[:ext_roof], 1, true)
    row_data_sub_ext_roof_annual += hash[:ext_roof]
    row_data_sub_ground << OpenStudio.toNeatString(hash[:ground], 1, true)
    row_data_sub_ground_annual += hash[:ground]
    row_data_total << OpenStudio.toNeatString(hash[:total], 1, true)
    row_data_total_annual += hash[:total]
  end

  # add annual total column in total and subtotal rows
  row_data_sub_ext_wall << OpenStudio.toNeatString(row_data_sub_ext_wall_annual, 1, true)
  row_data_sub_ext_roof << OpenStudio.toNeatString(row_data_sub_ext_roof_annual, 1, true)
  row_data_sub_ground << OpenStudio.toNeatString(row_data_sub_ground_annual, 1, true)
  row_data_total << OpenStudio.toNeatString(row_data_total_annual, 1, true)

  # register values
  runner.registerValue('ext_wall_heat_loss', row_data_sub_ext_wall.last.delete(',').to_f, 'kBtu')
  runner.registerValue('ext_roof_heat_loss', row_data_sub_ext_roof.last.delete(',').to_f, 'kBtu')
  runner.registerValue('ground_heat_loss', row_data_sub_ground.last.delete(',').to_f, 'kBtu')
  runner.registerValue('surface_heat_loss', row_data_total.last.delete(',').to_f, 'kBtu')

  # add rows
  monthly_surface_heat_losses_table[:data] << row_data_sub_ext_wall
  monthly_surface_heat_losses_table[:data] << row_data_sub_ext_roof
  monthly_surface_heat_losses_table[:data] << row_data_sub_ground
  monthly_surface_heat_losses_table[:data] << row_data_total

  return monthly_surface_heat_losses_table
end

.monthly_table_with_totals(model, sqlFile, runner, var, source_units, target_units) ⇒ Object

monthly monthly_table_with_totals



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
# File 'lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb', line 552

def self.monthly_table_with_totals(model, sqlFile, runner, var, source_units, target_units)
  # variables
  frequency = 'Monthly'

  # create table
  monthly_table_with_totals = {}
  monthly_table_with_totals[:title] = "#{var} (#{target_units})"
  monthly_table_with_totals[:header] = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Total']
  monthly_table_with_totals[:units] = [] # in title since all columns the same
  monthly_table_with_totals[:data] = []

  # get time series monthly data
  ann_env_pd = OsLib_ReportingHeatGainLoss.ann_env_pd(sqlFile)
  if ann_env_pd
    # loop through keys for variable
    keys = sqlFile.availableKeyValues(ann_env_pd, frequency, var)
    monthly_totals = ['Monthly Totals', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    keys.each do |key|
      total = 0.0
      var_value_monthly = [key]
      output_timeseries = sqlFile.timeSeries(ann_env_pd, frequency, var, key)
      # loop through timeseries and move the data from an OpenStudio timeseries to a normal Ruby array (vector)
      if output_timeseries.is_initialized # checks to see if time_series exists

        # see if filler needed at start or end of table/chart
        num_blanks_start = output_timeseries.get.dateTimes[0].date.monthOfYear.value - 2
        num_blanks_end = 12 - output_timeseries.get.values.size - num_blanks_start

        # fill in blank data for partial year simulations
        for i in 0..(num_blanks_start - 1)
          month = monthly_table_with_totals[:header][i + 1]
          var_value_monthly << ''
        end

        # get values
        output_timeseries = output_timeseries.get.values
        for i in 0..(output_timeseries.size - 1)
          month = monthly_table_with_totals[:header][i + 1 + num_blanks_start]
          value = OpenStudio.convert(output_timeseries[i], source_units, target_units).get
          total += value
          monthly_totals[i + 1] += value
          value_neat = OpenStudio.toNeatString(value, 1, true)
          var_value_monthly << value_neat
        end

        # fill in blank data for partial year simulations
        for i in 0..(num_blanks_end - 1)
          month = monthly_table_with_totals[:header][i]
          var_value_monthly << ''
        end

        # populate total column and clean up values
        total_neat = OpenStudio.toNeatString(total, 1, true)
        var_value_monthly << total_neat
        monthly_totals[13] += total

      else
        runner.registerWarning("Didn't find data for #{var} #{key}")
      end

      # add each key to data
      monthly_table_with_totals[:data] << var_value_monthly
    end

  else
    runner.registerWarning('An annual simulation was not run. Cannot get annual timeseries data')
    return false
  end

  # add table totals
  monthly_totals_neat = []
  monthly_totals.each do |total|
    if total == 'Monthly Totals'
      monthly_totals_neat << total
    else
      monthly_totals_neat << OpenStudio.toNeatString(total, 1, true)
    end
  end
  monthly_table_with_totals[:data] << monthly_totals_neat
  reg_val_display_name = "#{var}_annual"
  runner.registerValue(reg_val_string_prep(reg_val_display_name), monthly_totals.last, 'kBtu')

  return monthly_table_with_totals
end

.reg_val_string_prep(string) ⇒ Object

clean up unkown strings used for runner.registerValue names



63
64
65
66
67
68
69
70
71
# File 'lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb', line 63

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

.setup(runner) ⇒ Object

setup - get model, sql, and setup web assets path



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
# File 'lib/measures/envelope_and_internal_load_breakdown/resources/os_lib_reporting_envelope_and_internal_loads_breakdown.rb', line 10

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
  results[:web_asset_path] = OpenStudio.getSharedResourcesPath / OpenStudio::Path.new('web_assets')

  return results
end