File size: 925 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
type BoostRating = 'A' | 'B' | 'C' | 'D' | 'E' | 'F';

type BoostThreshold = {
	threshold: number;
	rating: BoostRating;
};

const BOOST_THRESHOLDS: BoostThreshold[] = [
	{ threshold: 90, rating: 'A' },
	{ threshold: 75, rating: 'B' },
	{ threshold: 50, rating: 'C' },
	{ threshold: 35, rating: 'D' },
	{ threshold: 25, rating: 'E' },
	{ threshold: 0, rating: 'F' },
];

export const getBoostRating = ( boostScore: number ): BoostRating => {
	for ( const { threshold, rating } of BOOST_THRESHOLDS ) {
		if ( boostScore > threshold ) {
			return rating;
		}
	}

	return 'F';
};

export const getBoostRatingClass = ( boostScore: number ): string => {
	const GOOD_BOOST_SCORE_THRESHOLD = 75;
	if ( boostScore > GOOD_BOOST_SCORE_THRESHOLD ) {
		return 'boost-score-good';
	}

	const OKAY_BOOST_SCORE_THRESHOLD = 35;
	if ( boostScore > OKAY_BOOST_SCORE_THRESHOLD ) {
		return 'boost-score-okay';
	}

	return 'boost-score-bad';
};