Skip to content

Commit 10e4068

Browse files
committed
WIP: refactor: Import contexts from sandbag
openbeta-graphql defines grade contexts used to map climbs to grade scales. The front end needs to do this too, so the existing functionality was copied to sandbag. Reuse that instead of having parallel implementations..
1 parent 9b0b35b commit 10e4068

File tree

1 file changed

+2
-192
lines changed

1 file changed

+2
-192
lines changed

src/GradeUtils.ts

Lines changed: 2 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,7 @@
1-
import { getScale, GradeScales, GradeScalesTypes } from '@openbeta/sandbag'
2-
import isoCountries from 'i18n-iso-countries'
1+
import { getScale, GradeScalesTypes, GradeContexts, gradeContextToGradeScales, getCountriesDefaultGradeContext } from '@openbeta/sandbag'
32
import { DisciplineType, ClimbGradeContextType } from './db/ClimbTypes.js'
43

5-
/**
6-
* Grade systems have minor variations between countries. gradeContext is a
7-
* short abbreviated string that identifies the context in which the grade was assigned
8-
* and should signify a regional or national variation that may be considered within
9-
* grade comparisons.
10-
*
11-
* Todo: move this to @openbeta/sandbag library
12-
*/
13-
export enum GradeContexts {
14-
/** Alaska (United States) */
15-
ALSK = 'ALSK',
16-
/** Australia */
17-
AU = 'AU',
18-
BRZ = 'BRZ',
19-
FIN = 'FIN',
20-
FR = 'FR',
21-
HK = 'HK',
22-
NWG = 'NWG',
23-
POL = 'POL',
24-
SA = 'SA',
25-
/** Sweden */
26-
SWE = 'SWE',
27-
SX = 'SX',
28-
UIAA = 'UIAA',
29-
/** United Kingdom */
30-
UK = 'UK',
31-
/** United States of Ameria */
32-
US = 'US'
33-
}
34-
35-
/**
36-
* A conversion from grade context to corresponding grade type / scale
37-
* Todo: move this to @openbeta/sandbag
38-
*/
39-
export const gradeContextToGradeScales: Partial<Record<GradeContexts, ClimbGradeContextType>> = {
40-
[GradeContexts.AU]: {
41-
trad: GradeScales.EWBANK,
42-
sport: GradeScales.EWBANK,
43-
bouldering: GradeScales.VSCALE,
44-
tr: GradeScales.EWBANK,
45-
deepwatersolo: GradeScales.EWBANK,
46-
alpine: GradeScales.YDS,
47-
mixed: GradeScales.YDS,
48-
aid: GradeScales.AID,
49-
snow: GradeScales.YDS, // is this the same as alpine?
50-
ice: GradeScales.WI
51-
},
52-
[GradeContexts.US]: {
53-
trad: GradeScales.YDS,
54-
sport: GradeScales.YDS,
55-
bouldering: GradeScales.VSCALE,
56-
tr: GradeScales.YDS,
57-
deepwatersolo: GradeScales.YDS,
58-
alpine: GradeScales.YDS,
59-
mixed: GradeScales.YDS,
60-
aid: GradeScales.AID,
61-
snow: GradeScales.YDS, // is this the same as alpine?
62-
ice: GradeScales.WI
63-
},
64-
[GradeContexts.FR]: {
65-
trad: GradeScales.FRENCH,
66-
sport: GradeScales.FRENCH,
67-
bouldering: GradeScales.FONT,
68-
tr: GradeScales.FRENCH,
69-
deepwatersolo: GradeScales.FRENCH,
70-
alpine: GradeScales.FRENCH,
71-
mixed: GradeScales.FRENCH,
72-
aid: GradeScales.AID,
73-
snow: GradeScales.FRENCH, // is this the same as alpine?
74-
ice: GradeScales.WI
75-
},
76-
[GradeContexts.SA]: {
77-
trad: GradeScales.FRENCH,
78-
sport: GradeScales.FRENCH,
79-
bouldering: GradeScales.FONT,
80-
tr: GradeScales.FRENCH,
81-
deepwatersolo: GradeScales.FRENCH,
82-
alpine: GradeScales.FRENCH,
83-
mixed: GradeScales.FRENCH,
84-
aid: GradeScales.AID,
85-
snow: GradeScales.FRENCH, // SA does not have a whole lot of snow
86-
ice: GradeScales.WI
87-
},
88-
[GradeContexts.UIAA]: {
89-
trad: GradeScales.UIAA,
90-
sport: GradeScales.UIAA,
91-
bouldering: GradeScales.FONT,
92-
tr: GradeScales.UIAA,
93-
deepwatersolo: GradeScales.FRENCH,
94-
alpine: GradeScales.UIAA,
95-
mixed: GradeScales.UIAA, // TODO: change to MI scale, once added
96-
aid: GradeScales.UIAA,
97-
snow: GradeScales.UIAA, // TODO: remove `snow` since it duplicates `ice`
98-
ice: GradeScales.WI
99-
}
100-
}
4+
export { GradeContexts, gradeContextToGradeScales, getCountriesDefaultGradeContext }
1015

