Add robot statistics UI - #2826
Conversation
a99fa6b to
18e6c4c
Compare
Response models for an upcoming robot-scoped statistics endpoint: mission run/success counts, task completion, and a per-week mission trend. SuccessRate is a 0-1 fraction that counts Successful and PartiallySuccessful runs as successes.
Introduce IStatisticsService/StatisticsService computing per-robot completed-mission and task success statistics plus weekly mission counts over a time window, honouring installation access control. Register it as a scoped service. Consumed by an upcoming statistics endpoint and the redesigned robot page.
Expose GET statistics/robots/{robotId}/missions returning the
aggregated RobotStatisticsResponse for a creation-time window
(minCreationTime/maxCreationTime as epoch seconds). Both bounds are
required and access is scoped to the caller's readable installations
via StatisticsService.
Cover the robot statistics endpoint against a real Postgres container: completed-only mission counts and success rate, task aggregation, creation-time window exclusion, weekly bucketing, empty results, and request validation.
Mirror the backend RobotStatisticsResponse DTO and add a getRobotStatistics client method that queries the statistics endpoint with a Unix-second creation-time window.
Add a "Performance" section to the robot page backed by the new statistics endpoint: mission success, task completion, and missions-per-week over the last 30 days, drawn with inline SVG charts (no new dependencies). Redesign the page around a NavBar, breadcrumb, hero and metrics cards, and restyle documentation as a strip. Build everything from EDS Card and Typography. Add English and Norwegian strings.
18e6c4c to
571bebc
Compare
There was a problem hiding this comment.
Pull request overview
Adds robot performance statistics end-to-end: a new backend aggregation endpoint (with DTOs and integration tests) plus a redesigned Robot page section that renders mission/task success and weekly mission counts using inline SVG charts and new translations.
Changes:
- Backend: introduce
GET statistics/robots/{robotId}/missionswith role-filtered aggregation of mission/task outcomes and weekly buckets. - Frontend: add a robot-scoped Performance section (donut + bar charts) driven by a new React Query hook and model.
- UI/UX: restructure Robot page layout around
NavBar, breadcrumb/hero cards, and restyle the documentation list; add EN/NO translations.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/pages/RobotPage/RobotStatistics/WeeklyBarChart.tsx | New inline-SVG weekly bar chart for missions-per-week. |
| frontend/src/pages/RobotPage/RobotStatistics/RobotStatisticsSection.tsx | New Performance section composing charts and summary stats for a robot. |
| frontend/src/pages/RobotPage/RobotStatistics/DonutChart.tsx | New inline-SVG donut chart used for success/completion rates. |
| frontend/src/pages/RobotPage/RobotPage.tsx | Redesign robot page layout (NavBar, breadcrumb, hero/actions, metrics) and adds statistics section. |
| frontend/src/pages/RobotPage/Documentation.tsx | Restyles documentation list into a compact card/strip layout. |
| frontend/src/models/RobotStatistics.ts | Adds frontend model for robot statistics response payload. |
| frontend/src/language/no.json | Adds Norwegian translations for new performance/statistics/documentation labels. |
| frontend/src/language/en.json | Adds English translations for new performance/statistics/documentation labels. |
| frontend/src/hooks/useRobotStatistics.tsx | New React Query hook to fetch robot statistics over a fixed time window. |
| frontend/src/api/BackendApi.tsx | Adds getRobotStatistics API call to the frontend backend client. |
| backend/api/Services/StatisticsService.cs | Implements aggregation logic for mission/task outcomes and weekly mission counts. |
| backend/api/Program.cs | Registers IStatisticsService in DI container. |
| backend/api/Controllers/StatisticsController.cs | Adds statistics endpoint, validation, and authorization. |
| backend/api/Controllers/Models/WeeklyMissionCountResponse.cs | DTO for weekly mission count bucket. |
| backend/api/Controllers/Models/TaskStatisticsResponse.cs | DTO for aggregated task statistics. |
| backend/api/Controllers/Models/RobotStatisticsResponse.cs | DTO for robot statistics response envelope. |
| backend/api/Controllers/Models/MissionStatisticsResponse.cs | DTO for aggregated mission statistics. |
| backend/api.test/Controllers/StatisticsControllerTests.cs | Integration tests validating endpoint behavior and bucketing semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ratioCaption={TranslateText('missions successful / run')} | ||
| successLegend={TranslateText('successful')} | ||
| restCount={missionsUnsuccessful} | ||
| restLegend={TranslateText('failed / aborted')} |
| <HeadingTitle>{TranslateText('Performance')}</HeadingTitle> | ||
| <HeadingSubtitle>{`· ${TranslateText('Last 30 days')}`}</HeadingSubtitle> | ||
| </SectionHeading> |
| const barWidth = Math.min(slotWidth * 0.5, MAX_BAR_WIDTH) | ||
|
|
||
| return ( | ||
| <StyledSvg viewBox={`0 0 ${WIDTH} ${HEIGHT}`} role="img" aria-label="Completed missions per week"> |
| } | ||
| if (maxCreationTime < minCreationTime) | ||
| { | ||
| return BadRequest("Max CreationTime cannot be less than min CreationTime"); |
| .Where(m => CompletedMissionStatuses.Contains(m.Status)) | ||
| .Where(m => | ||
| accessibleInstallationCodes.Contains( | ||
| m.InspectionArea.Installation.InstallationCode.ToUpper() |
andchiind
left a comment
There was a problem hiding this comment.
The information to calculate these statistics is already available on the frontend, I don't really see the point of doing these calculations on the backend. I think for a low priority task, it's benefitial to try to keep it as simple as possible. This PR seems to work well, but I am worried that the amount of added complexity will make maintaining it more costly.

Summary
GET statistics/robots/{robotId}/missionsendpoint (controller + service + DTOs, integration-tested) aggregating mission/task outcomes and weekly mission counts over a time window.NavBar, a breadcrumb, and hero/metrics cards built from EDSCard/Typography.Notes
Successful+PartiallySuccessful; mission totals count completed runs only.