Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: refactor: Import contexts from sandbag #343

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 2 additions & 192 deletions src/GradeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,103 +1,7 @@
import { getScale, GradeScales, GradeScalesTypes } from '@openbeta/sandbag'
import isoCountries from 'i18n-iso-countries'
import { getScale, GradeScalesTypes, GradeContexts, gradeContextToGradeScales, getCountriesDefaultGradeContext } from '@openbeta/sandbag'
import { DisciplineType, ClimbGradeContextType } from './db/ClimbTypes.js'

/**
* Grade systems have minor variations between countries. gradeContext is a
* short abbreviated string that identifies the context in which the grade was assigned
* and should signify a regional or national variation that may be considered within
* grade comparisons.
*
* Todo: move this to @openbeta/sandbag library
*/
export enum GradeContexts {
/** Alaska (United States) */
ALSK = 'ALSK',
/** Australia */
AU = 'AU',
BRZ = 'BRZ',
FIN = 'FIN',
FR = 'FR',
HK = 'HK',
NWG = 'NWG',
POL = 'POL',
SA = 'SA',
/** Sweden */
SWE = 'SWE',
SX = 'SX',
UIAA = 'UIAA',
/** United Kingdom */
UK = 'UK',
/** United States of Ameria */
US = 'US'
}

/**
* A conversion from grade context to corresponding grade type / scale
* Todo: move this to @openbeta/sandbag
*/
export const gradeContextToGradeScales: Partial<Record<GradeContexts, ClimbGradeContextType>> = {
[GradeContexts.AU]: {
trad: GradeScales.EWBANK,
sport: GradeScales.EWBANK,
bouldering: GradeScales.VSCALE,
tr: GradeScales.EWBANK,
deepwatersolo: GradeScales.EWBANK,
alpine: GradeScales.YDS,
mixed: GradeScales.YDS,
aid: GradeScales.AID,
snow: GradeScales.YDS, // is this the same as alpine?
ice: GradeScales.WI
},
[GradeContexts.US]: {
trad: GradeScales.YDS,
sport: GradeScales.YDS,
bouldering: GradeScales.VSCALE,
tr: GradeScales.YDS,
deepwatersolo: GradeScales.YDS,
alpine: GradeScales.YDS,
mixed: GradeScales.YDS,
aid: GradeScales.AID,
snow: GradeScales.YDS, // is this the same as alpine?
ice: GradeScales.WI
},
[GradeContexts.FR]: {
trad: GradeScales.FRENCH,
sport: GradeScales.FRENCH,
bouldering: GradeScales.FONT,
tr: GradeScales.FRENCH,
deepwatersolo: GradeScales.FRENCH,
alpine: GradeScales.FRENCH,
mixed: GradeScales.FRENCH,
aid: GradeScales.AID,
snow: GradeScales.FRENCH, // is this the same as alpine?
ice: GradeScales.WI
},
[GradeContexts.SA]: {
trad: GradeScales.FRENCH,
sport: GradeScales.FRENCH,
bouldering: GradeScales.FONT,
tr: GradeScales.FRENCH,
deepwatersolo: GradeScales.FRENCH,
alpine: GradeScales.FRENCH,
mixed: GradeScales.FRENCH,
aid: GradeScales.AID,
snow: GradeScales.FRENCH, // SA does not have a whole lot of snow
ice: GradeScales.WI
},
[GradeContexts.UIAA]: {
trad: GradeScales.UIAA,
sport: GradeScales.UIAA,
bouldering: GradeScales.FONT,
tr: GradeScales.UIAA,
deepwatersolo: GradeScales.FRENCH,
alpine: GradeScales.UIAA,
mixed: GradeScales.UIAA, // TODO: change to MI scale, once added
aid: GradeScales.UIAA,
snow: GradeScales.UIAA, // TODO: remove `snow` since it duplicates `ice`
ice: GradeScales.WI
}
}
export { GradeContexts, gradeContextToGradeScales, getCountriesDefaultGradeContext }

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

/**
* A record of all countries with a default grade context that is not US
*/
const COUNTRIES_DEFAULT_NON_US_GRADE_CONTEXT: Record<string, GradeContexts> = {
AND: GradeContexts.FR,
ATF: GradeContexts.FR,
AUS: GradeContexts.AU,
AUT: GradeContexts.UIAA,
AZE: GradeContexts.UIAA,
BEL: GradeContexts.FR,
BGR: GradeContexts.UIAA,
BIH: GradeContexts.FR,
BLR: GradeContexts.UIAA,
BRA: GradeContexts.BRZ,
BWA: GradeContexts.SA,
CHE: GradeContexts.FR,
CUB: GradeContexts.FR,
CZE: GradeContexts.UIAA,
DEU: GradeContexts.UIAA,
DNK: GradeContexts.UIAA,
EGY: GradeContexts.FR,
ESP: GradeContexts.FR,
EST: GradeContexts.FR,
FIN: GradeContexts.FIN,
FRA: GradeContexts.FR,
GBR: GradeContexts.UK,
GRC: GradeContexts.FR,
GUF: GradeContexts.FR,
HKG: GradeContexts.HK,
HRV: GradeContexts.FR,
HUN: GradeContexts.UIAA,
IOT: GradeContexts.UK,
IRL: GradeContexts.UK,
ITA: GradeContexts.FR,
JEY: GradeContexts.UK,
JOR: GradeContexts.FR,
KEN: GradeContexts.UK,
KGZ: GradeContexts.FR,
LAO: GradeContexts.FR,
LIE: GradeContexts.FR,
LSO: GradeContexts.SA,
LTU: GradeContexts.FR,
LUX: GradeContexts.FR,
LVA: GradeContexts.FR,
MAR: GradeContexts.FR,
MCO: GradeContexts.FR,
MDA: GradeContexts.FR,
MDG: GradeContexts.FR,
MKD: GradeContexts.FR,
MLT: GradeContexts.FR,
MNE: GradeContexts.UIAA,
MYS: GradeContexts.FR,
NAM: GradeContexts.SA,
NCL: GradeContexts.FR,
NLD: GradeContexts.FR,
NOR: GradeContexts.NWG,
NZL: GradeContexts.AU,
PER: GradeContexts.FR,
PNG: GradeContexts.AU,
POL: GradeContexts.POL,
PRT: GradeContexts.FR,
PYF: GradeContexts.FR,
ROU: GradeContexts.FR,
RUS: GradeContexts.FR,
SGP: GradeContexts.FR,
SRB: GradeContexts.FR,
SVK: GradeContexts.UIAA,
SVN: GradeContexts.FR,
SWE: GradeContexts.SWE,
THA: GradeContexts.FR,
TON: GradeContexts.AU,
TUN: GradeContexts.FR,
TUR: GradeContexts.FR,
UGA: GradeContexts.SA,
UKR: GradeContexts.FR,
VNM: GradeContexts.FR,
ZAF: GradeContexts.SA
}

/**
*
* @returns all countries with their default grade context
*/
export const getCountriesDefaultGradeContext = (): { [x: string]: GradeContexts } => {
const countries = { ...COUNTRIES_DEFAULT_NON_US_GRADE_CONTEXT }
for (const alpha3Code in isoCountries.getAlpha3Codes()) {
// Any country not found will have a US Grade Context
if (!(alpha3Code in countries)) {
countries[alpha3Code] = GradeContexts.US
}
}
return countries
}

export const validDisciplines = ['trad', 'sport', 'bouldering', 'deepwatersolo', 'alpine', 'snow', 'ice', 'mixed', 'aid', 'tr']

/**
Expand Down