Class: BuildingSync::Generator

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/buildingsync/generator.rb

Overview

Generator class that generates basic data that is used mostly for testing

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#help_calculate_hours, #help_convert, #help_count_number_of_days, #help_element_class_type_check, #help_get_attribute_value, #help_get_default_schedule_set, #help_get_duration, #help_get_end_time, #help_get_end_time_sat, #help_get_end_time_sun, #help_get_end_time_weekday, #help_get_or_create, #help_get_schedule_rule_set_from_schedule, #help_get_start_time, #help_get_start_time_sat, #help_get_start_time_sun, #help_get_start_time_weekday, #help_get_text_value, #help_get_text_value_as_bool, #help_get_text_value_as_date, #help_get_text_value_as_datetime, #help_get_text_value_as_float, #help_get_text_value_as_integer, #help_get_zone_name_list, #help_load_doc, #help_print_all_schedules, #help_print_schedule, #help_write_profile

Constructor Details

#initialize(ns = 'auc', version = '2.2.0') ⇒ Generator

Returns a new instance of Generator.

Parameters:

  • version (String) (defaults to: '2.2.0')

    version of BuildingSync



49
50
51
52
53
54
55
56
57
58
# File 'lib/buildingsync/generator.rb', line 49

def initialize(ns = 'auc', version = '2.2.0')
  supported_versions = ['2.0', '2.2.0']
  if !supported_versions.include? version
    @version = nil
    OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Generator.initialize', "The version: #{version} is not one of the supported versions: #{supported_versions}")
  else
    @version = version
  end
  @ns = ns
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



582
583
584
# File 'lib/buildingsync/generator.rb', line 582

def version
  @version
end

Instance Method Details

#add_all_resource_total_to_scenario(scenario_xml, end_use = 'All end uses', id = 'AllResourceTotal-1') ⇒ Object



231
232
233
234
235
236
237
238
239
240
# File 'lib/buildingsync/generator.rb', line 231

def add_all_resource_total_to_scenario(scenario_xml, end_use = 'All end uses', id = 'AllResourceTotal-1')
  all_resource_totals = help_get_or_create(scenario_xml, "#{@ns}:AllResourceTotals")

  all_resource_total = REXML::Element.new("#{@ns}:AllResourceTotal", all_resource_totals)
  all_resource_total.add_attribute('ID', id)
  eu = REXML::Element.new("#{@ns}:EndUse", all_resource_total)
  eu.text = end_use

  return all_resource_total
end

#add_energy_resource_use_to_scenario(scenario_xml, energy_resource_type = 'Electricity', end_use = 'All end uses', id = 'ResourceUse-1', native_units = nil) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/buildingsync/generator.rb', line 208

def add_energy_resource_use_to_scenario(scenario_xml, energy_resource_type = 'Electricity', end_use = 'All end uses', id = 'ResourceUse-1', native_units = nil)
  resource_uses = help_get_or_create(scenario_xml, "#{@ns}:ResourceUses")

  # Define ResourceUse and add ID
  resource_use = REXML::Element.new("#{@ns}:ResourceUse", resource_uses)
  resource_use.add_attribute('ID', id)

  # Add ResourceUnits
  if !native_units.nil?
    nu = REXML::Element.new("#{@ns}:ResourceUnits", resource_use)
    nu.text = native_units
  end

  # Add EnergyResource
  energy_resource = REXML::Element.new("#{@ns}:EnergyResource", resource_use)
  energy_resource.text = energy_resource_type

  # Add EndUse
  eu = REXML::Element.new("#{@ns}:EndUse", resource_use)
  eu.text = end_use
  return resource_use
end

#add_hvac_system_to_facility(facility_xml, id = 'HVACSystem-1', principal_hvac_system_type = nil) ⇒ Object

Adds hvac system with id. also adds principal hvac element if specified

Parameters:

  • facility_xml (REXML::Element)
  • id (String) (defaults to: 'HVACSystem-1')

See Also:



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/buildingsync/generator.rb', line 143

