Skip to content

Commit

Permalink
Add tests and fix default value for cost_calc_strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulScheerRLI committed Jun 7, 2024
1 parent 2ee22f5 commit 8bd4a94
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
4 changes: 2 additions & 2 deletions simba/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
50 changes: 48 additions & 2 deletions tests/test_cost_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,62 @@
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()
file = args.cost_parameters_file
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

0 comments on commit 8bd4a94

Please sign in to comment.