Table of Contents
09 — Analysis and trends
Technical reference. For task-based help, see the corresponding user guide.
Documentation status: complete for the current implementation
Reviewed: 2026-07-21
Primary users: premium-enabled families and assigned coaches with analysis access
Surfaces: mobile web app and platform API
Purpose
Analysis turns a baby's raw care records into totals, averages and time-based plots. Users can inspect all visible trackers together or focus on one, move between comparable date ranges and open an underlying activity to correct it. The feature is permission- and premium-gated; ordinary tracking remains available without it.
Entry points
| Context | Route |
|---|---|
| Family self-mode | /analysis |
| Coach phone view-as | /coach/families/:familyId/analysis with optional babyId |
The Analysis navigation contains All-in-one, Sleep, Breastfeed, Bottles, Nappies, Pumping, Solids and Medication. A family Home preference that hides a tracker also removes that tracker from Analysis navigation and from All-in-one summary contributions; it does not delete its records.
Access gate
The screen first loads the family summary and evaluates summary.access.subject.permissions.canViewAnalysis.
- An inactive family sees the premium-plan explanation and a route to monthly/yearly access.
- A coach sees the subject's current entitlement/permission state and cannot bypass it by using a family ID.
- The API independently checks
canViewAnalysisbefore returning analysis activities. - Development builds currently default
allowInactivePremiumAnalysisto true for local testing. That development override must not be interpreted as production entitlement behavior.
Baby and date controls
The family uses its persisted selected baby. Coach view-as uses a route-local baby choice that does not change the family's setting. With no baby, Analysis shows an add/select-baby state instead of issuing an unscoped query.
| Range | Behavior |
|---|---|
| Single Day | One family-local calendar day; totals are shown and the daily bar plot is omitted. |
| 7 Days | Today plus the preceding six family-local days initially. |
| 14 Days | Today plus the preceding thirteen days. |
| 30 Days | Today plus the preceding twenty-nine days. |
| Custom Range | User-selected inclusive start and end dates; it initially spans seven days. |
Previous/next shifts by the whole visible range: one day for Single Day, the preset length for presets and the inclusive custom-range length for Custom. All query boundaries are converted from family-local dates to UTC instants. Extra plot buffer may be loaded for smooth panning, but summary metrics remain locked to the labelled visible range.
Statistics
Single Day uses totals/counts; multi-day ranges use per-day averages and trends. Selecting any statistic opens a plain-language calculation and meaning explanation.
| View | Current metrics include |
|---|---|
| All-in-one | Feed count and breastfeeding duration, bottle volume, nappy changes, pumping volume and sleep duration for enabled trackers; multi-day equivalents are daily averages. |
| Breastfeed | Feed count and total duration; multi-day average feeds and duration per day. |
| Bottles | Feed count, total/average volume, and breastmilk/formula volume split. |
| Sleep | Nap count plus total day, night and combined sleep; multi-day average day, night and combined duration. |
| Nappies | Total, wet, dirty and mixed counts; multi-day daily averages. |
| Pumping | Session count, total duration and volume; multi-day daily averages. |
| Medication | Dose count and distinct medication count; multi-day average doses and most common medication. |
| Solids | Meal/reaction counts; multi-day average meals, linked stages and reaction rate. Selecting a ladder adds active stage, completion and ladder-specific meal/reaction metrics. |
Most non-sleep daily averages divide by days that contain matching data, rather than treating every blank calendar day as a recorded zero. Sleep averages are stricter: they use days containing both day and night sleep when available; a night-only dataset can use night groups, while incomplete mixed datasets show — instead of a misleading average. Overnight sleep is attributed to the product's sleep day consistently with Home/history.
Bottle and pumping volumes can be displayed in ml or oz. Values entered in mixed units are converted for aggregation without rewriting the source activity.
Charts and interaction
Activity Schedule Plot
All views use a time-of-day schedule plot. Points/bars retain activity type/subtype colors and can span midnight. Solids points identify linked ladder/stage and reaction state. Users can horizontally inspect the buffered date area; the visible date controls and plots remain synchronized.
Selecting a point opens the shared activity edit sheet. A family with write access can save/delete. A coach also needs canWriteActivities; coach updates preserve the family note and are audited. If realtime reports that the activity changed while open, the sheet blocks overwrite until it is reloaded or closed.
Daily bar plot
Multi-day Breastfeed, Bottles, Sleep, Nappies and Pumping views add a per-day bar plot:
- Breastfeed: left/right duration;
- Bottles: breastmilk/formula volume;
- Sleep: day/night duration;
- Nappies: dirty/wet counts (a mixed nappy contributes to each relevant series);
- Pumping: left/right volume.
All-in-one, Medication and Solids have schedule plots but no daily bar dataset in the current implementation. Single Day also omits the daily bar plot.
Loading, empty and error states
| State | Expected behavior |
|---|---|
| Summary loading | Show structured skeletons; do not request analysis before subject/access is known. |
| No baby | Offer the valid family add/select action or coach baby choice. |
| Premium inactive | Show the appropriate plan/access state without exposing analysis data. |
| No matching activities | Render zero/— statistics and empty plots without treating absence as an API failure. |
| Sparse sleep data | Show — when the average would imply completeness that was not logged. |
| Range/nav changing | Retain the stable layout with pending indicators until the matching response arrives. |
| API failure | Show a retryable API error and do not mix results from a previous baby/range into the new labels. |
| Permission changes while editing | Deny the mutation and close/disable write controls after refresh. |
Platform API contract
| Method and path | Role |
|---|---|
GET /families/me | Supplies subject identity, baby selection, visibility preferences, premium state and canViewAnalysis/canWriteActivities. |
GET /analysis/activities | Returns the authorized activity set for client-side statistics and plots. |
PATCH /activities/:id | Correct an activity opened from a chart when write permission is present. |
DELETE /activities/:id | Delete an activity opened from a chart when authorized. |
GET /analysis/activities requires babyId. It optionally accepts authorized familyUserId, activityType, and an ISO from/to pair. If one boundary is supplied without the other, schema validation rejects the request. The response is not cursor-paginated; the client requests the date-bounded dataset needed for the plot/range.
Authorization and data rules
- The platform resolves actor and family subject on every query and mutation.
- Premium entitlement determines analysis access; it does not determine whether the family may continue logging care.
- Coach analysis access and coach write access are separate permissions.
- Hidden Home trackers are a presentation preference, not data deletion or API authorization.
- Statistics are derived from persisted activity details/timezones; the client does not mutate source records to normalize units or dates.
Acceptance checklist
- Production users without
canViewAnalysiscannot load data by navigating directly or calling the API. - Range labels, queries, totals and plots use the family timezone and the same inclusive dates.
- Every statistic exposes a calculation/meaning explanation and handles sparse data honestly.
- Mixed ml/oz data aggregates into the selected display unit without changing source entries.
- Schedule points open the exact underlying activity and stale edits cannot overwrite external changes.
- Daily bars appear only for supported multi-day tracker views.
- Coach reads/writes remain assignment-scoped and preserve family-authored notes.
Source evidence
mobile-web/src/routes/AnalysisScreen.tsxmobile-web/src/analysis/analysis-model.tsmobile-web/src/analysis/analysis-stats.tsmobile-web/src/analysis/analysis-plots.tsmobile-web/src/analysis/analysis-stat-details.tsmobile-web/src/analysis/analysis-units.tsmobile-web/src/components/AnalysisCharts.tsxplatform/apps/api/src/routes/analysis-routes.tsplatform/apps/api/src/services/analysis-service.tsplatform/packages/shared/src/analysis.tsplatform/docs/multi-tenancy/06-existing-app-feature-inventory.md
