Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test and refactor csvtojson #133

Merged
merged 4 commits into from
Jul 14, 2023
Merged

Test and refactor csvtojson #133

merged 4 commits into from
Jul 14, 2023

Conversation

musoke
Copy link
Collaborator

@musoke musoke commented Jun 28, 2023

src/data/csvtojson.ts is a script used to convert CSV tables of grades
to JSON files used by sandbag at run time. The script is not tested in
CI, so it is not obvious if it is broken or if someone forgot to run it
while changing grade tables.

Add tests of this script.
Also check that it does not change the correspondning JSON files during
testing.

Fixes: #120

In addition, refactor csvtojson.ts to make tests straightforward and improve future maintainability by

  • exporting tables from csvtojson.ts so they can be tested
  • removing grade bands from JSON files (they were all "unknown")
  • matching headers of CSVs to fields in corresponding interfaces
    export interface Boulder {
    score: number
    v: string
    font: string
    band: GradeBandTypes
    }
    export interface Route {
    score: number
    yds: string
    french: string
    uiaa: string
    ewbank: string
    saxon: string
    norwegian: string
    band: GradeBandTypes
    }
    export interface IceGrade {
    score: number
    ai: string
    wi: string
    }
    export interface AidGrade {
    score: number
    aid: string
    }
    and removing the translation between them

Each discipline's CSV is parsed in the same way, but has its own
implementation.  This introduces the possibility of errors when adding
new scales.

Factor out all the parsing.
The grade bands are defined in `src/GradeBands.ts`.  They don't need to
appear in the JSON files or `src/scales/index.ts`.  Removing them
simplifies parsing the CSVs.
`src/data/csvtojson.ts` is a script used to convert CSV tables of grades
to JSON files used by sandbag at run time.  The script is not tested in
CI, so it is not obvious if it is broken or if someone forgot to run it
while changing grade tables.

Add tests of this script.
Also check that it does not change the corresponding JSON files during
testing.

Fixes: OpenBeta#120
@musoke musoke force-pushed the test-csv branch 2 times, most recently from fb24f8e to c7546d9 Compare June 28, 2023 22:13
Comment on lines +32 to +33
- name: Check if JSON conversions changed by running tests
run: git diff --exit-code "src/data/*.json"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@musoke musoke requested a review from actuallyyun June 28, 2023 22:16
@musoke
Copy link
Collaborator Author

musoke commented Jun 28, 2023

@actuallyyun, could you review this since you made the most recent changes to csvtojson.ts?

There is redundant information in the mappings from column titles in our
CSVs to field names of the corresponding interfaces.  Simplify this by
renaming the columns to match the fields they are written to.
@musoke musoke merged commit 5870f1f into OpenBeta:develop Jul 14, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test csvtojson in CI
1 participant