bodyweights: collapse to one row per local day (#30)#53
Conversation
Bodyweight is read off each workout post, so logging two workouts on the same calendar day produced two `bodyweights list` rows for that date (both markdown and JSON). Downstream per-day trend and plateau math then double-counts that day. Deduplicate in loadBodyweightEntries (shared by `list` and `stats`), keeping the latest measurement per local day. This also makes the stats monthly averages one-sample-per-day, which is the intended model: a day has a single bodyweight. Adds tests covering the same-day collision (keep latest) and the no-duplicate passthrough. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
DTTerastar
left a comment
There was a problem hiding this comment.
Verified locally: build, go vet, go test ./... all pass. entry.date is already .Local() before the 2006-01-02 key is taken, so days are bucketed in local time as intended, and the nondeterministic map iteration is harmless since the caller sorts afterward.
On the scope question: keeping the dedupe in the shared loader is right — a day has one bodyweight, so stats monthly averages should use one sample per day too.
On latest-vs-earliest, checked against real data (410 days). 21 days have more than one entry, and 19 of those carry identical values — bodyweight is attached to each post and usually just copied forward, so this isn't repeated measurement. Only 2 days disagree at all:
2025-03-08 08:08 -> 260, 21:08 -> 259
2025-05-20 13:39 -> 258, 15:05 -> 253
Both move downward over the day, which rules out food/water drift and points to the later entry being a correction. "Keep the latest" is the right rule. Nice fix.
Fixes #30.
Problem
Bodyweight is read off each workout post, so logging two workouts on the same calendar day yields two
bodyweights listrows for that date (both markdown and JSON). Per-day trend/plateau analysis then double-counts that day.Fix
Deduplicate in
loadBodyweightEntries(shared bylistandstats), keeping the latest measurement per local day.Scope note
Because the loader is shared,
bodyweights statsmonthly averages now use one sample per day as well. I believe that's the intended model (a day has a single bodyweight), but if you'd rather keep the fix limited tolist, I can move the dedupe into the list command only — happy to adjust.Tests
TestDedupeByDay_KeepsLatestPerDay— two entries on one day collapse to one, keeping the later measurement.TestDedupeByDay_NoDuplicates— distinct days pass through unchanged.go test ./...andgo vet ./...pass.🤖 Generated with Claude Code