def add_hvac_system_to_facility(facility_xml, id = 'HVACSystem-1', principal_hvac_system_type = nil)
  systems_xml = get_or_create_systems(facility_xml)
  hvac_system_xml = get_or_create_system_of_type(systems_xml, 'HVACSystem')

  hvac_system_xml.add_attribute('ID', id)
  if !principal_hvac_system_type.nil?
    principal_xml = REXML::Element.new("#{@ns}:PrincipalHVACSystemType", hvac_system_xml)
    principal_xml.text = principal_hvac_system_type
  end
  return hvac_system_xml
end

#add_hvac_system_to_first_facility(doc, id = 'HVACSystem-1', principal_hvac_system_type = nil) ⇒ Object



122
123
124
125
# File 'lib/buildingsync/generator.rb', line 122

def add_hvac_system_to_first_facility(doc, id = 'HVACSystem-1', principal_hvac_system_type = nil)
  facility_xml = get_first_facility_element(doc)
  return add_hvac_system_to_facility(facility_xml, id, principal_hvac_system_type)
end

#add_lighting_system_to_facility(facility_xml, id = 'LightingSystem-1') ⇒ Object

Adds lighting system with id. wrapper around:

Parameters:

  • facility_xml (REXML::Element)
  • id (String) (defaults to: 'LightingSystem-1')

See Also:



159
160
161
162
163
164
# File 'lib/buildingsync/generator.rb', line 159

def add_lighting_system_to_facility(facility_xml, id = 'LightingSystem-1')
  systems_xml = get_or_create_systems(facility_xml)
  lighting_system_xml = get_or_create_system_of_type(systems_xml, 'LightingSystem')
  lighting_system_xml.add_attribute('ID', id)
  return lighting_system_xml
end

#add_lighting_system_to_first_facility(doc, id = 'LightingSystem-1') ⇒ Object



128
129
130
131
# File 'lib/buildingsync/generator.rb', line 128

def add_lighting_system_to_first_facility(doc, id = 'LightingSystem-1')
  facility_xml = get_first_facility_element(doc)
  return add_lighting_system_to_facility(facility_xml, id)
end

#add_linked_building(base_xml, id) ⇒ Object



113
114
115
# File 'lib/buildingsync/generator.rb', line 113

def add_linked_building(base_xml, id)
  add_linked_premise(base_xml, id, 'Building')
end

#add_linked_premise(base_xml, id, premise_type) ⇒ Object



106
107
108
109
110
111
# File 'lib/buildingsync/generator.rb', line 106

def add_linked_premise(base_xml, id, premise_type)
  linked_premises_xml = get_or_create_linked_premises(base_xml)
  premise_type_xml = get_or_create_premise_of_type(linked_premises_xml, premise_type)
  add_linked_premise_of_type(premise_type_xml, premise_type, id)
  return linked_premises_xml
end

#add_linked_premise_of_type(premise_type_xml, premise_type, id) ⇒ Object



95
96
97
98
99
# File 'lib/buildingsync/generator.rb', line 95

def add_linked_premise_of_type(premise_type_xml, premise_type, id)
  linked_xml = REXML::Element.new("#{@ns}:Linked#{premise_type}ID", premise_type_xml)
  linked_xml.add_attribute('IDref', id)
  return linked_xml
end

#add_linked_section(base_xml, id) ⇒ Object



117
118
119
# File 'lib/buildingsync/generator.rb', line 117

def add_linked_section(base_xml, id)
  add_linked_premise(base_xml, id, 'Section')
end

#add_plug_load_to_facility(facility_xml, id = 'PlugLoad-1') ⇒ Object

Adds plug load with id. wrapper around:

Parameters:

  • facility_xml (REXML::Element)
  • id (String) (defaults to: 'PlugLoad-1')

See Also:



170
171
172
173
174
175
# File 'lib/buildingsync/generator.rb', line 170

def add_plug_load_to_facility(facility_xml, id = 'PlugLoad-1')
  systems_xml = get_or_create_systems(facility_xml)
  new_system_xml = get_or_create_system_of_type(systems_xml, 'PlugLoad')
  new_system_xml.add_attribute('ID', id)
  return new_system_xml
