1
|
|
|
import { RankingDataTeamObject } from "../Types/Ranking" |
2
|
|
|
import Axios from "axios" |
3
|
|
|
import { setupCache } from "axios-cache-interceptor" |
4
|
|
|
|
5
|
|
|
export function mapPsdStatus(statusCode: number): string | null { |
6
|
|
|
const statusCodes = new Map([ |
7
|
|
|
[0, `Gepland`], |
8
|
|
|
[1, `Forfait`], |
9
|
|
|
[2, `Afgelast`], |
10
|
|
|
[3, `Onderbroken`], |
11
|
|
|
]) |
12
|
|
|
|
13
|
|
|
return statusCodes.get(statusCode) || null |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
export function mapPsdStatusShort(statusCode: number): string | null { |
17
|
|
|
const statusCodes = new Map([ |
18
|
|
|
[0, ``], |
19
|
|
|
[1, `FF`], |
20
|
|
|
[2, `AFG`], |
21
|
|
|
[3, `STOP`], |
22
|
|
|
]) |
23
|
|
|
|
24
|
|
|
return statusCodes.get(statusCode) || null |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
export function sortRankings(a: RankingDataTeamObject, b: RankingDataTeamObject) { |
28
|
|
|
// Rank lager: A stijgt in sortering. |
29
|
|
|
if (a.rank < b.rank) { |
30
|
|
|
return -1 |
31
|
|
|
} |
32
|
|
|
if (a.rank > b.rank) { |
33
|
|
|
return 1 |
34
|
|
|
} |
35
|
|
|
// Aantal overwinningen hoger: A stijgt in sortering. |
36
|
|
|
if (a.wins > b.wins) { |
37
|
|
|
return -1 |
38
|
|
|
} |
39
|
|
|
if (a.wins < b.wins) { |
40
|
|
|
return 1 |
41
|
|
|
} |
42
|
|
|
// Doelpuntensaldo beter: A stijgt in sortering. |
43
|
|
|
if (a.goalsScored - a.goalsConceded > b.goalsScored - b.goalsConceded) { |
44
|
|
|
return -1 |
45
|
|
|
} |
46
|
|
|
if (a.goalsScored - a.goalsConceded < b.goalsScored - b.goalsConceded) { |
47
|
|
|
return 1 |
48
|
|
|
} |
49
|
|
|
// Aantal gemaakte doelpunten hoger: A stijgt in sortering. |
50
|
|
|
if (a.goalsScored > b.goalsScored) { |
51
|
|
|
return -1 |
52
|
|
|
} |
53
|
|
|
if (a.goalsScored < b.goalsScored) { |
54
|
|
|
return 1 |
55
|
|
|
} |
56
|
|
|
// Aantal uitoverwinningen hoger: A stijgt in sortering. |
57
|
|
|
if (a.winsAway > b.winsAway) { |
58
|
|
|
return -1 |
59
|
|
|
} |
60
|
|
|
if (a.winsAway < b.winsAway) { |
61
|
|
|
return 1 |
62
|
|
|
} |
63
|
|
|
// Doelpuntensaldo op verplaatsing beter: A stijgt in sortering. |
64
|
|
|
if (a.goalsScoredAway - a.goalsConcededAway > b.goalsScoredAway - b.goalsConcededAway) { |
65
|
|
|
return -1 |
66
|
|
|
} |
67
|
|
|
if (a.goalsScoredAway - a.goalsConcededAway < b.goalsScoredAway - b.goalsConcededAway) { |
68
|
|
|
return 1 |
69
|
|
|
} |
70
|
|
|
// Aantal gemaakte doelpunten op verplaatsing hoger: A stijgt in sortering. |
71
|
|
|
if (a.goalsScoredAway > b.goalsScoredAway) { |
72
|
|
|
return -1 |
73
|
|
|
} |
74
|
|
|
if (a.goalsScoredAway < b.goalsScoredAway) { |
75
|
|
|
return 1 |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return a.team?.club?.localName.localeCompare(b.team?.club?.localName) |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
export function replaceAll(source: string, search: string, replacement: string) { |
82
|
|
|
return source.replace(new RegExp(search, `g`), replacement) |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
export function translateGameResult(result: string) { |
86
|
|
|
const statusCodes = new Map([ |
87
|
|
|
[`WON`, `Gewonnen`], |
88
|
|
|
[`EQUAL`, `Gelijkgespeeld`], |
89
|
|
|
[`LOST`, `Verloren`], |
90
|
|
|
]) |
91
|
|
|
return statusCodes.get(result) || null |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Map a positionCode to a descriptive label. |
96
|
|
|
* |
97
|
|
|
* @param {string} positionCode |
98
|
|
|
*/ |
99
|
|
|
export function mapPositionCode(positionCode: string) { |
100
|
|
|
return getPositions().get(positionCode) || null |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* List of all positions, in order of position on the fields. |
105
|
|
|
* |
106
|
|
|
* @param {string} positionCode |
107
|
|
|
*/ |
108
|
|
|
export function getPositions() { |
109
|
|
|
const positions = new Map([ |
110
|
|
|
[`k`, `Doelman`], |
111
|
|
|
[`d`, `Verdediger`], |
112
|
|
|
[`m`, `Middenvelder`], |
113
|
|
|
[`a`, `Aanvaller`], |
114
|
|
|
[`j`, `Speler`], |
115
|
|
|
]) |
116
|
|
|
return positions |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Setup instance of axios with caching support. |
121
|
|
|
*/ |
122
|
|
|
export const request = setupCache(Axios, { cacheTakeover: false }) |
123
|
|
|
|