• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
shapedlines

shapedlines

operational-efficiency

Public
Like
operational-efficiency
Home
Code
9
bay-wheels
5
clearspace_screen_time
14
obplot-dataviz
1
untitled-folder-3015
whoop-sleep
.vtignore
AGENTS.md
H
dashboard.ts
deno.json
Environment variables
3
Branches
2
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
clearspace_screen_time
/
BACKFILL_ALGORITHM.md
Code
/
clearspace_screen_time
/
BACKFILL_ALGORITHM.md
Search
11/29/2025
Viewing readonly version of main branch: v349
View latest version
BACKFILL_ALGORITHM.md

Backfill Algorithm Implementation

Problem Statement

the timeline and volume grids were not fully capturing the amount of screentime in the data to overflow situations. This occurred when the cron job (running every 10 minutes) reported screen time increases greater than 10 minutes in a single interval.

Example Scenario

  • Record at 9:55 AM: 0 minutes
  • Record at 10:00 AM: 100 minutes
  • Problem: 100 minutes appeared in a 5-minute gap
  • Old behavior: Clamp to 10 minutes, lose 90 minutes to "Artifacts"
  • New behavior: Distribute 100 minutes backwards into empty blocks

Solution: Backfill Algorithm

Algorithm Steps

  1. Iterate through time blocks sequentially (7:00 AM - 11:40 PM, 100 blocks of 10 minutes each)

  2. Calculate raw usage for each block based on cumulative screen time data

  3. Handle overflow:

    • If usage ≤ 10 minutes: Use actual usage
    • If usage > 10 minutes:
      • Fill current block with 10 minutes
      • Add remainder to backlog
  4. Backfill process:

    • When backlog exists, work backwards from current block
    • Fill previous empty blocks until backlog is exhausted
    • Each block can hold maximum 10 minutes

Implementation Details

// Three-pass algorithm: // 1. Calculate raw usage for each block // 2. Apply backfill algorithm with backlog management // 3. Generate HTML and calculate statistics // Acceptance Criteria: // 1. the screen time total from the data should match the corresponding amount of blocks // 2. backfilled screen time blocks should start from the overfilled block, and overfill in a continuous manner from that block for the overfilled amount

Key Features

  • Volume Preservation: All screen time minutes are represented in the grid
  • Timeline Approximation: Usage is distributed backwards from sync points
  • Visual Clarity: No single "exploded" blocks with impossible usage
  • Grid Synchronization: Volume and timeline grids always show same number of active blocks
  • Enhanced Tooltips: Show backfilled vs. direct usage
  • Statistics Tracking: New "Backfilled" metric in blue

Results

Before (Clamping)

  • ❌ Lost minutes to "Artifacts/Bursts"
  • ❌ Timeline grid didn't match volume grid
  • ❌ Poor visual representation of actual usage

After (Backfill)

  • ✅ Volume: Total red blocks match total screen time
  • ✅ Timeline: Better approximation of when usage occurred
  • ✅ Synchronization: Both grids show identical number of active blocks
  • ✅ Statistics: Clear breakdown of backfilled vs. direct usage
  • ✅ Tooltips: Enhanced information about block contents
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.