end

#add_plug_load_to_first_facility(doc, id = 'PlugLoad-1') ⇒ Object



134
135
136
137
# File 'lib/buildingsync/generator.rb', line 134

def add_plug_load_to_first_facility(doc, id = 'PlugLoad-1')
  facility_xml = get_first_facility_element(doc)
  return add_plug_load_to_facility(facility_xml, id)
end

#add_report_to_first_facility(doc, id = 'Report-1') ⇒ REXML::Element

Add a Report element to the first Facility in the doc. If auc:Reports does not exist, this is added as well

Parameters:

  • doc (REXML::Document)

    a buildingsync document with atleast an auc:Facility

  • id (String) (defaults to: 'Report-1')

    id of the Report element to add

Returns:

  • (REXML::Element)

    the newly created Report element



279
280
281
282
283
284
285
# File 'lib/buildingsync/generator.rb', line 279

def add_report_to_first_facility(doc, id = 'Report-1')
  facility_xml = doc.get_elements(".//#{@ns}:Facilities/#{@ns}:Facility").first
  reports = help_get_or_create(facility_xml, "#{@ns}:Reports")
  report = REXML::Element.new("#{@ns}:Report", reports)
  report.add_attribute('ID', id)
  return report
end

#add_scenario_to_first_report(doc, scenario_type = nil, id = 'Scenario-1') ⇒ REXML::Element

Returns newly added scenario.

Parameters:

  • doc (REXML::Document)
  • scenario_type (String) (defaults to: nil)

    see add_scenario_type_to_scenario

  • id (String) (defaults to: 'Scenario-1')

    id for the new scenario

Returns:

  • (REXML::Element)

    newly added scenario



253
254
255
256
# File 'lib/buildingsync/generator.rb', line 253

def add_scenario_to_first_report(doc, scenario_type = nil, id = 'Scenario-1')
  report = doc.get_elements(".//#{@ns}:Reports/#{@ns}:Report").first
  return add_scenario_to_report(report, scenario_type, id)
end

#add_scenario_to_report(report_xml, scenario_type = nil, id = 'Scenario-1') ⇒ REXML::Element

Add a Scenario element to the Report XML element provided. If auc:Scenarios does not exist, this is added as well

Parameters:

  • report_xml (REXML::Element)

    an XML element of auc:Report

  • scenario_type (String) (defaults to: nil)

    see add_scenario_type_to_scenario

  • id (String) (defaults to: 'Scenario-1')

    id of the Scenario element to add

Returns:

  • (REXML::Element)

    the newly created Scenario element



264
265
266
267
268
269
270
271
272
# File 'lib/buildingsync/generator.rb', line 264

def add_scenario_to_report(report_xml, scenario_type = nil, id = 'Scenario-1')
  scenarios = report_xml.get_elements("./#{@ns}:Scenarios").first
  if scenarios.nil?
    scenarios = REXML::Element.new("#{@ns}:Scenarios", report_xml)
  end
  scenario = REXML::Element.new("#{@ns}:Scenario", scenarios)
  scenario.add_attribute('ID', id)
  return add_scenario_type_to_scenario(scenario, scenario_type)
end

#add_scenario_type_to_scenario(scenario_element, scenario_type) ⇒ REXML::Element

Add a specific scenario type to the provided scenario element

Parameters:

  • scenario_element (REXML::Element)
  • scenario_type (String)

    one of: [‘CBMeasured’, ‘CBModeled’, ‘POM’, ‘Benchmark’, ‘Target’]

Returns:

  • (REXML::Element)

    Scenario element



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/buildingsync/generator.rb', line 291

