Improve the design of the frontend 2

This commit is contained in:
Urtzi Alfaro
2025-08-08 23:06:54 +02:00
parent 62ca49d4b8
commit 8af17f1433
12 changed files with 325 additions and 66 deletions

View File

@@ -12,7 +12,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.core.database import get_db
from app.services.traffic_service import TrafficService
from app.services.messaging import data_publisher
from app.services.messaging import data_publisher, publish_traffic_updated
from app.schemas.external import (
TrafficDataResponse,
HistoricalTrafficRequest
@@ -45,7 +45,7 @@ async def get_current_traffic(
# Publish event (with error handling)
try:
await data_publisher.publish_traffic_updated({
await publish_traffic_updated({
"type": "current_requested",
"latitude": latitude,
"longitude": longitude,
@@ -91,7 +91,7 @@ async def get_historical_traffic(
# Publish event (with error handling)
try:
await data_publisher.publish_traffic_updated({
await publish_traffic_updated({
"type": "historical_requested",
"latitude": request.latitude,
"longitude": request.longitude,

View File

@@ -59,7 +59,7 @@ MADRID_BOUNDS = {
}
# Constants
MAX_HISTORICAL_DAYS = 365
MAX_HISTORICAL_DAYS = 1095 # 3 years - allow longer training periods
MAX_CSV_PROCESSING_ROWS = 5000000
MEASUREMENT_POINTS_LIMIT = 20
UTM_ZONE = 30 # Madrid is in UTM Zone 30N

View File

@@ -247,4 +247,7 @@ class DateAlignmentService:
now = datetime.now(timezone.utc)
current_month_start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
# Debug logging
logger.info(f"🔍 Madrid constraint check: end_date={end_date}, current_month_start={current_month_start}, violation={end_date >= current_month_start}")
return end_date >= current_month_start

View File

@@ -283,10 +283,13 @@ class TrainingDataOrchestrator:
# Traffic data collection
if DataSourceType.MADRID_TRAFFIC in aligned_range.available_sources:
logger.info(f"🚛 Traffic data source available, creating collection task for date range: {aligned_range.start} to {aligned_range.end}")
traffic_task = asyncio.create_task(
self._collect_traffic_data_with_timeout(lat, lon, aligned_range, tenant_id)
)
tasks.append(("traffic", traffic_task))
else:
logger.warning(f"🚫 Traffic data source NOT available in sources: {[s.value for s in aligned_range.available_sources]}")
# Execute tasks concurrently with proper error handling
results = {}
@@ -361,9 +364,12 @@ class TrainingDataOrchestrator:
try:
# Double-check Madrid constraint before making request
if self.date_alignment_service.check_madrid_current_month_constraint(aligned_range.end):
logger.warning("Madrid current month constraint violation, no traffic data available")
constraint_violated = self.date_alignment_service.check_madrid_current_month_constraint(aligned_range.end)
if constraint_violated:
logger.warning(f"🚫 Madrid current month constraint violation: end_date={aligned_range.end}, no traffic data available")
return []
else:
logger.info(f"✅ Madrid constraint passed: end_date={aligned_range.end}, proceeding with traffic data request")
start_date_str = aligned_range.start.isoformat()
end_date_str = aligned_range.end.isoformat()