mirror of
				https://github.com/Akkudoktor-EOS/EOS.git
				synced 2025-10-31 06:46:20 +00:00 
			
		
		
		
	Migrate from Flask to FastAPI (#163)
* Migrate from Flask to FastAPI
 * FastAPI migration:
    - Use pydantic model classes as input parameters to the
      data/calculation classes.
    - Interface field names changed to constructor parameter names (for
      simplicity only during transition, should be updated in a followup
      PR).
    - Add basic interface requirements (e.g. some values > 0, etc.).
 * Update tests for new data format.
 * Python requirement down to 3.9 (TypeGuard no longer needed)
 * Makefile: Add helpful targets (e.g. development server with reload)
* Move API doc from README to pydantic model classes (swagger)
 * Link to swagger.io with own openapi.yml.
 * Commit openapi.json and check with pytest for changes so the
   documentation is always up-to-date.
* Streamline docker
* FastAPI: Run startup action on dev server
 * Fix config for /strompreis, endpoint still broken however.
* test_openapi: Compare against docs/.../openapi.json
* Move fastapi to server/ submodule
 * See #187 for new repository structure.
			
			
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							ed3226e522
						
					
				
				
					commit
					f61665669f
				
			| @@ -1,10 +1,16 @@ | ||||
| import numpy as np | ||||
| import pytest | ||||
|  | ||||
| from akkudoktoreos.class_akku import PVAkku | ||||
| from akkudoktoreos.class_ems import EnergieManagementSystem | ||||
| from akkudoktoreos.class_haushaltsgeraet import Haushaltsgeraet | ||||
| from akkudoktoreos.class_inverter import Wechselrichter | ||||
| from akkudoktoreos.class_akku import EAutoParameters, PVAkku, PVAkkuParameters | ||||
| from akkudoktoreos.class_ems import ( | ||||
|     EnergieManagementSystem, | ||||
|     EnergieManagementSystemParameters, | ||||
| ) | ||||
| from akkudoktoreos.class_haushaltsgeraet import ( | ||||
|     Haushaltsgeraet, | ||||
|     HaushaltsgeraetParameters, | ||||
| ) | ||||
| from akkudoktoreos.class_inverter import Wechselrichter, WechselrichterParameters | ||||
| from akkudoktoreos.config import AppConfig | ||||
|  | ||||
| prediction_hours = 48 | ||||
| @@ -17,20 +23,28 @@ start_hour = 0 | ||||
| def create_ems_instance(tmp_config: AppConfig) -> EnergieManagementSystem: | ||||
|     """Fixture to create an EnergieManagementSystem instance with given test parameters.""" | ||||
|     # Initialize the battery and the inverter | ||||
|     akku = PVAkku(kapazitaet_wh=5000, start_soc_prozent=80, hours=48, min_soc_prozent=10) | ||||
|     akku = PVAkku( | ||||
|         PVAkkuParameters(kapazitaet_wh=5000, start_soc_prozent=80, min_soc_prozent=10), | ||||
|         hours=prediction_hours, | ||||
|     ) | ||||
|     akku.reset() | ||||
|     wechselrichter = Wechselrichter(10000, akku) | ||||
|     wechselrichter = Wechselrichter(WechselrichterParameters(max_leistung_wh=10000), akku) | ||||
|  | ||||
|     # Household device (currently not used, set to None) | ||||
|     home_appliance = Haushaltsgeraet( | ||||
|         HaushaltsgeraetParameters( | ||||
|             verbrauch_wh=2000, | ||||
|             dauer_h=2, | ||||
|         ), | ||||
|         hours=prediction_hours, | ||||
|         verbrauch_wh=2000, | ||||
|         dauer_h=2, | ||||
|     ) | ||||
|     home_appliance.set_startzeitpunkt(2) | ||||
|  | ||||
|     # Example initialization of electric car battery | ||||
|     eauto = PVAkku(kapazitaet_wh=26400, start_soc_prozent=100, hours=48, min_soc_prozent=100) | ||||
|     eauto = PVAkku( | ||||
|         EAutoParameters(kapazitaet_wh=26400, start_soc_prozent=100, min_soc_prozent=100), | ||||
|         hours=prediction_hours, | ||||
|     ) | ||||
|  | ||||
|     # Parameters based on previous example data | ||||
|     pv_prognose_wh = np.full(prediction_hours, 0) | ||||
| @@ -97,12 +111,15 @@ def create_ems_instance(tmp_config: AppConfig) -> EnergieManagementSystem: | ||||
|  | ||||
|     # Initialize the energy management system with the respective parameters | ||||
|     ems = EnergieManagementSystem( | ||||
|         config=tmp_config.eos, | ||||
|         pv_prognose_wh=pv_prognose_wh, | ||||
|         strompreis_euro_pro_wh=strompreis_euro_pro_wh, | ||||
|         einspeiseverguetung_euro_pro_wh=einspeiseverguetung_euro_pro_wh, | ||||
|         tmp_config.eos, | ||||
|         EnergieManagementSystemParameters( | ||||
|             pv_prognose_wh=pv_prognose_wh, | ||||
|             strompreis_euro_pro_wh=strompreis_euro_pro_wh, | ||||
|             einspeiseverguetung_euro_pro_wh=einspeiseverguetung_euro_pro_wh, | ||||
|             preis_euro_pro_wh_akku=0, | ||||
|             gesamtlast=gesamtlast, | ||||
|         ), | ||||
|         eauto=eauto, | ||||
|         gesamtlast=gesamtlast, | ||||
|         haushaltsgeraet=home_appliance, | ||||
|         wechselrichter=wechselrichter, | ||||
|     ) | ||||
| @@ -163,7 +180,7 @@ def test_simulation(create_ems_instance): | ||||
|         "akku_soc_pro_stunde", | ||||
|         "Einnahmen_Euro_pro_Stunde", | ||||
|         "Gesamtbilanz_Euro", | ||||
|         "E-Auto_SoC_pro_Stunde", | ||||
|         "EAuto_SoC_pro_Stunde", | ||||
|         "Gesamteinnahmen_Euro", | ||||
|         "Gesamtkosten_Euro", | ||||
|         "Verluste_Pro_Stunde", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user