feat: growth deltas in analytics overview (#31)#35
Merged
Conversation
Closes #31. overview now queries the previous equal-length window by default and shows the percent change per metric (green up, red down). --no-compare reproduces the single-window output. JSON gains previous and pct_change fields; previous == 0 yields a null pct_change / (new) marker instead of dividing by zero.
Previous window now ends the day before the current window starts, so the two equal-length windows do not double-count the shared day.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #31.
What
analytics overviewnow shows a period-over-period growth trend by default: each metric is compared to the previous equal-length window and rendered with a coloured percent change.green for positive, red for negative.
Behaviour
[today-2*days, today-days]for the same metrics and computes the percent change for views, estimatedMinutesWatched, averageViewDuration, likes, comments.--no-comparereproduces the previous single-window output (and skips the extra query). The flag is--compare/--no-compare, default on, leaving room for a future--compare-to.previous(the prior window's metrics) andpct_change(percent change per metric). When there is no prior-window baseline (previous == 0),pct_changeisnulland the table shows(new)instead of dividing by zero.Cost
One extra Analytics API query per overview when comparing. The Analytics API is separate from the Data API quota and cheap, so the impact is negligible.
Tests
Four new tests cover the table deltas, JSON
previous/pct_change,--no-compare(asserts only one query is issued), and the zero-previous guard. Full suite: 252 passing, ruff clean.Note
Following the issue's window sketch, the previous window's end date equals the current window's start date, so the boundary day is shared (matching the existing inclusive single-window semantics). Easy to tighten later if exact non-overlapping windows are preferred.