REFACTOR data service
This commit is contained in:
@@ -9,7 +9,7 @@ from typing import Dict, Any, List, Optional
|
||||
from datetime import datetime
|
||||
|
||||
# Import the shared clients
|
||||
from shared.clients import get_data_client, get_service_clients
|
||||
from shared.clients import get_sales_client, get_external_client, get_service_clients
|
||||
from app.core.config import settings
|
||||
|
||||
logger = structlog.get_logger()
|
||||
@@ -21,12 +21,13 @@ class DataClient:
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
# Get the shared data client configured for this service
|
||||
self.data_client = get_data_client(settings, "forecasting")
|
||||
# Get the new specialized clients
|
||||
self.sales_client = get_sales_client(settings, "forecasting")
|
||||
self.external_client = get_external_client(settings, "forecasting")
|
||||
|
||||
# Or alternatively, get all clients at once:
|
||||
# self.clients = get_service_clients(settings, "training")
|
||||
# Then use: self.clients.data.get_sales_data(...)
|
||||
# self.clients = get_service_clients(settings, "forecasting")
|
||||
# Then use: self.clients.sales.get_sales_data(...) and self.clients.external.get_weather_forecast(...)
|
||||
|
||||
|
||||
async def fetch_weather_forecast(
|
||||
@@ -41,7 +42,7 @@ class DataClient:
|
||||
All the error handling and retry logic is now in the base client!
|
||||
"""
|
||||
try:
|
||||
weather_data = await self.data_client.get_weather_forecast(
|
||||
weather_data = await self.external_client.get_weather_forecast(
|
||||
tenant_id=tenant_id,
|
||||
days=days,
|
||||
latitude=latitude,
|
||||
|
||||
@@ -8,7 +8,7 @@ import structlog
|
||||
from typing import Dict, Any, List, Optional
|
||||
|
||||
# Import shared clients - no more code duplication!
|
||||
from shared.clients import get_service_clients, get_training_client, get_data_client
|
||||
from shared.clients import get_service_clients, get_training_client, get_sales_client
|
||||
from shared.database.base import create_database_manager
|
||||
from app.core.config import settings
|
||||
|
||||
@@ -30,7 +30,7 @@ class ModelClient:
|
||||
|
||||
# Option 2: Get specific clients
|
||||
# self.training_client = get_training_client(settings, "forecasting")
|
||||
# self.data_client = get_data_client(settings, "forecasting")
|
||||
# self.sales_client = get_sales_client(settings, "forecasting")
|
||||
|
||||
async def get_available_models(
|
||||
self,
|
||||
|
||||
@@ -409,7 +409,9 @@ class PredictionService:
|
||||
# Traffic-based features
|
||||
'high_traffic': int(traffic > 150) if traffic > 0 else 0,
|
||||
'low_traffic': int(traffic < 50) if traffic > 0 else 0,
|
||||
'traffic_normalized': float((traffic - 100) / 50) if traffic > 0 else 0.0,
|
||||
# Fix: Use same normalization as training (when std=0, normalized=0.0)
|
||||
# Training uses constant 100.0 values, so std=0 and normalized=0.0
|
||||
'traffic_normalized': 0.0, # Match training behavior for consistent predictions
|
||||
'traffic_squared': traffic ** 2,
|
||||
'traffic_log': float(np.log1p(traffic)),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user