Improve the traffic fetching system
This commit is contained in:
@@ -317,7 +317,53 @@ class DataServiceClient(BaseServiceClient):
|
||||
else:
|
||||
logger.error("Failed to fetch traffic data - _make_request returned None")
|
||||
logger.error("This could be due to: network timeout, HTTP error, authentication failure, or service unavailable")
|
||||
return []
|
||||
return None
|
||||
|
||||
async def get_stored_traffic_data_for_training(
|
||||
self,
|
||||
tenant_id: str,
|
||||
start_date: str,
|
||||
end_date: str,
|
||||
latitude: Optional[float] = None,
|
||||
longitude: Optional[float] = None
|
||||
) -> Optional[List[Dict[str, Any]]]:
|
||||
"""
|
||||
Get stored traffic data specifically for model training/re-training
|
||||
This method prioritizes database-stored data over API calls
|
||||
"""
|
||||
# Prepare request payload
|
||||
payload = {
|
||||
"start_date": start_date,
|
||||
"end_date": end_date,
|
||||
"latitude": latitude or 40.4168, # Default Madrid coordinates
|
||||
"longitude": longitude or -3.7038,
|
||||
"stored_only": True # Flag to indicate we want stored data only
|
||||
}
|
||||
|
||||
logger.info(f"Training traffic data request: {payload}", tenant_id=tenant_id)
|
||||
|
||||
# Standard timeout since we're only querying the database
|
||||
training_timeout = httpx.Timeout(
|
||||
connect=30.0,
|
||||
read=120.0, # 2 minutes should be enough for database query
|
||||
write=30.0,
|
||||
pool=30.0
|
||||
)
|
||||
|
||||
result = await self._make_request(
|
||||
"POST",
|
||||
"traffic/stored", # New endpoint for stored traffic data
|
||||
tenant_id=tenant_id,
|
||||
data=payload,
|
||||
timeout=training_timeout
|
||||
)
|
||||
|
||||
if result:
|
||||
logger.info(f"Successfully retrieved {len(result)} stored traffic records for training")
|
||||
return result
|
||||
else:
|
||||
logger.warning("No stored traffic data available for training")
|
||||
return None
|
||||
|
||||
# ================================================================
|
||||
# PRODUCTS
|
||||
|
||||
Reference in New Issue
Block a user