Fix issues

This commit is contained in:
Urtzi Alfaro
2025-08-17 10:28:58 +02:00
parent 8914786973
commit 109961ef6e
10 changed files with 450 additions and 176 deletions

View File

@@ -192,4 +192,35 @@ class TrafficRepository:
except Exception as e:
logger.error("Failed to retrieve traffic data for training",
error=str(e), location_id=location_id)
raise DatabaseError(f"Training data retrieval failed: {str(e)}")
raise DatabaseError(f"Training data retrieval failed: {str(e)}")
async def get_recent_by_location(
self,
latitude: float,
longitude: float,
cutoff_datetime: datetime,
tenant_id: Optional[str] = None
) -> List[TrafficData]:
"""Get recent traffic data by location after a cutoff datetime"""
try:
location_id = f"{latitude:.4f},{longitude:.4f}"
stmt = select(TrafficData).where(
and_(
TrafficData.location_id == location_id,
TrafficData.date >= cutoff_datetime
)
).order_by(TrafficData.date.desc())
result = await self.session.execute(stmt)
records = result.scalars().all()
logger.info("Retrieved recent traffic data",
location_id=location_id, count=len(records),
cutoff=cutoff_datetime.isoformat())
return records
except Exception as e:
logger.error("Failed to retrieve recent traffic data",
error=str(e), location_id=f"{latitude:.4f},{longitude:.4f}")
raise DatabaseError(f"Recent traffic data retrieval failed: {str(e)}")