diff --git a/simba/costs.py b/simba/costs.py index 100644d..e03bd2b 100644 --- a/simba/costs.py +++ b/simba/costs.py @@ -305,11 +305,11 @@ def set_electricity_costs(self): # Get the calculation strategy / method from args. - # If no value is set use the same strategy as the charging strategy + # If no value is set, use the same strategy as the charging strategy default_cost_strategy = vars(self.args)["strategy_" + station.get("type")] strategy_name = "cost_calculation_strategy_" + station.get("type") - cost_calculation_strategy = vars(self.args).get(strategy_name, default_cost_strategy) + cost_calculation_strategy = vars(self.args).get(strategy_name) or default_cost_strategy # calculate costs for electricity try: diff --git a/tests/test_cost_calculation.py b/tests/test_cost_calculation.py index 92d41a2..b5ce6b4 100644 --- a/tests/test_cost_calculation.py +++ b/tests/test_cost_calculation.py @@ -2,6 +2,7 @@ from simba.util import uncomment_json_file from simba.costs import calculate_costs + class TestCostCalculation: def test_cost_calculation(self): schedule, scenario, args = BasicSchedule().basic_run() @@ -9,9 +10,54 @@ def test_cost_calculation(self): with open(file, "r") as file: cost_params = uncomment_json_file(file) - costs = calculate_costs(cost_params, scenario, schedule, args) + assert args.strategy_deps == "balanced" + assert args.strategy_opps == "greedy" + + args.cost_calculation_strategy_deps = None + args.cost_calculation_strategy_opps = None + + costs_vanilla = calculate_costs(cost_params, scenario, schedule, args) assert args.strategy_deps == "balanced" assert args.strategy_opps == "greedy" - args.cost_calculation_strategy_opps == "balanced" + args.cost_calculation_strategy_deps = "balanced" + args.cost_calculation_strategy_opps = "greedy" + costs_with_same_strat = calculate_costs(cost_params, scenario, schedule, args) + + # assert all costs are the same + for station in costs_vanilla.costs_per_gc: + for key in costs_vanilla.costs_per_gc[station]: + assert (costs_vanilla.costs_per_gc[station][key] == + costs_with_same_strat.costs_per_gc[station][key]), station + + args.cost_calculation_strategy_opps = "balanced_market" + args.cost_calculation_strategy_deps = "balanced_market" + costs_with_other_strat = calculate_costs(cost_params, scenario, schedule, args) + print(costs_vanilla.costs_per_gc["cumulated"]["c_total_annual"]) + print(costs_with_other_strat.costs_per_gc["cumulated"]["c_total_annual"]) + station = "cumulated" + for key in costs_vanilla.costs_per_gc[station]: + if not "el_energy" in key: + continue + assert (costs_vanilla.costs_per_gc[station][key] != + costs_with_other_strat.costs_per_gc[station][key]), key + + args.cost_calculation_strategy_opps = "peak_load_window" + args.cost_calculation_strategy_deps = "peak_load_window" + costs_with_other_strat = calculate_costs(cost_params, scenario, schedule, args) + station = "cumulated" + for key in costs_vanilla.costs_per_gc[station]: + if not "el_energy" in key: + continue + assert (costs_vanilla.costs_per_gc[station][key] != + costs_with_other_strat.costs_per_gc[station][key]), key + + args.cost_calculation_strategy_opps = "peak_shaving" + args.cost_calculation_strategy_deps = "peak_shaving" + costs_with_other_strat = calculate_costs(cost_params, scenario, schedule, args) + # assert all costs are the same + for station in costs_vanilla.costs_per_gc: + for key in costs_vanilla.costs_per_gc[station]: + assert (costs_vanilla.costs_per_gc[station][key] == + costs_with_other_strat.costs_per_gc[station][key]), station