Skip to content

bodyweights: collapse to one row per local day (#30)#53

Merged
DTTerastar merged 1 commit into
quantcli:mainfrom
vinistoisr:fix/30-bodyweights-dedupe-by-day
Jul 21, 2026
Merged

bodyweights: collapse to one row per local day (#30)#53
DTTerastar merged 1 commit into
quantcli:mainfrom
vinistoisr:fix/30-bodyweights-dedupe-by-day

Conversation

@vinistoisr

Copy link
Copy Markdown
Contributor

Fixes #30.

Problem

Bodyweight is read off each workout post, so logging two workouts on the same calendar day yields two bodyweights list rows for that date (both markdown and JSON). Per-day trend/plateau analysis then double-counts that day.

Fix

Deduplicate in loadBodyweightEntries (shared by list and stats), keeping the latest measurement per local day.

Scope note

Because the loader is shared, bodyweights stats monthly 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 to list, 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 ./... and go vet ./... pass.

🤖 Generated with Claude Code

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 DTTerastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DTTerastar
DTTerastar merged commit 6cbb1dc into quantcli:main Jul 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bodyweights list emits duplicate same-date rows when 2 workouts on one day

3 participants