1026
/**
1037
* Convert a human-readable grade to the appropriate grade object.
@@ -127,100 +31,6 @@ export const createGradeObject = (gradeStr: string, disciplines: DisciplineType
12731
}, undefined)
12832
}
12933

130-
/**
131-
* A record of all countries with a default grade context that is not US
132-
*/
133-
const COUNTRIES_DEFAULT_NON_US_GRADE_CONTEXT: Record<string, GradeContexts> = {
134-
AND: GradeContexts.FR,
135-
ATF: GradeContexts.FR,
136-
AUS: GradeContexts.AU,
137-
AUT: GradeContexts.UIAA,
138-
AZE: GradeContexts.UIAA,
139-
BEL: GradeContexts.FR,
140-
BGR: GradeContexts.UIAA,
141-
BIH: GradeContexts.FR,
142-
BLR: GradeContexts.UIAA,
143-
BRA: GradeContexts.BRZ,
144-
BWA: GradeContexts.SA,
145-
CHE: GradeContexts.FR,
146-
CUB: GradeContexts.FR,
147-
CZE: GradeContexts.UIAA,
148-
DEU: GradeContexts.UIAA,
149-
DNK: GradeContexts.UIAA,
150-
EGY: GradeContexts.FR,
151-
ESP: GradeContexts.FR,
152-
EST: GradeContexts.FR,
153-
FIN: GradeContexts.FIN,
154-
FRA: GradeContexts.FR,
155-
GBR: GradeContexts.UK,
156-
GRC: GradeContexts.FR,
157-
GUF: GradeContexts.FR,
158-
HKG: GradeContexts.HK,
159-
HRV: GradeContexts.FR,
160-
HUN: GradeContexts.UIAA,
161-
IOT: GradeContexts.UK,
162-
IRL: GradeContexts.UK,
163-
ITA: GradeContexts.FR,
164-
JEY: GradeContexts.UK,
165-
JOR: GradeContexts.FR,
166-
KEN: GradeContexts.UK,
167-
KGZ: GradeContexts.FR,
168-
LAO: GradeContexts.FR,
169-
LIE: GradeContexts.FR,
170-
LSO: GradeContexts.SA,
171-
LTU: GradeContexts.FR,
172-
LUX: GradeContexts.FR,
173-
LVA: GradeContexts.FR,
174-
MAR: GradeContexts.FR,
175-
MCO: GradeContexts.FR,
176-
MDA: GradeContexts.FR,
177-
MDG: GradeContexts.FR,
178-
MKD: GradeContexts.FR,
179-
MLT: GradeContexts.FR,
180-
MNE: GradeContexts.UIAA,
181-
MYS: GradeContexts.FR,
182-
NAM: GradeContexts.SA,
183-
NCL: GradeContexts.FR,
184-
NLD: GradeContexts.FR,
185-
NOR: GradeContexts.NWG,
186-
NZL: GradeContexts.AU,
187-
PER: GradeContexts.FR,
188-
PNG: GradeContexts.AU,
189-
POL: GradeContexts.POL,
190-
PRT: GradeContexts.FR,
191-
PYF: GradeContexts.FR,
192-
ROU: GradeContexts.FR,
193-
RUS: GradeContexts.FR,
194-
SGP: GradeContexts.FR,
195-
SRB: GradeContexts.FR,
196-
SVK: GradeContexts.UIAA,
197-
SVN: GradeContexts.FR,
198-
SWE: GradeContexts.SWE,
199-
THA: GradeContexts.FR,
200-
TON: GradeContexts.AU,
201-
TUN: GradeContexts.FR,
202-
TUR: GradeContexts.FR,
203-
UGA: GradeContexts.SA,
204-
UKR: GradeContexts.FR,
205-
VNM: GradeContexts.FR,
206-
ZAF: GradeContexts.SA
207-
}
208-
209-
/**
210-
*
211-
* @returns all countries with their default grade context
212-
*/
213-
export const getCountriesDefaultGradeContext = (): { [x: string]: GradeContexts } => {
214-
const countries = { ...COUNTRIES_DEFAULT_NON_US_GRADE_CONTEXT }
215-
for (const alpha3Code in isoCountries.getAlpha3Codes()) {
216-
// Any country not found will have a US Grade Context
217-
if (!(alpha3Code in countries)) {
218-
countries[alpha3Code] = GradeContexts.US
219-
}
220-
}
221-
return countries
222-
}
223-
22434
export const validDisciplines = ['trad', 'sport', 'bouldering', 'deepwatersolo', 'alpine', 'snow', 'ice', 'mixed', 'aid', 'tr']
22535

22636
/**

0 commit comments

Comments
 (0)