From 0be1aeb89e582bdce0c58f66e8a13526dc1ad474 Mon Sep 17 00:00:00 2001 From: Nathan Musoke Date: Mon, 26 Jun 2023 16:30:58 -0400 Subject: [PATCH] WIP parse grade tables at run time 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. --- src/GradeScale.ts | 4 ++++ src/data/csvtojson.ts | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/GradeScale.ts b/src/GradeScale.ts index 43877f7..e66c25a 100644 --- a/src/GradeScale.ts +++ b/src/GradeScale.ts @@ -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] @@ -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 } + diff --git a/src/data/csvtojson.ts b/src/data/csvtojson.ts index d77733e..653bd8f 100644 --- a/src/data/csvtojson.ts +++ b/src/data/csvtojson.ts @@ -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') @@ -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') @@ -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') @@ -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