my streak was lying to me for a month
went to add a simple 7-day sparkline. by the end of the night i had rewritten how hackfetch talks to hackatime and my streak field is finally accurate for the first time in weeks.
the plan was get the status from the last 7 days. draw ▁▂▃▄▅▆▇█ bars 
except the endpoint i needed straight up 404s. /users/current/summaries doesnt exist on the current hackatime deployment.
Which means every single time i ran hackfetch it was quietly making a 30-day range call that always failed, then falling back to a placeholder that said “if today has activity, streak = 1”. thats it. no matter how long ive actually been on a streak, the fetch would just show 1 day. 🤦
my streak has said 1 day for the last 2 weeks even though ive been coding literally every day. never noticed because 1 day looks kinda plausible (i added 1 day as a fallback so that it didn’t show an error a couple weeks ago and forgot
)
the fix:
went digging in hackatimes rails routes on github. turns out theres a whole /api/v1/ namespace i was never using. and one of the endpoints is /api/v1/users/:id/heartbeats/spans. one call, ~150kb of json, every coding session ive ever logged with start_time, end_time, duration. 2000+ spans.
which is exactly what i need for both features. bucket the timestamps by local calendar day, count unique days for streak, sum durations per day for the sparkline. one request covers both. and while i was already in the api layer i noticed fetchUser was making a whole separate call for my slack handle, which is silly because that data is already in the weekly stats response we cache. so i piggybacked it. weve gone from 4 api calls per fetch to 3.
the sparkline:
7-day chart ▄▄▇▅▄▅▃ 65h 28m
oldest on the left, newest on the right. that tall bar in the middle is a big lock-in session from earlier in the week. the two shorter ones on the right are today (still coding) and yesterday (took a break).
opt in for -status --sparkline if you want it in your tmux bar too:
2h 9m today · streak 9 · ▄▄▇▅▄▅▃ 65h 28m
teasing a backend:
I’m planning on building a whole leaderboard server on a free hack club nest box so people can compete on their hackatime hours. while i was poking around the routes file for the streak fix i noticed something.
/api/v1/leaderboard/daily and /api/v1/leaderboard/weekly already exist. public. no auth needed. no server needed. no cron sync. hackatime literally already has it directly.
so hackfetch -leaderboard is coming soon (private friend groups and personal competitions can come later)
last devlog before my next ship
after the ship the devlogs are going to be huge.
stay tuned :P
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.