From a9debf66a4baefc330d0bbe6c581172ebed3c167 Mon Sep 17 00:00:00 2001 From: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:14:51 -0700 Subject: [PATCH 1/7] add scenario planner and test --- docs/scenario_workflow_translation_plan.md | 9 +- lib/BOSS/baseline_hvac_planner.rb | 40 +- lib/BOSS/boss.rb | 18 +- lib/BOSS/scenario_hvac_planner.rb | 260 ++ lib/BOSS/scenario_measure_map.json | 1 + lib/BOSS/scenario_measure_mapper.rb | 16 +- ...mple-smalloffice-level2-hvac-retrofits.xml | 2905 +++++++++++++++++ .../integration/write_and_run_osws_spec.rb | 26 + spec/tests/unit/baseline_hvac_planner_spec.rb | 13 + spec/tests/unit/scenario_hvac_planner_spec.rb | 126 + spec/tests/unit/scenario_measure_map_spec.rb | 2 +- .../unit/scenario_measure_mapper_spec.rb | 24 +- 12 files changed, 3416 insertions(+), 24 deletions(-) create mode 100644 lib/BOSS/scenario_hvac_planner.rb create mode 100644 spec/files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml create mode 100644 spec/tests/unit/scenario_hvac_planner_spec.rb diff --git a/docs/scenario_workflow_translation_plan.md b/docs/scenario_workflow_translation_plan.md index 8a24232..cd03bf7 100644 --- a/docs/scenario_workflow_translation_plan.md +++ b/docs/scenario_workflow_translation_plan.md @@ -328,12 +328,19 @@ Use this roadmap as the tracker. Keep `Status` and `Delivered by` current when a ### PR 14E: Scenario HVAC Mappings -- Status: Planned +- Status: In progress (series close pending) - Delivered by: - - Depends on: PR 14D. - Scope: Map HVAC retrofit measures onto the steps `HvacTargetBinder` already produces (`bind` for topology `replace`, `bind_modifier` for `modify_existing_*`) through the PR 9 result contract. No new binding work belongs here. Order conditioning, then DOAS/ventilation, then modifiers. Keep existing economizer, DCV, and thermostat mappings from other gems. - Done when: One topology replacement and one modifier case run end to end, partial shared-system replacement is rejected, and mixed-source packages still write and run. - Avoid: Mapping "Replace boiler" or "Replace burner" to an efficiency edit, guessing values, or partial HVAC graphs. +- Decision: `BOSS::ScenarioHvacPlanner` (`lib/BOSS/scenario_hvac_planner.rb`) runs before the JSON map in `ScenarioMeasureMapper.map_measure`. It returns `:mapped` (its steps replace the JSON lookup), `:unmapped` (`hvac_measure_unmapped` warning; the scenario is skipped), or `:not_hvac` (fall through to the JSON map). It tries, in order: + - Replacement: the measure's `TechnologyCategories` reference `ExistingSystemReplaced` and `AlternativeSystemReplacement` HVACSystem IDrefs. `BaselineHvacPlanner#plan` reruns on the alternative systems with `operation: 'replace'` for conditioning (ventilation stays `create`). Every baseline HVACSystem must be in `ExistingSystemReplaced`; otherwise the measure is unmapped as a partial replacement. + - Modification: `ExistingSystemAffected` plus a `ModifiedSystem` HVACSystem. Efficiencies come from the modified system and bind through `bind_modifier` into the new `hvac_modifiers` phase (after `hvac_equipment`). DX cooling COP, heat pump heating COP, furnace `Thermal Efficiency`, and electric resistance map; other units (EER, SEER, AFUE, HSPF, kW/ton) are unmapped with no unit conversion. + - Named topology: with no IDrefs, only `Install variable refrigerant flow system` maps (VRF replace on the measure's premises, then sizing). This deviates from the 14B MeasureName rule with user approval; GSHP stays a mapping gap. +- Decision: proposed systems (`AlternativeSystemReplacement`/`ModifiedSystem` IDrefs) are excluded from baseline HVAC planning. `write_baseline_and_scenario_osws` accepts `hvac_retrofit_template:` (one of `HvacTargetBinder::STANDARDS_TEMPLATES`), defaulting to the baseline template. +- Fixture: `spec/files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml` adds proposed RTU and COP systems and scenarios `Scenario-POM-HVAC-RTU` (replacement), `-COP` (modifier), `-VRF` (named), and `-mixed` (COP modifier plus LEDs). `write_and_run_osws_spec.rb` writes and runs them. +- Limitations: a modifier and a replacement in the same package can target equipment the replacement removed, and `apply_hvac_modifier_to_object_scope` fails when nothing matches; such packages are not guarded yet. The named VRF replacement adds no DOAS. - Series close: merge the `buildingsync-measures-gem` branch upstream (`apply_hvac_topology_to_zone_scope`, `apply_standard_hvac_sizing_and_efficiency`, and any 14E measures), replace the CI branch-commit pin with the merged commit, and rerun the unit and integration suites. ### PR 15: CLI Command diff --git a/lib/BOSS/baseline_hvac_planner.rb b/lib/BOSS/baseline_hvac_planner.rb index 371ef55..c0b0421 100644 --- a/lib/BOSS/baseline_hvac_planner.rb +++ b/lib/BOSS/baseline_hvac_planner.rb @@ -35,8 +35,11 @@ def initialize(selector: HvacTopologySelector.new, binder: HvacTargetBinder.new) # @param hvac_systems [REXML::Element, nil] the facility HVACSystems element # @param standards_template [String] baseline create_typical template + # @param operation [String] binder operation for the conditioning step; ventilation is always created + # @param include_system_ids [Array, nil] when given, only these HVACSystems are planned + # @param exclude_system_ids [Array] HVACSystems left out, such as proposed scenario systems # @return [Plan] :topology with ordered OSW steps, or :fallback with the reasons - def plan(hvac_systems, standards_template) + def plan(hvac_systems, standards_template, operation: 'create', include_system_ids: nil, exclude_system_ids: []) return fallback(['No HVACSystems in the facility.']) if hvac_systems.nil? if !HvacTargetBinder::STANDARDS_TEMPLATES.include?(standards_template) @@ -44,7 +47,10 @@ def plan(hvac_systems, standards_template) "(#{HvacTargetBinder::STANDARDS_TEMPLATES.join(', ')})."]) end - results = @selector.select(hvac_systems) + results = @selector.select(hvac_systems).select do |result| + (include_system_ids.nil? || include_system_ids.include?(result.hvac_system_id)) && + !exclude_system_ids.include?(result.hvac_system_id) + end return fallback(['No HVACSystem records.']) if results.empty? unmatched = results.reject { |result| result.status == :match } @@ -65,9 +71,8 @@ def plan(hvac_systems, standards_template) end return fallback(problems) if !problems.empty? - bindings = (conditioning + ventilation).map do |result| - [result, @binder.bind(result, operation: 'create', standards_template:)] - end + bindings = conditioning.map { |result| [result, @binder.bind(result, operation:, standards_template:)] } + + ventilation.map { |result| [result, @binder.bind(result, operation: 'create', standards_template:)] } unbound = bindings.reject { |_, binding| binding.status == :bound } return fallback(unbound.map { |result, binding| describe(result, binding.status, binding.messages) }) if !unbound.empty? @@ -75,23 +80,19 @@ def plan(hvac_systems, standards_template) Plan.new(status: :topology, steps: bindings.map { |_, binding| binding.step } + [sizing_step], messages: []) end - private - - def merge(members, hvac_systems) - merged = members.first.dup - merged.premises = members.flat_map { |member| member.premises || [] }.uniq - building_id = covered_building_id(merged.premises, hvac_systems) - merged.premises = [{ type: 'Building', id: building_id }] if building_id - merged + # @return [Array] premises, or one Building premise when Section links cover the building + def self.normalize_premises(premises, document) + building_id = covered_building_id(premises, document) + building_id ? [{ type: 'Building', id: building_id }] : premises end # @return [String, nil] the building ID when every premise is a Section of the one # building and they include its 'Whole building' section or all of its other # non-empty sections - def covered_building_id(premises, hvac_systems) + def self.covered_building_id(premises, document) return nil if premises.empty? || !premises.all? { |premise| premise[:type] == 'Section' } - buildings = REXML::XPath.match(hvac_systems.document, "//*[local-name()='Building'][@ID]") + buildings = REXML::XPath.match(document, "//*[local-name()='Building'][@ID]") return nil if buildings.length != 1 sections = REXML::XPath.match(buildings.first, "*[local-name()='Sections']/*[local-name()='Section'][@ID]") @@ -109,6 +110,15 @@ def covered_building_id(premises, hvac_systems) whole_linked || parts_linked ? buildings.first.attributes['ID'] : nil end + private + + def merge(members, hvac_systems) + merged = members.first.dup + merged.premises = self.class.normalize_premises(members.flat_map { |member| member.premises || [] }.uniq, + hvac_systems.document) + merged + end + def fallback(messages) Plan.new(status: :fallback, steps: [], messages:) end diff --git a/lib/BOSS/boss.rb b/lib/BOSS/boss.rb index e0cbec0..2256ed8 100644 --- a/lib/BOSS/boss.rb +++ b/lib/BOSS/boss.rb @@ -12,6 +12,7 @@ require 'BOSS/external_measure_repo_manager' require 'BOSS/scenario_measure_mapper' require 'BOSS/baseline_hvac_planner' +require 'BOSS/scenario_hvac_planner' require 'openstudio/common_measures' require 'openstudio/model_articulation' @@ -59,7 +60,14 @@ def write_baseline_osw(xml_file_path, output_dir, epw_file_path, standard_to_be_ # @return [Hash] { baseline_osw_path:, scenario_results: [ { scenario_id:, scenario_name:, # report_id:, package_id:, status: :written | :skipped, osw_path:, skipped_measure_ids:, # warnings: } ], parser_warnings: } - def write_baseline_and_scenario_osws(xml_file_path, output_dir, epw_file_path, standard_to_be_used) + # @param hvac_retrofit_template [String, nil] standards template for scenario HVAC retrofits; + # defaults to the baseline template + def write_baseline_and_scenario_osws(xml_file_path, output_dir, epw_file_path, standard_to_be_used, + hvac_retrofit_template: nil) + if !hvac_retrofit_template.nil? && !HvacTargetBinder::STANDARDS_TEMPLATES.include?(hvac_retrofit_template) + raise ArgumentError, "hvac_retrofit_template must be one of #{HvacTargetBinder::STANDARDS_TEMPLATES.join(', ')}" + end + if !File.exist?(xml_file_path) message = "File '#{xml_file_path}' does not exist" OpenStudio.logFree(OpenStudio::Error, 'BOSS.write_baseline_and_scenario_osws', message) @@ -93,6 +101,8 @@ def write_baseline_and_scenario_osws(xml_file_path, output_dir, epw_file_path, s measures = bsync_reader.get_measures scenarios = bsync_reader.get_package_measure_scenarios id_warnings = scenario_output_id_warnings(scenarios) + hvac_planner = ScenarioHvacPlanner.new(bsync_reader.get_hvac_systems_xml, bsync_doc, + hvac_retrofit_template || bsync_reader.get_standard_template) scenario_results = [] scenario_osws = [] @@ -107,7 +117,7 @@ def write_baseline_and_scenario_osws(xml_file_path, output_dir, epw_file_path, s next end - mapped = mapper.map_package_scenario(scenario, measures, context:) + mapped = mapper.map_package_scenario(scenario, measures, context:, hvac_planner:) result = mapped.slice(:scenario_id, :scenario_name, :report_id, :package_id) .merge(status: :skipped, osw_path: nil, skipped_measure_ids: mapped[:skipped_measure_ids], warnings: mapped[:warnings]) @@ -202,7 +212,9 @@ def build_baseline_osw(bsync_reader) OSWArgPopulator::populate_change_building_location_args(baseline_osw, bsync_reader) OSWArgPopulator::populate_create_bar_from_building_type_ratios_args(baseline_osw, bsync_reader) - hvac_plan = BaselineHvacPlanner.new.plan(bsync_reader.get_hvac_systems_xml, bsync_reader.get_standard_template) + hvac_systems = bsync_reader.get_hvac_systems_xml + hvac_plan = BaselineHvacPlanner.new.plan(hvac_systems, bsync_reader.get_standard_template, + exclude_system_ids: ScenarioHvacPlanner.proposed_system_ids(hvac_systems)) OSWArgPopulator::populate_create_typical_building_from_model_args(baseline_osw, bsync_reader, add_hvac: !hvac_plan.topology?) if hvac_plan.topology? diff --git a/lib/BOSS/scenario_hvac_planner.rb b/lib/BOSS/scenario_hvac_planner.rb new file mode 100644 index 0000000..05ce3e4 --- /dev/null +++ b/lib/BOSS/scenario_hvac_planner.rb @@ -0,0 +1,260 @@ +# frozen_string_literal: true + +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'rexml/document' +require 'BOSS/baseline_hvac_planner' +require 'BOSS/hvac_topology_selector' +require 'BOSS/hvac_target_binder' + +module BOSS + # Plans split HVAC measure steps for one BuildingSync scenario measure. + # + # - Replacement with AlternativeSystemReplacement HVACSystems: the alternative systems go + # through the topology selector and bind with operation 'replace'. The replaced systems + # must be every existing HVACSystem, because generated zones cannot be split. + # - ModificationRetrocommissioning with ModifiedSystem HVACSystems: source efficiencies + # stated as COP or Thermal Efficiency become modify_existing_hvac_equipment_efficiencies steps. + # - Otherwise, a MeasureName in NAMED_TOPOLOGIES names exactly one topology and replaces + # whole-building HVAC. + # + # Measures that match none of these are :not_hvac and fall through to the JSON map. + class ScenarioHvacPlanner + PHASE = 'hvac_equipment' + MODIFIER_PHASE = 'hvac_modifiers' + EFFICIENCY_MODIFIER = 'modify_existing_hvac_equipment_efficiencies' + # MeasureName => [configuration, topology measure]. Only names that identify one topology. + NAMED_TOPOLOGIES = { + 'Install variable refrigerant flow system' => ['VRF Terminal Unit', 'hvac_vrf'] + }.freeze + + Result = Struct.new(:status, :steps, :messages, keyword_init: true) + + # @return [Array] HVACSystem IDs that measures name as alternatives or modified systems + def self.proposed_system_ids(hvac_systems) + return [] if hvac_systems.nil? + + system_ids = _system_ids(hvac_systems) + refs = REXML::XPath.match( + hvac_systems.document, + "//*[local-name()='Measure']/*[local-name()='TypeOfMeasure']//" \ + "*[local-name()='AlternativeSystemReplacement' or local-name()='ModifiedSystem']/@IDref" + ).map(&:value) + refs.uniq & system_ids + end + + def self._system_ids(hvac_systems) + REXML::XPath.match(hvac_systems, "*[local-name()='HVACSystem']/@ID").map(&:value) + end + + # @param hvac_systems [REXML::Element, nil] the facility HVACSystems element + # @param document [REXML::Document] the BuildingSync document + # @param standards_template [String] template for retrofit HVAC + def initialize(hvac_systems, document, standards_template, planner: BaselineHvacPlanner.new, binder: HvacTargetBinder.new) + @hvac_systems = hvac_systems + @document = document + @standards_template = standards_template + @planner = planner + @binder = binder + @system_ids = hvac_systems.nil? ? [] : self.class._system_ids(hvac_systems) + @proposed_ids = self.class.proposed_system_ids(hvac_systems) + end + + # @param measure [Hash] symbol-keyed measure hash from BuildingSyncReader#get_measures + # @return [Result] :mapped with OSW steps, :unmapped with reasons, or :not_hvac + def plan(measure) + measure_xml = REXML::XPath.first(@document, "//*[local-name()='Measure'][@ID=$id]", nil, + { 'id' => measure[:measure_id].to_s }) + return not_hvac if measure_xml.nil? + + alternatives = refs(measure_xml, 'Replacements', 'Replacement', 'AlternativeSystemReplacement') + modified = refs(measure_xml, 'ModificationRetrocommissions', 'ModificationRetrocommissioning', 'ModifiedSystem') + return plan_replacement(measure_xml, alternatives) if !alternatives.empty? + return plan_modification(measure_xml, modified) if !modified.empty? + return plan_named_replacement(measure_xml, measure[:measure_name]) if NAMED_TOPOLOGIES.key?(measure[:measure_name]) + + not_hvac + end + + private + + # HVACSystem IDs referenced by TypeOfMeasure//@IDref. + def refs(measure_xml, *names) + path = (['TypeOfMeasure'] + names).map { |name| "*[local-name()='#{name}']" }.join('/') + REXML::XPath.match(measure_xml, "#{path}/@IDref").map(&:value).uniq & @system_ids + end + + def plan_replacement(measure_xml, alternatives) + return unmapped([template_message]) if template_message + + replaced = refs(measure_xml, 'Replacements', 'Replacement', 'ExistingSystemReplaced') + existing = @system_ids - @proposed_ids + if replaced.empty? + return unmapped(['Replacement names no ExistingSystemReplaced HVACSystem.']) + end + + if !(existing - replaced).empty? + return unmapped(["Replacement leaves #{(existing - replaced).join(', ')} in place; " \ + 'partial HVAC replacement is not supported.']) + end + + hvac_plan = @planner.plan(@hvac_systems, @standards_template, operation: 'replace', include_system_ids: alternatives) + return unmapped(hvac_plan.messages) if !hvac_plan.topology? + + mapped(hvac_plan.steps) + end + + def plan_named_replacement(measure_xml, measure_name) + return unmapped([template_message]) if template_message + + configuration, topology = NAMED_TOPOLOGIES.fetch(measure_name) + result = HvacTopologySelector::Result.new( + status: :match, configuration:, measure: topology, hvac_system_id: nil, record_ids: [], + premises: BaselineHvacPlanner.normalize_premises(linked_premises(measure_xml), @document), + group_key: nil, messages: [], measure_arguments: {} + ) + binding = @binder.bind(result, operation: 'replace', standards_template: @standards_template) + return unmapped(binding.messages) if binding.status != :bound + + mapped([binding.step, sizing_step]) + end + + def plan_modification(measure_xml, modified) + affected = refs(measure_xml, 'ModificationRetrocommissions', 'ModificationRetrocommissioning', 'ExistingSystemAffected') + return unmapped(['ModificationRetrocommissioning names no ExistingSystemAffected HVACSystem.']) if affected.empty? + + settings = {} + problems = [] + premises = [] + modified.each do |system_id| + system = REXML::XPath.first(@hvac_systems, "*[local-name()='HVACSystem'][@ID=$id]", nil, { 'id' => system_id }) + premises.concat(linked_premises(system)) + source_efficiencies(system).each do |metric, value, problem| + next problems << "#{system_id}: #{problem}" if problem + + if settings.key?(metric) && settings[metric] != value + problems << "#{system_id}: conflicting #{metric} values #{settings[metric]} and #{value}." + end + settings[metric] ||= value + end + end + return unmapped(problems) if !problems.empty? + return unmapped(['ModifiedSystem states no COP or Thermal Efficiency source values.']) if settings.empty? + + premises = BaselineHvacPlanner.normalize_premises(premises.uniq, @document) + bindings = settings.map do |metric, value| + @binder.bind_modifier(modifier_measure: EFFICIENCY_MODIFIER, + modifier_arguments: { efficiency_metric: metric, efficiency_value: value }, premises:) + end + unbound = bindings.reject { |binding| binding.status == :bound } + return unmapped(unbound.flat_map(&:messages).uniq) if !unbound.empty? + + Result.new(status: :mapped, steps: bindings.map { |binding| binding.step.merge(workflow_phase: MODIFIER_PHASE) }, + messages: []) + end + + # @return [Array] [metric, value, nil] or [nil, nil, problem] per source with an efficiency value + def source_efficiencies(system) + cooling = sources(system, 'CoolingSources/CoolingSource', 'AnnualCoolingEfficiency').map do |source, value, units| + dx = node(source, 'CoolingSourceType/DX') + next [nil, nil, "#{id(source)} is not DX; only DX cooling COP is supported."] if dx.nil? + + metric = text(dx, 'DXSystemType') == 'Variable refrigerant flow' ? 'vrf_cooling_cop' : 'dx_cooling_cop' + cop(source, metric, value, units) + end + heating = sources(system, 'HeatingSources/HeatingSource', 'AnnualHeatingEfficiency').map do |source, value, units| + heating_efficiency(source, value, units) + end + cooling + heating + end + + def heating_efficiency(source, value, units) + type = node(source, 'HeatingSourceType') + if node(type, 'HeatPump') + cooling_id = REXML::XPath.first(type, "*[local-name()='HeatPump']/*[local-name()='CoolingSourceID']/@IDref")&.value + cooling = cooling_id && REXML::XPath.first(@hvac_systems, "//*[local-name()='CoolingSource'][@ID=$id]", nil, + { 'id' => cooling_id }) + vrf = cooling && text(node(cooling, 'CoolingSourceType/DX'), 'DXSystemType') == 'Variable refrigerant flow' + return cop(source, vrf ? 'vrf_heating_cop' : 'dx_heating_cop', value, units) + end + if node(type, 'Furnace') && text(source, 'PrimaryFuel') == 'Natural gas' + return fraction(source, 'gas_burner_efficiency', value, units) + end + return fraction(source, 'electric_heating_efficiency', value, units) if node(type, 'ElectricResistance') + + [nil, nil, "#{id(source)} heating type is not supported for efficiency changes."] + end + + def cop(source, metric, value, units) + return [nil, nil, "#{id(source)} efficiency units '#{units}' are not COP."] if units != 'COP' + return [nil, nil, "#{id(source)} COP must be positive."] if value <= 0 + + [metric, value, nil] + end + + def fraction(source, metric, value, units) + return [nil, nil, "#{id(source)} efficiency units '#{units}' are not Thermal Efficiency."] if units != 'Thermal Efficiency' + return [nil, nil, "#{id(source)} Thermal Efficiency must be in (0, 1]."] if value <= 0 || value > 1 + + [metric, value, nil] + end + + # [source, value, units] for sources that state an efficiency value. + def sources(system, path, prefix) + parent, child = path.split('/') + REXML::XPath.match(system, "*[local-name()='HeatingAndCoolingSystems']/*[local-name()='#{parent}']/" \ + "*[local-name()='#{child}']").filter_map do |source| + raw = text(source, "#{prefix}Value") + next if raw.nil? || raw.strip.empty? + + value = Float(raw, exception: false) + next [source, -1.0, text(source, "#{prefix}Units")] if value.nil? + + [source, value, text(source, "#{prefix}Units")] + end + end + + def linked_premises(xml) + REXML::XPath.match(xml, "*[local-name()='LinkedPremises']/*").flat_map do |premise_type| + premise_type.elements.to_a.filter_map do |link| + link.attributes['IDref'] && { type: premise_type.name, id: link.attributes['IDref'] } + end + end + end + + def node(xml, path) + return nil if xml.nil? + + REXML::XPath.first(xml, path.split('/').map { |name| "*[local-name()='#{name}']" }.join('/')) + end + + def text(xml, path) = node(xml, path)&.text&.strip + def id(xml) = xml.attributes['ID'] || xml.name + + def template_message + return nil if HvacTargetBinder::STANDARDS_TEMPLATES.include?(@standards_template) + + "Template '#{@standards_template}' is not supported by the split HVAC measures." + end + + def sizing_step + { measure_dir_name: BaselineHvacPlanner::SIZING_MEASURE, arguments: { standards_template: @standards_template } } + end + + def mapped(steps) + Result.new(status: :mapped, steps: steps.map { |step| step.merge(workflow_phase: PHASE) }, messages: []) + end + + def unmapped(messages) + Result.new(status: :unmapped, steps: [], messages:) + end + + def not_hvac + Result.new(status: :not_hvac, steps: [], messages: []) + end + end +end diff --git a/lib/BOSS/scenario_measure_map.json b/lib/BOSS/scenario_measure_map.json index 487d784..e95cf95 100644 --- a/lib/BOSS/scenario_measure_map.json +++ b/lib/BOSS/scenario_measure_map.json @@ -4,6 +4,7 @@ "envelope", "internal_loads", "hvac_equipment", + "hvac_modifiers", "controls_operations" ], "lookup_order": [ diff --git a/lib/BOSS/scenario_measure_mapper.rb b/lib/BOSS/scenario_measure_mapper.rb index fbe1c27..dfae723 100644 --- a/lib/BOSS/scenario_measure_mapper.rb +++ b/lib/BOSS/scenario_measure_mapper.rb @@ -37,11 +37,20 @@ def initialize(map_path = SCENARIO_MEASURE_MAP_PATH) # @param measure [Hash] symbol-keyed measure hash from the reader # @param context [Hash, nil] { building_type:, hvac_system_type: } used by conditional_arguments + # @param hvac_planner [ScenarioHvacPlanner, nil] tried before the JSON map; :not_hvac falls through # @return [Hash] { measure_id:, steps: [ { measure_dir_name:, arguments: {} } ], warnings: [] } - def map_measure(measure, context: {}) + def map_measure(measure, context: {}, hvac_planner: nil) context ||= {} raise ArgumentError, 'context must be a Hash' if !context.is_a?(Hash) + hvac = hvac_planner&.plan(measure) + if hvac&.status == :mapped + return { measure_id: measure[:measure_id], steps: hvac.steps, warnings: [] } + elsif hvac&.status == :unmapped + return _unmapped_result(measure, :hvac_measure_unmapped, + "HVAC measure cannot be mapped: #{hvac.messages.join(' ')}") + end + technology_category_key = _lookup_key(measure[:technology_category_element_name], measure[:measure_name]) system_category_key = _lookup_key(measure[:system_category_affected], measure[:measure_name]) @@ -84,9 +93,10 @@ def map_measure(measure, context: {}) # @param scenario [Hash] one record from BuildingSyncReader#get_package_measure_scenarios # @param measures [Hash] BuildingSyncReader#get_measures, keyed by measure ID # @param context [Hash, nil] forwarded to #map_measure + # @param hvac_planner [ScenarioHvacPlanner, nil] forwarded to #map_measure # @return [Hash] { scenario_id:, scenario_name:, report_id:, package_id:, # status: :writable | :skipped, steps: [], skipped_measure_ids: [], warnings: [] } - def map_package_scenario(scenario, measures, context: {}) + def map_package_scenario(scenario, measures, context: {}, hvac_planner: nil) context ||= {} raise ArgumentError, 'scenario must be a Hash' if !scenario.is_a?(Hash) raise ArgumentError, 'measures must be a Hash' if !measures.is_a?(Hash) @@ -116,7 +126,7 @@ def map_package_scenario(scenario, measures, context: {}) next end - result = map_measure(measure, context:) + result = map_measure(measure, context:, hvac_planner:) steps.concat(result[:steps]) skipped_measure_ids << measure_idref if result[:steps].empty? warnings.concat(result[:warnings].map { |warning| warning.merge(scenario_context) }) diff --git a/spec/files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml b/spec/files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml new file mode 100644 index 0000000..784f379 --- /dev/null +++ b/spec/files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml @@ -0,0 +1,2905 @@ + + + + + + + + + Prototype Small Office in Denver + Here we record general problems / issues identified in a walkthrough survey. + + + City Custom Building ID + some ID + + + Custom ID 1 + some other ID + + +
+ + + Some address + + + Denver + CO + 80014 +
+ -104.830000 + 39.660000 + Commercial + Office + + 1 + 0 + 1 + 0 + true + false + + + Gross + 5500.000000 + + + + + + Conditioned + 5500.000000 + + + + + + 6500.000000 + 0.000000 + 0.213300 + 0.050000 + 2000 + 2000 + 2010 + 2020-03-01 + 2000 + +
+ Space function + Office + Office + + + Peak total occupants + 31.000000 + + + + + 40.000000 + Hours per week + + + 50.000000 + Weeks per year + + + + + Gross + 5500.000000 + + + Conditioned + 5500.000000 + + + Single zone +
+
+ Whole building + Rectangular + + + A1 + + + 909.012230 + + + + + 180.187860 + + + + + 42.086890 + + + + + B1 + + + 606.008200 + + + + + 120.125240 + + + + + 0.000000 + + + + + C1 + + + 909.012230 + + + + + 180.187860 + + + + + 0.000000 + + + + + D1 + + + 606.008200 + + + + + 120.125240 + + + + + 0.000000 + + + + + + + + 6444.999000 + Good + + + + + + + 3891.153600 + + + +
+
+ + + + + + + + + + Single zone + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 10311.100000 + 10311.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9801.300000 + 9801.300000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 7858.100000 + 7858.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9067.800000 + 9067.800000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9855.400000 + 9855.400000 + W + Good + + + + + + + + + + 2000 + + + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 10198.900000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9847.200000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 7737.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9143.800000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9847.200000 + W + Good + + + + + + + + + + 2000 + + + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + + Digital + + +
+ + + + + +
+
+
+ + + Single zone + + + + + Warm air + + + Natural gas + Air + + + + + + + Packaged/unitary direct expansion/RTU + + + Electricity + + + + + + + Central fan + CAV terminal box no reheat + None + + + + + + + + +
+ +
+
+
+ + + + + + + Packaged Unitary + + + + 3.800000 + COP + + + + + + + Packaged/unitary heat pump + + + 3.500000 + COP + + + + + + + + + +
+ + + + + T8 + + + Standard Electronic + + 0.200000 + + 100.000000 + 5.500000 + 32.000000 + 4 + 1.000000 + 43 + false + + + + + + + Programmable + + + + false + +
+ + + + + +
+
+
+ + + + T12 + + + Standard Electronic + 100.000000 + 1.582575 + 316.516000 + 1 + 1.000000 + 5 + true + + + + + + + Programmable + + + + false + +
+ + + + + +
+
+
+ + + + LED + + + Standard Electronic + + 0.100000 + + 100.000000 + 2.752000 + 16.000000 + 4 + 1.000000 + 43 + false + + + + + + + Photocell + Continuous + + + + false + +
+ + + + + +
+
+
+
+ + + + + + + + 40.000000 + 123.000000 + + + Notes + + 1 + 3.600000 + Continuous + 123.000000 + 1.870180 + + Looped + Thermal Efficiency + 1.000000 + 40.000000 + 140.000000 + 1950.520000 + 11722.840000 + W + + + + + + + + + + 2000 + Electricity + Good + + + + +
+ +
+
+ 1 +
+
+ + + 0.536000 + 880.000000 + 880.000000 + Constant Volume + + + + + + 0.536000 + 872.000000 + 872.000000 + Variable Volume + + + + + + 0.536000 + 836.000000 + 836.000000 + Constant Volume + + + + + + 0.536000 + 830.000000 + 830.000000 + Variable Volume + + + + + + 0.536000 + 671.000000 + 671.000000 + Constant Volume + + + + + + 0.536000 + 664.000000 + 664.000000 + Variable Volume + + + + + + 0.536000 + 774.000000 + 774.000000 + Constant Volume + + + + + + 0.536000 + 766.000000 + 766.000000 + Variable Volume + + + + + + 0.536000 + 841.000000 + 841.000000 + Constant Volume + + + + + + 0.536000 + 833.000000 + 833.000000 + Variable Volume + + + + + + + + Wood frame + 0.547000 + + + + + Wood frame + 4.706000 + + + + + + + + Vinyl + Clear uncoated + Single pane + 3.241000 + 0.391000 + 0.391000 + + + + + + Vinyl + Low e + Triple pane + 0.300000 + 0.391000 + 0.391000 + + + + + Insulated metal + 0.500000 + + + Steel + 2.839000 + + + + + + + + 0.345000 + + + + Concrete poured + + + + + Miscellaneous Electric Load + 0.630000 + +
+ + + + + +
+
+
+
+ + + Notes on test + Tight + 0.151000 + ACHnatural + Blower door + +
+ +
+
+
+
+ + + Notes on test + +
+ +
+
+
+
+
+ + + + + Weekday + Occupied + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + Occupied + 06:00:00 + 07:00:00 + 11.000000 + + + Weekday + Occupied + 07:00:00 + 08:00:00 + 21.000000 + + + Weekday + Occupied + 08:00:00 + 12:00:00 + 100.000000 + + + Weekday + Occupied + 12:00:00 + 13:00:00 + 53.000000 + + + Weekday + Occupied + 13:00:00 + 17:00:00 + 100.000000 + + + Weekday + Occupied + 17:00:00 + 18:00:00 + 32.000000 + + + Weekday + Occupied + 18:00:00 + 22:00:00 + 11.000000 + + + Weekday + Occupied + 22:00:00 + 23:00:00 + 5.000000 + + + Weekday + Occupied + 23:00:00 + 23:59:59 + 0.000000 + + + Weekend + Occupied + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + Occupied + 00:00:00 + 23:59:59 + 0.000000 + + + + + + +
+ +
+
+
+ + + + Weekday + Lighting + 00:00:00 + 05:00:00 + 18.000000 + + + Weekday + Lighting + 05:00:00 + 07:00:00 + 23.000000 + + + Weekday + Lighting + 07:00:00 + 08:00:00 + 42.000000 + + + Weekday + Lighting + 08:00:00 + 12:00:00 + 90.000000 + + + Weekday + Lighting + 12:00:00 + 13:00:00 + 80.000000 + + + Weekday + Lighting + 13:00:00 + 17:00:00 + 90.000000 + + + Weekday + Lighting + 17:00:00 + 18:00:00 + 61.000000 + + + Weekday + Lighting + 18:00:00 + 20:00:00 + 42.000000 + + + Weekday + Lighting + 20:00:00 + 22:00:00 + 32.000000 + + + Weekday + Lighting + 22:00:00 + 23:00:00 + 23.000000 + + + Weekday + Lighting + 23:00:00 + 23:59:59 + 18.000000 + + + Weekend + Lighting + 00:00:00 + 23:59:59 + 18.000000 + + + Holiday + Lighting + 00:00:00 + 23:59:59 + 18.000000 + + + + + + + + + + + + Weekday + Miscellaneous equipment + 00:00:00 + 08:00:00 + 50.000000 + + + Weekday + Miscellaneous equipment + 08:00:00 + 12:00:00 + 100.000000 + + + Weekday + Miscellaneous equipment + 12:00:00 + 13:00:00 + 94.000000 + + + Weekday + Miscellaneous equipment + 13:00:00 + 17:00:00 + 100.000000 + + + Weekday + Miscellaneous equipment + 17:00:00 + 18:00:00 + 50.000000 + + + Weekday + Miscellaneous equipment + 18:00:00 + 23:59:59 + 20.000000 + + + Weekend + Miscellaneous equipment + 00:00:00 + 23:59:59 + 20.000000 + + + Holiday + Miscellaneous equipment + 00:00:00 + 23:59:59 + 20.000000 + + + + + + + + + + + + Weekday + HVAC equipment + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + HVAC equipment + 06:00:00 + 19:00:00 + 100.000000 + + + Weekday + HVAC equipment + 19:00:00 + 23:59:59 + 0.000000 + + + Weekend + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + + + + + + + + + + Weekday + HVAC equipment + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + HVAC equipment + 06:00:00 + 07:00:00 + 60.000000 + + + Weekday + HVAC equipment + 07:00:00 + 12:00:00 + 100.000000 + + + Weekday + HVAC equipment + 12:00:00 + 13:00:00 + 80.000000 + + + Weekday + HVAC equipment + 13:00:00 + 18:00:00 + 100.000000 + + + Weekday + HVAC equipment + 18:00:00 + 20:00:00 + 60.000000 + + + Weekday + HVAC equipment + 20:00:00 + 23:59:59 + 0.000000 + + + Weekend + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + + + + + + +
+ + + + + + + + + + + Lighting + + + + Retrofit with light emitting diode technologies + + + + Individual system + This measure is designed to replace all fluorescent bulbs with LEDs + 1 + 50.000000 + 774.000000 + true + 2021-01-01 + 2021-12-30 + + + + + + + + + + + Fan + + + + Add VSD motor controller + + + + Individual system + This measure is designed to retrofit all RTU fans with a VSD + 1 + 750.000000 + 1250.000000 + true + 2021-01-01 + 2021-12-30 + + + + + + + + + + + Cooling System + + + + Replace package units + + + + + + + + + + + + + + Cooling System + + + + Replace package units + + + + + + Cooling System + + + + + + + + + Install variable refrigerant flow system + + + + + + + + + + + + + + + + + + + Electricity + This is required to document irregularities in monthly energy patterns (Std 211 6.1.2.1.j). No irregularities found. + kWh + All end uses + 67334.150000 + 229.753657 + + + + + + + + + + + + + + + kW + 26.040000 + 26.040000 + 4613.820000 + + + + + + Natural gas + No irregularities in monthly energy consumption found. + MMBtu + All end uses + 8.720000 + 8.720000 + + + + + + + + + + + + + + + 540.830000 + + + + + + Electricity + kWh + Interior lighting + 28.705000 + 20062.690000 + 68.453898 + + + + Electricity + kWh + Heating + 6.722000 + 4698.230000 + 16.030361 + + + + Electricity + kWh + Cooling + 8.769000 + 6128.870000 + 20.911704 + + + + Electricity + kWh + Domestic hot water + 10.281000 + 7185.370000 + 24.516482 + + + + Electricity + kWh + Plug load + 21.379000 + 14942.150000 + 50.982616 + + + + + + Total + Energy + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 5933.100000 + + + + Total + Energy + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 5446.100000 + + + + Total + Energy + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 5736.490000 + + + + Total + Energy + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 4980.500000 + + + + Total + Energy + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 5187.210000 + + + + Total + Energy + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 5842.950000 + + + + Total + Energy + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 5801.730000 + + + + Total + Energy + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 6220.160000 + + + + Total + Energy + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 5682.870000 + + + + Total + Energy + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 5571.930000 + + + + Total + Energy + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 5525.150000 + + + + Total + Energy + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 5405.940000 + + + + Total + Energy + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 1.720000 + + + + Total + Energy + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 1.250000 + + + + Total + Energy + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 0.410000 + + + + Total + Energy + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 0.430000 + + + + Total + Energy + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 0.010000 + + + + Total + Energy + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 0.000000 + + + + Total + Energy + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 0.000000 + + + + Total + Energy + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 0.000000 + + + + Total + Energy + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 0.000000 + + + + Total + Energy + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 0.200000 + + + + Total + Energy + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 0.400000 + + + + Total + Energy + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 4.300000 + + + + Peak + On-peak + Power + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 23.580000 + + + + Peak + On-peak + Power + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 25.380000 + + + + Peak + On-peak + Power + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 26.040000 + + + + Peak + On-peak + Power + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 24.450000 + + + + Peak + On-peak + Power + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 17.030000 + + + + Peak + On-peak + Power + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 22.710000 + + + + Peak + On-peak + Power + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 22.010000 + + + + Peak + On-peak + Power + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 21.810000 + + + + Peak + On-peak + Power + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 20.630000 + + + + Peak + On-peak + Power + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 21.870000 + + + + Peak + On-peak + Power + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 21.630000 + + + + Peak + On-peak + Power + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 21.780000 + + + + Load factor + Power + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 0.340000 + + + + Load factor + Power + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 0.320000 + + + + Load factor + Power + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 0.300000 + + + + Load factor + Power + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 0.280000 + + + + Load factor + Power + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 0.410000 + + + + Load factor + Power + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 0.360000 + + + + Load factor + Power + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 0.350000 + + + + Load factor + Power + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 0.380000 + + + + Load factor + Power + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 0.380000 + + + + Load factor + Power + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 0.340000 + + + + Load factor + Power + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 0.350000 + + + + Load factor + Power + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 0.330000 + + + + Cost + Cost + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 332.160000 + + + + Cost + Cost + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 306.290000 + + + + Cost + Cost + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 321.720000 + + + + Cost + Cost + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 281.540000 + + + + Cost + Cost + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 292.530000 + + + + Cost + Cost + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 534.100000 + + + + Cost + Cost + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 530.450000 + + + + Cost + Cost + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 567.490000 + + + + Cost + Cost + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 519.930000 + + + + Cost + Cost + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 312.970000 + + + + Cost + Cost + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 310.490000 + + + + Cost + Cost + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 304.150000 + + + + Cost + Cost + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 46.690000 + + + + Cost + Cost + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 45.930000 + + + + Cost + Cost + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 44.550000 + + + + Cost + Cost + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 44.580000 + + + + Cost + Cost + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 43.900000 + + + + Cost + Cost + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 44.210000 + + + + Cost + Cost + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 44.530000 + + + + Cost + Cost + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 50.920000 + + + + + + 238473.656550 + 43.358800 + 737088.900000 + 134.000000 + 238473.656550 + 43.358800 + 238.473657 + 0.000000 + 0.000000 + 0.000000 + 4952.480000 + 0.900000 + + + + + + + + + + + + + + 2022-06-01 + + + Portfolio Manager + 2019 + 80.000000 + + + + + 238473.656550 + 43.358800 + 4952.480000 + + + + + + + + + + + + + 39070.530000 + 995 + 89.000000 + + + + + 190348.600000 + 34.600000 + 4846.040000 + 0.881000 + + + + + + + + + + + + + + TMY3 + Finished + + + + + + + Electricity + kWh + All end uses + 67334.150000 + 229.753657 + kW + 26.040000 + 26.040000 + + + Natural gas + MMBtu + All end uses + 8.720000 + 8.720000 + + + + + + + + + + POM-LEDs + + + + + + + Capital + 35.713000 + 772 + + + Electricity + kWh + 11524.540000 + + + Natural gas + MMBtu + 0.000000 + + + 3.220000 + 0 + 0.000000 + 0.000000 + 1 + 824.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 1.070000 + 0.000000 + + + + + + + + + + POM-VSDs + + + + + + + Capital + 5.175000 + 9 + + + Electricity + kWh + 207.240000 + + + Natural gas + MMBtu + 4.460000 + + + 0.420000 + 0 + 0.000000 + 0.000000 + 1 + 2000.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 230.150000 + 0.000000 + + + + + + + + + + POM-LEDs-VSDs + + + + + + + + Capital + 41.827000 + 781 + + + Electricity + kWh + 11701.620000 + + + Natural gas + MMBtu + 1.890000 + + + 4.700000 + 0 + 0.000000 + 0.000000 + 1 + 2824.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 3.620000 + 0.000000 + + + + + + + + + + POM-HVAC-RTU + + + + + + + + + + + POM-HVAC-COP + + + + + + + + + + + POM-HVAC-VRF + + + + + + + + + + + POM-HVAC-mixed + + + + + + + + + + + + Level 2: Energy Survey and Analysis + + + + + + + + + --06-01 + --09-30 + --06-01 + --09-30 + 0.088520 + 0.000000 + + + --01-01 + --05-31 + --01-01 + --05-31 + 0.053140 + 0.000000 + + + --10-01 + --12-31 + --10-01 + --12-31 + 0.053140 + 0.000000 + + + + + https://www.xcelenergy.com/company/rates_and_regulations/rates/rate_books + 16.880000 + + + 12345 + Xcel Energy + + Some-meter-ID + + some-account-number + Building Owner + + + + + + + + + --01-01 + --12-31 + 0.163600 + + + + + https://www.xcelenergy.com/company/rates_and_regulations/rates/rate_books + 43.880000 + + + Xcel Energy + + Some-meter-ID + + some-other-account-number + Building Owner + + + + + + + + + + + + + + Owner + + The dude + Some big company + + + 123-456-7890 + + + + + the.dude@somebigco.net + + + + + + Energy Auditor + + The lady + Auditeers + + + 123-456-7890 + + + + + the.lady@the-three-auditeers.com + + + + + + + diff --git a/spec/tests/integration/write_and_run_osws_spec.rb b/spec/tests/integration/write_and_run_osws_spec.rb index 308a4e0..71a9a0a 100644 --- a/spec/tests/integration/write_and_run_osws_spec.rb +++ b/spec/tests/integration/write_and_run_osws_spec.rb @@ -86,5 +86,31 @@ expect(steps['apply_standard_hvac_sizing_and_efficiency'][:result][:step_result]).to eq 'Success' end end + + it 'write and run HVAC retrofit scenarios. File: example-smalloffice-level2-hvac-retrofits.xml' do + xml_path = File.join(SPEC_FILES_DIR, 'v2.7.0', 'example-smalloffice-level2-hvac-retrofits.xml') + output_path = File.join(SPEC_OUTPUT_DIR, 'v2.7.0', 'hvac_retrofits') + + result = BOSS::Boss.write_baseline_and_scenario_osws(xml_path, output_path, nil, ASHRAE90_1) + by_id = result[:scenario_results].to_h { |scenario| [scenario[:scenario_id], scenario] } + hvac_ids = ['Scenario-POM-HVAC-RTU', 'Scenario-POM-HVAC-COP', 'Scenario-POM-HVAC-VRF', 'Scenario-POM-HVAC-mixed'] + hvac_ids.each { |id| expect(by_id.fetch(id)[:status]).to eq(:written), by_id.fetch(id)[:warnings].inspect } + + failures = BOSS::Boss.run_baseline_and_scenario_osws(result) + expect(failures).to be_empty, failures.inspect + + out = ->(path) { JSON.parse(File.read(File.join(File.dirname(path), 'out.osw')), symbolize_names: true) } + expect(out.call(result[:baseline_osw_path])[:completed_status]).to eq 'Success' + hvac_ids.each do |id| + out_osw = out.call(by_id.fetch(id)[:osw_path]) + expect(out_osw[:completed_status]).to eq('Success'), id + end + + rtu = out.call(by_id.fetch('Scenario-POM-HVAC-RTU')[:osw_path])[:steps] + .select { |step| step[:measure_dir_name] == 'apply_hvac_topology_to_zone_scope' }.last + expect(rtu[:arguments]).to include(topology_measure: 'hvac_packaged_rooftop_ac', operation: 'replace') + mixed = out.call(by_id.fetch('Scenario-POM-HVAC-mixed')[:osw_path])[:steps].map { |step| step[:measure_dir_name] } + expect(mixed).to include('SetLightingLoadsByLPD', 'apply_hvac_modifier_to_object_scope') + end end end diff --git a/spec/tests/unit/baseline_hvac_planner_spec.rb b/spec/tests/unit/baseline_hvac_planner_spec.rb index 099dae0..79151cf 100644 --- a/spec/tests/unit/baseline_hvac_planner_spec.rb +++ b/spec/tests/unit/baseline_hvac_planner_spec.rb @@ -8,6 +8,7 @@ require 'rexml/document' require 'BOSS/baseline_hvac_planner' +require 'BOSS/scenario_hvac_planner' require 'BOSS/boss_logger' require 'BOSS/buildingsync_reader/buildingsync_reader' @@ -129,4 +130,16 @@ def plan_for(results, systems, template = '90.1-2019') arguments: { standards_template: template }) end end + + it 'plans the baseline without proposed scenario HVACSystems' do + path = File.expand_path('../../files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml', __dir__) + doc = REXML::Document.new(File.read(path), ignore_whitespace_nodes: :all) + hvac_systems = REXML::XPath.first(doc, "//*[local-name()='HVACSystems']") + + expect(described_class.new.plan(hvac_systems, 'DOE Ref 1980-2004').status).to eq(:fallback) + plan = described_class.new.plan(hvac_systems, 'DOE Ref 1980-2004', + exclude_system_ids: BOSS::ScenarioHvacPlanner.proposed_system_ids(hvac_systems)) + expect(plan.status).to eq(:topology), plan.messages.join("\n") + expect(plan.steps.first[:arguments]).to include(topology_measure: 'hvac_packaged_rooftop_heat_pump', operation: 'create') + end end diff --git a/spec/tests/unit/scenario_hvac_planner_spec.rb b/spec/tests/unit/scenario_hvac_planner_spec.rb new file mode 100644 index 0000000..374aed0 --- /dev/null +++ b/spec/tests/unit/scenario_hvac_planner_spec.rb @@ -0,0 +1,126 @@ +# frozen_string_literal: true + +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'rexml/document' +require 'BOSS/scenario_hvac_planner' + +RSpec.describe BOSS::ScenarioHvacPlanner do + fixture = File.expand_path('../../files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml', __dir__) + template = 'DOE Ref 1980-2004' + sizing = { measure_dir_name: 'apply_standard_hvac_sizing_and_efficiency', arguments: { standards_template: template }, + workflow_phase: 'hvac_equipment' } + + let(:doc) { REXML::Document.new(File.read(fixture), ignore_whitespace_nodes: :all) } + let(:hvac_systems) { REXML::XPath.first(doc, "//*[local-name()='HVACSystems']") } + + def planner(doc, hvac_systems, template = 'DOE Ref 1980-2004') + described_class.new(hvac_systems, doc, template) + end + + def element(doc, id) + REXML::XPath.first(doc, "//*[@ID='#{id}']") + end + + it 'lists proposed HVACSystems named by measures' do + expect(described_class.proposed_system_ids(hvac_systems)) + .to contain_exactly('HVACSystem-proposed-RTU', 'HVACSystem-proposed-COP') + end + + it 'replaces HVAC with the alternative system topology' do + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-RTU', measure_name: 'Replace package units') + + expect(result.status).to eq(:mapped), result.messages.join("\n") + expect(result.steps.first).to eq( + measure_dir_name: 'apply_hvac_topology_to_zone_scope', workflow_phase: 'hvac_equipment', + arguments: { topology_measure: 'hvac_packaged_rooftop_ac', operation: 'replace', zone_scope: 'all_model_zones', + standards_template: template } + ) + expect(result.steps.last).to eq(sizing) + end + + it 'uses the configured retrofit template' do + result = planner(doc, hvac_systems, '90.1-2019').plan(measure_id: 'Measure-HVAC-RTU') + + expect(result.steps.map { |step| step[:arguments][:standards_template] }).to all(eq('90.1-2019')) + end + + it 'rejects an unsupported retrofit template' do + result = planner(doc, hvac_systems, 'DEER 2017').plan(measure_id: 'Measure-HVAC-RTU') + + expect(result.status).to eq(:unmapped) + expect(result.messages.join).to match(/DEER 2017/) + end + + it 'rejects partial replacement of existing HVAC' do + other = element(doc, 'HVACSystem-1').deep_clone + other.attributes['ID'] = 'HVACSystem-2' + hvac_systems.add_element(other) + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-RTU') + + expect(result.status).to eq(:unmapped) + expect(result.messages.join).to match(/HVACSystem-2 in place; partial HVAC replacement/) + end + + it 'rejects an alternative system that serves only part of the building' do + premises = REXML::XPath.first(element(doc, 'HVACSystem-proposed-RTU'), "*[local-name()='LinkedPremises']") + premises.elements.delete_all('*') + premises.add_element('ThermalZone').add_element('LinkedThermalZoneID', 'IDref' => 'TZ-1') + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-RTU') + + expect(result.status).to eq(:unmapped) + expect(result.messages.join).to match(/ThermalZone TZ-1.*only whole-building premises/) + end + + it 'maps ModifiedSystem COPs to efficiency modifier steps' do + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-COP') + + expect(result.status).to eq(:mapped), result.messages.join("\n") + expect(result.steps.map { |step| step[:arguments][:modifier_arguments_json] }).to eq( + ['{"efficiency_metric":"dx_cooling_cop","efficiency_value":3.5}', + '{"efficiency_metric":"dx_heating_cop","efficiency_value":3.8}'] + ) + expect(result.steps).to all(include(measure_dir_name: 'apply_hvac_modifier_to_object_scope', + workflow_phase: 'hvac_modifiers')) + expect(result.steps.first[:arguments]).to include(modifier_measure: 'modify_existing_hvac_equipment_efficiencies', + object_scope: 'all_matching_objects') + end + + it 'does not convert non-COP efficiency units' do + units = REXML::XPath.first(element(doc, 'CoolingSource-proposed-COP'), "*[local-name()='AnnualCoolingEfficiencyUnits']") + units.text = 'EER' + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-COP') + + expect(result.status).to eq(:unmapped) + expect(result.messages.join).to match(/units 'EER' are not COP/) + end + + it 'replaces HVAC with VRF from the MeasureName' do + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-VRF', + measure_name: 'Install variable refrigerant flow system') + + expect(result.status).to eq(:mapped), result.messages.join("\n") + expect(result.steps.first[:arguments]).to include(topology_measure: 'hvac_vrf', operation: 'replace') + expect(result.steps.last).to eq(sizing) + end + + it 'needs whole-building premises for a MeasureName topology' do + REXML::XPath.first(element(doc, 'Measure-HVAC-VRF'), "*[local-name()='LinkedPremises']").remove + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-VRF', + measure_name: 'Install variable refrigerant flow system') + + expect(result.status).to eq(:unmapped) + expect(result.messages.join).to match(/links no premises/) + end + + it 'leaves other measures to the JSON map' do + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-LEDs', + measure_name: 'Retrofit with light emitting diode technologies') + + expect(result.status).to eq(:not_hvac) + end +end diff --git a/spec/tests/unit/scenario_measure_map_spec.rb b/spec/tests/unit/scenario_measure_map_spec.rb index 85ea441..e6fdd37 100644 --- a/spec/tests/unit/scenario_measure_map_spec.rb +++ b/spec/tests/unit/scenario_measure_map_spec.rb @@ -85,7 +85,7 @@ it 'assigns each step a declared workflow phase' do expect(scenario_measure_map.fetch('workflow_phases')).to eq [ - 'envelope', 'internal_loads', 'hvac_equipment', 'controls_operations' + 'envelope', 'internal_loads', 'hvac_equipment', 'hvac_modifiers', 'controls_operations' ] phases = mappings.to_h do |mapping| diff --git a/spec/tests/unit/scenario_measure_mapper_spec.rb b/spec/tests/unit/scenario_measure_mapper_spec.rb index 86e758c..b2ebbcc 100644 --- a/spec/tests/unit/scenario_measure_mapper_spec.rb +++ b/spec/tests/unit/scenario_measure_mapper_spec.rb @@ -11,6 +11,7 @@ require 'BOSS/constants' require 'BOSS/buildingsync_reader/buildingsync_reader' require 'BOSS/scenario_measure_mapper' +require 'BOSS/scenario_hvac_planner' RSpec.describe 'ScenarioMeasureMapper' do def mapper_fixture_path(*parts) @@ -575,6 +576,27 @@ def package_scenario(measure_ids) end end + it 'use the HVAC planner before the JSON map' do + reader = fixture_reader('example-smalloffice-level2-hvac-retrofits.xml') + doc = REXML::Document.new(File.read(mapper_fixture_path('v2.7.0', 'example-smalloffice-level2-hvac-retrofits.xml')), + ignore_whitespace_nodes: :all) + hvac_planner = BOSS::ScenarioHvacPlanner.new(REXML::XPath.first(doc, "//*[local-name()='HVACSystems']"), doc, + 'DOE Ref 1980-2004') + scenarios = reader.get_package_measure_scenarios.to_h { |scenario| [scenario[:scenario_id], scenario] } + map = ->(id) { mapper.map_package_scenario(scenarios.fetch(id), reader.get_measures, hvac_planner:) } + + expect(map.call('Scenario-POM-HVAC-RTU')[:steps].map { |step| step[:measure_dir_name] }) + .to eq ['apply_hvac_topology_to_zone_scope', 'apply_standard_hvac_sizing_and_efficiency'] + expect(map.call('Scenario-POM-HVAC-mixed')[:steps].map { |step| step[:workflow_phase] }) + .to eq ['hvac_modifiers', 'hvac_modifiers', 'internal_loads'] + expect(mapper.map_package_scenario(scenarios.fetch('Scenario-POM-HVAC-RTU'), reader.get_measures)[:status]).to eq :skipped + + hvac_planner = BOSS::ScenarioHvacPlanner.new(REXML::XPath.first(doc, "//*[local-name()='HVACSystems']"), doc, 'DEER 2017') + result = mapper.map_package_scenario(scenarios.fetch('Scenario-POM-HVAC-RTU'), reader.get_measures, hvac_planner:) + expect(result[:status]).to eq :skipped + expect(result[:warnings].first).to include(code: :hvac_measure_unmapped, message: /DEER 2017/) + end + it 'raise ArgumentError for invalid inputs' do expect { mapper.map_package_scenario(package_scenario([]), measures, context: 'x') }.to raise_error(ArgumentError, /context/) expect { mapper.map_package_scenario(nil, measures) }.to raise_error(ArgumentError, /scenario must be a Hash/) @@ -658,7 +680,7 @@ def package_scenario(measure_ids) end it 'expose the shipped workflow phases in order' do - expect(mapper.workflow_phases).to eq ['envelope', 'internal_loads', 'hvac_equipment', 'controls_operations'] + expect(mapper.workflow_phases).to eq ['envelope', 'internal_loads', 'hvac_equipment', 'hvac_modifiers', 'controls_operations'] end it 'allow legacy maps without workflow phases' do From 9190006dbb7bf82d978b9b3462f9ec01ce337b91 Mon Sep 17 00:00:00 2001 From: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:25:04 -0700 Subject: [PATCH 2/7] Update write_and_run_osws_spec.rb --- spec/tests/integration/write_and_run_osws_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/tests/integration/write_and_run_osws_spec.rb b/spec/tests/integration/write_and_run_osws_spec.rb index 71a9a0a..fc89965 100644 --- a/spec/tests/integration/write_and_run_osws_spec.rb +++ b/spec/tests/integration/write_and_run_osws_spec.rb @@ -89,7 +89,7 @@ it 'write and run HVAC retrofit scenarios. File: example-smalloffice-level2-hvac-retrofits.xml' do xml_path = File.join(SPEC_FILES_DIR, 'v2.7.0', 'example-smalloffice-level2-hvac-retrofits.xml') - output_path = File.join(SPEC_OUTPUT_DIR, 'v2.7.0', 'hvac_retrofits') + output_path = File.join(SPEC_OUTPUT_DIR, 'v2.7.0', 'example-smalloffice-level2-hvac-retrofits') result = BOSS::Boss.write_baseline_and_scenario_osws(xml_path, output_path, nil, ASHRAE90_1) by_id = result[:scenario_results].to_h { |scenario| [scenario[:scenario_id], scenario] } From 8a02072058fb27eda663925abf87b0b8b575fc1a Mon Sep 17 00:00:00 2001 From: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:25:41 -0700 Subject: [PATCH 3/7] Squashed commit of the following: commit adda0955aa3028fa62ea8d950da63547823e8a6a Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Tue Nov 17 14:22:50 2026 -0700 restore Gemfile.lock from local change commit ef669f7f6d03ba79eb9f592d04034fb97dcdcc2d Merge: 6553159 8001036 Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Tue Nov 17 14:16:25 2026 -0700 Merge remote-tracking branch 'origin/scenario-workflow' into scenario-workflow-14d-baseline-hvac-integration commit 80010365b0a57d4bb257711fde68dd6016e7874e Merge: ab353fb f7c5ec0 Author: Jie Xiong Date: Tue Nov 17 12:26:37 2026 -0700 Merge pull request #28 from BuildingSync/scenario-workflow-14c-model-target-(zone)-binding Scenario workflow: 14C. model target (zone) binding commit f7c5ec009af86c3f0dc8f448ed8fbb6be7dee975 Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Fri Nov 13 11:28:03 2026 -0700 update binder for gas backup commit be0f3c63133209645a557acd3f49e9dffc13fe43 Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Thu Nov 12 23:38:36 2026 -0700 add binder for modifier measures commit 67e7d4f7d0a39ab7b134db6f248357150df7a2f2 Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Thu Nov 12 16:53:58 2026 -0700 update target binder to accept target zones commit abc7c64755fd8dab9897aea21a5166333984b891 Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Thu Nov 12 15:01:11 2026 -0700 add target binder work with the companion added measure in bs-measure-gem commit ab353fbcbf27c3c2b22b10966696ab2d12c9a125 Merge: 6fb5114 9f96a54 Author: Jie Xiong Date: Tue Nov 17 12:24:59 2026 -0700 Merge pull request #26 from BuildingSync/scenario-workflow-14b-hvac-selection-contract Scenario workflow: 14B. HVAC selection contract commit 9f96a54aa3d2515316f351582a7d54f91e143afb Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Fri Nov 13 02:12:01 2026 -0700 relax condenser rule commit f233a0e24df10844b0875bbffe91e155b0234b10 Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Fri Nov 13 01:54:34 2026 -0700 update selector rules to from updated measures-gem commit 11f34ee4f474c76517d09a13705e261a3a97889f Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Thu Nov 12 22:30:07 2026 -0700 add gap doc commit df85fe56a1776bb3df5458d4c8db3a17772f4934 Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Thu Nov 12 14:25:27 2026 -0700 add hvac topology selector commit 6fb511425c444a27faa026ce9eb716f0815909a2 Merge: f04575e bf0514e Author: Jie Xiong Date: Tue Nov 17 12:06:25 2026 -0700 Merge pull request #25 from BuildingSync/scenario-workflow-14a-local-measure-source-support Scenario workflow: 14A. local measure source support --- Gemfile.lock | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index f55db6f..9f58992 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,7 @@ GEM uuid (~> 2.3.9) yamler (= 0.1.0) zliby (= 0.0.5) + bigdecimal (4.1.2) builder (3.2.4) coderay (1.1.3) csv (3.3.5) @@ -63,6 +64,7 @@ GEM csv mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) + json (2.19.9) json-schema (4.3.1) addressable (>= 2.8) macaddr (1.7.2) @@ -78,6 +80,7 @@ GEM minitest (>= 5.0) ruby-progressbar multi_xml (0.9.1) + bigdecimal (>= 3.1, < 5) multipart-post (2.4.0) octokit (4.18.0) faraday (>= 0.9) @@ -144,6 +147,7 @@ GEM rspec-support (~> 3.13.0) rspec-support (3.13.7) rubocop (1.50.0) + json (~> 2.3) parallel (~> 1.10) parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) @@ -186,7 +190,6 @@ PLATFORMS arm64-darwin-24 ruby x64-mingw-ucrt - x64-mingw32 DEPENDENCIES BOSS! From ed3dbddc3c90faf2cbf9c38bfd98e9bc70670701 Mon Sep 17 00:00:00 2001 From: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:14:51 -0700 Subject: [PATCH 4/7] add scenario planner and test --- docs/scenario_workflow_translation_plan.md | 9 +- lib/BOSS/baseline_hvac_planner.rb | 40 +- lib/BOSS/boss.rb | 18 +- lib/BOSS/scenario_hvac_planner.rb | 260 ++ lib/BOSS/scenario_measure_map.json | 1 + lib/BOSS/scenario_measure_mapper.rb | 16 +- ...mple-smalloffice-level2-hvac-retrofits.xml | 2905 +++++++++++++++++ .../integration/write_and_run_osws_spec.rb | 26 + spec/tests/unit/baseline_hvac_planner_spec.rb | 13 + spec/tests/unit/scenario_hvac_planner_spec.rb | 126 + spec/tests/unit/scenario_measure_map_spec.rb | 2 +- .../unit/scenario_measure_mapper_spec.rb | 24 +- 12 files changed, 3416 insertions(+), 24 deletions(-) create mode 100644 lib/BOSS/scenario_hvac_planner.rb create mode 100644 spec/files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml create mode 100644 spec/tests/unit/scenario_hvac_planner_spec.rb diff --git a/docs/scenario_workflow_translation_plan.md b/docs/scenario_workflow_translation_plan.md index 8a24232..cd03bf7 100644 --- a/docs/scenario_workflow_translation_plan.md +++ b/docs/scenario_workflow_translation_plan.md @@ -328,12 +328,19 @@ Use this roadmap as the tracker. Keep `Status` and `Delivered by` current when a ### PR 14E: Scenario HVAC Mappings -- Status: Planned +- Status: In progress (series close pending) - Delivered by: - - Depends on: PR 14D. - Scope: Map HVAC retrofit measures onto the steps `HvacTargetBinder` already produces (`bind` for topology `replace`, `bind_modifier` for `modify_existing_*`) through the PR 9 result contract. No new binding work belongs here. Order conditioning, then DOAS/ventilation, then modifiers. Keep existing economizer, DCV, and thermostat mappings from other gems. - Done when: One topology replacement and one modifier case run end to end, partial shared-system replacement is rejected, and mixed-source packages still write and run. - Avoid: Mapping "Replace boiler" or "Replace burner" to an efficiency edit, guessing values, or partial HVAC graphs. +- Decision: `BOSS::ScenarioHvacPlanner` (`lib/BOSS/scenario_hvac_planner.rb`) runs before the JSON map in `ScenarioMeasureMapper.map_measure`. It returns `:mapped` (its steps replace the JSON lookup), `:unmapped` (`hvac_measure_unmapped` warning; the scenario is skipped), or `:not_hvac` (fall through to the JSON map). It tries, in order: + - Replacement: the measure's `TechnologyCategories` reference `ExistingSystemReplaced` and `AlternativeSystemReplacement` HVACSystem IDrefs. `BaselineHvacPlanner#plan` reruns on the alternative systems with `operation: 'replace'` for conditioning (ventilation stays `create`). Every baseline HVACSystem must be in `ExistingSystemReplaced`; otherwise the measure is unmapped as a partial replacement. + - Modification: `ExistingSystemAffected` plus a `ModifiedSystem` HVACSystem. Efficiencies come from the modified system and bind through `bind_modifier` into the new `hvac_modifiers` phase (after `hvac_equipment`). DX cooling COP, heat pump heating COP, furnace `Thermal Efficiency`, and electric resistance map; other units (EER, SEER, AFUE, HSPF, kW/ton) are unmapped with no unit conversion. + - Named topology: with no IDrefs, only `Install variable refrigerant flow system` maps (VRF replace on the measure's premises, then sizing). This deviates from the 14B MeasureName rule with user approval; GSHP stays a mapping gap. +- Decision: proposed systems (`AlternativeSystemReplacement`/`ModifiedSystem` IDrefs) are excluded from baseline HVAC planning. `write_baseline_and_scenario_osws` accepts `hvac_retrofit_template:` (one of `HvacTargetBinder::STANDARDS_TEMPLATES`), defaulting to the baseline template. +- Fixture: `spec/files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml` adds proposed RTU and COP systems and scenarios `Scenario-POM-HVAC-RTU` (replacement), `-COP` (modifier), `-VRF` (named), and `-mixed` (COP modifier plus LEDs). `write_and_run_osws_spec.rb` writes and runs them. +- Limitations: a modifier and a replacement in the same package can target equipment the replacement removed, and `apply_hvac_modifier_to_object_scope` fails when nothing matches; such packages are not guarded yet. The named VRF replacement adds no DOAS. - Series close: merge the `buildingsync-measures-gem` branch upstream (`apply_hvac_topology_to_zone_scope`, `apply_standard_hvac_sizing_and_efficiency`, and any 14E measures), replace the CI branch-commit pin with the merged commit, and rerun the unit and integration suites. ### PR 15: CLI Command diff --git a/lib/BOSS/baseline_hvac_planner.rb b/lib/BOSS/baseline_hvac_planner.rb index 371ef55..c0b0421 100644 --- a/lib/BOSS/baseline_hvac_planner.rb +++ b/lib/BOSS/baseline_hvac_planner.rb @@ -35,8 +35,11 @@ def initialize(selector: HvacTopologySelector.new, binder: HvacTargetBinder.new) # @param hvac_systems [REXML::Element, nil] the facility HVACSystems element # @param standards_template [String] baseline create_typical template + # @param operation [String] binder operation for the conditioning step; ventilation is always created + # @param include_system_ids [Array, nil] when given, only these HVACSystems are planned + # @param exclude_system_ids [Array] HVACSystems left out, such as proposed scenario systems # @return [Plan] :topology with ordered OSW steps, or :fallback with the reasons - def plan(hvac_systems, standards_template) + def plan(hvac_systems, standards_template, operation: 'create', include_system_ids: nil, exclude_system_ids: []) return fallback(['No HVACSystems in the facility.']) if hvac_systems.nil? if !HvacTargetBinder::STANDARDS_TEMPLATES.include?(standards_template) @@ -44,7 +47,10 @@ def plan(hvac_systems, standards_template) "(#{HvacTargetBinder::STANDARDS_TEMPLATES.join(', ')})."]) end - results = @selector.select(hvac_systems) + results = @selector.select(hvac_systems).select do |result| + (include_system_ids.nil? || include_system_ids.include?(result.hvac_system_id)) && + !exclude_system_ids.include?(result.hvac_system_id) + end return fallback(['No HVACSystem records.']) if results.empty? unmatched = results.reject { |result| result.status == :match } @@ -65,9 +71,8 @@ def plan(hvac_systems, standards_template) end return fallback(problems) if !problems.empty? - bindings = (conditioning + ventilation).map do |result| - [result, @binder.bind(result, operation: 'create', standards_template:)] - end + bindings = conditioning.map { |result| [result, @binder.bind(result, operation:, standards_template:)] } + + ventilation.map { |result| [result, @binder.bind(result, operation: 'create', standards_template:)] } unbound = bindings.reject { |_, binding| binding.status == :bound } return fallback(unbound.map { |result, binding| describe(result, binding.status, binding.messages) }) if !unbound.empty? @@ -75,23 +80,19 @@ def plan(hvac_systems, standards_template) Plan.new(status: :topology, steps: bindings.map { |_, binding| binding.step } + [sizing_step], messages: []) end - private - - def merge(members, hvac_systems) - merged = members.first.dup - merged.premises = members.flat_map { |member| member.premises || [] }.uniq - building_id = covered_building_id(merged.premises, hvac_systems) - merged.premises = [{ type: 'Building', id: building_id }] if building_id - merged + # @return [Array] premises, or one Building premise when Section links cover the building + def self.normalize_premises(premises, document) + building_id = covered_building_id(premises, document) + building_id ? [{ type: 'Building', id: building_id }] : premises end # @return [String, nil] the building ID when every premise is a Section of the one # building and they include its 'Whole building' section or all of its other # non-empty sections - def covered_building_id(premises, hvac_systems) + def self.covered_building_id(premises, document) return nil if premises.empty? || !premises.all? { |premise| premise[:type] == 'Section' } - buildings = REXML::XPath.match(hvac_systems.document, "//*[local-name()='Building'][@ID]") + buildings = REXML::XPath.match(document, "//*[local-name()='Building'][@ID]") return nil if buildings.length != 1 sections = REXML::XPath.match(buildings.first, "*[local-name()='Sections']/*[local-name()='Section'][@ID]") @@ -109,6 +110,15 @@ def covered_building_id(premises, hvac_systems) whole_linked || parts_linked ? buildings.first.attributes['ID'] : nil end + private + + def merge(members, hvac_systems) + merged = members.first.dup + merged.premises = self.class.normalize_premises(members.flat_map { |member| member.premises || [] }.uniq, + hvac_systems.document) + merged + end + def fallback(messages) Plan.new(status: :fallback, steps: [], messages:) end diff --git a/lib/BOSS/boss.rb b/lib/BOSS/boss.rb index e0cbec0..2256ed8 100644 --- a/lib/BOSS/boss.rb +++ b/lib/BOSS/boss.rb @@ -12,6 +12,7 @@ require 'BOSS/external_measure_repo_manager' require 'BOSS/scenario_measure_mapper' require 'BOSS/baseline_hvac_planner' +require 'BOSS/scenario_hvac_planner' require 'openstudio/common_measures' require 'openstudio/model_articulation' @@ -59,7 +60,14 @@ def write_baseline_osw(xml_file_path, output_dir, epw_file_path, standard_to_be_ # @return [Hash] { baseline_osw_path:, scenario_results: [ { scenario_id:, scenario_name:, # report_id:, package_id:, status: :written | :skipped, osw_path:, skipped_measure_ids:, # warnings: } ], parser_warnings: } - def write_baseline_and_scenario_osws(xml_file_path, output_dir, epw_file_path, standard_to_be_used) + # @param hvac_retrofit_template [String, nil] standards template for scenario HVAC retrofits; + # defaults to the baseline template + def write_baseline_and_scenario_osws(xml_file_path, output_dir, epw_file_path, standard_to_be_used, + hvac_retrofit_template: nil) + if !hvac_retrofit_template.nil? && !HvacTargetBinder::STANDARDS_TEMPLATES.include?(hvac_retrofit_template) + raise ArgumentError, "hvac_retrofit_template must be one of #{HvacTargetBinder::STANDARDS_TEMPLATES.join(', ')}" + end + if !File.exist?(xml_file_path) message = "File '#{xml_file_path}' does not exist" OpenStudio.logFree(OpenStudio::Error, 'BOSS.write_baseline_and_scenario_osws', message) @@ -93,6 +101,8 @@ def write_baseline_and_scenario_osws(xml_file_path, output_dir, epw_file_path, s measures = bsync_reader.get_measures scenarios = bsync_reader.get_package_measure_scenarios id_warnings = scenario_output_id_warnings(scenarios) + hvac_planner = ScenarioHvacPlanner.new(bsync_reader.get_hvac_systems_xml, bsync_doc, + hvac_retrofit_template || bsync_reader.get_standard_template) scenario_results = [] scenario_osws = [] @@ -107,7 +117,7 @@ def write_baseline_and_scenario_osws(xml_file_path, output_dir, epw_file_path, s next end - mapped = mapper.map_package_scenario(scenario, measures, context:) + mapped = mapper.map_package_scenario(scenario, measures, context:, hvac_planner:) result = mapped.slice(:scenario_id, :scenario_name, :report_id, :package_id) .merge(status: :skipped, osw_path: nil, skipped_measure_ids: mapped[:skipped_measure_ids], warnings: mapped[:warnings]) @@ -202,7 +212,9 @@ def build_baseline_osw(bsync_reader) OSWArgPopulator::populate_change_building_location_args(baseline_osw, bsync_reader) OSWArgPopulator::populate_create_bar_from_building_type_ratios_args(baseline_osw, bsync_reader) - hvac_plan = BaselineHvacPlanner.new.plan(bsync_reader.get_hvac_systems_xml, bsync_reader.get_standard_template) + hvac_systems = bsync_reader.get_hvac_systems_xml + hvac_plan = BaselineHvacPlanner.new.plan(hvac_systems, bsync_reader.get_standard_template, + exclude_system_ids: ScenarioHvacPlanner.proposed_system_ids(hvac_systems)) OSWArgPopulator::populate_create_typical_building_from_model_args(baseline_osw, bsync_reader, add_hvac: !hvac_plan.topology?) if hvac_plan.topology? diff --git a/lib/BOSS/scenario_hvac_planner.rb b/lib/BOSS/scenario_hvac_planner.rb new file mode 100644 index 0000000..05ce3e4 --- /dev/null +++ b/lib/BOSS/scenario_hvac_planner.rb @@ -0,0 +1,260 @@ +# frozen_string_literal: true + +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'rexml/document' +require 'BOSS/baseline_hvac_planner' +require 'BOSS/hvac_topology_selector' +require 'BOSS/hvac_target_binder' + +module BOSS + # Plans split HVAC measure steps for one BuildingSync scenario measure. + # + # - Replacement with AlternativeSystemReplacement HVACSystems: the alternative systems go + # through the topology selector and bind with operation 'replace'. The replaced systems + # must be every existing HVACSystem, because generated zones cannot be split. + # - ModificationRetrocommissioning with ModifiedSystem HVACSystems: source efficiencies + # stated as COP or Thermal Efficiency become modify_existing_hvac_equipment_efficiencies steps. + # - Otherwise, a MeasureName in NAMED_TOPOLOGIES names exactly one topology and replaces + # whole-building HVAC. + # + # Measures that match none of these are :not_hvac and fall through to the JSON map. + class ScenarioHvacPlanner + PHASE = 'hvac_equipment' + MODIFIER_PHASE = 'hvac_modifiers' + EFFICIENCY_MODIFIER = 'modify_existing_hvac_equipment_efficiencies' + # MeasureName => [configuration, topology measure]. Only names that identify one topology. + NAMED_TOPOLOGIES = { + 'Install variable refrigerant flow system' => ['VRF Terminal Unit', 'hvac_vrf'] + }.freeze + + Result = Struct.new(:status, :steps, :messages, keyword_init: true) + + # @return [Array] HVACSystem IDs that measures name as alternatives or modified systems + def self.proposed_system_ids(hvac_systems) + return [] if hvac_systems.nil? + + system_ids = _system_ids(hvac_systems) + refs = REXML::XPath.match( + hvac_systems.document, + "//*[local-name()='Measure']/*[local-name()='TypeOfMeasure']//" \ + "*[local-name()='AlternativeSystemReplacement' or local-name()='ModifiedSystem']/@IDref" + ).map(&:value) + refs.uniq & system_ids + end + + def self._system_ids(hvac_systems) + REXML::XPath.match(hvac_systems, "*[local-name()='HVACSystem']/@ID").map(&:value) + end + + # @param hvac_systems [REXML::Element, nil] the facility HVACSystems element + # @param document [REXML::Document] the BuildingSync document + # @param standards_template [String] template for retrofit HVAC + def initialize(hvac_systems, document, standards_template, planner: BaselineHvacPlanner.new, binder: HvacTargetBinder.new) + @hvac_systems = hvac_systems + @document = document + @standards_template = standards_template + @planner = planner + @binder = binder + @system_ids = hvac_systems.nil? ? [] : self.class._system_ids(hvac_systems) + @proposed_ids = self.class.proposed_system_ids(hvac_systems) + end + + # @param measure [Hash] symbol-keyed measure hash from BuildingSyncReader#get_measures + # @return [Result] :mapped with OSW steps, :unmapped with reasons, or :not_hvac + def plan(measure) + measure_xml = REXML::XPath.first(@document, "//*[local-name()='Measure'][@ID=$id]", nil, + { 'id' => measure[:measure_id].to_s }) + return not_hvac if measure_xml.nil? + + alternatives = refs(measure_xml, 'Replacements', 'Replacement', 'AlternativeSystemReplacement') + modified = refs(measure_xml, 'ModificationRetrocommissions', 'ModificationRetrocommissioning', 'ModifiedSystem') + return plan_replacement(measure_xml, alternatives) if !alternatives.empty? + return plan_modification(measure_xml, modified) if !modified.empty? + return plan_named_replacement(measure_xml, measure[:measure_name]) if NAMED_TOPOLOGIES.key?(measure[:measure_name]) + + not_hvac + end + + private + + # HVACSystem IDs referenced by TypeOfMeasure//@IDref. + def refs(measure_xml, *names) + path = (['TypeOfMeasure'] + names).map { |name| "*[local-name()='#{name}']" }.join('/') + REXML::XPath.match(measure_xml, "#{path}/@IDref").map(&:value).uniq & @system_ids + end + + def plan_replacement(measure_xml, alternatives) + return unmapped([template_message]) if template_message + + replaced = refs(measure_xml, 'Replacements', 'Replacement', 'ExistingSystemReplaced') + existing = @system_ids - @proposed_ids + if replaced.empty? + return unmapped(['Replacement names no ExistingSystemReplaced HVACSystem.']) + end + + if !(existing - replaced).empty? + return unmapped(["Replacement leaves #{(existing - replaced).join(', ')} in place; " \ + 'partial HVAC replacement is not supported.']) + end + + hvac_plan = @planner.plan(@hvac_systems, @standards_template, operation: 'replace', include_system_ids: alternatives) + return unmapped(hvac_plan.messages) if !hvac_plan.topology? + + mapped(hvac_plan.steps) + end + + def plan_named_replacement(measure_xml, measure_name) + return unmapped([template_message]) if template_message + + configuration, topology = NAMED_TOPOLOGIES.fetch(measure_name) + result = HvacTopologySelector::Result.new( + status: :match, configuration:, measure: topology, hvac_system_id: nil, record_ids: [], + premises: BaselineHvacPlanner.normalize_premises(linked_premises(measure_xml), @document), + group_key: nil, messages: [], measure_arguments: {} + ) + binding = @binder.bind(result, operation: 'replace', standards_template: @standards_template) + return unmapped(binding.messages) if binding.status != :bound + + mapped([binding.step, sizing_step]) + end + + def plan_modification(measure_xml, modified) + affected = refs(measure_xml, 'ModificationRetrocommissions', 'ModificationRetrocommissioning', 'ExistingSystemAffected') + return unmapped(['ModificationRetrocommissioning names no ExistingSystemAffected HVACSystem.']) if affected.empty? + + settings = {} + problems = [] + premises = [] + modified.each do |system_id| + system = REXML::XPath.first(@hvac_systems, "*[local-name()='HVACSystem'][@ID=$id]", nil, { 'id' => system_id }) + premises.concat(linked_premises(system)) + source_efficiencies(system).each do |metric, value, problem| + next problems << "#{system_id}: #{problem}" if problem + + if settings.key?(metric) && settings[metric] != value + problems << "#{system_id}: conflicting #{metric} values #{settings[metric]} and #{value}." + end + settings[metric] ||= value + end + end + return unmapped(problems) if !problems.empty? + return unmapped(['ModifiedSystem states no COP or Thermal Efficiency source values.']) if settings.empty? + + premises = BaselineHvacPlanner.normalize_premises(premises.uniq, @document) + bindings = settings.map do |metric, value| + @binder.bind_modifier(modifier_measure: EFFICIENCY_MODIFIER, + modifier_arguments: { efficiency_metric: metric, efficiency_value: value }, premises:) + end + unbound = bindings.reject { |binding| binding.status == :bound } + return unmapped(unbound.flat_map(&:messages).uniq) if !unbound.empty? + + Result.new(status: :mapped, steps: bindings.map { |binding| binding.step.merge(workflow_phase: MODIFIER_PHASE) }, + messages: []) + end + + # @return [Array] [metric, value, nil] or [nil, nil, problem] per source with an efficiency value + def source_efficiencies(system) + cooling = sources(system, 'CoolingSources/CoolingSource', 'AnnualCoolingEfficiency').map do |source, value, units| + dx = node(source, 'CoolingSourceType/DX') + next [nil, nil, "#{id(source)} is not DX; only DX cooling COP is supported."] if dx.nil? + + metric = text(dx, 'DXSystemType') == 'Variable refrigerant flow' ? 'vrf_cooling_cop' : 'dx_cooling_cop' + cop(source, metric, value, units) + end + heating = sources(system, 'HeatingSources/HeatingSource', 'AnnualHeatingEfficiency').map do |source, value, units| + heating_efficiency(source, value, units) + end + cooling + heating + end + + def heating_efficiency(source, value, units) + type = node(source, 'HeatingSourceType') + if node(type, 'HeatPump') + cooling_id = REXML::XPath.first(type, "*[local-name()='HeatPump']/*[local-name()='CoolingSourceID']/@IDref")&.value + cooling = cooling_id && REXML::XPath.first(@hvac_systems, "//*[local-name()='CoolingSource'][@ID=$id]", nil, + { 'id' => cooling_id }) + vrf = cooling && text(node(cooling, 'CoolingSourceType/DX'), 'DXSystemType') == 'Variable refrigerant flow' + return cop(source, vrf ? 'vrf_heating_cop' : 'dx_heating_cop', value, units) + end + if node(type, 'Furnace') && text(source, 'PrimaryFuel') == 'Natural gas' + return fraction(source, 'gas_burner_efficiency', value, units) + end + return fraction(source, 'electric_heating_efficiency', value, units) if node(type, 'ElectricResistance') + + [nil, nil, "#{id(source)} heating type is not supported for efficiency changes."] + end + + def cop(source, metric, value, units) + return [nil, nil, "#{id(source)} efficiency units '#{units}' are not COP."] if units != 'COP' + return [nil, nil, "#{id(source)} COP must be positive."] if value <= 0 + + [metric, value, nil] + end + + def fraction(source, metric, value, units) + return [nil, nil, "#{id(source)} efficiency units '#{units}' are not Thermal Efficiency."] if units != 'Thermal Efficiency' + return [nil, nil, "#{id(source)} Thermal Efficiency must be in (0, 1]."] if value <= 0 || value > 1 + + [metric, value, nil] + end + + # [source, value, units] for sources that state an efficiency value. + def sources(system, path, prefix) + parent, child = path.split('/') + REXML::XPath.match(system, "*[local-name()='HeatingAndCoolingSystems']/*[local-name()='#{parent}']/" \ + "*[local-name()='#{child}']").filter_map do |source| + raw = text(source, "#{prefix}Value") + next if raw.nil? || raw.strip.empty? + + value = Float(raw, exception: false) + next [source, -1.0, text(source, "#{prefix}Units")] if value.nil? + + [source, value, text(source, "#{prefix}Units")] + end + end + + def linked_premises(xml) + REXML::XPath.match(xml, "*[local-name()='LinkedPremises']/*").flat_map do |premise_type| + premise_type.elements.to_a.filter_map do |link| + link.attributes['IDref'] && { type: premise_type.name, id: link.attributes['IDref'] } + end + end + end + + def node(xml, path) + return nil if xml.nil? + + REXML::XPath.first(xml, path.split('/').map { |name| "*[local-name()='#{name}']" }.join('/')) + end + + def text(xml, path) = node(xml, path)&.text&.strip + def id(xml) = xml.attributes['ID'] || xml.name + + def template_message + return nil if HvacTargetBinder::STANDARDS_TEMPLATES.include?(@standards_template) + + "Template '#{@standards_template}' is not supported by the split HVAC measures." + end + + def sizing_step + { measure_dir_name: BaselineHvacPlanner::SIZING_MEASURE, arguments: { standards_template: @standards_template } } + end + + def mapped(steps) + Result.new(status: :mapped, steps: steps.map { |step| step.merge(workflow_phase: PHASE) }, messages: []) + end + + def unmapped(messages) + Result.new(status: :unmapped, steps: [], messages:) + end + + def not_hvac + Result.new(status: :not_hvac, steps: [], messages: []) + end + end +end diff --git a/lib/BOSS/scenario_measure_map.json b/lib/BOSS/scenario_measure_map.json index 487d784..e95cf95 100644 --- a/lib/BOSS/scenario_measure_map.json +++ b/lib/BOSS/scenario_measure_map.json @@ -4,6 +4,7 @@ "envelope", "internal_loads", "hvac_equipment", + "hvac_modifiers", "controls_operations" ], "lookup_order": [ diff --git a/lib/BOSS/scenario_measure_mapper.rb b/lib/BOSS/scenario_measure_mapper.rb index fbe1c27..dfae723 100644 --- a/lib/BOSS/scenario_measure_mapper.rb +++ b/lib/BOSS/scenario_measure_mapper.rb @@ -37,11 +37,20 @@ def initialize(map_path = SCENARIO_MEASURE_MAP_PATH) # @param measure [Hash] symbol-keyed measure hash from the reader # @param context [Hash, nil] { building_type:, hvac_system_type: } used by conditional_arguments + # @param hvac_planner [ScenarioHvacPlanner, nil] tried before the JSON map; :not_hvac falls through # @return [Hash] { measure_id:, steps: [ { measure_dir_name:, arguments: {} } ], warnings: [] } - def map_measure(measure, context: {}) + def map_measure(measure, context: {}, hvac_planner: nil) context ||= {} raise ArgumentError, 'context must be a Hash' if !context.is_a?(Hash) + hvac = hvac_planner&.plan(measure) + if hvac&.status == :mapped + return { measure_id: measure[:measure_id], steps: hvac.steps, warnings: [] } + elsif hvac&.status == :unmapped + return _unmapped_result(measure, :hvac_measure_unmapped, + "HVAC measure cannot be mapped: #{hvac.messages.join(' ')}") + end + technology_category_key = _lookup_key(measure[:technology_category_element_name], measure[:measure_name]) system_category_key = _lookup_key(measure[:system_category_affected], measure[:measure_name]) @@ -84,9 +93,10 @@ def map_measure(measure, context: {}) # @param scenario [Hash] one record from BuildingSyncReader#get_package_measure_scenarios # @param measures [Hash] BuildingSyncReader#get_measures, keyed by measure ID # @param context [Hash, nil] forwarded to #map_measure + # @param hvac_planner [ScenarioHvacPlanner, nil] forwarded to #map_measure # @return [Hash] { scenario_id:, scenario_name:, report_id:, package_id:, # status: :writable | :skipped, steps: [], skipped_measure_ids: [], warnings: [] } - def map_package_scenario(scenario, measures, context: {}) + def map_package_scenario(scenario, measures, context: {}, hvac_planner: nil) context ||= {} raise ArgumentError, 'scenario must be a Hash' if !scenario.is_a?(Hash) raise ArgumentError, 'measures must be a Hash' if !measures.is_a?(Hash) @@ -116,7 +126,7 @@ def map_package_scenario(scenario, measures, context: {}) next end - result = map_measure(measure, context:) + result = map_measure(measure, context:, hvac_planner:) steps.concat(result[:steps]) skipped_measure_ids << measure_idref if result[:steps].empty? warnings.concat(result[:warnings].map { |warning| warning.merge(scenario_context) }) diff --git a/spec/files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml b/spec/files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml new file mode 100644 index 0000000..784f379 --- /dev/null +++ b/spec/files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml @@ -0,0 +1,2905 @@ + + + + + + + + + Prototype Small Office in Denver + Here we record general problems / issues identified in a walkthrough survey. + + + City Custom Building ID + some ID + + + Custom ID 1 + some other ID + + +
+ + + Some address + + + Denver + CO + 80014 +
+ -104.830000 + 39.660000 + Commercial + Office + + 1 + 0 + 1 + 0 + true + false + + + Gross + 5500.000000 + + + + + + Conditioned + 5500.000000 + + + + + + 6500.000000 + 0.000000 + 0.213300 + 0.050000 + 2000 + 2000 + 2010 + 2020-03-01 + 2000 + +
+ Space function + Office + Office + + + Peak total occupants + 31.000000 + + + + + 40.000000 + Hours per week + + + 50.000000 + Weeks per year + + + + + Gross + 5500.000000 + + + Conditioned + 5500.000000 + + + Single zone +
+
+ Whole building + Rectangular + + + A1 + + + 909.012230 + + + + + 180.187860 + + + + + 42.086890 + + + + + B1 + + + 606.008200 + + + + + 120.125240 + + + + + 0.000000 + + + + + C1 + + + 909.012230 + + + + + 180.187860 + + + + + 0.000000 + + + + + D1 + + + 606.008200 + + + + + 120.125240 + + + + + 0.000000 + + + + + + + + 6444.999000 + Good + + + + + + + 3891.153600 + + + +
+
+ + + + + + + + + + Single zone + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 10311.100000 + 10311.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9801.300000 + 9801.300000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 7858.100000 + 7858.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9067.800000 + 9067.800000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9855.400000 + 9855.400000 + W + Good + + + + + + + + + + 2000 + + + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 10198.900000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9847.200000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 7737.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9143.800000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9847.200000 + W + Good + + + + + + + + + + 2000 + + + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + + Digital + + +
+ + + + + +
+
+
+ + + Single zone + + + + + Warm air + + + Natural gas + Air + + + + + + + Packaged/unitary direct expansion/RTU + + + Electricity + + + + + + + Central fan + CAV terminal box no reheat + None + + + + + + + + +
+ +
+
+
+ + + + + + + Packaged Unitary + + + + 3.800000 + COP + + + + + + + Packaged/unitary heat pump + + + 3.500000 + COP + + + + + + + + + +
+ + + + + T8 + + + Standard Electronic + + 0.200000 + + 100.000000 + 5.500000 + 32.000000 + 4 + 1.000000 + 43 + false + + + + + + + Programmable + + + + false + +
+ + + + + +
+
+
+ + + + T12 + + + Standard Electronic + 100.000000 + 1.582575 + 316.516000 + 1 + 1.000000 + 5 + true + + + + + + + Programmable + + + + false + +
+ + + + + +
+
+
+ + + + LED + + + Standard Electronic + + 0.100000 + + 100.000000 + 2.752000 + 16.000000 + 4 + 1.000000 + 43 + false + + + + + + + Photocell + Continuous + + + + false + +
+ + + + + +
+
+
+
+ + + + + + + + 40.000000 + 123.000000 + + + Notes + + 1 + 3.600000 + Continuous + 123.000000 + 1.870180 + + Looped + Thermal Efficiency + 1.000000 + 40.000000 + 140.000000 + 1950.520000 + 11722.840000 + W + + + + + + + + + + 2000 + Electricity + Good + + + + +
+ +
+
+ 1 +
+
+ + + 0.536000 + 880.000000 + 880.000000 + Constant Volume + + + + + + 0.536000 + 872.000000 + 872.000000 + Variable Volume + + + + + + 0.536000 + 836.000000 + 836.000000 + Constant Volume + + + + + + 0.536000 + 830.000000 + 830.000000 + Variable Volume + + + + + + 0.536000 + 671.000000 + 671.000000 + Constant Volume + + + + + + 0.536000 + 664.000000 + 664.000000 + Variable Volume + + + + + + 0.536000 + 774.000000 + 774.000000 + Constant Volume + + + + + + 0.536000 + 766.000000 + 766.000000 + Variable Volume + + + + + + 0.536000 + 841.000000 + 841.000000 + Constant Volume + + + + + + 0.536000 + 833.000000 + 833.000000 + Variable Volume + + + + + + + + Wood frame + 0.547000 + + + + + Wood frame + 4.706000 + + + + + + + + Vinyl + Clear uncoated + Single pane + 3.241000 + 0.391000 + 0.391000 + + + + + + Vinyl + Low e + Triple pane + 0.300000 + 0.391000 + 0.391000 + + + + + Insulated metal + 0.500000 + + + Steel + 2.839000 + + + + + + + + 0.345000 + + + + Concrete poured + + + + + Miscellaneous Electric Load + 0.630000 + +
+ + + + + +
+
+
+
+ + + Notes on test + Tight + 0.151000 + ACHnatural + Blower door + +
+ +
+
+
+
+ + + Notes on test + +
+ +
+
+
+
+
+ + + + + Weekday + Occupied + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + Occupied + 06:00:00 + 07:00:00 + 11.000000 + + + Weekday + Occupied + 07:00:00 + 08:00:00 + 21.000000 + + + Weekday + Occupied + 08:00:00 + 12:00:00 + 100.000000 + + + Weekday + Occupied + 12:00:00 + 13:00:00 + 53.000000 + + + Weekday + Occupied + 13:00:00 + 17:00:00 + 100.000000 + + + Weekday + Occupied + 17:00:00 + 18:00:00 + 32.000000 + + + Weekday + Occupied + 18:00:00 + 22:00:00 + 11.000000 + + + Weekday + Occupied + 22:00:00 + 23:00:00 + 5.000000 + + + Weekday + Occupied + 23:00:00 + 23:59:59 + 0.000000 + + + Weekend + Occupied + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + Occupied + 00:00:00 + 23:59:59 + 0.000000 + + + + + + +
+ +
+
+
+ + + + Weekday + Lighting + 00:00:00 + 05:00:00 + 18.000000 + + + Weekday + Lighting + 05:00:00 + 07:00:00 + 23.000000 + + + Weekday + Lighting + 07:00:00 + 08:00:00 + 42.000000 + + + Weekday + Lighting + 08:00:00 + 12:00:00 + 90.000000 + + + Weekday + Lighting + 12:00:00 + 13:00:00 + 80.000000 + + + Weekday + Lighting + 13:00:00 + 17:00:00 + 90.000000 + + + Weekday + Lighting + 17:00:00 + 18:00:00 + 61.000000 + + + Weekday + Lighting + 18:00:00 + 20:00:00 + 42.000000 + + + Weekday + Lighting + 20:00:00 + 22:00:00 + 32.000000 + + + Weekday + Lighting + 22:00:00 + 23:00:00 + 23.000000 + + + Weekday + Lighting + 23:00:00 + 23:59:59 + 18.000000 + + + Weekend + Lighting + 00:00:00 + 23:59:59 + 18.000000 + + + Holiday + Lighting + 00:00:00 + 23:59:59 + 18.000000 + + + + + + + + + + + + Weekday + Miscellaneous equipment + 00:00:00 + 08:00:00 + 50.000000 + + + Weekday + Miscellaneous equipment + 08:00:00 + 12:00:00 + 100.000000 + + + Weekday + Miscellaneous equipment + 12:00:00 + 13:00:00 + 94.000000 + + + Weekday + Miscellaneous equipment + 13:00:00 + 17:00:00 + 100.000000 + + + Weekday + Miscellaneous equipment + 17:00:00 + 18:00:00 + 50.000000 + + + Weekday + Miscellaneous equipment + 18:00:00 + 23:59:59 + 20.000000 + + + Weekend + Miscellaneous equipment + 00:00:00 + 23:59:59 + 20.000000 + + + Holiday + Miscellaneous equipment + 00:00:00 + 23:59:59 + 20.000000 + + + + + + + + + + + + Weekday + HVAC equipment + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + HVAC equipment + 06:00:00 + 19:00:00 + 100.000000 + + + Weekday + HVAC equipment + 19:00:00 + 23:59:59 + 0.000000 + + + Weekend + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + + + + + + + + + + Weekday + HVAC equipment + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + HVAC equipment + 06:00:00 + 07:00:00 + 60.000000 + + + Weekday + HVAC equipment + 07:00:00 + 12:00:00 + 100.000000 + + + Weekday + HVAC equipment + 12:00:00 + 13:00:00 + 80.000000 + + + Weekday + HVAC equipment + 13:00:00 + 18:00:00 + 100.000000 + + + Weekday + HVAC equipment + 18:00:00 + 20:00:00 + 60.000000 + + + Weekday + HVAC equipment + 20:00:00 + 23:59:59 + 0.000000 + + + Weekend + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + + + + + + +
+ + + + + + + + + + + Lighting + + + + Retrofit with light emitting diode technologies + + + + Individual system + This measure is designed to replace all fluorescent bulbs with LEDs + 1 + 50.000000 + 774.000000 + true + 2021-01-01 + 2021-12-30 + + + + + + + + + + + Fan + + + + Add VSD motor controller + + + + Individual system + This measure is designed to retrofit all RTU fans with a VSD + 1 + 750.000000 + 1250.000000 + true + 2021-01-01 + 2021-12-30 + + + + + + + + + + + Cooling System + + + + Replace package units + + + + + + + + + + + + + + Cooling System + + + + Replace package units + + + + + + Cooling System + + + + + + + + + Install variable refrigerant flow system + + + + + + + + + + + + + + + + + + + Electricity + This is required to document irregularities in monthly energy patterns (Std 211 6.1.2.1.j). No irregularities found. + kWh + All end uses + 67334.150000 + 229.753657 + + + + + + + + + + + + + + + kW + 26.040000 + 26.040000 + 4613.820000 + + + + + + Natural gas + No irregularities in monthly energy consumption found. + MMBtu + All end uses + 8.720000 + 8.720000 + + + + + + + + + + + + + + + 540.830000 + + + + + + Electricity + kWh + Interior lighting + 28.705000 + 20062.690000 + 68.453898 + + + + Electricity + kWh + Heating + 6.722000 + 4698.230000 + 16.030361 + + + + Electricity + kWh + Cooling + 8.769000 + 6128.870000 + 20.911704 + + + + Electricity + kWh + Domestic hot water + 10.281000 + 7185.370000 + 24.516482 + + + + Electricity + kWh + Plug load + 21.379000 + 14942.150000 + 50.982616 + + + + + + Total + Energy + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 5933.100000 + + + + Total + Energy + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 5446.100000 + + + + Total + Energy + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 5736.490000 + + + + Total + Energy + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 4980.500000 + + + + Total + Energy + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 5187.210000 + + + + Total + Energy + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 5842.950000 + + + + Total + Energy + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 5801.730000 + + + + Total + Energy + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 6220.160000 + + + + Total + Energy + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 5682.870000 + + + + Total + Energy + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 5571.930000 + + + + Total + Energy + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 5525.150000 + + + + Total + Energy + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 5405.940000 + + + + Total + Energy + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 1.720000 + + + + Total + Energy + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 1.250000 + + + + Total + Energy + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 0.410000 + + + + Total + Energy + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 0.430000 + + + + Total + Energy + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 0.010000 + + + + Total + Energy + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 0.000000 + + + + Total + Energy + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 0.000000 + + + + Total + Energy + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 0.000000 + + + + Total + Energy + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 0.000000 + + + + Total + Energy + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 0.200000 + + + + Total + Energy + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 0.400000 + + + + Total + Energy + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 4.300000 + + + + Peak + On-peak + Power + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 23.580000 + + + + Peak + On-peak + Power + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 25.380000 + + + + Peak + On-peak + Power + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 26.040000 + + + + Peak + On-peak + Power + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 24.450000 + + + + Peak + On-peak + Power + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 17.030000 + + + + Peak + On-peak + Power + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 22.710000 + + + + Peak + On-peak + Power + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 22.010000 + + + + Peak + On-peak + Power + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 21.810000 + + + + Peak + On-peak + Power + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 20.630000 + + + + Peak + On-peak + Power + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 21.870000 + + + + Peak + On-peak + Power + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 21.630000 + + + + Peak + On-peak + Power + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 21.780000 + + + + Load factor + Power + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 0.340000 + + + + Load factor + Power + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 0.320000 + + + + Load factor + Power + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 0.300000 + + + + Load factor + Power + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 0.280000 + + + + Load factor + Power + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 0.410000 + + + + Load factor + Power + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 0.360000 + + + + Load factor + Power + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 0.350000 + + + + Load factor + Power + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 0.380000 + + + + Load factor + Power + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 0.380000 + + + + Load factor + Power + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 0.340000 + + + + Load factor + Power + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 0.350000 + + + + Load factor + Power + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 0.330000 + + + + Cost + Cost + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 332.160000 + + + + Cost + Cost + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 306.290000 + + + + Cost + Cost + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 321.720000 + + + + Cost + Cost + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 281.540000 + + + + Cost + Cost + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 292.530000 + + + + Cost + Cost + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 534.100000 + + + + Cost + Cost + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 530.450000 + + + + Cost + Cost + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 567.490000 + + + + Cost + Cost + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 519.930000 + + + + Cost + Cost + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 312.970000 + + + + Cost + Cost + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 310.490000 + + + + Cost + Cost + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 304.150000 + + + + Cost + Cost + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 46.690000 + + + + Cost + Cost + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 45.930000 + + + + Cost + Cost + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 44.550000 + + + + Cost + Cost + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 44.580000 + + + + Cost + Cost + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 43.900000 + + + + Cost + Cost + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 44.210000 + + + + Cost + Cost + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 44.530000 + + + + Cost + Cost + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 50.920000 + + + + + + 238473.656550 + 43.358800 + 737088.900000 + 134.000000 + 238473.656550 + 43.358800 + 238.473657 + 0.000000 + 0.000000 + 0.000000 + 4952.480000 + 0.900000 + + + + + + + + + + + + + + 2022-06-01 + + + Portfolio Manager + 2019 + 80.000000 + + + + + 238473.656550 + 43.358800 + 4952.480000 + + + + + + + + + + + + + 39070.530000 + 995 + 89.000000 + + + + + 190348.600000 + 34.600000 + 4846.040000 + 0.881000 + + + + + + + + + + + + + + TMY3 + Finished + + + + + + + Electricity + kWh + All end uses + 67334.150000 + 229.753657 + kW + 26.040000 + 26.040000 + + + Natural gas + MMBtu + All end uses + 8.720000 + 8.720000 + + + + + + + + + + POM-LEDs + + + + + + + Capital + 35.713000 + 772 + + + Electricity + kWh + 11524.540000 + + + Natural gas + MMBtu + 0.000000 + + + 3.220000 + 0 + 0.000000 + 0.000000 + 1 + 824.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 1.070000 + 0.000000 + + + + + + + + + + POM-VSDs + + + + + + + Capital + 5.175000 + 9 + + + Electricity + kWh + 207.240000 + + + Natural gas + MMBtu + 4.460000 + + + 0.420000 + 0 + 0.000000 + 0.000000 + 1 + 2000.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 230.150000 + 0.000000 + + + + + + + + + + POM-LEDs-VSDs + + + + + + + + Capital + 41.827000 + 781 + + + Electricity + kWh + 11701.620000 + + + Natural gas + MMBtu + 1.890000 + + + 4.700000 + 0 + 0.000000 + 0.000000 + 1 + 2824.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 3.620000 + 0.000000 + + + + + + + + + + POM-HVAC-RTU + + + + + + + + + + + POM-HVAC-COP + + + + + + + + + + + POM-HVAC-VRF + + + + + + + + + + + POM-HVAC-mixed + + + + + + + + + + + + Level 2: Energy Survey and Analysis + + + + + + + + + --06-01 + --09-30 + --06-01 + --09-30 + 0.088520 + 0.000000 + + + --01-01 + --05-31 + --01-01 + --05-31 + 0.053140 + 0.000000 + + + --10-01 + --12-31 + --10-01 + --12-31 + 0.053140 + 0.000000 + + + + + https://www.xcelenergy.com/company/rates_and_regulations/rates/rate_books + 16.880000 + + + 12345 + Xcel Energy + + Some-meter-ID + + some-account-number + Building Owner + + + + + + + + + --01-01 + --12-31 + 0.163600 + + + + + https://www.xcelenergy.com/company/rates_and_regulations/rates/rate_books + 43.880000 + + + Xcel Energy + + Some-meter-ID + + some-other-account-number + Building Owner + + + + + + + + + + + + + + Owner + + The dude + Some big company + + + 123-456-7890 + + + + + the.dude@somebigco.net + + + + + + Energy Auditor + + The lady + Auditeers + + + 123-456-7890 + + + + + the.lady@the-three-auditeers.com + + + + + + + diff --git a/spec/tests/integration/write_and_run_osws_spec.rb b/spec/tests/integration/write_and_run_osws_spec.rb index 308a4e0..71a9a0a 100644 --- a/spec/tests/integration/write_and_run_osws_spec.rb +++ b/spec/tests/integration/write_and_run_osws_spec.rb @@ -86,5 +86,31 @@ expect(steps['apply_standard_hvac_sizing_and_efficiency'][:result][:step_result]).to eq 'Success' end end + + it 'write and run HVAC retrofit scenarios. File: example-smalloffice-level2-hvac-retrofits.xml' do + xml_path = File.join(SPEC_FILES_DIR, 'v2.7.0', 'example-smalloffice-level2-hvac-retrofits.xml') + output_path = File.join(SPEC_OUTPUT_DIR, 'v2.7.0', 'hvac_retrofits') + + result = BOSS::Boss.write_baseline_and_scenario_osws(xml_path, output_path, nil, ASHRAE90_1) + by_id = result[:scenario_results].to_h { |scenario| [scenario[:scenario_id], scenario] } + hvac_ids = ['Scenario-POM-HVAC-RTU', 'Scenario-POM-HVAC-COP', 'Scenario-POM-HVAC-VRF', 'Scenario-POM-HVAC-mixed'] + hvac_ids.each { |id| expect(by_id.fetch(id)[:status]).to eq(:written), by_id.fetch(id)[:warnings].inspect } + + failures = BOSS::Boss.run_baseline_and_scenario_osws(result) + expect(failures).to be_empty, failures.inspect + + out = ->(path) { JSON.parse(File.read(File.join(File.dirname(path), 'out.osw')), symbolize_names: true) } + expect(out.call(result[:baseline_osw_path])[:completed_status]).to eq 'Success' + hvac_ids.each do |id| + out_osw = out.call(by_id.fetch(id)[:osw_path]) + expect(out_osw[:completed_status]).to eq('Success'), id + end + + rtu = out.call(by_id.fetch('Scenario-POM-HVAC-RTU')[:osw_path])[:steps] + .select { |step| step[:measure_dir_name] == 'apply_hvac_topology_to_zone_scope' }.last + expect(rtu[:arguments]).to include(topology_measure: 'hvac_packaged_rooftop_ac', operation: 'replace') + mixed = out.call(by_id.fetch('Scenario-POM-HVAC-mixed')[:osw_path])[:steps].map { |step| step[:measure_dir_name] } + expect(mixed).to include('SetLightingLoadsByLPD', 'apply_hvac_modifier_to_object_scope') + end end end diff --git a/spec/tests/unit/baseline_hvac_planner_spec.rb b/spec/tests/unit/baseline_hvac_planner_spec.rb index 099dae0..79151cf 100644 --- a/spec/tests/unit/baseline_hvac_planner_spec.rb +++ b/spec/tests/unit/baseline_hvac_planner_spec.rb @@ -8,6 +8,7 @@ require 'rexml/document' require 'BOSS/baseline_hvac_planner' +require 'BOSS/scenario_hvac_planner' require 'BOSS/boss_logger' require 'BOSS/buildingsync_reader/buildingsync_reader' @@ -129,4 +130,16 @@ def plan_for(results, systems, template = '90.1-2019') arguments: { standards_template: template }) end end + + it 'plans the baseline without proposed scenario HVACSystems' do + path = File.expand_path('../../files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml', __dir__) + doc = REXML::Document.new(File.read(path), ignore_whitespace_nodes: :all) + hvac_systems = REXML::XPath.first(doc, "//*[local-name()='HVACSystems']") + + expect(described_class.new.plan(hvac_systems, 'DOE Ref 1980-2004').status).to eq(:fallback) + plan = described_class.new.plan(hvac_systems, 'DOE Ref 1980-2004', + exclude_system_ids: BOSS::ScenarioHvacPlanner.proposed_system_ids(hvac_systems)) + expect(plan.status).to eq(:topology), plan.messages.join("\n") + expect(plan.steps.first[:arguments]).to include(topology_measure: 'hvac_packaged_rooftop_heat_pump', operation: 'create') + end end diff --git a/spec/tests/unit/scenario_hvac_planner_spec.rb b/spec/tests/unit/scenario_hvac_planner_spec.rb new file mode 100644 index 0000000..374aed0 --- /dev/null +++ b/spec/tests/unit/scenario_hvac_planner_spec.rb @@ -0,0 +1,126 @@ +# frozen_string_literal: true + +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'rexml/document' +require 'BOSS/scenario_hvac_planner' + +RSpec.describe BOSS::ScenarioHvacPlanner do + fixture = File.expand_path('../../files/v2.7.0/example-smalloffice-level2-hvac-retrofits.xml', __dir__) + template = 'DOE Ref 1980-2004' + sizing = { measure_dir_name: 'apply_standard_hvac_sizing_and_efficiency', arguments: { standards_template: template }, + workflow_phase: 'hvac_equipment' } + + let(:doc) { REXML::Document.new(File.read(fixture), ignore_whitespace_nodes: :all) } + let(:hvac_systems) { REXML::XPath.first(doc, "//*[local-name()='HVACSystems']") } + + def planner(doc, hvac_systems, template = 'DOE Ref 1980-2004') + described_class.new(hvac_systems, doc, template) + end + + def element(doc, id) + REXML::XPath.first(doc, "//*[@ID='#{id}']") + end + + it 'lists proposed HVACSystems named by measures' do + expect(described_class.proposed_system_ids(hvac_systems)) + .to contain_exactly('HVACSystem-proposed-RTU', 'HVACSystem-proposed-COP') + end + + it 'replaces HVAC with the alternative system topology' do + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-RTU', measure_name: 'Replace package units') + + expect(result.status).to eq(:mapped), result.messages.join("\n") + expect(result.steps.first).to eq( + measure_dir_name: 'apply_hvac_topology_to_zone_scope', workflow_phase: 'hvac_equipment', + arguments: { topology_measure: 'hvac_packaged_rooftop_ac', operation: 'replace', zone_scope: 'all_model_zones', + standards_template: template } + ) + expect(result.steps.last).to eq(sizing) + end + + it 'uses the configured retrofit template' do + result = planner(doc, hvac_systems, '90.1-2019').plan(measure_id: 'Measure-HVAC-RTU') + + expect(result.steps.map { |step| step[:arguments][:standards_template] }).to all(eq('90.1-2019')) + end + + it 'rejects an unsupported retrofit template' do + result = planner(doc, hvac_systems, 'DEER 2017').plan(measure_id: 'Measure-HVAC-RTU') + + expect(result.status).to eq(:unmapped) + expect(result.messages.join).to match(/DEER 2017/) + end + + it 'rejects partial replacement of existing HVAC' do + other = element(doc, 'HVACSystem-1').deep_clone + other.attributes['ID'] = 'HVACSystem-2' + hvac_systems.add_element(other) + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-RTU') + + expect(result.status).to eq(:unmapped) + expect(result.messages.join).to match(/HVACSystem-2 in place; partial HVAC replacement/) + end + + it 'rejects an alternative system that serves only part of the building' do + premises = REXML::XPath.first(element(doc, 'HVACSystem-proposed-RTU'), "*[local-name()='LinkedPremises']") + premises.elements.delete_all('*') + premises.add_element('ThermalZone').add_element('LinkedThermalZoneID', 'IDref' => 'TZ-1') + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-RTU') + + expect(result.status).to eq(:unmapped) + expect(result.messages.join).to match(/ThermalZone TZ-1.*only whole-building premises/) + end + + it 'maps ModifiedSystem COPs to efficiency modifier steps' do + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-COP') + + expect(result.status).to eq(:mapped), result.messages.join("\n") + expect(result.steps.map { |step| step[:arguments][:modifier_arguments_json] }).to eq( + ['{"efficiency_metric":"dx_cooling_cop","efficiency_value":3.5}', + '{"efficiency_metric":"dx_heating_cop","efficiency_value":3.8}'] + ) + expect(result.steps).to all(include(measure_dir_name: 'apply_hvac_modifier_to_object_scope', + workflow_phase: 'hvac_modifiers')) + expect(result.steps.first[:arguments]).to include(modifier_measure: 'modify_existing_hvac_equipment_efficiencies', + object_scope: 'all_matching_objects') + end + + it 'does not convert non-COP efficiency units' do + units = REXML::XPath.first(element(doc, 'CoolingSource-proposed-COP'), "*[local-name()='AnnualCoolingEfficiencyUnits']") + units.text = 'EER' + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-COP') + + expect(result.status).to eq(:unmapped) + expect(result.messages.join).to match(/units 'EER' are not COP/) + end + + it 'replaces HVAC with VRF from the MeasureName' do + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-VRF', + measure_name: 'Install variable refrigerant flow system') + + expect(result.status).to eq(:mapped), result.messages.join("\n") + expect(result.steps.first[:arguments]).to include(topology_measure: 'hvac_vrf', operation: 'replace') + expect(result.steps.last).to eq(sizing) + end + + it 'needs whole-building premises for a MeasureName topology' do + REXML::XPath.first(element(doc, 'Measure-HVAC-VRF'), "*[local-name()='LinkedPremises']").remove + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-HVAC-VRF', + measure_name: 'Install variable refrigerant flow system') + + expect(result.status).to eq(:unmapped) + expect(result.messages.join).to match(/links no premises/) + end + + it 'leaves other measures to the JSON map' do + result = planner(doc, hvac_systems).plan(measure_id: 'Measure-LEDs', + measure_name: 'Retrofit with light emitting diode technologies') + + expect(result.status).to eq(:not_hvac) + end +end diff --git a/spec/tests/unit/scenario_measure_map_spec.rb b/spec/tests/unit/scenario_measure_map_spec.rb index 85ea441..e6fdd37 100644 --- a/spec/tests/unit/scenario_measure_map_spec.rb +++ b/spec/tests/unit/scenario_measure_map_spec.rb @@ -85,7 +85,7 @@ it 'assigns each step a declared workflow phase' do expect(scenario_measure_map.fetch('workflow_phases')).to eq [ - 'envelope', 'internal_loads', 'hvac_equipment', 'controls_operations' + 'envelope', 'internal_loads', 'hvac_equipment', 'hvac_modifiers', 'controls_operations' ] phases = mappings.to_h do |mapping| diff --git a/spec/tests/unit/scenario_measure_mapper_spec.rb b/spec/tests/unit/scenario_measure_mapper_spec.rb index 86e758c..b2ebbcc 100644 --- a/spec/tests/unit/scenario_measure_mapper_spec.rb +++ b/spec/tests/unit/scenario_measure_mapper_spec.rb @@ -11,6 +11,7 @@ require 'BOSS/constants' require 'BOSS/buildingsync_reader/buildingsync_reader' require 'BOSS/scenario_measure_mapper' +require 'BOSS/scenario_hvac_planner' RSpec.describe 'ScenarioMeasureMapper' do def mapper_fixture_path(*parts) @@ -575,6 +576,27 @@ def package_scenario(measure_ids) end end + it 'use the HVAC planner before the JSON map' do + reader = fixture_reader('example-smalloffice-level2-hvac-retrofits.xml') + doc = REXML::Document.new(File.read(mapper_fixture_path('v2.7.0', 'example-smalloffice-level2-hvac-retrofits.xml')), + ignore_whitespace_nodes: :all) + hvac_planner = BOSS::ScenarioHvacPlanner.new(REXML::XPath.first(doc, "//*[local-name()='HVACSystems']"), doc, + 'DOE Ref 1980-2004') + scenarios = reader.get_package_measure_scenarios.to_h { |scenario| [scenario[:scenario_id], scenario] } + map = ->(id) { mapper.map_package_scenario(scenarios.fetch(id), reader.get_measures, hvac_planner:) } + + expect(map.call('Scenario-POM-HVAC-RTU')[:steps].map { |step| step[:measure_dir_name] }) + .to eq ['apply_hvac_topology_to_zone_scope', 'apply_standard_hvac_sizing_and_efficiency'] + expect(map.call('Scenario-POM-HVAC-mixed')[:steps].map { |step| step[:workflow_phase] }) + .to eq ['hvac_modifiers', 'hvac_modifiers', 'internal_loads'] + expect(mapper.map_package_scenario(scenarios.fetch('Scenario-POM-HVAC-RTU'), reader.get_measures)[:status]).to eq :skipped + + hvac_planner = BOSS::ScenarioHvacPlanner.new(REXML::XPath.first(doc, "//*[local-name()='HVACSystems']"), doc, 'DEER 2017') + result = mapper.map_package_scenario(scenarios.fetch('Scenario-POM-HVAC-RTU'), reader.get_measures, hvac_planner:) + expect(result[:status]).to eq :skipped + expect(result[:warnings].first).to include(code: :hvac_measure_unmapped, message: /DEER 2017/) + end + it 'raise ArgumentError for invalid inputs' do expect { mapper.map_package_scenario(package_scenario([]), measures, context: 'x') }.to raise_error(ArgumentError, /context/) expect { mapper.map_package_scenario(nil, measures) }.to raise_error(ArgumentError, /scenario must be a Hash/) @@ -658,7 +680,7 @@ def package_scenario(measure_ids) end it 'expose the shipped workflow phases in order' do - expect(mapper.workflow_phases).to eq ['envelope', 'internal_loads', 'hvac_equipment', 'controls_operations'] + expect(mapper.workflow_phases).to eq ['envelope', 'internal_loads', 'hvac_equipment', 'hvac_modifiers', 'controls_operations'] end it 'allow legacy maps without workflow phases' do From 69018de960d05ede0a750f4891f95a0715be641c Mon Sep 17 00:00:00 2001 From: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:25:04 -0700 Subject: [PATCH 5/7] Update write_and_run_osws_spec.rb --- spec/tests/integration/write_and_run_osws_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/tests/integration/write_and_run_osws_spec.rb b/spec/tests/integration/write_and_run_osws_spec.rb index 71a9a0a..fc89965 100644 --- a/spec/tests/integration/write_and_run_osws_spec.rb +++ b/spec/tests/integration/write_and_run_osws_spec.rb @@ -89,7 +89,7 @@ it 'write and run HVAC retrofit scenarios. File: example-smalloffice-level2-hvac-retrofits.xml' do xml_path = File.join(SPEC_FILES_DIR, 'v2.7.0', 'example-smalloffice-level2-hvac-retrofits.xml') - output_path = File.join(SPEC_OUTPUT_DIR, 'v2.7.0', 'hvac_retrofits') + output_path = File.join(SPEC_OUTPUT_DIR, 'v2.7.0', 'example-smalloffice-level2-hvac-retrofits') result = BOSS::Boss.write_baseline_and_scenario_osws(xml_path, output_path, nil, ASHRAE90_1) by_id = result[:scenario_results].to_h { |scenario| [scenario[:scenario_id], scenario] } From 95fcd7d609cd9221447b16bcbe9f341fc5aba906 Mon Sep 17 00:00:00 2001 From: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:41:55 -0700 Subject: [PATCH 6/7] Squashed commit of the following: commit b45ec370153af9e11b80ed140e6f12214b5265b7 Merge: 0496378 e0bb39b Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Tue Nov 17 17:39:18 2026 -0700 Merge branch 'develop' into scenario-workflow commit e0bb39b7d48cf3bccdd1b637e8d76fd5005f6224 Merge: 1929a26 65bb0a9 Author: Jie Xiong Date: Tue Nov 17 17:30:42 2026 -0700 Merge pull request #32 from BuildingSync/speed-up-ci Speed up CI commit 65bb0a9940b2511104b4cafc5b8406fbc49ef9bb Author: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Tue Nov 17 14:01:59 2026 -0700 split jobs into unit and integration, split integration into 4 shards doc-only PRs skip integration skip-integration label skips integration commit 1929a263badfb662bcfaedd93578682391657270 Merge: 871317d 711e45f Author: Katherine Fleming <2205659+kflemin@users.noreply.github.com> Date: Thu Nov 12 10:43:31 2026 -0700 Merge pull request #22 from BuildingSync/fix/floor-area-building-first Fix/floor area building first commit 711e45f12b949d1d64efdd621f10a9d48bd7ef44 Author: Katherine Fleming <2205659+kflemin@users.noreply.github.com> Date: Wed Nov 11 12:29:18 2026 -0700 fix test commit bcf2317df8055734cc5ea2b07c6311d85bea46ed Author: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Date: Tue Nov 10 22:21:50 2026 +0000 Handle missing Building in floor area fallback Co-authored-by: kflemin <2205659+kflemin@users.noreply.github.com> commit 35abcbf617b63bcf90f7eca222d2cfe2d9e58bc9 Author: Katherine Fleming <2205659+kflemin@users.noreply.github.com> Date: Tue Nov 10 12:57:19 2026 -0700 Require logger and constants in BuildingSyncReader The reader calls BOSS.BOSS_logger and uses ASHRAE90_1 and other constants, but relied on other files to load them. Running buildingsync_reader_spec.rb on its own failed with "undefined method `BOSS_logger' for BOSS:Module". Require both directly. Co-Authored-By: Claude Opus 5.5 commit 43fc2da0720970218c52cdaadb4ef0130f386eb0 Author: Katherine Fleming <2205659+kflemin@users.noreply.github.com> Date: Tue Nov 10 12:53:24 2026 -0700 Prefer Building floor area over Site get_total_floor_area checked Site FloorAreas before Building, so a Site value overrode the Building's own value. Check the more specific Building first and fall back to Site, matching the method comment. Add specs for Building only, Site only, and both present. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 93 ++++++++++++++++++- README.md | 30 +++++- .../buildingsync_reader.rb | 17 ++-- .../integration/write_and_run_osws_spec.rb | 13 +++ spec/tests/unit/buildingsync_reader_spec.rb | 49 ++++++++++ 5 files changed, 189 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a799b4..bc67b53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,17 +2,26 @@ name: Continuous Integration on: pull_request: + types: [opened, synchronize, reopened, labeled, unlabeled] push: branches: - "develop" tags: - '*' + schedule: + - cron: '0 7 * * *' + workflow_dispatch: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true jobs: - tests: - name: Tests + unit: + name: unit container: nrel/openstudio:3.10.0 runs-on: ubuntu-latest + timeout-minutes: 20 env: LANG: C.UTF-8 LC_ALL: C.UTF-8 @@ -37,6 +46,82 @@ jobs: gem install bundler -v 2.4.10 bundle config set --local path "$GITHUB_WORKSPACE/.bundle/install" bundle install + - name: Run Unit Tests + run: bundle exec rspec spec/tests/unit --profile 10 + + changes: + name: detect changes + runs-on: ubuntu-latest + outputs: + code: ${{ steps.diff.outputs.code }} + steps: + - name: Checkout Code + if: github.event_name == 'pull_request' + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check for non-documentation changes + id: diff + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + if [ "${{ github.event_name }}" != "pull_request" ]; then + echo "code=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + # Documentation-only paths; anything else counts as a code change. + code_files=$(git diff --name-only "$BASE_SHA"..."$HEAD_SHA" \ + | grep -Ev '(\.md$|^docs/|^LICENSE)' || true) + if [ -n "$code_files" ]; then + echo "code=true" >> "$GITHUB_OUTPUT" + else + echo "code=false" >> "$GITHUB_OUTPUT" + fi + + integration: + name: integration (shard ${{ matrix.shard }}) + needs: changes + if: >- + needs.changes.outputs.code == 'true' && + !contains(github.event.pull_request.labels.*.name, 'skip-integration') + container: nrel/openstudio:3.10.0 + runs-on: ubuntu-latest + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + shard: [0, 1, 2, 3] + env: + LANG: C.UTF-8 + LC_ALL: C.UTF-8 + BOSS_SHARD: ${{ matrix.shard }} + BOSS_SHARDS: '4' + steps: + - name: Checkout Code + uses: actions/checkout@v4 + - name: Cache gems + uses: actions/cache@v4 + with: + path: .bundle/install + key: gems-${{ runner.os }}-os3.10.0-${{ hashFiles('Gemfile.lock', '*.gemspec') }} + - name: Cache external measures + uses: actions/cache@v4 + with: + path: vendor/external_measures + key: ext-measures-${{ hashFiles('config/external_measure_repos.yml') }} + - name: Setup + run: | + git config --global --add safe.directory '*' + gem install bundler -v 2.4.10 + bundle config set --local path "$GITHUB_WORKSPACE/.bundle/install" + bundle install bundle exec rake measures:install_external - - name: Run Tests - run: bundle exec rspec + - name: Run Integration Tests + run: bundle exec rspec spec/tests/integration --profile 10 + - name: Upload output on failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: integration-output-shard-${{ matrix.shard }} + path: spec/output diff --git a/README.md b/README.md index 2c3d74c..b598c6f 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ The table below maps in detail the BuildingSync XML data to measure inputs. Note | | climate_zone | get_climate_zone | either `.../Site/ClimateZoneType/ASHRAE/ClimateZone` or `.../Site/ClimateZoneType/CaliforniaTitle24/ClimateZone` depending on standard | | [create_bar_from_building_type_ratios] | | | | | | bldg_type_a | get_building_type_and_bar_division_method | `.../Building/OccupancyClassification` + requirements for `get_total_floor_area` (+ requirements for `get_floor_above_grade` lest defaulted to 1 + requirements for `get_floor_below_grade` lest defaulted to 0) | -| | total_bldg_floor_area | get_total_floor_area | at least one entry of `/FloorArea` in either `.../Site/FloorAreas/` or `.../Building/FloorAreas/`, with `FloorAreaType` of "Gross", "Conditioned", "Common", "Heated and Cooled", "Heated Only", "Cooled Only", "Conditioned above grade", or "Conditioned below grade" | +| | total_bldg_floor_area | get_total_floor_area | at least one entry of `/FloorArea` in either `.../Building/FloorAreas/` or `.../Site/FloorAreas/` (Building is used when both have one), with `FloorAreaType` of "Gross", "Conditioned", "Common", "Heated and Cooled", "Heated Only", "Cooled Only", "Conditioned above grade", or "Conditioned below grade" | | | floor_height | get_floor_to_floor_height | at least on entry of `.../Building/Sections/Section` with entry `/FloorToFloorHeight` | | | num_stories_above_grade | get_floor_above_grade | either `.../Building/FloorsAboveGrade` or `.../Building/ConditionedFloorsAboveGrade` and `.../Building/UnconditionedFloorsAboveGrade` | | | num_stories_below_grade | get_floor_below_grade | either `.../Building/FloorsBelowGrade` or `.../Building/ConditionedFloorsBelowGrade` and `.../Building/UnconditionedFloorsBelowGrade` | @@ -175,8 +175,34 @@ bundle exec boss write_baseline_osw "spec/files/v2.7.0/L100_Audit-1.0.0.xml" -o ## Tests -To run the tests you can use the Rake task: +Integration tests need the external measures installed first: + +```bash +bundle exec rake measures:install_external +``` + +Run the full suite (unit + all integration simulations): ```bash bundle exec rake ``` + +Run only the fast unit tests: + +```bash +bundle exec rspec spec/tests/unit +``` + +Run the integration smoke subset (2 simulations): + +```bash +BOSS_SMOKE=1 bundle exec rspec spec/tests/integration +``` + +Run one shard of the full integration suite (here shard 0 of 4, as in CI): + +```bash +BOSS_SHARD=0 BOSS_SHARDS=4 bundle exec rspec spec/tests/integration +``` + +In CI, unit tests run on every pull request. The full integration suite (4 parallel shards) also runs on every pull request, except documentation-only changes (`*.md`, `docs/`, `LICENSE`) or pull requests labeled `skip-integration`. It always runs on pushes to `develop`, tags, nightly, and on manual dispatch. diff --git a/lib/BOSS/buildingsync_reader/buildingsync_reader.rb b/lib/BOSS/buildingsync_reader/buildingsync_reader.rb index 9ddb68d..167eda7 100644 --- a/lib/BOSS/buildingsync_reader/buildingsync_reader.rb +++ b/lib/BOSS/buildingsync_reader/buildingsync_reader.rb @@ -6,6 +6,8 @@ require 'json' require 'openstudio-standards' +require 'BOSS/boss_logger' +require 'BOSS/constants' require_relative 'systems_map' require_relative 'bcl_weather_file_downloader' include Math @@ -218,7 +220,15 @@ def get_building_type_and_bar_division_method # tries to get total floor area from: # 1. /FloorAreas of building # 2. /FloorAreas of site + # The building is more specific than the site, so its value wins when both are present. def get_total_floor_area(num_indent=2) + # check building floor area + BOSS.BOSS_logger.info("#{"|\t"*num_indent}- checking building for total floor area...") + building_floor_areas_xml = @building_xml.nil? ? nil : @building_xml.elements["#{@ns}FloorAreas"] + building_area = !building_floor_areas_xml.nil? ? _get_total_floor_area_from_floor_areas_xml(building_floor_areas_xml, num_indent+1) : 0 + BOSS.BOSS_logger.info("#{"|\t"*num_indent} building floor area is #{building_area}") + return building_area if building_area > 0 + # check site floor area BOSS.BOSS_logger.info("#{"|\t"*num_indent}- checking site for total floor area...") site_floor_areas_xml = @site_xml.elements["#{@ns}FloorAreas"] @@ -226,13 +236,6 @@ def get_total_floor_area(num_indent=2) BOSS.BOSS_logger.info("#{"|\t"*num_indent} site floor area is #{site_area}") return site_area if site_area > 0 - # check building floor area - BOSS.BOSS_logger.info("#{"|\t"*num_indent}- checking building for total floor area...") - building_floor_areas_xml = @building_xml.elements["#{@ns}FloorAreas"] - building_area = !building_floor_areas_xml.nil? ? _get_total_floor_area_from_floor_areas_xml(building_floor_areas_xml, num_indent+1) : 0 - BOSS.BOSS_logger.info("#{"|\t"*num_indent} building floor area is #{building_area}") - return building_area if building_area > 0 - # TODO: read sections end diff --git a/spec/tests/integration/write_and_run_osws_spec.rb b/spec/tests/integration/write_and_run_osws_spec.rb index fc89965..1a19216 100644 --- a/spec/tests/integration/write_and_run_osws_spec.rb +++ b/spec/tests/integration/write_and_run_osws_spec.rb @@ -34,6 +34,19 @@ ['Reference-PrimarySchool-L100-Audit.xml', ASHRAE90_1, nil, 'v2.7.0'], ] +# BOSS_SMOKE=1 runs a small representative subset (used on pull requests). +SMOKE_FILES = ['building_151.xml', 'example-smalloffice-level1.xml'].freeze +test_configs = test_configs.select { |config| SMOKE_FILES.include?(config[0]) } if ENV['BOSS_SMOKE'] == '1' + +# BOSS_SHARD / BOSS_SHARDS split the fixtures across parallel CI jobs. +if ENV['BOSS_SHARDS'] + shards = Integer(ENV['BOSS_SHARDS']) + shard = Integer(ENV.fetch('BOSS_SHARD', '0')) + raise ArgumentError, "BOSS_SHARD must be in 0...#{shards}" if shards < 1 || shard.negative? || shard >= shards + + test_configs = test_configs.select.with_index { |_config, index| index % shards == shard } +end + RSpec.describe 'BOSS' do describe 'boss should' do before do diff --git a/spec/tests/unit/buildingsync_reader_spec.rb b/spec/tests/unit/buildingsync_reader_spec.rb index 220e055..a51ff7e 100644 --- a/spec/tests/unit/buildingsync_reader_spec.rb +++ b/spec/tests/unit/buildingsync_reader_spec.rb @@ -695,6 +695,55 @@ def wrap_in_systems(xml) end describe 'get_total_floor_area should' do + def floor_areas(gross) + <<~XML + + + Gross + #{gross} + + + XML + end + + def site_with_building(site_xml, building_xml) + wrap_in_site(<<~XML) + #{site_xml} + + + #{building_xml} + + + XML + end + + it "prefer building over site when both have floor area" do + doc = REXML::Document.new site_with_building(floor_areas(20000), floor_areas(15000)) + buidingsync_reader = BOSS::BuildingSyncReader.new(doc, nil, ASHRAE90_1) + + expect(buidingsync_reader.get_total_floor_area).to eq 15000 + end + + it "get from building" do + doc = REXML::Document.new site_with_building('', floor_areas(15000)) + buidingsync_reader = BOSS::BuildingSyncReader.new(doc, nil, ASHRAE90_1) + + expect(buidingsync_reader.get_total_floor_area).to eq 15000 + end + + it "fall back to site when building has no floor area" do + doc = REXML::Document.new site_with_building(floor_areas(20000), '') + buidingsync_reader = BOSS::BuildingSyncReader.new(doc, nil, ASHRAE90_1) + + expect(buidingsync_reader.get_total_floor_area).to eq 20000 + end + + it "get from site when building is missing" do + doc = REXML::Document.new wrap_in_site(floor_areas(20000)) + buidingsync_reader = BOSS::BuildingSyncReader.new(doc, nil, ASHRAE90_1) + + expect(buidingsync_reader.get_total_floor_area).to eq 20000 + end end describe 'get_floor_above_grade should' do From d15fff0bb13ae9acfa8991541fdbfcf6661de006 Mon Sep 17 00:00:00 2001 From: JieXiong9119 <69597597+JieXiong9119@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:57:30 -0700 Subject: [PATCH 7/7] update ci for buildingsync-measures-gem ref, move the topology and HVAC-retrofit examples run into shard 0 --- .github/workflows/ci.yml | 32 +++++++++++++++---- .../integration/write_and_run_osws_spec.rb | 5 +++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc67b53..bbf00d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,10 @@ concurrency: group: ci-${{ github.ref }} cancel-in-progress: true +env: + # Pinned commit of the sibling checkout that config/external_measure_repos.yml loads via local_path. + BSYNC_MEASURES_REF: 789bd50ec0ba42559f85e5cac23fcbbf8f9bdfbe + jobs: unit: name: unit @@ -38,11 +42,16 @@ jobs: uses: actions/checkout@v4 with: repository: BuildingSync/buildingsync-measures-gem - ref: 789bd50ec0ba42559f85e5cac23fcbbf8f9bdfbe + ref: ${{ env.BSYNC_MEASURES_REF }} path: buildingsync-measures-gem + - name: Cache gems + uses: actions/cache@v4 + with: + path: .bundle/install + key: gems-${{ runner.os }}-os3.10.0-${{ hashFiles('BOSS/Gemfile.lock', 'BOSS/*.gemspec') }} - name: Setup run: | - git config --global --add safe.directory "$GITHUB_WORKSPACE" + git config --global --add safe.directory '*' gem install bundler -v 2.4.10 bundle config set --local path "$GITHUB_WORKSPACE/.bundle/install" bundle install @@ -97,19 +106,30 @@ jobs: LC_ALL: C.UTF-8 BOSS_SHARD: ${{ matrix.shard }} BOSS_SHARDS: '4' + defaults: + run: + working-directory: BOSS steps: - name: Checkout Code uses: actions/checkout@v4 + with: + path: BOSS + - name: Checkout buildingsync-measures-gem + uses: actions/checkout@v4 + with: + repository: BuildingSync/buildingsync-measures-gem + ref: ${{ env.BSYNC_MEASURES_REF }} + path: buildingsync-measures-gem - name: Cache gems uses: actions/cache@v4 with: path: .bundle/install - key: gems-${{ runner.os }}-os3.10.0-${{ hashFiles('Gemfile.lock', '*.gemspec') }} + key: gems-${{ runner.os }}-os3.10.0-${{ hashFiles('BOSS/Gemfile.lock', 'BOSS/*.gemspec') }} - name: Cache external measures uses: actions/cache@v4 with: - path: vendor/external_measures - key: ext-measures-${{ hashFiles('config/external_measure_repos.yml') }} + path: BOSS/vendor/external_measures + key: ext-measures-${{ hashFiles('BOSS/config/external_measure_repos.yml') }} - name: Setup run: | git config --global --add safe.directory '*' @@ -124,4 +144,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: integration-output-shard-${{ matrix.shard }} - path: spec/output + path: BOSS/spec/output diff --git a/spec/tests/integration/write_and_run_osws_spec.rb b/spec/tests/integration/write_and_run_osws_spec.rb index 1a19216..7caf985 100644 --- a/spec/tests/integration/write_and_run_osws_spec.rb +++ b/spec/tests/integration/write_and_run_osws_spec.rb @@ -39,12 +39,15 @@ test_configs = test_configs.select { |config| SMOKE_FILES.include?(config[0]) } if ENV['BOSS_SMOKE'] == '1' # BOSS_SHARD / BOSS_SHARDS split the fixtures across parallel CI jobs. +run_extra_examples = ENV['BOSS_SMOKE'] != '1' if ENV['BOSS_SHARDS'] shards = Integer(ENV['BOSS_SHARDS']) shard = Integer(ENV.fetch('BOSS_SHARD', '0')) raise ArgumentError, "BOSS_SHARD must be in 0...#{shards}" if shards < 1 || shard.negative? || shard >= shards test_configs = test_configs.select.with_index { |_config, index| index % shards == shard } + # Examples outside test_configs run once, in shard 0. + run_extra_examples &&= shard.zero? end RSpec.describe 'BOSS' do @@ -77,6 +80,8 @@ end + next unless run_extra_examples + { 'example-smalloffice-level2.xml' => ['smalloffice_l2_topology_doe_ref', 'DOE Ref 1980-2004'], 'example-smalloffice-level2-built-2012.xml' => ['smalloffice_l2_topology', '90.1-2013']