diff --git a/BuildingSync.xsd b/BuildingSync.xsd index 7b406856..228937bf 100644 --- a/BuildingSync.xsd +++ b/BuildingSync.xsd @@ -2187,7 +2187,7 @@ - + Benchmark against the U.S. Energy Information Administration Residential Energy Consumption Survey (RECS), typically used for multifamily and other residential buildings. @@ -2579,7 +2579,7 @@ - + @@ -2888,7 +2888,7 @@ - + Other type of rate structure, or combination of other types. @@ -5579,17 +5579,10 @@ - + Output capacity of equipment. - - - - - - - @@ -5602,19 +5595,10 @@ - + List of controls for HeatingSource. - - - - - Control for HeatingSource. - - - - @@ -5756,19 +5740,10 @@ - + List of controls for CoolingSource. - - - - - CoolingSource control. - - - - @@ -5842,7 +5817,7 @@ - + @@ -5922,7 +5897,7 @@ - + @@ -5950,19 +5925,10 @@ Main fuel used by the system. - + List of controls for DeliverySystem. - - - - - DeliverySystem control. - - - - @@ -6380,17 +6346,10 @@ - + Output capacity of equipment. - - - - - - - @@ -6510,17 +6469,10 @@ - + Output capacity of equipment. - - - - - - - @@ -6539,17 +6491,10 @@ - + Output capacity of equipment. - - - - - - - @@ -6572,15 +6517,10 @@ Does the building/system include or connect to a building automation or management system? - + HeatingPlant equipment control strategies. - - - - - @@ -6755,15 +6695,10 @@ Does the building/system include a building automation or management system? - + CoolingPlant equipment control strategies. - - - - - @@ -7033,7 +6968,7 @@ - + @@ -7045,15 +6980,10 @@ Does the building/system include a building automation or management system? - + CondenserPlant equipment control strategies. - - - - - @@ -7284,19 +7214,10 @@ - + List of controls for other HVAC systems. - - - - - Other HVAC system control. - - - - @@ -7908,7 +7829,7 @@ - + @@ -8048,19 +7969,10 @@ - + List of controls for solar hot water. - - - - - Solar hot water control. - - - - @@ -8086,7 +7998,7 @@ - + @@ -8094,7 +8006,7 @@ - + @@ -8197,7 +8109,7 @@ - + @@ -8208,7 +8120,7 @@ - + @@ -8355,19 +8267,10 @@ - + List of controls for domestic hot water. - - - - - Domestic hot water control. - - - - @@ -8882,19 +8785,10 @@ - + List of controls for dishwasher. - - - - - Dishwasher control. - - - - @@ -8968,7 +8862,7 @@ - + @@ -8997,19 +8891,10 @@ - + List of controls for laundry system. - - - - - LaundrySystem control. - - - - @@ -9159,19 +9044,10 @@ - + List of controls for pump system. - - - - - Pump system control. - - - - @@ -9383,19 +9259,10 @@ - + List of controls for FanSystem. - - - - - FanSystem control. - - - - @@ -9531,19 +9398,10 @@ - + List of controls for MotorSystem. - - - - - MotorSystem control. - - - - @@ -9624,19 +9482,10 @@ - + List of controls for heat recovery system. - - - - - Heat recovery system control. - - - - @@ -10652,7 +10501,7 @@ - + @@ -11075,7 +10924,7 @@ - + @@ -11117,7 +10966,7 @@ - + @@ -11230,19 +11079,10 @@ - + List of controls for critical IT system. - - - - - Critical IT system control. - - - - @@ -11323,19 +11163,10 @@ - + List of plug load controls. - - - - - Plug load control. - - - - @@ -11409,19 +11240,10 @@ - + List of process load controls. - - - - - Process load control. - - - - @@ -11496,19 +11318,10 @@ - + List of conveyance system controls. - - - - - Conveyance system control. - - - - @@ -11809,19 +11622,10 @@ - + List of onsite storage transmission controls. - - - - - Onsite storage transmission control. - - - - @@ -11936,19 +11740,10 @@ - + List of controls for heated pool. - - - - - Heated pool control. - - - - @@ -12051,19 +11846,10 @@ - + List of controls for water use system. - - - - - Control for water use. - - - - @@ -12156,7 +11942,7 @@ - + @@ -12173,7 +11959,7 @@ The 'EngineeringCalculation' calculation method is used to represent a scenario in which a spreadsheet style calculation, or some other modeling approach that is not full building energy modeling, was used to derive data represented by this scenario type. - + @@ -12365,6 +12151,40 @@ + + + List of general equipment or system controls. + + + + + + General equipment or system control. + + + + + + + + List of equipment control strategies. + + + + + + + + + + Other type. + + + + + Commercial Buildings Energy Consumption Survey (CBECS) characterization, including the CBECS climate zone. + + Type of system operation control. @@ -15365,7 +15185,7 @@ - + diff --git a/proposals/2026/Consolidate Remaining Identical Duplicate Elements.md b/proposals/2026/Consolidate Remaining Identical Duplicate Elements.md new file mode 100644 index 00000000..646f1042 --- /dev/null +++ b/proposals/2026/Consolidate Remaining Identical Duplicate Elements.md @@ -0,0 +1,90 @@ +## Overview + +This proposal addresses part of [schema#356](https://github.com/BuildingSync/schema/issues/356) by consolidating remaining **identical duplicate element declarations** into shared global elements and local `ref` use sites, while preserving all existing XML names, paths, local context annotations, and cardinality at each use site. + +Scope is intentionally limited to pure patch-safe deduplication: + +- `Capacity` local duplicates (4) -> shared existing global `auc:Capacity` +- `ControlSystemTypes` local wrappers (3) -> new shared global `auc:ControlSystemTypes` +- General `Controls` local wrappers (19, excluding lighting) -> new shared global `auc:Controls` +- `Other` locals that are exactly `type="auc:OtherType"` (16) -> new shared global `auc:Other` +- `CBECS` local declarations (2) -> new shared global `auc:CBECS` typed `auc:CBECSType` +- `spec/validation_spec.rb` ignored duplicate list cleanup for `Capacity`, `CBECS`, and `ControlSystemTypes` only + +This change is classified as **PATCH** (non-breaking patch-level restructuring). It changes declaration structure only and preserves validation of existing BuildingSync instance documents. + +## Justification + +The schema currently carries repeated local element declarations that are structurally identical, increasing maintenance burden and duplicate-name exceptions without adding expressive value. Reusing shared global elements: + +- reduces duplicate name declarations while preserving instance compatibility, +- keeps context-specific wrapper documentation at ref sites, +- aligns with the long-running duplicate cleanup effort tracked in [#323](https://github.com/BuildingSync/schema/issues/323), [#324](https://github.com/BuildingSync/schema/issues/324), and [#325](https://github.com/BuildingSync/schema/issues/325). + +No instance migration is required because element names/paths/cardinality remain unchanged in place. + +## Implementation + +### Classification + +**PATCH**: refactor from local identical declarations to shared globals / refs only. +No element renames, no path moves, no type widening/narrowing, no sequence reordering, no new required content. + +### Exact schema edits + +Line references below identify the baseline `4f69954`, not the edited schema. + +| Element | Use sites | Shared declaration and preserved constraints | +| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `Capacity` | `HeatingSource`, `HeatingPlantType/Boiler`, `HeatingPlantType/DistrictHeating`, `HeatingPlantType/SolarThermal` (L5574, L6374, L6504, L6533) | Reuse the existing global at L12316 unchanged: decimal content with `auc:Source`. Keep each optional use in its choice with `OutputCapacity`, and retain its "Output capacity of equipment." annotation. | +| `ControlSystemTypes` | `HeatingPlantType`, `CoolingPlantType`, `CondenserPlantType` (L6566, L6749, L7039) | New global with inline complex type and sequence containing ``. Preserve optional wrappers and plant-specific annotations on refs. | +| General `Controls` | All 19 wrappers whose child is typed `auc:ControlGeneralType`; exclude the lighting wrapper at L7806 | New global with inline complex type and sequence containing local ``. The wrapper stays optional, but if present requires at least one control. Preserve use-site wrapper annotations. | +| `CBECS` | `ScenarioType/Benchmark/BenchmarkType`, `ClimateZoneType` (L2190, L15173) | New global typed `auc:CBECSType` (unchanged). Refs remain optional. | +| Empty `Other` | All 16 declarations typed exactly `auc:OtherType`, including the annotated use at L2883 | New global `Other` typed `auc:OtherType`; refs remain optional. The type remains empty. Preserve the five distinct inline variants, including custom climate-zone and communication-protocol content. | + +New global documentation is "Commercial Buildings Energy Consumption Survey (CBECS) characterization, including the CBECS climate zone." for `CBECS`, "List of equipment control strategies." for `ControlSystemTypes`, +"List of general equipment or system controls." for `Controls`, and "Other type." for `Other`. +The shared local `Control` child is documented as "General equipment or system control."; +the enclosing ref retains the equipment-specific context. + +Do not make `Control` global: that name collides with gbXML. Do not put occurrence attributes on global +declarations. Remove only `Capacity`, `CBECS`, and `ControlSystemTypes` from `ignored_dupes`. +`Controls` and `Control` each retain two declarations (general and lighting); `Other` retains six. + +### Scope exclusions in this proposal + +- `WaterSideEconomizer` widening and semantic renames remain separate work. +- No unions, schema version changes, or changelog changes. + +### Quantified impact + +- Named declarations: **1585 -> 1527** (**-58**) +- Duplicate names tracked in this effort: **32 -> 29** +- Declarations across those originally duplicated names: **177 -> 119** (still-duplicated-only subtotal: **116**) +- Replaced use sites: **44 total** (`4 + 3 + 19 + 16 + 2`) + +### Compatibility / downstream notes + +- XML instance paths and names are unchanged; no XML migration script needed. +- Generated code bindings may need regeneration/review after declaration consolidation. +- XPath consumers retain the same instance paths. This proposal does not claim a runtime audit of downstream consumers. +- `CBECS` is a ref to a global typed with a named complex type. Until [website#229](https://github.com/BuildingSync/BuildingSync-website/issues/229) ships, the schema viewer will not display its `ClimateZone` child; validation is unaffected. The other new wrappers use inline types or an empty type and are unaffected. +- Proposal acceptance is required before merge per proposal process. +- PR labels: `Non-breaking Change` and `Schema: General`. This is part of #356, not a resolution of its remaining duplicates. + +### Required checks for implementation PR + +- `bundle exec rake remove_tabs` +- `bundle exec rake` +- `bundle exec rake generate_data_dictionary` +- `poetry run pre-commit run --all-files` + +## References + +- https://github.com/BuildingSync/schema/issues/356 +- https://github.com/BuildingSync/schema/issues/323 +- https://github.com/BuildingSync/schema/issues/324 +- https://github.com/BuildingSync/schema/issues/325 +- https://github.com/BuildingSync/schema/pull/349 +- https://github.com/BuildingSync/schema/issues/474 +- https://github.com/BuildingSync/BuildingSync-website/issues/229 diff --git a/spec/validation_spec.rb b/spec/validation_spec.rb index 4b15db8c..e5df3f4f 100644 --- a/spec/validation_spec.rb +++ b/spec/validation_spec.rb @@ -82,6 +82,53 @@ @xsd = Nokogiri::XML::Schema.from_document(schema_doc) end + def auc_ns + {'auc' => 'http://buildingsync.net/schemas/bedes-auc/2019'} + end + + def xsd_ns + {'xs' => 'http://www.w3.org/2001/XMLSchema'} + end + + def load_example(path) + Nokogiri::XML(File.read(path)) + end + + def auc_node(xml) + Nokogiri::XML("#{xml}").root.element_children.first + end + + def expect_valid(doc) + errors = @xsd.validate(doc) + expect(errors).to be_empty, errors.map(&:message).join("\n") + end + + def expect_invalid(doc) + errors = @xsd.validate(doc) + expect(errors).not_to be_empty + end + + def set_choice_capacity(target, value) + target.xpath('auc:OutputCapacity | auc:Capacity', auc_ns).remove + capacity = auc_node("#{value}") + units = target.at_xpath('auc:CapacityUnits', auc_ns) + if units + units.add_previous_sibling(capacity) + else + target.add_child(capacity) + end + end + + def add_output_capacity(target, value) + output_capacity = auc_node("#{value}") + units = target.at_xpath('auc:CapacityUnits', auc_ns) + if units + units.add_previous_sibling(output_capacity) + else + target.add_child(output_capacity) + end + end + it 'should validate xmls' do total_errors = 0 Dir['examples/*.xml'].each do |xml| @@ -105,6 +152,231 @@ expect(total_errors).to eq 0 end + + it 'keeps issue 356 patch structure and cardinality constraints' do + schema_doc = Nokogiri::XML(File.read('BuildingSync.xsd')) + + expect(schema_doc.xpath("//xs:element[@name='Capacity']", xsd_ns).length).to eq 1 + expect(schema_doc.xpath("//xs:element[@name='CBECS']", xsd_ns).length).to eq 1 + expect(schema_doc.at_xpath("/xs:schema/xs:element[@name='CBECS']", xsd_ns)['type']).to eq 'auc:CBECSType' + expect(schema_doc.xpath("//xs:element[@ref='auc:CBECS']", xsd_ns).length).to eq 2 + expect(schema_doc.xpath("//xs:element[@name='ControlSystemTypes']", xsd_ns).length).to eq 1 + expect(schema_doc.xpath("//xs:element[@name='Controls']", xsd_ns).length).to eq 2 + expect(schema_doc.xpath("//xs:element[@name='Control']", xsd_ns).length).to eq 2 + expect(schema_doc.xpath("//xs:element[@name='Other']", xsd_ns).length).to eq 6 + expect(schema_doc.xpath("/xs:schema/xs:element[@name='Control']", xsd_ns).length).to eq 0 + + expect(schema_doc.xpath("//xs:element[@ref='auc:Controls']", xsd_ns).length).to eq 19 + expect(schema_doc.xpath("//xs:element[@ref='auc:ControlSystemTypes']", xsd_ns).length).to eq 3 + expect(schema_doc.xpath("//xs:element[@ref='auc:Other']", xsd_ns).length).to eq 16 + %w[Capacity CBECS Controls ControlSystemTypes Other].each do |name| + schema_doc.xpath("//xs:element[@ref='auc:#{name}']", xsd_ns).each do |node| + expect(node['minOccurs']).to eq '0' + expect(node['maxOccurs'] || '1').to eq '1' + end + end + expect(schema_doc.at_xpath("/xs:schema/xs:element[@name='Other']", xsd_ns)['type']).to eq 'auc:OtherType' + + global_controls = schema_doc.at_xpath("/xs:schema/xs:element[@name='Controls']", xsd_ns) + global_control = global_controls.at_xpath('./xs:complexType/xs:sequence/xs:element[@name="Control"]', xsd_ns) + expect(global_control['type']).to eq 'auc:ControlGeneralType' + expect(global_control['maxOccurs']).to eq 'unbounded' + expect(global_control['minOccurs']).to be_nil + + control_system_types = schema_doc.at_xpath("/xs:schema/xs:element[@name='ControlSystemTypes']", xsd_ns) + control_system_type_child = control_system_types.at_xpath('./xs:complexType/xs:sequence/xs:element[@ref="auc:ControlSystemType"]', xsd_ns) + expect(control_system_type_child['minOccurs']).to eq '0' + expect(control_system_type_child['maxOccurs']).to eq 'unbounded' + end + + it 'validates consolidated Capacity behavior across the four patched contexts' do + contexts = { + 'HeatingSource' => lambda { |doc| + doc.at_xpath("//auc:HeatingSource[@ID='HeatingSource-70049129212260']", auc_ns) + }, + 'Boiler' => lambda { |doc| + doc.at_xpath("//auc:HeatingPlant[@ID='HeatingPlantType-70049116420780']/auc:Boiler", auc_ns) + }, + 'DistrictHeating' => lambda { |doc| + boiler = doc.at_xpath("//auc:HeatingPlant[@ID='HeatingPlantType-70049116420780']/auc:Boiler", auc_ns) + boiler.replace(auc_node('Hot waterkBtu/hr')) + doc.at_xpath("//auc:HeatingPlant[@ID='HeatingPlantType-70049116420780']/auc:DistrictHeating", auc_ns) + }, + 'SolarThermal' => lambda { |doc| + boiler = doc.at_xpath("//auc:HeatingPlant[@ID='HeatingPlantType-70049116420780']/auc:Boiler", auc_ns) + boiler.replace(auc_node('kBtu/hr')) + doc.at_xpath("//auc:HeatingPlant[@ID='HeatingPlantType-70049116420780']/auc:SolarThermal", auc_ns) + } + } + + contexts.each do |name, target_builder| + aggregate_failures(name) do + valid_doc = load_example('examples/AT_example_SF_audit_report.xml') + valid_target = target_builder.call(valid_doc) + set_choice_capacity(valid_target, '123.45') + expect_valid(valid_doc) + + invalid_non_decimal_doc = load_example('examples/AT_example_SF_audit_report.xml') + invalid_non_decimal_target = target_builder.call(invalid_non_decimal_doc) + set_choice_capacity(invalid_non_decimal_target, 'abc') + expect_invalid(invalid_non_decimal_doc) + + invalid_both_doc = load_example('examples/AT_example_SF_audit_report.xml') + invalid_both_target = target_builder.call(invalid_both_doc) + set_choice_capacity(invalid_both_target, '123.45') + add_output_capacity(invalid_both_target, '456.0') + expect_invalid(invalid_both_doc) + + no_capacity_doc = load_example('examples/AT_example_SF_audit_report.xml') + no_capacity_target = target_builder.call(no_capacity_doc) + no_capacity_target.xpath('auc:OutputCapacity | auc:Capacity', auc_ns).remove + expect_valid(no_capacity_doc) + end + end + end + + it 'keeps consolidated CBECS behavior in benchmark and climate zone contexts' do + contexts = { + 'Benchmark' => lambda { |doc, cbecs_xml| + scenario = doc.at_xpath("//auc:Scenario[@ID='ScenarioType-70049018982360']/auc:ScenarioType", auc_ns) + scenario.children.remove + scenario.add_child(auc_node("#{cbecs_xml}")) + }, + 'ClimateZoneType' => lambda { |doc, cbecs_xml| + climate_zone_type = doc.at_xpath('//auc:ClimateZoneType', auc_ns) + climate_zone_type.children.remove + climate_zone_type.add_child(auc_node(cbecs_xml)) + } + } + examples = { + 'Benchmark' => 'examples/AT_example_SF_audit_report.xml', + 'ClimateZoneType' => 'examples/BuildingSync Website Valid Schema.xml' + } + + contexts.each do |name, builder| + aggregate_failures(name) do + ['', '1', + '5'].each do |xml| + doc = load_example(examples[name]) + builder.call(doc, xml) + expect_valid(doc) + end + + ['6', + '12', + 'text'].each do |xml| + doc = load_example(examples[name]) + builder.call(doc, xml) + expect_invalid(doc) + end + end + end + end + + it 'keeps consolidated ControlSystemTypes semantics for all three plant contexts' do + plant_paths = [ + "//auc:HeatingPlant[@ID='HeatingPlantType-70049116420780']", + "//auc:CoolingPlant[@ID='CoolingPlantType-70049112503700']", + "//auc:CondenserPlant[@ID='CondenserPlantType-70049110218100']" + ] + + plant_paths.each do |plant_path| + empty_doc = load_example('examples/AT_example_SF_audit_report.xml') + empty_plant = empty_doc.at_xpath(plant_path, auc_ns) + empty_plant.at_xpath('auc:ControlSystemTypes', auc_ns)&.remove + empty_plant.at_xpath('auc:UserDefinedFields', auc_ns).add_previous_sibling(auc_node('')) + expect_valid(empty_doc) + + repeated_doc = load_example('examples/AT_example_SF_audit_report.xml') + repeated_plant = repeated_doc.at_xpath(plant_path, auc_ns) + repeated_plant.at_xpath('auc:ControlSystemTypes', auc_ns)&.remove + repeated_plant.at_xpath('auc:UserDefinedFields', auc_ns).add_previous_sibling( + auc_node('Custom protocol') + ) + expect_valid(repeated_doc) + end + + invalid_doc = load_example('examples/AT_example_SF_audit_report.xml') + invalid_heating_plant = invalid_doc.at_xpath("//auc:HeatingPlant[@ID='HeatingPlantType-70049116420780']", auc_ns) + invalid_heating_plant.at_xpath('auc:ControlSystemTypes', auc_ns)&.remove + invalid_heating_plant.at_xpath('auc:UserDefinedFields', auc_ns).add_previous_sibling( + auc_node('Analog') + ) + expect_invalid(invalid_doc) + end + + it 'preserves general Controls wrapper behavior and value boundaries' do + source_path = "//auc:HeatingSource[@ID='HeatingSource-70049129212260']" + + omitted_doc = load_example('examples/AT_example_SF_audit_report.xml') + omitted_doc.at_xpath("#{source_path}/auc:Controls", auc_ns).remove + expect_valid(omitted_doc) + + empty_doc = load_example('examples/AT_example_SF_audit_report.xml') + empty_doc.at_xpath("#{source_path}/auc:Controls", auc_ns).replace(auc_node('')) + expect_invalid(empty_doc) + + one_control_doc = load_example('examples/AT_example_SF_audit_report.xml') + one_control_doc.at_xpath("#{source_path}/auc:Controls", auc_ns).replace( + auc_node('Manual') + ) + expect_valid(one_control_doc) + + multi_control_doc = load_example('examples/AT_example_SF_audit_report.xml') + multi_control_doc.at_xpath("#{source_path}/auc:Controls", auc_ns).replace( + auc_node('ManualManual') + ) + expect_valid(multi_control_doc) + + invalid_daylighting_doc = load_example('examples/AT_example_SF_audit_report.xml') + invalid_daylighting_doc.at_xpath("#{source_path}/auc:Controls", auc_ns).replace( + auc_node('') + ) + expect_invalid(invalid_daylighting_doc) + end + + it 'keeps lighting Controls specific to lighting control types' do + lighting_controls_path = "//auc:LightingSystem[@ID='LightingSystemType-70049015970580']/auc:Controls" + + lighting_daylighting_doc = load_example('examples/AT_example_SF_audit_report.xml') + lighting_daylighting_doc.at_xpath(lighting_controls_path, auc_ns).replace( + auc_node('Photocell') + ) + expect_valid(lighting_daylighting_doc) + + lighting_thermostat_doc = load_example('examples/AT_example_SF_audit_report.xml') + lighting_thermostat_doc.at_xpath(lighting_controls_path, auc_ns).replace( + auc_node('') + ) + expect_invalid(lighting_thermostat_doc) + end + + it 'keeps consolidated Other element strict while preserving distinct typed Other variants' do + scenario_other_path = "//auc:Scenario[@ID='ScenarioType-70049018982360']/auc:ScenarioType/auc:Other" + + valid_empty_other_doc = load_example('examples/AT_example_SF_audit_report.xml') + expect_valid(valid_empty_other_doc) + + invalid_text_other_doc = load_example('examples/AT_example_SF_audit_report.xml') + invalid_text_other_doc.at_xpath(scenario_other_path, auc_ns).content = 'unexpected text' + expect_invalid(invalid_text_other_doc) + + invalid_child_other_doc = load_example('examples/AT_example_SF_audit_report.xml') + invalid_child_other_doc.at_xpath(scenario_other_path, auc_ns).add_child(auc_node('bad')) + expect_invalid(invalid_child_other_doc) + + climate_zone_doc = load_example('examples/BuildingSync Website Valid Schema.xml') + climate_zone_doc.at_xpath('//auc:ClimateZoneType', auc_ns).add_child( + auc_node('Custom climate zone') + ) + expect_valid(climate_zone_doc) + + control_system_other_doc = load_example('examples/AT_example_SF_audit_report.xml') + control_system_other_doc.at_xpath("//auc:HeatingPlant[@ID='HeatingPlantType-70049116420780']/auc:ControlSystemTypes", auc_ns).replace( + auc_node('Protocol X') + ) + expect_valid(control_system_other_doc) + end end @@ -243,14 +515,11 @@ 'AdvancedPowerStrip', 'AssemblyType', 'Building', - 'CBECS', - 'Capacity', 'ClimateZone', 'CommunicationProtocol', 'Control', 'ControlSensor', 'ControlStrategy', - 'ControlSystemTypes', 'Controls', 'ConveyanceSystems', 'Facility',