Skip to content

Commit

Permalink
feat: Ice context
Browse files Browse the repository at this point in the history
This adds basic support for ice climbs with the WI grade scales.

This currently assumes that all contexts use only Winter Ice grades
rather than a mix of Alpine Ice and Winter Ice.  This is not the case;
the grade scale depends on the local climate.

To enable AI grades in future, the ice grades allowed in most contexts
should be an array: `[GradeScales.AI, GradeScales.WI]`.
  • Loading branch information
musoke committed Jun 1, 2023
1 parent fb7bf62 commit cc6bdfa
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/GradeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const gradeContextToGradeScales: Partial<Record<GradeContexts, ClimbGrade
mixed: GradeScales.YDS,
aid: GradeScales.YDS,
snow: GradeScales.YDS, // is this the same as alpine?
ice: GradeScales.YDS // is this the same as alpine?
ice: GradeScales.WI

Check failure on line 49 in src/GradeUtils.ts

View workflow job for this annotation

GitHub Actions / build

Property 'WI' does not exist on type '{ readonly VSCALE: "vscale"; readonly YDS: "yds"; readonly FONT: "font"; readonly FRENCH: "french"; readonly UIAA: "uiaa"; readonly EWBANK: "ewbank"; }'.
},
[GradeContexts.US]: {
trad: GradeScales.YDS,
Expand All @@ -57,7 +57,7 @@ export const gradeContextToGradeScales: Partial<Record<GradeContexts, ClimbGrade
mixed: GradeScales.YDS,
aid: GradeScales.YDS,
snow: GradeScales.YDS, // is this the same as alpine?
ice: GradeScales.YDS // is this the same as alpine?
ice: GradeScales.WI

Check failure on line 60 in src/GradeUtils.ts

View workflow job for this annotation

GitHub Actions / build

Property 'WI' does not exist on type '{ readonly VSCALE: "vscale"; readonly YDS: "yds"; readonly FONT: "font"; readonly FRENCH: "french"; readonly UIAA: "uiaa"; readonly EWBANK: "ewbank"; }'.
},
[GradeContexts.FR]: {
trad: GradeScales.FRENCH,
Expand All @@ -68,7 +68,7 @@ export const gradeContextToGradeScales: Partial<Record<GradeContexts, ClimbGrade
mixed: GradeScales.FRENCH,
aid: GradeScales.FRENCH,
snow: GradeScales.FRENCH, // is this the same as alpine?
ice: GradeScales.FRENCH // is this the same as alpine?
ice: GradeScales.WI

Check failure on line 71 in src/GradeUtils.ts

View workflow job for this annotation

GitHub Actions / build

Property 'WI' does not exist on type '{ readonly VSCALE: "vscale"; readonly YDS: "yds"; readonly FONT: "font"; readonly FRENCH: "french"; readonly UIAA: "uiaa"; readonly EWBANK: "ewbank"; }'.
},
[GradeContexts.SA]: {
trad: GradeScales.FRENCH,
Expand All @@ -79,7 +79,7 @@ export const gradeContextToGradeScales: Partial<Record<GradeContexts, ClimbGrade
mixed: GradeScales.FRENCH,
aid: GradeScales.FRENCH,
snow: GradeScales.FRENCH, // SA does not have a whole lot of snow
ice: GradeScales.FRENCH // SA does not have a whole lot of ice
ice: GradeScales.WI

Check failure on line 82 in src/GradeUtils.ts

View workflow job for this annotation

GitHub Actions / build

Property 'WI' does not exist on type '{ readonly VSCALE: "vscale"; readonly YDS: "yds"; readonly FONT: "font"; readonly FRENCH: "french"; readonly UIAA: "uiaa"; readonly EWBANK: "ewbank"; }'.
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/gradeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ describe('Test grade utilities', () => {
vscale: 'V4'
})

actual = createGradeObject('WI2', sanitizeDisciplines({ ice: true }), context)
expect(actual).toEqual({
wi: 'WI2'
})

// mismatch input and discipline
actual = createGradeObject('V4', sanitizeDisciplines({ trad: true }), context)
expect(actual).toBeUndefined()
Expand All @@ -75,6 +80,11 @@ describe('Test grade utilities', () => {
vscale: 'v11'
})

actual = createGradeObject('WI2', sanitizeDisciplines({ ice: true }), context)
expect(actual).toEqual({
wi: 'WI2'
})

// Invalid input
actual = createGradeObject('5.9', sanitizeDisciplines({ sport: true }), context)
expect(actual).toBeUndefined()
Expand All @@ -94,6 +104,11 @@ describe('Test grade utilities', () => {
font: '7c'
})

actual = createGradeObject('WI2', sanitizeDisciplines({ ice: true }), context)
expect(actual).toEqual({
wi: 'WI2'
})

// Invalid input
actual = createGradeObject('5.9', sanitizeDisciplines({ bouldering: true }), context)
expect(actual).toBeUndefined()
Expand Down
36 changes: 31 additions & 5 deletions src/model/__tests__/MutableClimbDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ describe('Climb CRUD', () => {
disciplines: {
trad: true
}
},
{
name: 'Icy ice one',
disciplines: {
ice: true
}
}
]

Expand Down Expand Up @@ -73,6 +79,14 @@ describe('Climb CRUD', () => {
grade: '5c'
}

const newIceRoute: ClimbChangeInputType = {
name: 'Cool Ice line',
disciplines: {
ice: true
},
grade: 'WI8+'
}

beforeAll(async () => {
await connectDB()
stream = await streamListener()
Expand Down Expand Up @@ -247,14 +261,19 @@ describe('Climb CRUD', () => {
const newClimbingArea = await areas.addArea(testUser, 'Climbing area 1', null, 'aus')
if (newClimbingArea == null) fail('Expect new area to be created')

const newclimbs = [
{ ...newSportClimb1, grade: '17' }, // good sport grade
{ ...newSportClimb2, grade: '29/30', disciplines: { trad: true } }, // good trad and slash grade
{ ...newSportClimb2, grade: '5.9' }, // bad AU context grade
{ ...newIceRoute, grade: 'WI4+' } // good WI AU context grade
]

const newIDs = await climbs.addOrUpdateClimbs(
testUser,
newClimbingArea.metadata.area_id,
[{ ...newSportClimb1, grade: '17' }, // good sport grade
{ ...newSportClimb2, grade: '29/30', disciplines: { trad: true } }, // good trad and slash grade
{ ...newSportClimb2, grade: '5.9' }]) // bad AU context grade

expect(newIDs).toHaveLength(3)
newclimbs
)
expect(newIDs).toHaveLength(newclimbs.length)

const climb1 = await climbs.findOneClimbByMUUID(muid.from(newIDs[0]))
expect(climb1?.grades).toEqual({ ewbank: '17' })
Expand All @@ -267,6 +286,13 @@ describe('Climb CRUD', () => {

const climb3 = await climbs.findOneClimbByMUUID(muid.from(newIDs[2]))
expect(climb3?.grades).toEqual(undefined)

const climb4 = await climbs.findOneClimbByMUUID(muid.from(newIDs[3]))
expect(climb4?.grades).toEqual({ wi: 'WI4+' })
expect(climb4?.type.sport).toBe(false)
expect(climb4?.type.trad).toBe(false)
expect(climb4?.type.bouldering).toBe(false)
expect(climb4?.type.ice).toBe(true)
}

{
Expand Down

0 comments on commit cc6bdfa

Please sign in to comment.