Fix issues
This commit is contained in:
@@ -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)}")
|
||||
Reference in New Issue
Block a user