def add_scenario_type_to_scenario(scenario_element, scenario_type)
  scenario_type_element = REXML::Element.new("#{@ns}:ScenarioType", scenario_element)
  if scenario_type.nil?
    return scenario_element
  elsif scenario_type == 'CBMeasured'
    cb_element = REXML::Element.new("#{@ns}:CurrentBuilding", scenario_type_element)
    cm_element = REXML::Element.new("#{@ns}:CalculationMethod", cb_element)
    measured = REXML::Element.new("#{@ns}:Measured", cm_element)
  elsif scenario_type == 'CBModeled'
    cb_element = REXML::Element.new("#{@ns}:CurrentBuilding", scenario_type_element)
    cm_element = REXML::Element.new("#{@ns}:CalculationMethod", cb_element)
    modeled = REXML::Element.new("#{@ns}:Modeled", cm_element)
  elsif scenario_type == 'POM'
    pom = REXML::Element.new("#{@ns}:PackageOfMeasures", scenario_type_element)
  elsif scenario_type == 'Benchmark'
    benchmark = REXML::Element.new("#{@ns}:Benchmark", scenario_type_element)
  elsif scenario_type == 'Target'
    target = REXML::Element.new("#{@ns}:Target", scenario_type_element)
  end
  return scenario_element
end

#add_section_to_first_building(doc, id = 'Section-1') ⇒ Object



200
201
202
203
204
205
206
# File 'lib/buildingsync/generator.rb', line 200

def add_section_to_first_building(doc, id = 'Section-1')
  building_xml = get_first_building_element(doc)
  sections_xml = help_get_or_create(building_xml, "#{@ns}:Sections")
  section = REXML::Element.new("#{@ns}:Section", sections_xml)
  section.add_attribute('ID', id)
  return section
end

#add_time_series_to_scenario(scenario_xml, id = 'TimeSeries-1') ⇒ Object



242
243
244
245
246
247
# File 'lib/buildingsync/generator.rb', line 242

def add_time_series_to_scenario(scenario_xml, id = 'TimeSeries-1')
  time_series_data = help_get_or_create(scenario_xml, "#{@ns}:TimeSeriesData")
  time_series = REXML::Element.new("#{@ns}:TimeSeries", time_series_data)
  time_series.add_attribute('ID', id)
  return time_series
end

#create_bsync_root_to_buildingString

Starts from scratch and creates all necessary elements up to and including an

- Sites/Site/Buildings/Building/Sections/Section
- Reports/Report/Scenarios/Scenario

Returns:

  • (String)

    string formatted XML document



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
# File 'lib/buildingsync/generator.rb', line 64

def create_bsync_root_to_building
  xml = Builder::XmlMarkup.new(indent: 2)
  auc_ns = 'http://buildingsync.net/schemas/bedes-auc/2019'
  location = "https://raw.githubusercontent.com/BuildingSync/schema/v#{@version}/BuildingSync.xsd"
  xml.instruct! :xml
  xml.tag!("#{@ns}:BuildingSync",
           :"xmlns:#{@ns}" => auc_ns,
           :"xsi:schemaLocation" => "#{auc_ns} #{location}",
           :"xmlns:xsi" => 'http://www.w3.org/2001/XMLSchema-instance',
           :version => @version.to_s) do |buildsync|

    buildsync.tag!("#{@ns}:Facilities") do |faclts|
      faclts.tag!("#{@ns}:Facility", ID: 'Facility1') do |faclt|
        faclt.tag!("#{@ns}:Sites") do |sites|
          sites.tag!("#{@ns}:Site", ID: 'Site1') do |site|
            site.tag!("#{@ns}:Buildings") do |builds|
              builds.tag!("#{@ns}:Building", ID: 'Building1') do |build|
              end
            end
          end
        end
      end
    end
  end
end

#create_calculation_method_element(result) ⇒ REXML::Element

create and return the set of elements:

auc:CalculationMethod/auc:Modeled/
  auc:SoftwareProgramUsed = OpenStudio
  auc:SoftwareProgramVersion = ...
  auc:WeatherDataType = TMY
  auc:SimulationCompletionStatus = Success or Failed, depending on result[:completion_status]

Parameters:

  • result (hash)

    must have key: result

Returns:

  • (REXML::Element)


564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/buildingsync/generator.rb', line 564

