Skip to content

Interactive visualization of the midpoint + 6h sleep-grouping rule#10

Merged
gsbernstein merged 1 commit into
masterfrom
cursor/midpoint-threshold-viz-c98f
Jun 6, 2026
Merged

Interactive visualization of the midpoint + 6h sleep-grouping rule#10
gsbernstein merged 1 commit into
masterfrom
cursor/midpoint-threshold-viz-c98f

Conversation

@gsbernstein

Copy link
Copy Markdown
Owner

What

Adds a self-contained, interactive web visualization of the "midpoint + 6 hours" rule that Bedger uses to assign a sleep session to a calendar day (SleepSession.dateForGrouping in Bedtime/Bedtime/Models/SleepData.swift).

The visualization shows, for any sleep session:

  • the midpoint of the session,
  • the midpoint shifted forward by 6 hours,
  • and the resulting assigned day (startOfDay(shiftedMidpoint)),

making it clear that the "new day" for sleep grouping effectively begins at 6:00 PM.

Try it

  • Drag the blue sleep block to move it, or grab either edge to resize start/end.
  • Use the start / duration sliders.
  • Use presets (overnight, afternoon nap, early evening, late riser, quick doze) to see how each lands on a day — including the "rolled to next day" case when the midpoint falls after 6 PM.

Hosting

  • The viz is a single static file at docs/index.html (no build step, no dependencies).
  • A GitHub Pages workflow (.github/workflows/pages.yml) uploads docs/ and deploys on push to master, and can be triggered manually via workflow_dispatch.
  • To go live: in repo Settings → Pages, set the source to GitHub Actions. It will then be hosted at the repo's Pages URL.

Notes

  • Pure vanilla JS + inline SVG; no third-party code.
  • Computation logic mirrors the Swift implementation 1:1.
Open in Web Open in Cursor 

…Pages deploy

Co-authored-by: Greg <gsbernstein@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a self-contained static web visualization (hosted via GitHub Pages) to demonstrate how Bedger assigns a sleep session to a calendar day using the “midpoint + 6 hours” grouping rule.

Changes:

  • Added docs/index.html: interactive SVG/JS timeline + controls showing midpoint, shifted midpoint, and assigned day.
  • Added GitHub Actions workflow to deploy docs/ to GitHub Pages on pushes affecting docs/**.
  • Updated README to link to the visualization and briefly explain the grouping rule.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
README.md Links to the new visualization and explains where it lives/how it’s hosted
docs/index.html New interactive, no-deps visualization implementing the midpoint+6h grouping concept
.github/workflows/pages.yml GitHub Pages deployment workflow for docs/

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/index.html
<div class="card">
<h2>Timeline</h2>
<div class="timeline-shell">
<svg id="viz" viewBox="0 0 1000 320" preserveAspectRatio="xMidYMid meet" aria-label="Sleep grouping timeline"></svg>
Comment thread docs/index.html
Comment on lines +388 to +390
document.getElementById("dayVal").innerHTML =
DAY_NAMES[di] +
(rolled ? '<span class="badge">rolled to next day (midpoint after 6 PM)</span>' : '');
Comment thread docs/index.html
Comment on lines +287 to +291
const end = start + dur;
const mid = start + dur / 2;
const shifted = mid + SHIFT;
const assignedDay = Math.floor(shifted / DAY) * DAY;

@gsbernstein gsbernstein marked this pull request as ready for review June 6, 2026 21:48
@gsbernstein gsbernstein merged commit 6986de1 into master Jun 6, 2026
1 check passed
@gsbernstein gsbernstein deleted the cursor/midpoint-threshold-viz-c98f branch June 6, 2026 21:48
@gsbernstein gsbernstein restored the cursor/midpoint-threshold-viz-c98f branch June 6, 2026 22:03
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.

3 participants