diff --git a/simba/costs.py b/simba/costs.py index 690b45b..5f3d682 100644 --- a/simba/costs.py +++ b/simba/costs.py @@ -134,8 +134,10 @@ def get_unit(self, key): :return: Unit associated with the key :rtype: str """ - if "maximum_gc_power" == key: + if "power" in key: return "kW" + elif "station_type" == key: + return "[-]" elif "maximum Nr charging stations" == key: return "[-]" elif "total_km_per_year" == key: @@ -184,7 +186,7 @@ def get_gc_cost_variables(self): """ return [ # various kpis and attributes - "station_type", "maximum_gc_power", "maximum Nr charging stations", + "station_type", "maximum_gc_power", "max_power_in_plw", "maximum Nr charging stations", "total_km_per_year", "annual_kWh_from_grid", "annual_kWh_from_feed_in", # investment costs @@ -372,8 +374,11 @@ def set_electricity_costs(self): 'levies_fees_and_taxes_per_year', error_value) self.costs_per_gc[gcID]["c_el_feed_in_remuneration_annual"] = costs_electricity.get( 'feed_in_remuneration_per_year', error_value) - self.costs_per_gc[gcID]["c_el_annual"] = costs_electricity.get('total_costs_per_year', - error_value) + self.costs_per_gc[gcID]["c_el_annual"] = costs_electricity.get( + 'total_costs_per_year', error_value) + self.costs_per_gc[gcID]["max_power_in_plw"] = costs_electricity.get( + 'peak_power_in_windows', error_value) + return self def set_garage_costs(self): @@ -633,10 +638,13 @@ def cumulate(self): """ # Cumulate gcs variables for key in self.get_gc_cost_variables(): + # skip special attributes + if key in ["station_type", "maximum_gc_power", "max_power_in_plw"]: + continue # Vehicle costs cannot be cumulated since they might be double counted for vehicles # with multiple depots. Instead, the vehicle costs were previously calculated in # set_vehicle_costs_per_gc() - if key in ["c_vehicles", "c_vehicles_annual", "station_type"]: + if key in ["c_vehicles", "c_vehicles_annual"]: continue self.costs_per_gc[self.CUMULATED][key] = 0 for gc in self.costs_per_gc.keys() - [self.CUMULATED]: @@ -713,8 +721,4 @@ def to_csv_lists(self): except TypeError: row.append(num) output.append(row) - - transposed_output = [] - for column, _ in enumerate(output[0]): - transposed_output.append([row[column] for row in output]) - return transposed_output + return output diff --git a/tests/test_simulate.py b/tests/test_simulate.py index 41accd6..8ca283c 100644 --- a/tests/test_simulate.py +++ b/tests/test_simulate.py @@ -200,15 +200,24 @@ def test_mode_report(self, tmp_path): # read out vehicle costs, procurement price must match with (tmp_path / "report_1/summary_vehicles_costs.csv").open() as csvfile: reader = DictReader(csvfile) + # save procurement costs and annual energy for each Station + station_data = {s: {"energy_costs": None, "energy_amount": None} + for s in reader.fieldnames if s.startswith("Station")} for row in reader: - if row["parameter"] == "unit": - continue - energy = float(row["annual_kWh_from_grid"]) - price = float(row["c_el_procurement_annual"]) + if row["parameter"] == "c_el_procurement_annual": + for name in station_data: + station_data[name]["energy_costs"] = float(row[name]) + if row["parameter"] == "annual_kWh_from_grid": + for name in station_data: + station_data[name]["energy_amount"] = float(row[name]) + # check quotient: no energy must mean no cost, otherwise procurement price + for name in station_data: + energy = station_data[name]["energy_amount"] + cost = station_data[name]["energy_costs"] if energy == 0: - assert price == 0 + assert cost == 0, f"{name} has costs without energy" else: - assert pytest.approx(price / energy) == procurement_price + assert pytest.approx(cost/energy) == procurement_price, f"{name}: procurement" def test_empty_report(self, tmp_path): # report with no rotations