Compare commits

...
3 Commits
Author SHA1 Message Date
Alexander Heldt 35275e6c2c Step the sleep and walk trend charts by clock hour
Both charts walked the day in fixed hours from midnight, so on a DST day
the curve ended at 23:00 (autumn) or 01:00 the next day (spring), cutting
or padding that day's total and its share of the average, and today's
line ended an hour off the now marker, which reads the clock. Step through
the day with clockHourTs and plot points at their clock hour instead.
2026-10-28 20:03:22 +00:00
Alexander Heldt a7d3575474 Round the puppy's age in days instead of flooring it
The days between two local midnights are an hour short of whole days
once a spring DST switch falls between them, so flooring dropped a day
from the age (and ticked weeks and months over a day late) until the
autumn switch evened it out.
2026-10-28 20:03:17 +00:00
Alexander Heldt e2369f3a3e Place actogram bars by clock time so DST days fit the row
On the day the clocks go back the day is 25 hours long, and bars were
positioned by elapsed time over a fixed 24h, so everything after 3 am
was drawn an hour late and the evening sleep ran past the row's end.
Position bars and the now marker by wall-clock time instead.
2026-10-28 19:54:31 +00:00
2 changed files with 55 additions and 14 deletions

No files matched your search

+52 -14
View File
@@ -281,7 +281,9 @@
const birth = startOfDay(new Date(y, mo - 1, d)); const birth = startOfDay(new Date(y, mo - 1, d));
const ref = startOfDay(new Date(Number.isFinite(at) ? at : Date.now())); const ref = startOfDay(new Date(Number.isFinite(at) ? at : Date.now()));
if (birth > ref) return null; if (birth > ref) return null;
const days = Math.floor((ref - birth) / 86_400_000); // Rounded, not floored: between local midnights a spring DST switch makes
// the span an hour short of whole days, and flooring would drop a day.
const days = Math.round((ref - birth) / 86_400_000);
const weeks = Math.floor(days / 7); const weeks = Math.floor(days / 7);
let months = (ref.getFullYear() - birth.getFullYear()) * 12 + let months = (ref.getFullYear() - birth.getFullYear()) * 12 +
(ref.getMonth() - birth.getMonth()); (ref.getMonth() - birth.getMonth());
@@ -290,7 +292,7 @@
// Whole weeks left over after the calendar months (so "N months and M weeks"). // Whole weeks left over after the calendar months (so "N months and M weeks").
const anchor = startOfDay(new Date(birth.getFullYear(), const anchor = startOfDay(new Date(birth.getFullYear(),
birth.getMonth() + months, birth.getDate())); birth.getMonth() + months, birth.getDate()));
const remWeeks = Math.floor((ref - anchor) / 86_400_000 / 7); const remWeeks = Math.floor(Math.round((ref - anchor) / 86_400_000) / 7);
return { days, weeks, months, remWeeks }; return { days, weeks, months, remWeeks };
} }
@@ -2829,8 +2831,34 @@
// Where "now" falls in the day, 0..1 — the shared x for the charts that run // Where "now" falls in the day, 0..1 — the shared x for the charts that run
// midnight to midnight. // midnight to midnight.
function nowDayFraction() { function nowDayFraction() {
const now = new Date(); return clockDayFraction(Date.now());
return (now.getTime() - startOfDay(now).getTime()) / 86_400_000; }
// Wall-clock time of day as 0..1, read off the clock rather than counted
// from midnight, so a 23- or 25-hour day (the DST switches) still fits the
// 0h–24h axis: the hour that repeats in autumn is drawn over itself and the
// hour skipped in spring is just a gap.
function clockDayFraction(ts) {
const d = new Date(ts);
return (d.getHours() * 3_600_000 + d.getMinutes() * 60_000 +
d.getSeconds() * 1000 + d.getMilliseconds()) / 86_400_000;
}
// The instant the clock reads h:00 on the day starting at dayStart; h = 24
// is the next midnight. On a DST day this is not dayStart + h hours, so the
// hour-of-day charts step through the day with this rather than adding up
// fixed hours. (A skipped hour lands on the next one; a repeated one on its
// first pass.)
function clockHourTs(dayStart, h) {
const d = new Date(dayStart);
d.setHours(h, 0, 0, 0);
return d.getTime();
}
// Hour of day 0..24 by the clock for a time within the day starting at
// dayStart, with the next midnight as 24 rather than 0.
function clockHourOf(ts, dayStart) {
return ts >= clockHourTs(dayStart, 24) ? 24 : clockDayFraction(ts) * 24;
} }
// Vertical "now" rule for those charts: ink over a surface-coloured underlay // Vertical "now" rule for those charts: ink over a surface-coloured underlay
@@ -2870,7 +2898,6 @@
const rowGap = N <= 31 ? 2 : N <= 90 ? 1 : 0; const rowGap = N <= 31 ? 2 : N <= 90 ? 1 : 0;
const H = MT + MB + N * rowH + (N - 1) * rowGap; const H = MT + MB + N * rowH + (N - 1) * rowGap;
svg.setAttribute("viewBox", `0 0 ${W} ${H}`); svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
const dayMs = 86_400_000;
// Rows thinner than the text get a label only every so often — enough // Rows thinner than the text get a label only every so often — enough
// rows apart that labels don't overlap — counted back from the last day. // rows apart that labels don't overlap — counted back from the last day.
const labelEvery = Math.max(1, Math.ceil(11 / (rowH + rowGap))); const labelEvery = Math.max(1, Math.ceil(11 / (rowH + rowGap)));
@@ -2907,8 +2934,12 @@
const s = Math.max(wdw.start, dayStart); const s = Math.max(wdw.start, dayStart);
const e = Math.min(wdw.end, dayEnd); const e = Math.min(wdw.end, dayEnd);
if (e <= s) continue; if (e <= s) continue;
const x = xOf((s - dayStart) / dayMs); // Placed by clock time, not elapsed time, so a DST day lines up with
const wpx = ((e - s) / dayMs) * innerW; // the hour gridlines; a window ending at the next midnight runs to 24h.
const fs = clockDayFraction(s);
const fe = e >= dayEnd ? 1 : clockDayFraction(e);
const x = xOf(fs);
const wpx = (fe - fs) * innerW;
parts.push(`<rect class="${barCls}" x="${x.toFixed(1)}" y="${y.toFixed(1)}" width="${Math.max(0.6, wpx).toFixed(1)}" height="${rowH.toFixed(1)}" rx="1.5"/>`); parts.push(`<rect class="${barCls}" x="${x.toFixed(1)}" y="${y.toFixed(1)}" width="${Math.max(0.6, wpx).toFixed(1)}" height="${rowH.toFixed(1)}" rx="1.5"/>`);
} }
} }
@@ -2961,7 +2992,7 @@
// guess; walks are decisions, and projecting them would be predicting the // guess; walks are decisions, and projecting them would be predicting the
// handler, not the dog. // handler, not the dog.
function walkTrendCurves(events) { function walkTrendCurves(events) {
const HOUR = 3_600_000, MIN = 60_000, DAY = 86_400_000; const MIN = 60_000;
const windows = walkWindows(events); // an ongoing walk is already clipped to now const windows = walkWindows(events); // an ongoing walk is already clipped to now
const walkedMs = (from, to) => { const walkedMs = (from, to) => {
let total = 0; let total = 0;
@@ -2980,13 +3011,20 @@
return d; return d;
}; };
const dayStartTs = (daysAgo) => dayAgo(daysAgo).getTime(); const dayStartTs = (daysAgo) => dayAgo(daysAgo).getTime();
const pointsAt = (start, stops) => // x is the clock hour, held from stepping back inside the hour that
stops.map(t => ({ x: (t - start) / HOUR, y: walkedMs(start, t) / MIN })); // repeats when the clocks go back, so the step line never folds over.
const pointsAt = (start, stops) => {
let lastX = 0;
return stops.map(t => {
lastX = Math.max(lastX, clockHourOf(t, start));
return { x: lastX, y: walkedMs(start, t) / MIN };
});
};
// Every boundary falling inside the day, plus the day's two ends, is a // Every boundary falling inside the day, plus the day's two ends, is a
// corner of the step line. capTs (today only) ends it at "now". // corner of the step line. capTs (today only) ends it at "now".
const curveFor = (start, capTs) => { const curveFor = (start, capTs) => {
const end = capTs != null ? capTs : start + DAY; const end = capTs != null ? capTs : clockHourTs(start, 24);
const stops = new Set([start, end]); const stops = new Set([start, end]);
for (const w of windows) { for (const w of windows) {
if (w.end <= start || w.start >= end) continue; if (w.end <= start || w.start >= end) continue;
@@ -2997,7 +3035,7 @@
}; };
const hourlyFor = (start) => { const hourlyFor = (start) => {
const stops = []; const stops = [];
for (let h = 0; h <= 24; h++) stops.push(start + h * HOUR); for (let h = 0; h <= 24; h++) stops.push(clockHourTs(start, h));
return pointsAt(start, stops); return pointsAt(start, stops);
}; };
const totalOf = (pts) => pts[pts.length - 1].y; const totalOf = (pts) => pts[pts.length - 1].y;
@@ -3241,9 +3279,9 @@
const curveFor = (start, capTs) => { const curveFor = (start, capTs) => {
const pts = []; const pts = [];
for (let h = 0; h <= 24; h++) { for (let h = 0; h <= 24; h++) {
const to = start + h * HOUR; const to = clockHourTs(start, h);
if (capTs != null && to >= capTs) { if (capTs != null && to >= capTs) {
pts.push({ x: (capTs - start) / HOUR, y: sleptMs(start, capTs) / HOUR }); pts.push({ x: clockHourOf(capTs, start), y: sleptMs(start, capTs) / HOUR });
break; break;
} }
pts.push({ x: h, y: sleptMs(start, to) / HOUR }); pts.push({ x: h, y: sleptMs(start, to) / HOUR });
+3
View File
@@ -1,4 +1,7 @@
[ [
{ "date": "2026-10-28", "text": "The Sleep trend and Walk trend charts handle the days the clocks change. Their hour axis counted hours from midnight rather than reading the clock, so on the Sunday the clocks go back the day’s line stopped at 11 pm and left out the last hour — taking it off that day’s total and off the average day built from it — and in spring the day ran on into 1 am the next morning. Today’s line also ended an hour away from the “now” marker on those days. Both charts now follow the clock, so every day runs from midnight to midnight whatever its length" },
{ "date": "2026-10-28", "text": "His age is no longer a day short for part of the year. Depending on when he was born, counting the days since his birthday could come up one short between the clocks going forward in spring and going back in autumn, and the week and month counts in “16 weeks (3 months and 3 weeks) old” ticked over a day late" },
{ "date": "2026-10-28", "text": "The When sleeping and When walking grids draw the days the clocks change correctly. On the Sunday the clocks go back the day is 25 hours long, and everything after 3 am was drawn an hour late — the evening sleep ran off the right-hand end of the row. In spring the 23-hour day stopped short of 24h instead. Each nap and walk now sits at the time the clock showed, lining up with the hour lines like every other day, and the “now” marker does the same on those days" },
{ "date": "2026-10-03", "text": "The charts can cover any stretch of dates, not just the last 7, 14 or 30 days. Tap Custom on the “Charts cover” row and pick a from and a to date — up to a year at a time, and the to date can be in the past, so you can look back at, say, May on its own and see how much he slept or walked then. Every chart and panel that follows the 7 / 14 / 30 buttons follows the custom dates too, and their headings and trend sentences name the dates (“Over May 1 – Jun 15, daily sleep is down about 2h”). On a long range the daily bars sit edge to edge and the axis shows dates instead of weekdays, and the When sleeping and When walking grids use thinner rows so a few months still fit on the screen. The “average day” line on the Sleep trend and Walk trend is averaged over the custom dates as well. Tapping 7d, 14d or 30d goes back to the rolling window, and Custom remembers the dates you picked last" }, { "date": "2026-10-03", "text": "The charts can cover any stretch of dates, not just the last 7, 14 or 30 days. Tap Custom on the “Charts cover” row and pick a from and a to date — up to a year at a time, and the to date can be in the past, so you can look back at, say, May on its own and see how much he slept or walked then. Every chart and panel that follows the 7 / 14 / 30 buttons follows the custom dates too, and their headings and trend sentences name the dates (“Over May 1 – Jun 15, daily sleep is down about 2h”). On a long range the daily bars sit edge to edge and the axis shows dates instead of weekdays, and the When sleeping and When walking grids use thinner rows so a few months still fit on the screen. The “average day” line on the Sleep trend and Walk trend is averaged over the custom dates as well. Tapping 7d, 14d or 30d goes back to the rolling window, and Custom remembers the dates you picked last" },
{ "date": "2026-10-01", "text": "The app opens straight away when you have no connection. It used to check in with the server before showing anything, and on a weak signal or with the server out of reach that check could take a long while to give up, leaving a blank screen even though all your data was already on the phone. It now opens on the account you were last signed in to and checks in the background; if that sign-in has run out you are taken to the login screen as before" }, { "date": "2026-10-01", "text": "The app opens straight away when you have no connection. It used to check in with the server before showing anything, and on a weak signal or with the server out of reach that check could take a long while to give up, leaving a blank screen even though all your data was already on the phone. It now opens on the account you were last signed in to and checks in the background; if that sign-in has run out you are taken to the login screen as before" },
{ "date": "2026-09-30", "text": "The Waking → pee and Meal → poo rows are gone from the Timing panel again. With a puppy who takes lots of short naps, most wake-ups were followed by another nap before any pee, so Waking → pee was built from a handful of odd cases and was hard to make sense of. The Pees, Poos and Meals rows are unchanged" }, { "date": "2026-09-30", "text": "The Waking → pee and Meal → poo rows are gone from the Timing panel again. With a puppy who takes lots of short naps, most wake-ups were followed by another nap before any pee, so Waking → pee was built from a handful of odd cases and was hard to make sense of. The Pees, Poos and Meals rows are unchanged" },