mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-07-20 00:38:12 +00:00
Some checks failed
Bump Version / Bump Version Workflow (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
docker-build / platform-excludes (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
Rename the German field names of the genetic optimization API to English with full backward compatibility: - English names are canonical and documented in the OpenAPI schema; the German names are still accepted on input via validation aliases and re-emitted in responses as deprecated computed fields - fix visualization receiving the raw German-keyed simulation dict (KeyError: load_wh_per_hour) - rename internal German identifiers (optimize_ems, total_balance, battery_residual_value, self_consumption, extra_data keys) - use amount instead of currency/euro in chart labels and schema descriptions; document currency handling (whole currency units, never cents) in the API description - regenerate openapi.json and generated docs Co-authored-by: Tobias Welz <tobias.wizneteu@gmail.com>
129 lines
5.0 KiB
Python
129 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Quick test to verify API field name translations work correctly."""
|
|
|
|
import json
|
|
|
|
from akkudoktoreos.optimization.genetic.geneticparams import (
|
|
GeneticEnergyManagementParameters,
|
|
)
|
|
from akkudoktoreos.optimization.genetic.geneticsolution import GeneticSimulationResult
|
|
|
|
|
|
def test_genetic_params_german_input():
|
|
"""Test that German field names are accepted as input."""
|
|
data_de = {
|
|
"pv_prognose_wh": [100.0, 200.0],
|
|
"strompreis_euro_pro_wh": [0.0003, 0.0003],
|
|
"einspeiseverguetung_euro_pro_wh": 0.00007,
|
|
"preis_euro_pro_wh_akku": 0.0001,
|
|
"gesamtlast": [500.0, 600.0],
|
|
}
|
|
params = GeneticEnergyManagementParameters(**data_de)
|
|
assert params.pv_forecast_wh == [100.0, 200.0]
|
|
print("✅ German input accepted")
|
|
|
|
def test_genetic_params_english_input():
|
|
"""Test that English field names are accepted as input."""
|
|
data_en = {
|
|
"pv_forecast_wh": [100.0, 200.0],
|
|
"electricity_price_per_wh": [0.0003, 0.0003],
|
|
"feed_in_tariff_per_wh": 0.00007,
|
|
"price_per_wh_battery": 0.0001,
|
|
"total_load": [500.0, 600.0],
|
|
}
|
|
params = GeneticEnergyManagementParameters(**data_en)
|
|
assert params.pv_forecast_wh == [100.0, 200.0]
|
|
print("✅ English input accepted")
|
|
|
|
def test_genetic_params_english_output():
|
|
"""Test that both English and German field names are in JSON output (backward compatibility)."""
|
|
data_de = {
|
|
"pv_prognose_wh": [100.0, 200.0],
|
|
"strompreis_euro_pro_wh": [0.0003, 0.0003],
|
|
"einspeiseverguetung_euro_pro_wh": 0.00007,
|
|
"preis_euro_pro_wh_akku": 0.0001,
|
|
"gesamtlast": [500.0, 600.0],
|
|
}
|
|
params = GeneticEnergyManagementParameters(**data_de)
|
|
json_output = json.loads(params.model_dump_json(by_alias=True))
|
|
|
|
# English names should be in output
|
|
assert "pv_forecast_wh" in json_output
|
|
assert "electricity_price_per_wh" in json_output
|
|
assert "feed_in_tariff_per_wh" in json_output
|
|
assert "price_per_wh_battery" in json_output
|
|
assert "total_load" in json_output
|
|
|
|
# German names should ALSO be in output (backward compatibility)
|
|
assert "pv_prognose_wh" in json_output
|
|
assert "strompreis_euro_pro_wh" in json_output
|
|
assert "einspeiseverguetung_euro_pro_wh" in json_output
|
|
assert "preis_euro_pro_wh_akku" in json_output
|
|
assert "gesamtlast" in json_output
|
|
|
|
# Both should have same values
|
|
assert json_output["pv_forecast_wh"] == json_output["pv_prognose_wh"]
|
|
assert json_output["electricity_price_per_wh"] == json_output["strompreis_euro_pro_wh"]
|
|
print("✅ Both English and German output generated")
|
|
|
|
def test_simulation_result_translations():
|
|
"""Test simulation result field translations."""
|
|
data_de = {
|
|
"Last_Wh_pro_Stunde": [100.0, 200.0],
|
|
"EAuto_SoC_pro_Stunde": [50.0, 60.0],
|
|
"Einnahmen_Euro_pro_Stunde": [0.1, 0.2],
|
|
"Gesamt_Verluste": 50.0,
|
|
"Gesamtbilanz_Euro": -10.0,
|
|
"Gesamteinnahmen_Euro": 5.0,
|
|
"Gesamtkosten_Euro": 15.0,
|
|
"Home_appliance_wh_per_hour": [0.0, 100.0],
|
|
"Kosten_Euro_pro_Stunde": [0.2, 0.3],
|
|
"Netzbezug_Wh_pro_Stunde": [50.0, 60.0],
|
|
"Netzeinspeisung_Wh_pro_Stunde": [10.0, 20.0],
|
|
"Verluste_Pro_Stunde": [5.0, 10.0],
|
|
"akku_soc_pro_stunde": [80.0, 90.0],
|
|
"Electricity_price": [0.0003, 0.0003],
|
|
}
|
|
result = GeneticSimulationResult(**data_de)
|
|
json_output = json.loads(result.model_dump_json(by_alias=True))
|
|
|
|
# Check English field names in output
|
|
english_names = [
|
|
"load_wh_per_hour",
|
|
"ev_soc_per_hour",
|
|
"revenue_per_hour",
|
|
"total_losses",
|
|
"total_balance",
|
|
"total_revenue",
|
|
"total_costs",
|
|
"home_appliance_wh_per_hour",
|
|
"costs_per_hour",
|
|
"grid_consumption_wh_per_hour",
|
|
"grid_feed_in_wh_per_hour",
|
|
"losses_per_hour",
|
|
"battery_soc_per_hour",
|
|
"electricity_price",
|
|
]
|
|
for name in english_names:
|
|
assert name in json_output, f"English field {name} missing in output"
|
|
|
|
# Check ALL deprecated German field names are still in output (backward compatibility)
|
|
for name in data_de:
|
|
assert name in json_output, f"Deprecated field {name} missing in output"
|
|
|
|
# Deprecated fields must mirror the values of the renamed fields
|
|
assert json_output["Last_Wh_pro_Stunde"] == json_output["load_wh_per_hour"]
|
|
assert json_output["Home_appliance_wh_per_hour"] == json_output["home_appliance_wh_per_hour"]
|
|
assert json_output["Gesamtbilanz_Euro"] == json_output["total_balance"]
|
|
assert json_output["akku_soc_pro_stunde"] == json_output["battery_soc_per_hour"]
|
|
assert json_output["Electricity_price"] == json_output["electricity_price"]
|
|
|
|
print("✅ Simulation result translations work")
|
|
|
|
if __name__ == "__main__":
|
|
test_genetic_params_german_input()
|
|
test_genetic_params_english_input()
|
|
test_genetic_params_english_output()
|
|
test_simulation_result_translations()
|
|
print("\n✅✅✅ All translation tests passed! ✅✅✅")
|