-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcalculations.js
57 lines (46 loc) · 1.68 KB
/
calculations.js
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
const checkingFunctions = {
alwaysTrue: transformedData => true,
hasOutcome: outcome => transformedData =>
transformedData.some(round => round.results.some(result => result.outcome === outcome)),
hasMatches: transformedData =>
transformedData.some(round => round.results.some(result => result.match))
};
export default {
'points': {
check: checkingFunctions.alwaysTrue,
calculate: result => result.change || 0
},
'rounds': {
check: checkingFunctions.alwaysTrue,
calculate: result => result.change === null ? 0 : 1
},
'wins': {
check: checkingFunctions.hasOutcome('win'),
calculate: result => result.outcome === 'win' ? 1 : 0
},
'losses': {
check: checkingFunctions.hasOutcome('loss'),
calculate: result => result.outcome === 'loss' ? 1 : 0
},
'draws': {
check: checkingFunctions.hasOutcome('draw'),
calculate: result => result.outcome === 'draw' ? 1 : 0
},
'goalsFor': {
check: checkingFunctions.hasMatches,
calculate: result => result.match ? result.match.score : 0
},
'goalsAgainst': {
check: checkingFunctions.hasMatches,
calculate: result => result.match ? result.match.opponentScore : 0
},
'goalsDifference': {
check: checkingFunctions.hasMatches,
calculate: result => result.match ? result.match.score - result.match.opponentScore : 0
},
'winningPercentage': {
check: checkingFunctions.hasOutcome('win'),
calculate: calculatedResult => calculatedResult.rounds.total ? calculatedResult.wins.total / calculatedResult.rounds.total : 0,
isPost: true
}
};