-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathvitalsScore.ts
57 lines (52 loc) · 1.35 KB
/
vitalsScore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { IThresholdTier, IStepsThresholds, IVitalsScore } from './types';
const rtScore = [100, 200];
const tbtScore = [200, 600];
const ntbtScore = [200, 600];
export const STEP_THRESHOLDS: IStepsThresholds = {
[IThresholdTier.instant]: {
vitalsThresholds: [100, 200],
maxOutlierThreshold: 10000,
},
[IThresholdTier.quick]: {
vitalsThresholds: [200, 500],
maxOutlierThreshold: 10000,
},
[IThresholdTier.moderate]: {
vitalsThresholds: [500, 1000],
maxOutlierThreshold: 10000,
},
[IThresholdTier.slow]: {
vitalsThresholds: [1000, 2000],
maxOutlierThreshold: 10000,
},
[IThresholdTier.unavoidable]: {
vitalsThresholds: [2000, 5000],
maxOutlierThreshold: 20000,
},
};
export const webVitalsScore: Record<string, number[]> = {
RT: rtScore,
TBT: tbtScore,
NTBT: ntbtScore,
};
export const getRating = (
value: number,
vitalsThresholds: [number, number],
): IVitalsScore => {
if (value <= vitalsThresholds[0]) {
return 'good';
}
return value <= vitalsThresholds[1] ? 'needsImprovement' : 'poor';
};
export const getVitalsScore = (
measureName: string,
value: number,
): IVitalsScore => {
if (!webVitalsScore[measureName]) {
return null;
}
if (value <= webVitalsScore[measureName][0]) {
return 'good';
}
return value <= webVitalsScore[measureName][1] ? 'needsImprovement' : 'poor';
};