Skip to content

Commit

Permalink
Draft Polish scale implementaion
Browse files Browse the repository at this point in the history
  • Loading branch information
Agilulfo committed Sep 18, 2024
1 parent f47983a commit 4ac4a7f
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/GradeScale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export const GradeScales = {
EWBANK: 'ewbank',
SAXON: 'saxon',
NORWEGIAN: 'norwegian',
BRAZILIAN_CRUX: 'brazilian_crux'
BRAZILIAN_CRUX: 'brazilian_crux',
POLISH: 'polish'
} as const

export type GradeScalesTypes = typeof GradeScales[keyof typeof GradeScales]
Expand Down
97 changes: 97 additions & 0 deletions src/__tests__/scales/polish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// import { GradeBands } from '../../GradeBands'
import { Polish } from '../../scales'

describe('Polish', () => {
describe('isPolish', () => {
test('VI', () => {
expect(Polish.isType('VI'))
})
})
// describe('Get Score', () => {
// test('9a > 5c', () => {
// const lowGrade = Polish.getScore('5c')
// const highGrade = Polish.getScore('9a')
// expect(highGrade[0]).toBeGreaterThan(lowGrade[1])
// })

// test('1c > 1a+', () => {
// const highGrade = Polish.getScore('1c')
// const lowGrade = Polish.getScore('1a+')
// expect(highGrade[0]).toBeGreaterThan(lowGrade[1])
// })

// test('1a/1a+ > 1a, one grade away', () => {
// const highGrade = Polish.getScore('1a/1a+')
// const lowGrade = Polish.getScore('1a')
// expect(highGrade[0] < lowGrade[1] && highGrade[0] > lowGrade[0])
// expect(highGrade[1]).toBeGreaterThan(lowGrade[1])
// })

// test('4a > 3c+/4a, one grade away', () => {
// const highGrade = Polish.getScore('4a')
// const lowGrade = Polish.getScore('3c+/4a')
// expect(highGrade[0] < lowGrade[1] && highGrade[0] > lowGrade[0])
// expect(highGrade[1]).toBeGreaterThan(lowGrade[1])
// })
// })

// describe('invalid grade format', () => {
// jest.spyOn(console, 'warn').mockImplementation()
// beforeEach(() => {
// jest.clearAllMocks()
// })
// test('extra plus modifier', () => {
// const invalidGrade = Polish.getScore('5a++')
// expect(console.warn).toHaveBeenCalledWith('Unexpected grade format: 5a++ for grade scale polish')
// expect(invalidGrade).toEqual(-1)
// })
// test('invalid minus modifier', () => {
// const invalidGrade = Polish.getScore('5a-')
// expect(console.warn).toHaveBeenCalledWith('Unexpected grade format: 5a- for grade scale polish')
// expect(invalidGrade).toEqual(-1)
// })
// test('extra slash grade', () => {
// const invalidGrade = Polish.getScore('5a/5a+/5b+')
// expect(console.warn).toHaveBeenCalledWith('Unexpected grade format: 5a/5a+/5b+ for grade scale polish')
// expect(invalidGrade).toEqual(-1)
// })
// test('extra slash', () => {
// const invalidGrade = Polish.getScore('5a/')
// expect(console.warn).toHaveBeenCalledWith('Unexpected grade format: 5a/ for grade scale polish')
// expect(invalidGrade).toEqual(-1)
// })
// test('not Polish scale', () => {
// const invalidGrade = Polish.getScore('v11')
// expect(console.warn).toHaveBeenCalledWith('Unexpected grade format: v11 for grade scale polish')
// expect(invalidGrade).toEqual(-1)
// })
// })

// describe('Get Grade', () => {
// test('bottom of range', () => {
// expect(Polish.getGrade(0)).toBe('1a')
// })

// test('top of range', () => {
// expect(Polish.getGrade(1000)).toBe('9c+')
// })

// test('single score provided', () => {
// expect(Polish.getGrade(34)).toBe('3c+')
// expect(Polish.getGrade(34.5)).toBe('3c+')
// expect(Polish.getGrade(35)).toBe('3c+')
// })
// test('range of scores provided', () => {
// expect(Polish.getGrade([0.5, 2])).toBe('1a/1a+')
// expect(Polish.getGrade([8, 12])).toBe('1c/2a')
// expect(Polish.getGrade([16, 17])).toBe('2b')
// })
// })

// describe('Get Grade Band', () => {
// test('gets Gradeband', () => {
// expect(Polish.getGradeBand('1a')).toEqual(GradeBands.BEGINNER)
// expect(Polish.getGradeBand('9c+')).toEqual(GradeBands.EXPERT)
// })
// })
})
42 changes: 39 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
convertGrade
} from './GradeParser'
import { GradeBands, GradeBandTypes } from './GradeBands'
import { AI, Aid, Ewbank, Font, French, Norwegian, Saxon, UIAA, VScale, WI, YosemiteDecimal, BrazilianCrux } from './scales'
import { AI, Aid, Ewbank, Font, French, Norwegian, Saxon, UIAA, VScale, WI, YosemiteDecimal, BrazilianCrux, Polish } from './scales'

