Add FastAPI backend for energy trading system
Implements FastAPI backend with ML model support for energy trading, including price prediction models and RL-based battery trading policy. Features dashboard, trading, backtest, and settings API routes with WebSocket support for real-time updates.
This commit is contained in:
3
backend/app/ml/utils/__init__.py
Normal file
3
backend/app/ml/utils/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from app.ml.utils import time_based_split, MLConfig
|
||||
|
||||
__all__ = ["time_based_split", "MLConfig"]
|
||||
16
backend/app/ml/utils/config.py
Normal file
16
backend/app/ml/utils/config.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Dict, Any
|
||||
|
||||
|
||||
@dataclass
|
||||
class MLConfig:
|
||||
enable_gpu: bool = False
|
||||
n_jobs: int = 4
|
||||
verbose: bool = True
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, config_dict: Dict[str, Any]) -> "MLConfig":
|
||||
return cls(**{k: v for k, v in config_dict.items() if k in cls.__annotations__})
|
||||
|
||||
|
||||
__all__ = ["MLConfig"]
|
||||
25
backend/app/ml/utils/data_split.py
Normal file
25
backend/app/ml/utils/data_split.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from typing import Tuple
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def time_based_split(
|
||||
df: pd.DataFrame,
|
||||
timestamp_col: str = "timestamp",
|
||||
train_pct: float = 0.70,
|
||||
val_pct: float = 0.85,
|
||||
) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
|
||||
df_sorted = df.sort_values(timestamp_col)
|
||||
|
||||
n_total = len(df_sorted)
|
||||
n_train = int(n_total * train_pct)
|
||||
n_val = int(n_total * val_pct)
|
||||
|
||||
train = df_sorted.iloc[:n_train]
|
||||
val = df_sorted.iloc[n_train:n_val]
|
||||
test = df_sorted.iloc[n_val:]
|
||||
|
||||
return train, val, test
|
||||
|
||||
|
||||
__all__ = ["time_based_split"]
|
||||
4
backend/app/ml/utils/evaluation.py
Normal file
4
backend/app/ml/utils/evaluation.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from app.ml.utils.data_split import time_based_split
|
||||
from app.ml.utils.config import MLConfig
|
||||
|
||||
__all__ = ["time_based_split", "MLConfig"]
|
||||
Reference in New Issue
Block a user