From 9650b1335ed2845c2a27a663cca51926845a37ef Mon Sep 17 00:00:00 2001 From: Rajendra Adhikari Date: Tue, 9 Jul 2024 08:50:41 -0500 Subject: [PATCH] Simplify upgrade step --- .../residential/residential_hpxml.py | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/buildstockbatch/workflow_generator/residential/residential_hpxml.py b/buildstockbatch/workflow_generator/residential/residential_hpxml.py index 0ca4c745..529c755f 100644 --- a/buildstockbatch/workflow_generator/residential/residential_hpxml.py +++ b/buildstockbatch/workflow_generator/residential/residential_hpxml.py @@ -171,38 +171,36 @@ def create_osw(self, sim_id, building_id, upgrade_idx): return osw def add_upgrade_step_to_osw(self, upgrade_idx, osw): - num_regular_upgrades = len(self.cfg.get("upgrades", [])) if upgrade_idx is None: return - if upgrade_idx < num_regular_upgrades: - measure_d = self.cfg["upgrades"][upgrade_idx] - apply_upgrade_measure = { - "measure_dir_name": "ApplyUpgrade", - "arguments": {"run_measure": 1}, - } - if "upgrade_name" in measure_d: - apply_upgrade_measure["arguments"]["upgrade_name"] = measure_d["upgrade_name"] - for opt_num, option in enumerate(measure_d["options"], 1): - apply_upgrade_measure["arguments"]["option_{}".format(opt_num)] = option["option"] - if "lifetime" in option: - apply_upgrade_measure["arguments"]["option_{}_lifetime".format(opt_num)] = option["lifetime"] - if "apply_logic" in option: - apply_upgrade_measure["arguments"]["option_{}_apply_logic".format(opt_num)] = ( - self.make_apply_logic_arg(option["apply_logic"]) - ) - for cost_num, cost in enumerate(option.get("costs", []), 1): - for arg in ("value", "multiplier"): - if arg not in cost: - continue - apply_upgrade_measure["arguments"]["option_{}_cost_{}_{}".format(opt_num, cost_num, arg)] = ( - cost[arg] - ) - if "package_apply_logic" in measure_d: - apply_upgrade_measure["arguments"]["package_apply_logic"] = self.make_apply_logic_arg( - measure_d["package_apply_logic"] + measure_d = self.cfg["upgrades"][upgrade_idx] + apply_upgrade_measure = { + "measure_dir_name": "ApplyUpgrade", + "arguments": {"run_measure": 1}, + } + if "upgrade_name" in measure_d: + apply_upgrade_measure["arguments"]["upgrade_name"] = measure_d["upgrade_name"] + for opt_num, option in enumerate(measure_d["options"], 1): + apply_upgrade_measure["arguments"]["option_{}".format(opt_num)] = option["option"] + if "lifetime" in option: + apply_upgrade_measure["arguments"]["option_{}_lifetime".format(opt_num)] = option["lifetime"] + if "apply_logic" in option: + apply_upgrade_measure["arguments"]["option_{}_apply_logic".format(opt_num)] = self.make_apply_logic_arg( + option["apply_logic"] ) - osw["steps"].insert(1, apply_upgrade_measure) # right after BuildExistingModel + for cost_num, cost in enumerate(option.get("costs", []), 1): + for arg in ("value", "multiplier"): + if arg not in cost: + continue + apply_upgrade_measure["arguments"]["option_{}_cost_{}_{}".format(opt_num, cost_num, arg)] = cost[ + arg + ] + if "package_apply_logic" in measure_d: + apply_upgrade_measure["arguments"]["package_apply_logic"] = self.make_apply_logic_arg( + measure_d["package_apply_logic"] + ) + osw["steps"].insert(1, apply_upgrade_measure) # right after BuildExistingModel def _get_measure_args(self, workflow_block_args, measure_dir_name, debug): """