-
-
Notifications
You must be signed in to change notification settings - Fork 283
feat: fix known download anomalies with interpolation #1636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+483
−5
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b189a1e
hampel
jycouet 230585e
IQR multiplier
jycouet 88b2745
manual anomalies
jycouet c5faf4c
$t
jycouet 5fa129e
Merge branch 'main' into feat/clean-up-graphs
graphieros bd98130
fix: add missing comma
graphieros 5f7cbbc
fix: add missing comma
graphieros 1360b84
fix: add missing comma
graphieros f597318
fix: add missing brace & comma
graphieros 5ce3608
rename
jycouet dd7d952
update
jycouet 474e3ea
namings
jycouet fc63eb7
obj
jycouet 6fb207b
Merge branch 'feat/clean-up-graphs' of github.com:jycouet/npmx.dev in…
jycouet ccaa0ad
Merge branch 'main' of github.com:npmx-dev/npmx.dev into feat/clean-u…
jycouet f5303d6
naming²
jycouet 9f5aa2e
tooltip info
jycouet 84e9bdb
Merge branch 'main' into feat/clean-up-graphs
graphieros 6722a92
multi
jycouet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /** | ||
| * Bidirectional moving average. Blends a trailing (left-anchored) and leading | ||
| * (right-anchored) average by position so transitions from both fixed endpoints | ||
| * are smooth. | ||
| * First and last points are preserved. | ||
| * | ||
| * @param halfWindow - number of points on each side (0 = disabled) | ||
| */ | ||
| export function movingAverage<T extends { value: number }>(data: T[], halfWindow: number): T[] { | ||
| if (halfWindow <= 0 || data.length < 3) return data | ||
|
|
||
| const n = data.length | ||
|
|
||
| // Trailing average (anchored to start): average of [max(0, i-halfWindow), i] | ||
| const trailing: number[] = Array.from({ length: n }) | ||
| for (let i = 0; i < n; i++) { | ||
| const lo = Math.max(0, i - halfWindow) | ||
| let sum = 0 | ||
| for (let j = lo; j <= i; j++) sum += data[j]!.value | ||
| trailing[i] = sum / (i - lo + 1) | ||
| } | ||
|
|
||
| // Leading average (anchored to end): average of [i, min(n-1, i+halfWindow)] | ||
| const leading: number[] = Array.from({ length: n }) | ||
| for (let i = 0; i < n; i++) { | ||
| const hi = Math.min(n - 1, i + halfWindow) | ||
| let sum = 0 | ||
| for (let j = i; j <= hi; j++) sum += data[j]!.value | ||
| leading[i] = sum / (hi - i + 1) | ||
| } | ||
|
|
||
| // Position-based blend: near start → mostly trailing, near end → mostly leading | ||
| const result = data.map(d => ({ ...d })) | ||
| for (let i = 1; i < n - 1; i++) { | ||
| const t = i / (n - 1) | ||
| result[i]!.value = (1 - t) * trailing[i]! + t * leading[i]! | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| /** | ||
| * Forward-backward exponential smoothing (zero-phase). | ||
| * Smooths without introducing lag — preserves the dynamics/timing of trends. | ||
| * First and last points are preserved. | ||
| * | ||
| * @param tau - time constant (0 = disabled, higher = smoother) | ||
| */ | ||
| export function smoothing<T extends { value: number }>(data: T[], tau: number): T[] { | ||
| if (tau <= 0 || data.length < 3) return data | ||
|
|
||
| const alpha = 1 / (1 + tau) | ||
| const n = data.length | ||
|
|
||
| // Forward pass | ||
| const forward: number[] = Array.from({ length: n }) | ||
| forward[0] = data[0]!.value | ||
| for (let i = 1; i < n; i++) { | ||
| forward[i] = alpha * data[i]!.value + (1 - alpha) * forward[i - 1]! | ||
| } | ||
|
|
||
| // Backward pass | ||
| const backward: number[] = Array.from({ length: n }) | ||
| backward[n - 1] = data[n - 1]!.value | ||
| for (let i = n - 2; i >= 0; i--) { | ||
| backward[i] = alpha * data[i]!.value + (1 - alpha) * backward[i + 1]! | ||
| } | ||
|
|
||
| // Position-based blend: near start → mostly forward, near end → mostly backward | ||
| // This ensures smooth transitions from both fixed endpoints | ||
| const result = data.map(d => ({ ...d })) | ||
| for (let i = 1; i < n - 1; i++) { | ||
| const t = i / (n - 1) | ||
| result[i]!.value = (1 - t) * forward[i]! + t * backward[i]! | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| export interface ChartFilterSettings { | ||
| averageWindow: number | ||
| smoothingTau: number | ||
| } | ||
|
|
||
| /** | ||
| * Applies moving average then smoothing in sequence. | ||
| */ | ||
| export function applyDataCorrection<T extends { value: number }>( | ||
| data: T[], | ||
| settings: ChartFilterSettings, | ||
| ): T[] { | ||
| let result = data | ||
| result = movingAverage(result, settings.averageWindow) | ||
| result = smoothing(result, settings.smoothingTau) | ||
| return result | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import type { DownloadAnomaly } from './download-anomalies' | ||
|
|
||
| export const DOWNLOAD_ANOMALIES: DownloadAnomaly[] = [ | ||
| // vite rogue CI spike | ||
| { | ||
| packageName: 'vite', | ||
| start: { date: '2025-08-04', weeklyDownloads: 33_913_132 }, | ||
| end: { date: '2025-09-08', weeklyDownloads: 38_665_727 }, | ||
| }, | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.