def create_calculation_method_element(result)
  calc_method = REXML::Element.new("#{@ns}:CalculationMethod")
  modeled = REXML::Element.new("#{@ns}:Modeled", calc_method)
  software_program_used = REXML::Element.new("#{@ns}:SoftwareProgramUsed", modeled)
  software_program_used.text = 'OpenStudio'

  software_program_version = REXML::Element.new("#{@ns}:SoftwareProgramVersion", modeled)
  software_program_version.text = OpenStudio.openStudioLongVersion.to_s

  weather_data_type = REXML::Element.new("#{@ns}:WeatherDataType", modeled)
  weather_data_type.text = 'TMY3'

  sim_completion_status = REXML::Element.new("#{@ns}:SimulationCompletionStatus", modeled)
  sim_completion_status.text = result[:completed_status] == 'Success' ? 'Finished' : 'Failed'

  return calc_method
end

#create_minimum_building(occupancy_classification, year_of_const, floor_area_type, floor_area_value) ⇒ Object



385
386
387
388
389
390
391
392
393
394
# File 'lib/buildingsync/generator.rb', line 385

def create_minimum_building(occupancy_classification, year_of_const, floor_area_type, floor_area_value)
  xml_snippet = create_minimum_snippet(occupancy_classification, year_of_const, floor_area_type, floor_area_value)

  building_element = xml_snippet.elements["/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Sites/#{@ns}:Site/#{@ns}:Buildings/#{@ns}:Building"]
  if !building_element.nil?
    return BuildingSync::Building.new(building_element, '', '', @ns)
  else
    expect(building_element.nil?).to be false
  end
end

#create_minimum_facility(occupancy_classification, year_of_const, floor_area_type, floor_area_value, floors_above_grade = 1) ⇒ Object

creates a minimum facility

Parameters:

  • occupancy_classification (String)
  • year_of_const (Integer)
  • floor_area_type (String)
  • floor_area_value (Float)

Returns:

  • BuildingSync::Facility



359
360
361
362
363
364
365
366
367
# File 'lib/buildingsync/generator.rb', line 359

def create_minimum_facility(occupancy_classification, year_of_const, floor_area_type, floor_area_value, floors_above_grade = 1)
  xml_snippet = create_minimum_snippet(occupancy_classification, year_of_const, floor_area_type, floor_area_value, floors_above_grade)
  facility_element = xml_snippet.elements["/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility"]
  if !facility_element.nil?
    return BuildingSync::Facility.new(facility_element, @ns)
  else
    expect(facility_element.nil?).to be false
  end
end

#create_minimum_section_xml(typical_usage_hours = 40) ⇒ Object



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/buildingsync/generator.rb', line 396

def create_minimum_section_xml(typical_usage_hours = 40)
  section = REXML::Element.new("#{@ns}:Section")
  # adding the XML elements for the typical hourly usage per week
  typical_usages = REXML::Element.new("#{@ns}:TypicalOccupantUsages")
  section.add_element(typical_usages)
  typical_usage = REXML::Element.new("#{@ns}:TypicalOccupantUsage")
  typical_usages.add_element(typical_usage)
  typical_usage_unit = REXML::Element.new("#{@ns}:TypicalOccupantUsageUnits")
  typical_usage_unit.text = 'Hours per week'
  typical_usage.add_element(typical_usage_unit)
  typical_usage_value = REXML::Element.new("#{@ns}:TypicalOccupantUsageValue")
  typical_usage_value.text = typical_usage_hours
  typical_usage.add_element(typical_usage_value)
  return section
end

#create_minimum_site(occupancy_classification, year_of_const, floor_area_type, floor_area_value) ⇒ BuildingSync::Site

create minimum site

Parameters:

  • occupancy_classification (String)
  • year_of_const (Integer)
  • floor_area_type (String)
  • floor_area_value (Float)

Returns:



375
376
377
378
379
380
381
382
383
# File 'lib/buildingsync/generator.rb', line 375

