MCPcopy
hub / github.com/npmx-dev/npmx.dev / winsorize

Function winsorize

app/utils/charts.ts:117–126  ·  view source on GitHub ↗
(
  values: number[],
  lowerQuantile: number,
  upperQuantile: number,
)

Source from the content-addressed store, hash-verified

115 * @returns A new array with values clamped to the computed quantile bounds
116 */
117export function winsorize(
118 values: number[],
119 lowerQuantile: number,
120 upperQuantile: number,
121): number[] {
122 const sorted = values.toSorted((a, b) => a - b)
123 const lowerBound = quantile(sorted, lowerQuantile)
124 const upperBound = quantile(sorted, upperQuantile)
125 return values.map(v => clamp(v, lowerBound, upperBound))
126}
127
128export type LineChartAnalysis = {
129 mean: number

Callers 2

charts.spec.tsFile · 0.90
computeLineChartAnalysisFunction · 0.85

Calls 2

quantileFunction · 0.85
clampFunction · 0.85

Tested by

no test coverage detected