2025-07-19 21:44:52 +02:00
|
|
|
# ================================================================
|
|
|
|
|
# TRAINING SERVICE CONFIGURATION
|
|
|
|
|
# services/training/app/core/config.py
|
|
|
|
|
# ================================================================
|
|
|
|
|
|
2025-07-17 13:09:24 +02:00
|
|
|
"""
|
|
|
|
|
Training service configuration
|
2025-07-19 21:44:52 +02:00
|
|
|
ML model training and management
|
2025-07-17 13:09:24 +02:00
|
|
|
"""
|
|
|
|
|
|
2025-07-19 21:44:52 +02:00
|
|
|
from shared.config.base import BaseServiceSettings
|
2025-07-17 13:09:24 +02:00
|
|
|
import os
|
|
|
|
|
|
2025-07-19 21:44:52 +02:00
|
|
|
class TrainingSettings(BaseServiceSettings):
|
|
|
|
|
"""Training service specific settings"""
|
2025-07-17 13:09:24 +02:00
|
|
|
|
2025-07-19 21:44:52 +02:00
|
|
|
# Service Identity
|
2025-07-17 13:09:24 +02:00
|
|
|
APP_NAME: str = "Training Service"
|
2025-07-19 21:44:52 +02:00
|
|
|
SERVICE_NAME: str = "training-service"
|
|
|
|
|
DESCRIPTION: str = "Machine learning model training service"
|
2025-07-17 13:09:24 +02:00
|
|
|
|
2025-09-27 11:18:13 +02:00
|
|
|
# Database configuration (secure approach - build from components)
|
|
|
|
|
@property
|
|
|
|
|
def DATABASE_URL(self) -> str:
|
|
|
|
|
"""Build database URL from secure components"""
|
|
|
|
|
# Try complete URL first (for backward compatibility)
|
|
|
|
|
complete_url = os.getenv("TRAINING_DATABASE_URL")
|
|
|
|
|
if complete_url:
|
|
|
|
|
return complete_url
|
|
|
|
|
|
|
|
|
|
# Build from components (secure approach)
|
|
|
|
|
user = os.getenv("TRAINING_DB_USER", "training_user")
|
|
|
|
|
password = os.getenv("TRAINING_DB_PASSWORD", "training_pass123")
|
|
|
|
|
host = os.getenv("TRAINING_DB_HOST", "localhost")
|
|
|
|
|
port = os.getenv("TRAINING_DB_PORT", "5432")
|
|
|
|
|
name = os.getenv("TRAINING_DB_NAME", "training_db")
|
|
|
|
|
|
|
|
|
|
return f"postgresql+asyncpg://{user}:{password}@{host}:{port}/{name}"
|
2025-07-17 13:09:24 +02:00
|
|
|
|
2025-07-19 21:44:52 +02:00
|
|
|
# Redis Database (dedicated for training cache)
|
|
|
|
|
REDIS_DB: int = 1
|
2025-07-17 13:09:24 +02:00
|
|
|
|
2025-07-19 21:44:52 +02:00
|
|
|
# ML Model Storage
|
2025-07-17 13:09:24 +02:00
|
|
|
MODEL_STORAGE_PATH: str = os.getenv("MODEL_STORAGE_PATH", "/app/models")
|
2025-07-19 21:44:52 +02:00
|
|
|
MODEL_BACKUP_ENABLED: bool = os.getenv("MODEL_BACKUP_ENABLED", "true").lower() == "true"
|
|
|
|
|
MODEL_VERSIONING_ENABLED: bool = os.getenv("MODEL_VERSIONING_ENABLED", "true").lower() == "true"
|
|
|
|
|
|
|
|
|
|
# Training Configuration
|
2025-07-17 13:09:24 +02:00
|
|
|
MAX_TRAINING_TIME_MINUTES: int = int(os.getenv("MAX_TRAINING_TIME_MINUTES", "30"))
|
2025-07-19 21:44:52 +02:00
|
|
|
MAX_CONCURRENT_TRAINING_JOBS: int = int(os.getenv("MAX_CONCURRENT_TRAINING_JOBS", "3"))
|
2025-07-17 13:09:24 +02:00
|
|
|
MIN_TRAINING_DATA_DAYS: int = int(os.getenv("MIN_TRAINING_DATA_DAYS", "30"))
|
2025-07-19 21:44:52 +02:00
|
|
|
TRAINING_BATCH_SIZE: int = int(os.getenv("TRAINING_BATCH_SIZE", "1000"))
|
2025-07-17 13:09:24 +02:00
|
|
|
|
2025-07-19 21:44:52 +02:00
|
|
|
# Prophet Specific Configuration
|
2025-07-17 13:09:24 +02:00
|
|
|
PROPHET_SEASONALITY_MODE: str = os.getenv("PROPHET_SEASONALITY_MODE", "additive")
|
2025-07-19 21:44:52 +02:00
|
|
|
PROPHET_CHANGEPOINT_PRIOR_SCALE: float = float(os.getenv("PROPHET_CHANGEPOINT_PRIOR_SCALE", "0.05"))
|
|
|
|
|
PROPHET_SEASONALITY_PRIOR_SCALE: float = float(os.getenv("PROPHET_SEASONALITY_PRIOR_SCALE", "10.0"))
|
|
|
|
|
PROPHET_HOLIDAYS_PRIOR_SCALE: float = float(os.getenv("PROPHET_HOLIDAYS_PRIOR_SCALE", "10.0"))
|
|
|
|
|
|
|
|
|
|
# Spanish Holiday Integration
|
|
|
|
|
ENABLE_SPANISH_HOLIDAYS: bool = True
|
|
|
|
|
ENABLE_MADRID_HOLIDAYS: bool = True
|
|
|
|
|
ENABLE_CUSTOM_HOLIDAYS: bool = os.getenv("ENABLE_CUSTOM_HOLIDAYS", "true").lower() == "true"
|
2025-07-17 13:09:24 +02:00
|
|
|
|
2025-07-19 21:44:52 +02:00
|
|
|
# Data Processing
|
|
|
|
|
DATA_PREPROCESSING_ENABLED: bool = True
|
|
|
|
|
OUTLIER_DETECTION_ENABLED: bool = os.getenv("OUTLIER_DETECTION_ENABLED", "true").lower() == "true"
|
|
|
|
|
SEASONAL_DECOMPOSITION_ENABLED: bool = os.getenv("SEASONAL_DECOMPOSITION_ENABLED", "true").lower() == "true"
|
2025-07-19 21:16:25 +02:00
|
|
|
|
2025-07-19 21:44:52 +02:00
|
|
|
# Model Validation
|
|
|
|
|
CROSS_VALIDATION_ENABLED: bool = os.getenv("CROSS_VALIDATION_ENABLED", "true").lower() == "true"
|
|
|
|
|
VALIDATION_SPLIT_RATIO: float = float(os.getenv("VALIDATION_SPLIT_RATIO", "0.2"))
|
|
|
|
|
MIN_MODEL_ACCURACY: float = float(os.getenv("MIN_MODEL_ACCURACY", "0.7"))
|
2025-07-19 21:16:25 +02:00
|
|
|
|
2025-07-19 21:44:52 +02:00
|
|
|
# Distributed Training (for future scaling)
|
|
|
|
|
DISTRIBUTED_TRAINING_ENABLED: bool = os.getenv("DISTRIBUTED_TRAINING_ENABLED", "false").lower() == "true"
|
|
|
|
|
TRAINING_WORKER_COUNT: int = int(os.getenv("TRAINING_WORKER_COUNT", "1"))
|
2025-07-25 14:10:27 +02:00
|
|
|
|
|
|
|
|
PROPHET_DAILY_SEASONALITY: bool = True
|
|
|
|
|
PROPHET_WEEKLY_SEASONALITY: bool = True
|
|
|
|
|
PROPHET_YEARLY_SEASONALITY: bool = True
|
|
|
|
|
PROPHET_SEASONALITY_MODE: str = "additive"
|
2025-07-17 13:09:24 +02:00
|
|
|
|
2025-07-19 21:44:52 +02:00
|
|
|
settings = TrainingSettings()
|