mirror of
				https://github.com/Akkudoktor-EOS/EOS.git
				synced 2025-10-30 22:36:21 +00:00 
			
		
		
		
	Structure code in logically separated submodules (#188)
This commit is contained in:
		| @@ -1,24 +0,0 @@ | ||||
| import json | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
|  | ||||
| class NumpyEncoder(json.JSONEncoder): | ||||
|     def default(self, obj): | ||||
|         if isinstance(obj, np.ndarray): | ||||
|             return obj.tolist()  # Convert NumPy arrays to lists | ||||
|         if isinstance(obj, np.generic): | ||||
|             return obj.item()  # Convert NumPy scalars to native Python types | ||||
|         return super(NumpyEncoder, self).default(obj) | ||||
|  | ||||
|     @staticmethod | ||||
|     def dumps(data): | ||||
|         """Static method to serialize a Python object into a JSON string using NumpyEncoder. | ||||
|  | ||||
|         Args: | ||||
|             data: The Python object to serialize. | ||||
|  | ||||
|         Returns: | ||||
|             str: A JSON string representation of the object. | ||||
|         """ | ||||
|         return json.dumps(data, cls=NumpyEncoder) | ||||
							
								
								
									
										0
									
								
								src/akkudoktoreos/devices/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/akkudoktoreos/devices/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -1,6 +1,6 @@ | ||||
| from pydantic import BaseModel, Field | ||||
| 
 | ||||
| from akkudoktoreos.class_akku import PVAkku | ||||
| from akkudoktoreos.devices.battery import PVAkku | ||||
| 
 | ||||
| 
 | ||||
| class WechselrichterParameters(BaseModel): | ||||
							
								
								
									
										0
									
								
								src/akkudoktoreos/optimization/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/akkudoktoreos/optimization/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -6,17 +6,14 @@ from deap import algorithms, base, creator, tools | ||||
| from pydantic import BaseModel, Field, field_validator, model_validator | ||||
| from typing_extensions import Self | ||||
| 
 | ||||
| from akkudoktoreos.class_akku import EAutoParameters, PVAkku, PVAkkuParameters | ||||
| from akkudoktoreos.class_ems import ( | ||||
| from akkudoktoreos.config import AppConfig | ||||
| from akkudoktoreos.devices.battery import EAutoParameters, PVAkku, PVAkkuParameters | ||||
| from akkudoktoreos.devices.generic import Haushaltsgeraet, HaushaltsgeraetParameters | ||||
| from akkudoktoreos.devices.inverter import Wechselrichter, WechselrichterParameters | ||||
| from akkudoktoreos.prediction.ems import ( | ||||
|     EnergieManagementSystem, | ||||
|     EnergieManagementSystemParameters, | ||||
| ) | ||||
| from akkudoktoreos.class_haushaltsgeraet import ( | ||||
|     Haushaltsgeraet, | ||||
|     HaushaltsgeraetParameters, | ||||
| ) | ||||
| from akkudoktoreos.class_inverter import Wechselrichter, WechselrichterParameters | ||||
| from akkudoktoreos.config import AppConfig | ||||
| from akkudoktoreos.visualize import visualisiere_ergebnisse | ||||
| 
 | ||||
| 
 | ||||
							
								
								
									
										0
									
								
								src/akkudoktoreos/prediction/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/akkudoktoreos/prediction/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -5,10 +5,10 @@ import numpy as np | ||||
| from pydantic import BaseModel, Field, model_validator | ||||
| from typing_extensions import Self | ||||
| 
 | ||||
| from akkudoktoreos.class_akku import PVAkku | ||||
| from akkudoktoreos.class_haushaltsgeraet import Haushaltsgeraet | ||||
| from akkudoktoreos.class_inverter import Wechselrichter | ||||
| from akkudoktoreos.config import EOSConfig | ||||
| from akkudoktoreos.devices.battery import PVAkku | ||||
| from akkudoktoreos.devices.generic import Haushaltsgeraet | ||||
| from akkudoktoreos.devices.inverter import Wechselrichter | ||||
| 
 | ||||
| 
 | ||||
| class EnergieManagementSystemParameters(BaseModel): | ||||
| @@ -43,9 +43,9 @@ import pandas as pd | ||||
| import requests | ||||
| from pydantic import BaseModel, ValidationError | ||||
| 
 | ||||
| from akkudoktoreos.cachefilestore import cache_in_file | ||||
| from akkudoktoreos.datetimeutil import to_datetime | ||||
| from akkudoktoreos.logutil import get_logger | ||||
| from akkudoktoreos.utils.cachefilestore import cache_in_file | ||||
| from akkudoktoreos.utils.datetimeutil import to_datetime | ||||
| from akkudoktoreos.utils.logutil import get_logger | ||||
| 
 | ||||
| logger = get_logger(__name__, logging_level="DEBUG") | ||||
| 
 | ||||
| @@ -16,22 +16,22 @@ import pandas as pd | ||||
| from fastapi import FastAPI, Query | ||||
| from fastapi.responses import FileResponse, RedirectResponse | ||||
|  | ||||
| from akkudoktoreos.class_load import LoadForecast | ||||
| from akkudoktoreos.class_load_container import Gesamtlast | ||||
| from akkudoktoreos.class_load_corrector import LoadPredictionAdjuster | ||||
| from akkudoktoreos.class_optimize import ( | ||||
|     OptimizationParameters, | ||||
|     OptimizeResponse, | ||||
|     optimization_problem, | ||||
| ) | ||||
| from akkudoktoreos.class_pv_forecast import ForecastResponse, PVForecast | ||||
| from akkudoktoreos.class_strompreis import HourlyElectricityPriceForecast | ||||
| from akkudoktoreos.config import ( | ||||
|     SetupIncomplete, | ||||
|     get_start_enddate, | ||||
|     get_working_dir, | ||||
|     load_config, | ||||
| ) | ||||
| from akkudoktoreos.optimization.genetic import ( | ||||
|     OptimizationParameters, | ||||
|     OptimizeResponse, | ||||
|     optimization_problem, | ||||
| ) | ||||
| from akkudoktoreos.prediction.load_container import Gesamtlast | ||||
| from akkudoktoreos.prediction.load_corrector import LoadPredictionAdjuster | ||||
| from akkudoktoreos.prediction.load_forecast import LoadForecast | ||||
| from akkudoktoreos.prediction.price_forecast import HourlyElectricityPriceForecast | ||||
| from akkudoktoreos.prediction.pv_forecast import ForecastResponse, PVForecast | ||||
|  | ||||
| app = FastAPI( | ||||
|     title="Akkudoktor-EOS", | ||||
|   | ||||
							
								
								
									
										0
									
								
								src/akkudoktoreos/utils/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/akkudoktoreos/utils/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -34,8 +34,8 @@ import threading | ||||
| from datetime import date, datetime, time, timedelta | ||||
| from typing import List, Optional, Union | ||||
| 
 | ||||
| from akkudoktoreos.datetimeutil import to_datetime, to_timedelta | ||||
| from akkudoktoreos.logutil import get_logger | ||||
| from akkudoktoreos.utils.datetimeutil import to_datetime, to_timedelta | ||||
| from akkudoktoreos.utils.logutil import get_logger | ||||
| 
 | ||||
| logger = get_logger(__file__) | ||||
| 
 | ||||
| @@ -1,6 +1,9 @@ | ||||
| import datetime | ||||
| import json | ||||
| import zoneinfo | ||||
| 
 | ||||
| import numpy as np | ||||
| 
 | ||||
| 
 | ||||
| # currently unused | ||||
| def ist_dst_wechsel(tag: datetime.datetime, timezone="Europe/Berlin") -> bool: | ||||
| @@ -16,6 +19,27 @@ def ist_dst_wechsel(tag: datetime.datetime, timezone="Europe/Berlin") -> bool: | ||||
|     return dst_change | ||||
| 
 | ||||
| 
 | ||||
| class NumpyEncoder(json.JSONEncoder): | ||||
|     def default(self, obj): | ||||
|         if isinstance(obj, np.ndarray): | ||||
|             return obj.tolist()  # Convert NumPy arrays to lists | ||||
|         if isinstance(obj, np.generic): | ||||
|             return obj.item()  # Convert NumPy scalars to native Python types | ||||
|         return super(NumpyEncoder, self).default(obj) | ||||
| 
 | ||||
|     @staticmethod | ||||
|     def dumps(data): | ||||
|         """Static method to serialize a Python object into a JSON string using NumpyEncoder. | ||||
| 
 | ||||
|         Args: | ||||
|             data: The Python object to serialize. | ||||
| 
 | ||||
|         Returns: | ||||
|             str: A JSON string representation of the object. | ||||
|         """ | ||||
|         return json.dumps(data, cls=NumpyEncoder) | ||||
| 
 | ||||
| 
 | ||||
| # # Example usage | ||||
| # start_date = datetime.datetime(2024, 3, 31)  # Date of the DST change | ||||
| # if ist_dst_wechsel(start_date): | ||||
		Reference in New Issue
	
	Block a user