// Free Climbing Grades
// YDS
Expand Down Expand Up @@ -261,6 +261,39 @@ const NORWAY_ARRAY = [
'12+'
]

// TODO: check this is acutally needed and where it is used
// seems recent changes for the brasilian scale did not introduce this change
const POLISH_ARRAY = [
'I',
'II',
'III',
'IV',
'IV+',
'V-',
'V',
'V+',
'VI',
'VI+',
'VI.1',
'VI.1+',
'VI.2',
'VI.2+',
'VI.3',
'VI.3+',
'VI.4',
'VI.4+',
'VI.5',
'VI.5+',
'VI.6',
'VI.6+',
'VI.7',
'VI.7+',
'VI.8',
'VI.8+',
'VI.9',
'VI.9+'
]

const CLASS_ARRAY = ['Class 1', 'Class 2', 'Class 3', 'Class 4', 'Class 5']

export const protection = ['G', 'PG', 'PG13', 'R', 'X']
Expand All @@ -280,7 +313,9 @@ export const freeClimbing = {
Ewbank: EWBANK_ARRAY,
Saxon: SAXON_ARRAY,
Norwegian: NORWAY_ARRAY,
BrazilianCrux: BrazilianCrux.grades
// TODO: check why this differ
BrazilianCrux: BrazilianCrux.grades,
Polish: POLISH_ARRAY
},
community: {}
}
Expand Down Expand Up @@ -312,5 +347,6 @@ export {
VScale,
WI,
YosemiteDecimal,
BrazilianCrux
BrazilianCrux,

Check warning on line 350 in src/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
Polish

Check warning on line 351 in src/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
}
5 changes: 4 additions & 1 deletion src/scales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import AI from './ai'
import Aid from './aid'
import WI from './wi'
import BrazilianCrux from './brazilian'
import Polish from './polish'
import UIAA from './uiaa'
import GradeScale, { GradeScales } from '../GradeScale'
export { Aid, VScale, Font, YosemiteDecimal, French, Saxon, UIAA, Ewbank, AI, WI, Norwegian, BrazilianCrux }
export { Aid, VScale, Font, YosemiteDecimal, French, Saxon, UIAA, Ewbank, AI, WI, Norwegian, BrazilianCrux, Polish }

