Skip to content

Commit

Permalink
refactor: remove cwvInterpolationFN, simpleCWVInterploationFN, INTERP…
Browse files Browse the repository at this point in the history
…OLATION_THRESHOLD from utils (#8)
  • Loading branch information
karlpauls authored Oct 11, 2024
1 parent a390472 commit f0706f6
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,38 +172,6 @@ export function scoreBundle(bundle) {
return 'poor';
}

export const INTERPOLATION_THRESHOLD = 10;

export function simpleCWVInterpolationFn(metric, threshold) {
return (cwvs) => {
const valuedWeights = Object.values(cwvs)
.filter((value) => value.weight !== undefined)
.map((value) => value.weight)
.reduce((acc, value) => acc + value, 0);
return cwvs[threshold + metric].weight / valuedWeights;
};
}
export function cwvInterpolationFn(targetMetric) {
return (cwvs) => {
const valueCount = cwvs.goodCWV.count + cwvs.niCWV.count + cwvs.poorCWV.count;
const valuedWeights = cwvs.goodCWV.weight + cwvs.niCWV.weight + cwvs.poorCWV.weight;

if (valueCount < INTERPOLATION_THRESHOLD) {
// not enough data to interpolate
return 0;
}
// total weight
const totalWeight = cwvs.goodCWV.weight
+ cwvs.niCWV.weight
+ cwvs.poorCWV.weight
+ cwvs.noCWV.weight;
// share of targetMetric compared to all CWV
const share = cwvs[targetMetric].weight / (valuedWeights);
// interpolate the share to the total weight
return Math.round(share * totalWeight);
};
}

/**
* Conversion rates are computed as the ratio of conversions to visits. The conversion rate is
* capped at 100%.
Expand Down

0 comments on commit f0706f6

Please sign in to comment.