def create_minimum_site(occupancy_classification, year_of_const, floor_area_type, floor_area_value)
  xml_snippet = create_minimum_snippet(occupancy_classification, year_of_const, floor_area_type, floor_area_value)
  site_element = xml_snippet.elements["/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Sites/#{@ns}:Site"]
  if !site_element.nil?
    return BuildingSync::Site.new(site_element, @ns)
  else
    expect(site_element.nil?).to be false
  end
end

#create_minimum_snippet(occupancy_classification, year_of_const = 2000, floor_area_type = 'Gross', floor_area_value = 1000, floors_above_grade = 1) ⇒ Object

creates a minimum building sync snippet

Parameters:

  • occupancy_classification (String)
  • year_of_const (Integer) (defaults to: 2000)
  • floor_area_type (String) (defaults to: 'Gross')
  • floor_area_value (Float) (defaults to: 1000)
  • ns (String)

Returns:

  • REXML::Document



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
# File 'lib/buildingsync/generator.rb', line 320

def create_minimum_snippet(occupancy_classification, year_of_const = 2000, floor_area_type = 'Gross', floor_area_value = 1000, floors_above_grade = 1)
  doc_string = create_bsync_root_to_building
  doc = REXML::Document.new(doc_string)

  facility_element = doc.elements["/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility"]
  site_element = facility_element.elements["#{@ns}:Sites/#{@ns}:Site"]
  building_element = site_element.elements["#{@ns}:Buildings/#{@ns}:Building"]

  # Add Facility info
  report_element = add_report_to_first_facility(doc)
  junk = add_scenario_to_report(report_element, 'CBModeled')

  # Add Site info
  occupancy_classification_element = REXML::Element.new("#{@ns}:OccupancyClassification", site_element)
  occupancy_classification_element.text = occupancy_classification

  # Add Building info
  year_of_construction_element = REXML::Element.new("#{@ns}:YearOfConstruction", building_element)
  year_of_construction_element.text = year_of_const
  floor_areas_element = REXML::Element.new("#{@ns}:FloorAreas", building_element)
  floor_area_element = REXML::Element.new("#{@ns}:FloorArea", floor_areas_element)
  floor_area_type_element = REXML::Element.new("#{@ns}:FloorAreaType", floor_area_element)
  floor_area_type_element.text = floor_area_type
  floor_area_value_element = REXML::Element.new("#{@ns}:FloorAreaValue", floor_area_element)
  floor_area_value_element.text = floor_area_value
  floors_above_grade_element = REXML::Element.new("#{@ns}:FloorsAboveGrade", building_element)
  floors_above_grade_element.text = floors_above_grade
  occupancy_classification_element = REXML::Element.new("#{@ns}:OccupancyClassification", building_element)
  occupancy_classification_element.text = occupancy_classification

  return doc
end

#generate_baseline_building_sections(xml_path, occupancy_classification, total_floor_area) ⇒ Object



446
447
448
449
450
451
452
453
454
455
456
# File 'lib/buildingsync/generator.rb', line 446

def generate_baseline_building_sections(xml_path, occupancy_classification, total_floor_area)
  building_sections = []

  doc = help_load_doc(xml_path)
  building_xml = get_first_building_element(doc)

  building_xml.elements.each("#{@ns}:Sections/#{@ns}:Section") do |building_element|
    building_sections.push(BuildingSync::BuildingSection.new(building_element, occupancy_classification, total_floor_area, 1, @ns))
  end
  return building_sections
end

#generate_baseline_buildings(xml_path, occupancy_classification, total_floor_area) ⇒ Object



434
435
436
437
438
439
440
441
442
443
444
# File 'lib/buildingsync/generator.rb', line 434

def generate_baseline_buildings(xml_path, occupancy_classification, total_floor_area)
  buildings = []

  doc = help_load_doc(xml_path)
  site_xml = get_first_site_element(doc)

  site_xml.elements.each("#{@ns}:Buildings/#{@ns}:Building") do |building_element|
    buildings.push(BuildingSync::Building.new(building_element, occupancy_classification, total_floor_area, @ns))
  end
  return buildings
end

#generate_baseline_facilities(xml_path) ⇒ Object

