Repository navigation
fix(insights): trend chart plots the rolling selected window so it always matches the headline - #576
Merged
Merged
Conversation
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.
Summary
On longer date presets the trend chart's line endpoints disagreed with the headline card and the leaderboard — e.g. a brand showing 16.6 in the cards (the whole 90-day window's score) while its line ended at 18.6 (just the last day's score). Both numbers were correct, but they answered different questions on the same card.
The chart now plots a rolling window: each day's point is the AI Visibility Score over the trailing window of the selected length ending that day. Consequences:
Mechanics:
00042(already applied to the hosted database):visibility_rate_trendday buckets gainposition_n(answers carrying a mention position) for the brand and each competitor — needed to weight rolling position factors correctly (Σ pf×n / Σ n). Purely additive keys; the MCP trend endpoint and existing consumers are unaffected.getVisibilityRateTrendfetches one extra window of trailing days (reusing the already-computedprevFrom) to warm up the earliest points, then computes rolling sums with a two-pointer sweep — no extra RPC round trips.Related issue
—
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)