Skip to content

Commit

Permalink
feat: Ice context
Browse files Browse the repository at this point in the history
The grade contexts know nothing about ice climbing grades. Instead, they
use sport/trad grades.

Add support for ice climbs with WI grades.

This commit assumes that all contexts use only Winter Ice grades.  This
does not completely reflect real world usage - single regions often have
a mix of WI and AI grades.

In the short term, this could be overriden for local areas.
Longer term, ice grades allowed in these contexts should be either of
`GradeScales.AI` and `GradeScales.WI`.
  • Loading branch information
musoke committed Jun 28, 2023
1 parent dab9388 commit e6b80aa
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@babel/runtime": "^7.17.2",
"@google-cloud/storage": "^6.9.5",
"@graphql-tools/schema": "^8.3.1",
"@openbeta/sandbag": "^0.0.37",
"@openbeta/sandbag": "^0.0.45",
"@turf/area": "^6.5.0",
"@turf/bbox": "^6.5.0",
"@turf/bbox-polygon": "^6.5.0",
Expand Down
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
},
[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
},
[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
},
[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
}
}

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 @@ -44,6 +44,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
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1579,10 +1579,10 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@openbeta/sandbag@^0.0.37":
version "0.0.37"
resolved "https://registry.yarnpkg.com/@openbeta/sandbag/-/sandbag-0.0.37.tgz#59befbb2bace586be19c0a3c6d9f8046c05fa05e"
integrity sha512-oeCqXAZkvgHkUOHZefhZyftxsarcdHUtS2oEttIACCRpZ/Vs2hAmyXIn1Yg7dxnQEKbJ3TtVD4trUmNoJSolag==
"@openbeta/sandbag@^0.0.45":
version "0.0.45"
resolved "https://registry.yarnpkg.com/@openbeta/sandbag/-/sandbag-0.0.45.tgz#b6230ddf63f265b91d0a0359a2f87c5359dded74"
integrity sha512-8s2YFeUBU3lK2EzQIZSsf/apEIaxhtHJNfWWDmtjIE7/wlgqm84BSX72wur1FGrqcI9o3P1dkZmevHnu0ItGZQ==

"@panva/asn1.js@^1.0.0":
version "1.0.0"
Expand Down

0 comments on commit e6b80aa

Please sign in to comment.