Fix data fetch
This commit is contained in:
@@ -94,10 +94,14 @@ class DataServiceClient:
|
||||
headers = service_auth.get_request_headers(tenant_id)
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
|
||||
params = {strta date, end date, lat, long }
|
||||
|
||||
async with httpx.AsyncClient(timeout=self.timeout) as client:
|
||||
response = await client.get(
|
||||
f"{self.base_url}/api/v1/tenants/{tenant_id}/weather/history",
|
||||
headers=headers
|
||||
headers=headers,
|
||||
params=params,
|
||||
timeout=30.0
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
|
||||
@@ -176,6 +176,7 @@ class TrainingService:
|
||||
# Publish completion event
|
||||
await publish_job_completed(job_id, tenant_id, training_results)
|
||||
|
||||
logger.info(f"Training results {training_results}")
|
||||
logger.info(f"Training job {job_id} completed successfully")
|
||||
metrics.increment_counter("training_jobs_completed")
|
||||
|
||||
@@ -207,17 +208,16 @@ class TrainingService:
|
||||
|
||||
# Fetch data
|
||||
sales_data = await self._fetch_product_sales_data(tenant_id, product_name, request)
|
||||
|
||||
weather_data = []
|
||||
traffic_data = []
|
||||
|
||||
if request.include_weather:
|
||||
await self._update_job_status(db, job_id, "running", 30, "Fetching weather data")
|
||||
weather_data = await self._fetch_weather_data(tenant_id, request)
|
||||
weather_data = await self.data_client.fetch_weather_data(tenant_id, request)
|
||||
|
||||
if request.include_traffic:
|
||||
await self._update_job_status(db, job_id, "running", 50, "Fetching traffic data")
|
||||
traffic_data = await self._fetch_traffic_data(tenant_id, request)
|
||||
traffic_data = await self.data_client.fetch_traffic_data(tenant_id, request)
|
||||
|
||||
# Execute training
|
||||
await self._update_job_status(db, job_id, "running", 70, f"Training model for {product_name}")
|
||||
@@ -507,62 +507,6 @@ class TrainingService:
|
||||
logger.error(f"Error fetching product sales data: {str(e)}")
|
||||
return []
|
||||
|
||||
async def _fetch_weather_data(self, tenant_id: str, request: Any) -> List[Dict]:
|
||||
"""Fetch weather data from data service"""
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
params = { }
|
||||
|
||||
if hasattr(request, 'start_date') and request.start_date:
|
||||
params["start_date"] = request.start_date.isoformat()
|
||||
|
||||
if hasattr(request, 'end_date') and request.end_date:
|
||||
params["end_date"] = request.end_date.isoformat()
|
||||
|
||||
response = await client.get(
|
||||
f"{settings.DATA_SERVICE_URL}/tenants/{tenant_id}/weather/history",
|
||||
params=params,
|
||||
timeout=30.0
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
return response.json().get("weather", [])
|
||||
else:
|
||||
logger.warning(f"Failed to fetch weather data: {response.status_code}")
|
||||
return []
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Error fetching weather data: {str(e)}")
|
||||
return []
|
||||
|
||||
async def _fetch_traffic_data(self, tenant_id: str, request: Any) -> List[Dict]:
|
||||
"""Fetch traffic data from data service"""
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
params = { }
|
||||
|
||||
if hasattr(request, 'start_date') and request.start_date:
|
||||
params["start_date"] = request.start_date.isoformat()
|
||||
|
||||
if hasattr(request, 'end_date') and request.end_date:
|
||||
params["end_date"] = request.end_date.isoformat()
|
||||
|
||||
response = await client.get(
|
||||
f"http://gateway:8000/tenants/{tenant_id}/traffic/historical",
|
||||
params=params,
|
||||
timeout=30.0
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
return response.json().get("traffic", [])
|
||||
else:
|
||||
logger.warning(f"Failed to fetch traffic data: {response.status_code}")
|
||||
return []
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Error fetching traffic data: {str(e)}")
|
||||
return []
|
||||
|
||||
async def _store_trained_models(self,
|
||||
db: AsyncSession,
|
||||
tenant_id: str,
|
||||
|
||||
Reference in New Issue
Block a user