-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathresults.ts
More file actions
50 lines (42 loc) · 1.34 KB
/
results.ts
File metadata and controls
50 lines (42 loc) · 1.34 KB
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
import {
EventId,
RankingType,
AttemptResult,
formatMultiResult,
decodeMultiResult,
formatCentiseconds,
Cutoff,
} from '@wca/helpers';
export const renderResultByEventId = (
eventId: EventId,
rankingType: RankingType,
result: AttemptResult,
) => {
// Return empty string if result is null, undefined, or NaN
if (result == null || (typeof result === 'number' && isNaN(result))) {
return '';
}
if (eventId === '333fm') {
return rankingType === 'average' ? ((result as number) / 100).toFixed(2).toString() : result;
}
if (eventId === '333mbf') {
return formatMultiResult(decodeMultiResult(result));
}
return formatCentiseconds(result as number);
};
export const renderCutoff = (cutoff: Cutoff) => {
if (cutoff.numberOfAttempts === 0) {
return '-';
}
return `${formatCentiseconds(cutoff.attemptResult)}`;
};
export const renderCentiseconds = (centiseconds: number) => {
if (centiseconds >= 360000) {
const hours = Math.floor(centiseconds / 360000);
const minutes = Math.floor((centiseconds % 360000) / 6000);
const seconds = Math.floor((centiseconds % 6000) / 100);
const centis = centiseconds % 100;
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}.${centis.toString().padStart(2, '0')}`;
}
return formatCentiseconds(centiseconds);
};