Read a layer.
Goal: read the wellness layer of a synthetic twin, understand its shape, read one week of a kind as a series and handle missing days without inventing values.
STEP 1 Read the layer#
Any twin with data works: one of the 8 synthetic twins your project came with, or the twin from tutorial 01. The outputs below come from the tutorial twin after tutorial 03 and tutorial 04 sent it a week of synthetic observations.
curl "$API/twins/$TWIN/layers/wellness" -H "Authorization: Bearer $STARCO_KEY"layer = requests.get(f"{API}/twins/{twin_id}/layers/wellness", headers=H).json()import { Client } from '@starco/sdk';
const c = new Client({ baseUrl: "https://api.starco.dev/v1", apiKey: process.env.STARCO_KEY });
const twinId = process.env.TWIN; // the id of the twin: export TWIN=… as in tutorial 01
const layer = await c.twins.layer(twinId, "wellness");starco layer <twin> wellnessSTEP 2 Understand the shape#
{ "twin_id": "3a9d5e2c-8b14-4f7a-a6d1-c2e09f4b7d31", "layer": "wellness", "template": "daily_movement",
"computed_at": "2026-11-19T15:46:10Z", "observation_count": 16,
"description": "Descriptive values of the observations received: no reference range, no interpretation, no score. Null means no data.",
"kinds": [
{ "kind": "exercise_minutes", "unit": "min", "count": 0, "latest": null, "min": null, "max": null,
"mean": null, "mean_last_7_days": null, "first_observed_at": null, "last_observed_at": null },
{ "kind": "steps", "unit": "steps", "count": 7,
"latest": { "value": 7765, "observed_at": "2026-11-18T21:00:00Z" },
"min": 5880, "max": 10240, "mean": 7956.4286, "mean_last_7_days": 7956.4286,
"first_observed_at": "2026-11-12T21:00:00Z", "last_observed_at": "2026-11-18T21:00:00Z" },
…,
{ "kind": "sleep_hours", "unit": "h", "count": 6,
"latest": { "value": 7.7, "observed_at": "2026-11-18T07:00:00Z" },
"min": 6.8, "max": 8, "mean": 7.3833, "mean_last_7_days": 7.3833,
"first_observed_at": "2026-11-12T07:00:00Z", "last_observed_at": "2026-11-18T07:00:00Z" },
{ "kind": "hydration_glasses", "unit": "glasses", "count": 3, … },
… ] }- computed_at
- When the layer was last recomputed: after the last batch that touched it.
- observation_count
- How many observations the layer holds, over all its kinds.
- kinds[]
- One entry per kind of the layer, in the template's order:
count,latest(value and time),min,max,mean(rounded to 4 decimals),mean_last_7_days(the 7 days that end at the kind's latest observation),first_observed_atandlast_observed_at. Nothing more: no scores, no normal or high or low.
STEP 3 Handle null honestly#
exercise_minutes was never sent: count is 0 and every value is null. If you turn null into 0, a chart shows a day with no exercise that nobody recorded. Keep it as «no data» all the way to the screen.
for k in layer["kinds"]:
if k["count"] == 0:
print(f"{k['kind']}: no data")
else:
print(f"{k['kind']}: {k['count']} observations, mean {k['mean']} {k['unit']}")curl -s "$API/twins/$TWIN/layers/wellness" -H "Authorization: Bearer $STARCO_KEY" \
| jq -r '.kinds[] | select(.count > 0) | "\(.kind) \(.count) \(.mean)"'for (const k of layer.kinds) {
console.log(k.count === 0 ? `${k.kind}: no data` : `${k.kind}: ${k.count} observations, mean ${k.mean} ${k.unit}`);
}starco --json layer <twin> wellness | jq -r '.kinds[] | select(.count > 0) | "\(.kind) \(.count) \(.mean)"'exercise_minutes: no data
steps: 7 observations, mean 7956.4286 steps
sitting_breaks: no data
…
sleep_hours: 6 observations, mean 7.3833 hSTEP 4 Read a week as a series#
The layer summarises; the series gives every observation. Filter by kind, from (inclusive) and to (exclusive), RFC 3339 with an offset.
curl "$API/twins/$TWIN/observations?kind=sleep_hours&from=2026-11-12T00:00:00Z&to=2026-11-19T00:00:00Z" \
-H "Authorization: Bearer $STARCO_KEY"series = requests.get(f"{API}/twins/{twin_id}/observations", headers=H, params={
"kind": "sleep_hours", "from": "2026-11-12T00:00:00Z", "to": "2026-11-19T00:00:00Z"}).json()["data"]const series = await c.observations.list(twinId, {
kind: "sleep_hours", from: "2026-11-12T00:00:00Z", to: "2026-11-19T00:00:00Z" });starco obs list <twin> --kind sleep_hours --from 2026-11-12T00:00:00Z --to 2026-11-19T00:00:00Z{ "twin_id": "3a9d5e2c-8b14-4f7a-a6d1-c2e09f4b7d31",
"data": [ { "kind": "sleep_hours", "value": 7.2, "unit": "h", "observed_at": "2026-11-12T07:00:00Z", "origin": "api" },
{ "kind": "sleep_hours", "value": 6.8, "unit": "h", "observed_at": "2026-11-13T07:00:00Z", "origin": "api" },
{ "kind": "sleep_hours", "value": 7.5, "unit": "h", "observed_at": "2026-11-15T07:00:00Z", "origin": "api" },
… ] }The week, drawn
The 14th has no line at all: nothing was recorded that night. The series never fills a gap.
STEP 5 Print a small table, gaps included#
from datetime import date, timedelta
by_day = {o["observed_at"][:10]: o["value"] for o in series}
start = date(2026, 11, 12)
for i in range(7):
d = (start + timedelta(days=i)).isoformat()
v = by_day.get(d)
print(d, f"{int(v)} h {round(v % 1 * 60):02d} min" if v is not None else "no data")const byDay = Object.fromEntries(series.map((o) => [o.observed_at.slice(0, 10), o.value]));
for (let i = 0; i < 7; i++) {
const d = new Date(Date.UTC(2026, 10, 12 + i)).toISOString().slice(0, 10);
const v = byDay[d];
console.log(d, v === undefined ? "no data" : `${Math.trunc(v)} h ${String(Math.round((v % 1) * 60)).padStart(2, "0")} min`);
}2026-11-12 7 h 12 min
2026-11-13 6 h 48 min
2026-11-14 no data
2026-11-15 7 h 30 min
2026-11-16 7 h 06 min
2026-11-17 8 h 00 min
2026-11-18 7 h 42 minWhat just happened
You read the wellness layer, recomputed by STARCO after the last batch: descriptive values per kind, with null where there were no observations. Then you read the series of one kind and kept the missing night as «no data» all the way to the screen. Both reads are rows of the project's audit chain (layers.show and observations.index).