Skip to content

Commit

Permalink
feat: #204 global endpoint for dashboard rankings
Browse files Browse the repository at this point in the history
  • Loading branch information
marthevienne committed Dec 16, 2024
1 parent 83553f3 commit 5a7b7db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backend/bloom/routers/v1/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions backend/bloom/services/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,25 @@ 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"
),
)
.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:
Expand Down

0 comments on commit 5a7b7db

Please sign in to comment.