Skip to content

Instantly share code, notes, and snippets.

@genmon
genmon / streak.py
Last active February 6, 2024 01:20
Calculating a blogging streak -- pseudocode
# A Monday preceding the first post on this blog. Used for calculating week numbers
# (Weeks start on Mondays)
FIRST_MONDAY = date(2000, 2, 14)
# Calculate week_number and streak_weeks for every post, in order. For calculating today's
# streak, we only need to know about the most recent post, but there's a certain amount of
# looking at other posts to figure that out.
# Note: this code looks at *all* posts because I want to calculate all streaks. For just
# today's streak, a quicker algorithm would run in reverse chronological order and stop at
# the first break.