From 2ade068a84c345844207effc6f09557973b83f00 Mon Sep 17 00:00:00 2001 From: Flavio Di Natale Date: Thu, 24 Oct 2024 12:23:20 +0200 Subject: [PATCH] Define ConversionGroups enum --- src/GradeScale.ts | 11 ++++++++++- src/scales/ai.ts | 4 ++-- src/scales/aid.ts | 4 ++-- src/scales/brazilian.ts | 4 ++-- src/scales/ewbank.ts | 4 ++-- src/scales/font.ts | 4 ++-- src/scales/french.ts | 4 ++-- src/scales/norwegian.ts | 4 ++-- src/scales/saxon.ts | 4 ++-- src/scales/uiaa.ts | 4 ++-- src/scales/v.ts | 4 ++-- src/scales/wi.ts | 4 ++-- src/scales/yds.ts | 4 ++-- 13 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/GradeScale.ts b/src/GradeScale.ts index 7abae36..098b4a9 100644 --- a/src/GradeScale.ts +++ b/src/GradeScale.ts @@ -10,7 +10,7 @@ export default interface GradeScale { displayName: string name: GradeScalesTypes offset: number - conversionGroup: string + conversionGroup: ConversionGroupsTypes grades?: string[] } @@ -31,6 +31,15 @@ export const GradeScales = { export type GradeScalesTypes = typeof GradeScales[keyof typeof GradeScales] +export const ConversionGroups = { + AID: 'aid', + FREE: 'free', + BOULDERING: 'bouldering', + ICE: 'ice' +} as const + +export type ConversionGroupsTypes = typeof ConversionGroups[keyof typeof ConversionGroups] + export const findScoreRange = (compareFn, list): number | Tuple => { const scores = list.filter(compareFn) .map(b => b.score) diff --git a/src/scales/ai.ts b/src/scales/ai.ts index 68b6844..09f34be 100644 --- a/src/scales/ai.ts +++ b/src/scales/ai.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple } from '../GradeScale' import ice_table from '../data/ice.json' import { IceGrade } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' @@ -13,7 +13,7 @@ const AIScale: GradeScale = { displayName: 'AI Grade', name: GradeScales.AI, offset: 1000, - conversionGroup: 'Ice', + conversionGroup: ConversionGroups.ICE, isType: (grade: string): boolean => { if (isAI(grade) === null) { return false diff --git a/src/scales/aid.ts b/src/scales/aid.ts index 359f4f7..4e70ff7 100644 --- a/src/scales/aid.ts +++ b/src/scales/aid.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple } from '../GradeScale' import aid_table from '../data/aid.json' import { AidGrade } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' @@ -12,7 +12,7 @@ const AidScale: GradeScale = { displayName: 'Aid Grade', name: GradeScales.AID, offset: 1000, - conversionGroup: 'Aid', + conversionGroup: ConversionGroups.AID, isType: (grade: string): boolean => { if (isAid(grade) === null) { return false diff --git a/src/scales/brazilian.ts b/src/scales/brazilian.ts index 96e5c02..9924177 100644 --- a/src/scales/brazilian.ts +++ b/src/scales/brazilian.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple, getRoundedScoreTuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple, getRoundedScoreTuple } from '../GradeScale' import routes from '../data/routes.json' import { Route } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' @@ -71,7 +71,7 @@ const BrazilianCrux: GradeScale = { displayName: 'Brazilian Crux Scale', name: GradeScales.BRAZILIAN_CRUX, offset: 1000, - conversionGroup: 'Free', + conversionGroup: ConversionGroups.FREE, isType: (grade: string): boolean => isBrazilianCrux(grade) !== null, getScore, getGrade: (score: number | Tuple): string => { diff --git a/src/scales/ewbank.ts b/src/scales/ewbank.ts index 3f58dd2..3743be9 100644 --- a/src/scales/ewbank.ts +++ b/src/scales/ewbank.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, getRoundedScoreTuple, Tuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, getRoundedScoreTuple, Tuple } from '../GradeScale' import routes from '../data/routes.json' import { Route } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' @@ -15,7 +15,7 @@ const EwbankScale: GradeScale = { displayName: 'Ewbank Grade', name: GradeScales.EWBANK, offset: 1000, - conversionGroup: 'Free', + conversionGroup: ConversionGroups.FREE, isType: (grade: string): boolean => { if (isEwbank(grade) === null) { return false diff --git a/src/scales/font.ts b/src/scales/font.ts index 46d98ad..9f64404 100644 --- a/src/scales/font.ts +++ b/src/scales/font.ts @@ -1,5 +1,5 @@ import boulder from '../data/boulder.json' -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple, getRoundedScoreTuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple, getRoundedScoreTuple } from '../GradeScale' import { Boulder } from '.' import { boulderScoreToBand, GradeBandTypes } from '../GradeBands' @@ -14,7 +14,7 @@ const FontScale: GradeScale = { displayName: 'Fontainebleau', name: GradeScales.FONT, offset: 1000, - conversionGroup: 'Bouldering', + conversionGroup: ConversionGroups.BOULDERING, isType: (grade: string): boolean => { if (isFont(grade) === null) { return false diff --git a/src/scales/french.ts b/src/scales/french.ts index c4f1452..0a92f6d 100644 --- a/src/scales/french.ts +++ b/src/scales/french.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple, getRoundedScoreTuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple, getRoundedScoreTuple } from '../GradeScale' import routes from '../data/routes.json' import { Route } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' @@ -13,7 +13,7 @@ const FrenchScale: GradeScale = { displayName: 'French Scale', name: GradeScales.FRENCH, offset: 1000, - conversionGroup: 'Free', + conversionGroup: ConversionGroups.FREE, isType: (grade: string): boolean => { if (isFrench(grade) === null) { return false diff --git a/src/scales/norwegian.ts b/src/scales/norwegian.ts index 7478683..a9691ee 100644 --- a/src/scales/norwegian.ts +++ b/src/scales/norwegian.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple, getRoundedScoreTuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple, getRoundedScoreTuple } from '../GradeScale' import routes from '../data/routes.json' import { Route } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' @@ -13,7 +13,7 @@ const Norwegian: GradeScale = { displayName: 'Norwegian Scale', name: GradeScales.NORWEGIAN, offset: 1000, - conversionGroup: 'Free', + conversionGroup: ConversionGroups.FREE, isType: (grade: string): boolean => { if (isNorwegian(grade) === null) { return false diff --git a/src/scales/saxon.ts b/src/scales/saxon.ts index ba62732..b7c3a13 100644 --- a/src/scales/saxon.ts +++ b/src/scales/saxon.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple, getRoundedScoreTuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple, getRoundedScoreTuple } from '../GradeScale' import routes from '../data/routes.json' import { Route } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' @@ -14,7 +14,7 @@ const SaxonScale: GradeScale = { displayName: 'Saxon Scale', name: GradeScales.SAXON, offset: 1000, - conversionGroup: 'Free', + conversionGroup: ConversionGroups.FREE, isType: (grade: string): boolean => { if (isSaxon(grade) === null) { return false diff --git a/src/scales/uiaa.ts b/src/scales/uiaa.ts index 6104f8b..083d7ff 100644 --- a/src/scales/uiaa.ts +++ b/src/scales/uiaa.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple, getRoundedScoreTuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple, getRoundedScoreTuple } from '../GradeScale' import routes from '../data/routes.json' import { Route } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' @@ -14,7 +14,7 @@ const UIAAScale: GradeScale = { displayName: 'UIAA Scale', name: GradeScales.UIAA, offset: 2000, - conversionGroup: 'Free', + conversionGroup: ConversionGroups.FREE, isType: (grade: string): boolean => { if (isUIAA(grade) === null) { return false diff --git a/src/scales/v.ts b/src/scales/v.ts index ec64593..430c7f6 100644 --- a/src/scales/v.ts +++ b/src/scales/v.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple, getRoundedScoreTuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple, getRoundedScoreTuple } from '../GradeScale' import boulder from '../data/boulder.json' import { Boulder } from '.' import { boulderScoreToBand, GradeBandTypes } from '../GradeBands' @@ -9,7 +9,7 @@ const VScale: GradeScale = { displayName: 'V Scale', name: GradeScales.VSCALE, offset: 1000, - conversionGroup: 'Bouldering', + conversionGroup: ConversionGroups.BOULDERING, isType: (grade: string): boolean => { const isVGrade = grade.match(vGradeRegex) // If there isn't a match sort it to the bottom diff --git a/src/scales/wi.ts b/src/scales/wi.ts index 8f4ab8b..604025b 100644 --- a/src/scales/wi.ts +++ b/src/scales/wi.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple } from '../GradeScale' import ice_table from '../data/ice.json' import { IceGrade } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' @@ -13,7 +13,7 @@ const WIScale: GradeScale = { displayName: 'WI Grade', name: GradeScales.WI, offset: 1000, - conversionGroup: 'Ice', + conversionGroup: ConversionGroups.ICE, isType: (grade: string): boolean => { if (isWI(grade) === null) { return false diff --git a/src/scales/yds.ts b/src/scales/yds.ts index c6ea265..7b810b3 100644 --- a/src/scales/yds.ts +++ b/src/scales/yds.ts @@ -1,4 +1,4 @@ -import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple, getRoundedScoreTuple } from '../GradeScale' +import GradeScale, { findScoreRange, getAvgScore, GradeScales, ConversionGroups, Tuple, getRoundedScoreTuple } from '../GradeScale' import routes from '../data/routes.json' import { Route } from '.' import { GradeBandTypes, routeScoreToBand } from '../GradeBands' @@ -19,7 +19,7 @@ const YosemiteDecimal: GradeScale = { displayName: 'Yosemite Decimal System', name: GradeScales.YDS, offset: 1000, - conversionGroup: 'Free', + conversionGroup: ConversionGroups.FREE, isType: (grade: string): boolean => { if (isYds(grade) === null) { return false