Add POI feature and imporve the overall backend implementation

This commit is contained in:
Urtzi Alfaro
2025-11-12 15:34:10 +01:00
parent e8096cd979
commit 5783c7ed05
173 changed files with 16862 additions and 9078 deletions

View File

@@ -58,7 +58,17 @@ class DataIngestionManager:
failures=failures
)
return successes == len(results)
# Consider success if we have at least some cities initialized (majority success)
# This allows the system to continue even if some external APIs are temporarily unavailable
if successes > 0:
logger.info(
"Partial success achieved - continuing with available data",
success_ratio=f"{successes}/{len(results)}"
)
return True
else:
logger.error("All city initializations failed - system cannot proceed")
return False
async def initialize_city(
self,
@@ -123,23 +133,55 @@ class DataIngestionManager:
logger.error("Adapter validation failed", city=city.name)
return False
weather_data = await adapter.fetch_historical_weather(
start_date, end_date
)
# Fetch data with error handling to allow partial success
weather_data = []
traffic_data = []
# Fetch weather data
try:
weather_data = await adapter.fetch_historical_weather(
start_date, end_date
)
logger.info("Weather data fetched successfully",
records=len(weather_data), city=city.name)
except Exception as weather_error:
logger.error("Failed to fetch weather data",
city=city.name, error=str(weather_error))
# Don't return False here - continue with whatever data we can get
traffic_data = await adapter.fetch_historical_traffic(
start_date, end_date
)
# Fetch traffic data
try:
traffic_data = await adapter.fetch_historical_traffic(
start_date, end_date
)
logger.info("Traffic data fetched successfully",
records=len(traffic_data), city=city.name)
except Exception as traffic_error:
logger.error("Failed to fetch traffic data",
city=city.name, error=str(traffic_error))
# Don't return False here - continue with weather data only if available
# Store available data (at least one type should be available for partial success)
async with self.database_manager.get_session() as session:
repo = CityDataRepository(session)
weather_stored = await repo.bulk_store_weather(
city_id, weather_data
)
traffic_stored = await repo.bulk_store_traffic(
city_id, traffic_data
)
weather_stored = 0
traffic_stored = 0
if weather_data:
weather_stored = await repo.bulk_store_weather(
city_id, weather_data
)
if traffic_data:
traffic_stored = await repo.bulk_store_traffic(
city_id, traffic_data
)
# Only fail if both data types failed to fetch
if not weather_data and not traffic_data:
logger.error("Both weather and traffic data fetch failed", city=city.name)
return False
logger.info(
"City initialization complete",