Skip to content

Commit

Permalink
WIP parse grade tables at run time
Browse files Browse the repository at this point in the history
sandbag requires that json files in `src/data/` be regenerated and
committed whenever grade tables change.  This is error prone for two
reasons:
- CI doesn't check that the conversion script works.
- CI doesn't check that the conversion script was run.

Simplify this by changing `src/data/csvtojson.ts` to a module that
exports the requisite tables.
  • Loading branch information
musoke committed Jun 26, 2023
1 parent 5b15469 commit 0be1aeb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/GradeScale.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { GradeBandTypes } from './GradeBands'
import { BOULDER_GRADE_TABLE, ROUTE_GRADE_TABLE, ICE_GRADE_TABLE, AID_GRADE_TABLE } from './data/csvtojson'

export { BOULDER_GRADE_TABLE, ROUTE_GRADE_TABLE, ICE_GRADE_TABLE, AID_GRADE_TABLE }

export type Tuple = [number, number]

Expand Down Expand Up @@ -47,3 +50,4 @@ export const findScoreRange = (compareFn, list): number | Tuple => {
export function getAvgScore (score: number | Tuple): number {
return typeof score === 'number' ? score : (score[1] + score[0]) / 2
}

12 changes: 8 additions & 4 deletions src/data/csvtojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ function parseRowBoulder (row): Object {
font: row['Font Scale']
}
}
void getData(CSV_PATH_BOULDER, JSON_PATH_BOULDER, boulderGrades, parseRowBoulder)
const BOULDER_GRADE_TABLE = getData(CSV_PATH_BOULDER, JSON_PATH_BOULDER, boulderGrades, parseRowBoulder)
export await BOULDER_GRADE_TABLE

const CSV_PATH_ROUTES = path.join(dataDir, 'routes.csv')
const JSON_PATH_ROUTES = path.join(dataDir, 'routes.json')
Expand All @@ -56,7 +57,8 @@ function parseRowRoutes (row): Object {
norwegian: row.Norwegian
}
}
void getData(CSV_PATH_ROUTES, JSON_PATH_ROUTES, routeGrades, parseRowRoutes)
const ROUTE_GRADE_TABLE = getData(CSV_PATH_ROUTES, JSON_PATH_ROUTES, routeGrades, parseRowRoutes)
export await ROUTE_GRADE_TABLE

const CSV_PATH_ICE = path.join(dataDir, 'ice.csv')
const JSON_PATH_ICE = path.join(dataDir, 'ice.json')
Expand All @@ -68,7 +70,8 @@ function parseRowIce (row): Object {
ai: row.AI
}
}
void getData(CSV_PATH_ICE, JSON_PATH_ICE, iceGrades, parseRowIce)
const ICE_GRADE_TABLE = getData(CSV_PATH_ICE, JSON_PATH_ICE, iceGrades, parseRowIce)
export await ICE_GRADE_TABLE

const CSV_PATH_AID = path.join(dataDir, 'aid.csv')
const JSON_PATH_AID = path.join(dataDir, 'aid.json')
Expand All @@ -79,4 +82,5 @@ function parseRowAid (row): Object {
aid: row.Aid
}
}
void getData(CSV_PATH_AID, JSON_PATH_AID, aidGrades, parseRowAid)
const AID_GRADE_TABLE = getData(CSV_PATH_AID, JSON_PATH_AID, aidGrades, parseRowAid)
export await AID_GRADE_TABLE

0 comments on commit 0be1aeb

Please sign in to comment.