export interface Boulder {
score: number
Expand All @@ -28,6 +29,7 @@ export interface Route {
saxon: string
norwegian: string
brazilian: string
polish: string
}

export interface IceGrade {
Expand All @@ -54,6 +56,7 @@ GradeScale | null
[GradeScales.SAXON]: Saxon,
[GradeScales.NORWEGIAN]: Norwegian,
[GradeScales.BRAZILIAN_CRUX]: BrazilianCrux,
[GradeScales.POLISH]: Polish,
[GradeScales.AI]: AI,
[GradeScales.WI]: WI,
[GradeScales.AID]: Aid
Expand Down
79 changes: 79 additions & 0 deletions src/scales/polish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import GradeScale, { findScoreRange, getAvgScore, GradeScales, Tuple, getRoundedScoreTuple } from '../GradeScale'
import routes from '../data/routes.json'
import { Route } from '.'
import { GradeBandTypes, routeScoreToBand } from '../GradeBands'

// TODO: set this regexp
const polishGradeRegex = /^([1-9][a-c][+]?){1}(?:(\/)([1-9][a-c][+]?))?$/i
// Supports 1a -> 9c+, slash grades i.e. 5a/5a+ or 6a+/6b
// NOTE: this currently assumes "incorrect" slash grades follows the normal pattern
// i.e. 6b+/5a => 6b+/6c
const isPolish = (grade: string): RegExpMatchArray | null => grade.match(polishGradeRegex)

const PolishScale: GradeScale = {
displayName: 'Polish Scale',
name: GradeScales.POLISH,
offset: 1000,
allowableConversionType: [GradeScales.YDS, GradeScales.EWBANK, GradeScales.SAXON],
isType: (grade: string): boolean => {
if (isPolish(grade) === null) {
return false
}
return true

Check warning on line 22 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
},
getScore: (grade: string): number | Tuple => {

Check warning on line 24 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return getScore(grade)

Check warning on line 25 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
},
getGrade: (score: number | Tuple): string => {

Check warning on line 27 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const validateScore = (score: number): number => {

Check warning on line 28 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const validScore = Number.isInteger(score) ? score : Math.ceil(score)

Check warning on line 29 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 29 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 29 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
return Math.min(Math.max(0, validScore), routes.length - 1)

Check warning on line 30 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 31 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

if (typeof score === 'number') {
return routes[validateScore(score)].polish

Check warning on line 34 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 35 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 35 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

const low: string = routes[validateScore(score[0])].polish

Check warning on line 37 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const high: string = routes[validateScore(score[1])].polish

Check warning on line 38 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
if (low === high) return low

Check warning on line 39 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 39 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 39 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
return `${low}/${high}`

Check warning on line 40 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
},
getGradeBand: (grade: string): GradeBandTypes => {

Check warning on line 42 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const score = getScore(grade)

Check warning on line 43 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
return routeScoreToBand(getAvgScore(score))

Check warning on line 44 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}
}

const getScore = (grade: string): number | Tuple => {

Check warning on line 48 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const parse = isPolish(grade)

Check warning on line 49 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
if (parse == null) {
console.warn(`Unexpected grade format: ${grade} for grade scale polish`)

Check warning on line 51 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
return -1

Check warning on line 52 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 53 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 53 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const [wholeMatch, basicGrade, slash] = parse

Check warning on line 54 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const basicScore = findScoreRange((r: Route) => {
return r.polish === basicGrade

Check warning on line 56 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}, routes)

Check warning on line 57 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

if (wholeMatch !== basicGrade) {
// 5a/5a+
let otherGrade
if (slash !== null) {
otherGrade = (typeof basicScore === 'number' ? basicScore : basicScore[1]) + 1

Check warning on line 63 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 63 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 63 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 64 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 64 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
if (otherGrade !== undefined) {
const nextGrade = findScoreRange(
(r: Route) => r.polish.toLowerCase() === routes[otherGrade].polish.toLowerCase(),

Check warning on line 67 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
routes

Check warning on line 68 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
)
const basicAvg = getAvgScore(basicScore)

Check warning on line 70 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const nextGradeAvg = getAvgScore(nextGrade)

Check warning on line 71 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const tuple = getRoundedScoreTuple(basicAvg, nextGradeAvg)

Check warning on line 72 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
return tuple

Check warning on line 73 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 74 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 74 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 75 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 75 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
return basicScore

Check warning on line 76 in src/scales/polish.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

export default PolishScale

0 comments on commit 4ac4a7f

Please sign in to comment.