– Generate Baseline functions



413
414
415
416
417
418
419
420
421
# File 'lib/buildingsync/generator.rb', line 413

def generate_baseline_facilities(xml_path)
  facilities = []
  doc = help_load_doc(xml_path)

  doc.elements.each("#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility") do |facility_element|
    facilities.push(BuildingSync::Facility.new(facility_element, @ns))
  end
  return facilities
end

#generate_baseline_sites(xml_path) ⇒ Object



423
424
425
426
427
428
429
430
431
432
# File 'lib/buildingsync/generator.rb', line 423

def generate_baseline_sites(xml_path)
  sites = []
  doc = help_load_doc(xml_path)
  facility_xml = get_first_facility_element(doc)

  facility_xml.elements.each("#{@ns}:Sites/#{@ns}:Site") do |site_element|
    sites.push(BuildingSync::Site.new(site_element, @ns))
  end
  return sites
end

#get_building_from_file(xml_file_path) ⇒ Object



525
526
527
528
529
530
531
532
# File 'lib/buildingsync/generator.rb', line 525

def get_building_from_file(xml_file_path)
  doc = nil
  File.open(xml_file_path, 'r') do |file|
    doc = REXML::Document.new(file)
  end
  building = get_first_building_element(doc)
  return BuildingSync::Building.new(building, 'Office', '20000', @ns)
end

#get_building_section_from_file(xml_file_path) ⇒ Object



534
535
536
537
538
539
540
541
# File 'lib/buildingsync/generator.rb', line 534

def get_building_section_from_file(xml_file_path)
  doc = nil
  File.open(xml_file_path, 'r') do |file|
    doc = REXML::Document.new(file)
  end
  section = get_first_building_section_element(doc)
  return BuildingSync::BuildingSection.new(section, 'Office', '20000', 1, @ns)
end

#get_facility_from_file(xml_file_path) ⇒ Object



516
517
518
519
520
521
522
523
# File 'lib/buildingsync/generator.rb', line 516

def get_facility_from_file(xml_file_path)
  doc = nil
  File.open(xml_file_path, 'r') do |file|
    doc = REXML::Document.new(file)
  end
  facility = get_first_facility_element(doc)
  return BuildingSync::Facility.new(facility, @ns)
end

#get_first_building_element(doc) ⇒ Object



468
469
470
471
# File 'lib/buildingsync/generator.rb', line 468

def get_first_building_element(doc)
  building = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Sites/#{@ns}:Site/#{@ns}:Buildings/#{@ns}:Building").first
  return building
end

#get_first_building_section_element(doc) ⇒ Object



473
474
475
476
# File 'lib/buildingsync/generator.rb', line 473

def get_first_building_section_element(doc)
  section = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Sites/#{@ns}:Site/#{@ns}:Buildings/#{@ns}:Building/#{@ns}:Sections/#{@ns}:Section").first
  return section
end

#get_first_facility_element(doc) ⇒ Object



458
459
460
461
# File 'lib/buildingsync/generator.rb', line 458

def get_first_facility_element(doc)
  facility = doc.get_elements("#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility").first
  return facility
end

#get_first_hvac_system_element(doc) ⇒ Object



493
494
495
496
# File 'lib/buildingsync/generator.rb', line 493

def get_first_hvac_system_element(doc)
  scenario = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Systems/#{@ns}:HVACSystems/#{@ns}:HVACSystem").first
  return scenario
end

#get_first_report_element(doc) ⇒ Object



478
479
480
481
# File 'lib/buildingsync/generator.rb', line 478

def get_first_report_element(doc)
  report = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Reports/#{@ns}:Report").first
  return report
end

#get_first_scenario_element(doc) ⇒ Object



483
484
485
486
# File 'lib/buildingsync/generator.rb', line 483

def get_first_scenario_element(doc)
  scenario = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Reports/#{@ns}:Report/#{@ns}:Scenarios/#{@ns}:Scenario").first
  return scenario
end

#get_first_site_element(doc) ⇒ Object



