diff --git a/backend/bloom/routers/v1/metrics.py b/backend/bloom/routers/v1/metrics.py index b86827e4..4cd3afbf 100644 --- a/backend/bloom/routers/v1/metrics.py +++ b/backend/bloom/routers/v1/metrics.py @@ -125,7 +125,7 @@ async def read_metrics_all_vessels_visiting_time_by_zone(request: Request, return jsonable_encoder(payload) -@router.get("/metrics/vessels-activity/{category}") +@router.get("/metrics/vessels-activity") # @cache async def read_metrics_all_vessels_visiting_time_in_zones( request: Request, @@ -147,7 +147,7 @@ async def read_metrics_all_vessels_visiting_time_in_zones( return jsonable_encoder(payload) -@router.get("/metrics/zones-visited/{category}") +@router.get("/metrics/zones-visited") # @cache async def read_metrics_all_zones_visited( request: Request, diff --git a/backend/bloom/services/metrics.py b/backend/bloom/services/metrics.py index b9d11351..b1909d35 100644 --- a/backend/bloom/services/metrics.py +++ b/backend/bloom/services/metrics.py @@ -87,7 +87,7 @@ def get_vessels_activity_in_zones( with self.session_factory() as session: stmt = ( select( - sql_model.Vessel, + sql_model.Vessel, func.sum(sql_model.Metrics.duration_total).label( "total_time_in_zones" ), @@ -95,14 +95,17 @@ def get_vessels_activity_in_zones( .select_from(sql_model.Metrics) .join( sql_model.Vessel, - sql_model.Vessel.id == sql_model.Metrics.vessel_id, + sql_model.Metrics.vessel_id == sql_model.Vessel.id, + isouter=True, ) .where( sql_model.Metrics.timestamp.between( datetime_range.start_at, datetime_range.end_at ) ) - .group_by(sql_model.Vessel) + .group_by( + sql_model.Vessel + ) ) stmt = stmt.offset(pagination.offset) if pagination.offset != None else stmt if category: