Skip to content
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

refactor: remove cwvInterpolationFN, simpleCWVInterploationFN, INTERPOLATION_THRESHOLD from utils #8

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ const series = {
engagement,
};

export { DataChunks, utils, stats, series };
export {
DataChunks, utils, stats, series,
};
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
Loading