463
464
465
466
# File 'lib/buildingsync/generator.rb', line 463

def get_first_site_element(doc)
  site = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Sites/#{@ns}:Site").first
  return site
end

#get_first_utility_element(doc) ⇒ Object



488
489
490
491
# File 'lib/buildingsync/generator.rb', line 488

def get_first_utility_element(doc)
  scenario = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Reports/#{@ns}:Report/#{@ns}:Utilities/#{@ns}:Utility").first
  return scenario
end

#get_hvac_system_from_file(xml_file_path) ⇒ BuildingSync::HVACSystem

get hvac system from xml file

Parameters:

  • xml_file_name (String)
  • standard_to_be_used (String)

Returns:



547
548
549
550
551
552
553
554
# File 'lib/buildingsync/generator.rb', line 547

def get_hvac_system_from_file(xml_file_path)
  doc = nil
  File.open(xml_file_path, 'r') do |file|
    doc = REXML::Document.new(file)
  end
  hvac_system = get_first_hvac_system_element(doc)
  return BuildingSync::HVACSystem.new(hvac_system, @ns)
end

#get_or_create_linked_premises(element_xml) ⇒ Object



90
91
92
93
# File 'lib/buildingsync/generator.rb', line 90

def get_or_create_linked_premises(element_xml)
  linked_premises_xml = help_get_or_create(element_xml, "#{@ns}:LinkedPremises")
  return linked_premises_xml
end

#get_or_create_premise_of_type(premise_xml, premise_type) ⇒ Object



101
102
103
104
# File 'lib/buildingsync/generator.rb', line 101

def get_or_create_premise_of_type(premise_xml, premise_type)
  premise_type_xml = help_get_or_create(premise_xml, "#{@ns}:#{premise_type}")
  return premise_type_xml
end

#get_or_create_system_of_type(systems_xml, system_type) ⇒ Object

Create new system without id. Will check for pluralized version and create if not there, else gets existing pluralized version and adds new singular as child. @example:

systems_xml = <auc:Systems/>
system_type = HVACSystem
returns <auc:Systems><auc:HVACSystems><auc:HVACSystem/></..></..>

@example:

systems_xml = <auc:Systems><auc:HVACSystems/></..>
system_type = HVACSystem
returns <auc:System><auc:HVACSystems><auc:HVACSystem/></..></..>

Parameters:

  • systems_xml (REXML::Element)

    pass the auc:Systems element

  • system_type (String)

    a valid BSync system type: HVACSystem, LightingSystem, etc.



189
190
191
192
193
# File 'lib/buildingsync/generator.rb', line 189

def get_or_create_system_of_type(systems_xml, system_type)
  new_systems_xml = help_get_or_create(systems_xml, "#{@ns}:#{system_type}s")
  new_system_xml = REXML::Element.new("#{@ns}:#{system_type}", new_systems_xml)
  return new_system_xml
end

#get_or_create_systems(facility_xml) ⇒ Object

Get or create <auc:Systems/> from <auc:Facility>…</..>



196
197
198
# File 'lib/buildingsync/generator.rb', line 196

def get_or_create_systems(facility_xml)
  return help_get_or_create(facility_xml, "#{@ns}:Systems")
end

#get_report_from_file(xml_file_path) ⇒ Object



507
508
509
510
511
512
513
514
# File 'lib/buildingsync/generator.rb', line 507

def get_report_from_file(xml_file_path)
  doc = nil
  File.open(xml_file_path, 'r') do |file|
    doc = REXML::Document.new(file)
  end
  report = get_first_report_element(doc)
  return BuildingSync::Report.new(report, @ns)
end

#get_utility_from_file(xml_file_path) ⇒ Object



498
499
500
501
502
503
504
505
# File 'lib/buildingsync/generator.rb', line 498

def get_utility_from_file(xml_file_path)
  doc = nil
  File.open(xml_file_path, 'r') do |file|
    doc = REXML::Document.new(file)
  end
  report = get_first_utility_element(doc)
  return BuildingSync::Utility.new(report, @ns)
end