Skip to content

Commit

Permalink
static map disciplineCode if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
nimarion committed Dec 22, 2023
1 parent 2ed7695 commit b8f63f0
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ jobs:
- name: Run monitoring script
uses: actions/checkout@v4
- run: |
bash monitoring.sh
bash monitoring.sh
- name: Update Disciplines
run: |
bash updateDisciplines.sh
git config user.name Github Action
git config user.email [email protected]
git add src/disciplines.json
timestamp=$(date -u)
git commit -m "update disciplines: ${timestamp}" || exit 0
git push
6 changes: 3 additions & 3 deletions src/athletes/athlete.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Performance = z.object({
return date;
}),
discipline: z.string(),
disciplineCode: z.string(),
disciplineCode: z.string().nullable(),
mark: z.string(),
venue: z.string(),
indoor: z.boolean(),
Expand Down Expand Up @@ -59,10 +59,10 @@ const Result = z.object({
return date;
}),
discipline: z.string(),
disciplineCode: z.string(),
disciplineCode: z.string().nullable(),
mark: z.string(),
venue: z.string(),
indoor: z.boolean(),
indoor: z.boolean().nullable().default(false),
competition: z.string(),
place: z.preprocess((val) => {
return Number(val);
Expand Down
4 changes: 3 additions & 1 deletion src/athletes/athletes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Athlete } from './athlete.dto';
import ATHLETE_QUERY from './athlete.query';
import { Athlete as AthleteSchema } from './athlete.zod';
import parseVenue from './venue.utils';
import mapDisciplineToCode from 'src/discipline.utils';

@Injectable()
export class AthletesService {
Expand Down Expand Up @@ -78,7 +79,8 @@ export class AthletesService {
return {
date: result.date,
discipline: result.discipline,
disciplineCode: result.disciplineCode,
disciplineCode:
result.disciplineCode || mapDisciplineToCode(result.discipline),
mark: result.mark.replace(/[^0-9:.]/g, ''),
venue: result.venue,
location,
Expand Down
2 changes: 1 addition & 1 deletion src/athletes/results/result.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from 'zod';
export const ResultsByEvent = z.object({
resultsByEvent: z.array(
z.object({
disciplineCode: z.string(),
disciplineCode: z.string().nullable(),
discipline: z.string(),
indoor: z.boolean(),
results: z.array(
Expand Down
9 changes: 9 additions & 0 deletions src/discipline.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as disciplines from './disciplines.json';

export default function mapDisciplineToCode(discipline: string): string {
const disciplineItem = disciplines.find((d) => d.discipline === discipline);
if (disciplineItem) {
return disciplineItem.disciplineCode;
}
throw new Error(`Discipline ${discipline} not found`);
}
1 change: 1 addition & 0 deletions src/disciplines.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"discipline":"50 Metres","disciplineCode":"50"},{"discipline":"55 Metres","disciplineCode":"55"},{"discipline":"60 Metres","disciplineCode":"60"},{"discipline":"100 Yards","disciplineCode":"100y"},{"discipline":"100 Metres","disciplineCode":"100"},{"discipline":"150 Metres","disciplineCode":"150"},{"discipline":"200 Metres","disciplineCode":"200"},{"discipline":"200 Metres Short Track","disciplineCode":"200sh"},{"discipline":"300 Metres","disciplineCode":"300"},{"discipline":"300 Metres Short Track","disciplineCode":"300sh"},{"discipline":"400 Metres","disciplineCode":"400"},{"discipline":"400 Metres Short Track","disciplineCode":"400sh"},{"discipline":"500 Metres","disciplineCode":"500"},{"discipline":"500 Metres Short Track","disciplineCode":"500sh"},{"discipline":"600 Metres","disciplineCode":"600"},{"discipline":"600 Metres Short Track","disciplineCode":"600sh"},{"discipline":"800 Metres","disciplineCode":"800"},{"discipline":"800 Metres Short Track","disciplineCode":"800sh"},{"discipline":"1000 Metres","disciplineCode":"1000"},{"discipline":"1000 Metres Short Track","disciplineCode":"1000sh"},{"discipline":"1500 Metres","disciplineCode":"1500"},{"discipline":"1500 Metres Short Track","disciplineCode":"1500sh"},{"discipline":"Mile","disciplineCode":"MILE"},{"discipline":"Mile Short Track","disciplineCode":"MILEsh"},{"discipline":"2000 Metres","disciplineCode":"2000"},{"discipline":"2000 Metres Short Track","disciplineCode":"2000sh"},{"discipline":"3000 Metres","disciplineCode":"3000"},{"discipline":"3000 Metres Short Track","disciplineCode":"3000sh"},{"discipline":"2 Miles","disciplineCode":"2MLS"},{"discipline":"2 Miles Short Track","disciplineCode":"2MLSsh"},{"discipline":"5000 Metres","disciplineCode":"5000"},{"discipline":"5000 Metres Short Track","disciplineCode":"5000sh"},{"discipline":"5 Kilometres Road","disciplineCode":"5RR"},{"discipline":"10,000 Metres","disciplineCode":"10K"},{"discipline":"10,000 Metres Short Track","disciplineCode":"10Ksh"},{"discipline":"10 Kilometres Road","disciplineCode":"10RR"},{"discipline":"12 Kilometres Road","disciplineCode":"12RR"},{"discipline":"15,000 Metres","disciplineCode":"15K"},{"discipline":"15 Kilometres Road","disciplineCode":"15RR"},{"discipline":"20,000 Metres","disciplineCode":"20K"},{"discipline":"20 Kilometres Road","disciplineCode":"20RR"},{"discipline":"One Hour","disciplineCode":"HOUR"},{"discipline":"Half Marathon","disciplineCode":"HMAR"},{"discipline":"25,000 Metres","disciplineCode":"25K"},{"discipline":"25 Kilometres Road","disciplineCode":"25RR"},{"discipline":"30,000 Metres","disciplineCode":"30K"},{"discipline":"30 Kilometres Road","disciplineCode":"30RR"},{"discipline":"50 Kilometres Road","disciplineCode":"50RR"},{"discipline":"Marathon","disciplineCode":"MAR"},{"discipline":"100 Kilometres Road","disciplineCode":"100K"},{"discipline":"2000 Metres Steeplechase","disciplineCode":"2KSC"},{"discipline":"2000 Metres Steeplechase Short Track","disciplineCode":"2KSCsh"},{"discipline":"2000 Metres Steeplechase (0.84)","disciplineCode":"2KSC84"},{"discipline":"3000 Metres Steeplechase","disciplineCode":"3KSC"},{"discipline":"3000 Metres Steeplechase Short Track","disciplineCode":"3KSCsh"},{"discipline":"50 Metres Hurdles","disciplineCode":"50H"},{"discipline":"50 Metres Hurdles (91.4cm)","disciplineCode":"50HB"},{"discipline":"50 Metres Hurdles (76.2cm)","disciplineCode":"50HG"},{"discipline":"55 Metres Hurdles","disciplineCode":"55H"},{"discipline":"60 Metres Hurdles","disciplineCode":"60H"},{"discipline":"60 Metres Hurdles (99.0cm)","disciplineCode":"60HJ"},{"discipline":"60 Metres Hurdles (91.4cm)","disciplineCode":"60HY"},{"discipline":"60 Metres Hurdles (76.2cm)","disciplineCode":"60HYG"},{"discipline":"80 Metres Hurdles","disciplineCode":"80H"},{"discipline":"100 Metres Hurdles","disciplineCode":"100H"},{"discipline":"100 Metres Hurdles (76.2cm)","disciplineCode":"100HY"},{"discipline":"110 Metres Hurdles (99.0cm)","disciplineCode":"110HJ"},{"discipline":"110 Metres Hurdles (91.4cm)","disciplineCode":"110HY"},{"discipline":"110 Metres Hurdles","disciplineCode":"110H"},{"discipline":"200 Metres Hurdles","disciplineCode":"200H"},{"discipline":"300 Metres Hurdles","disciplineCode":"300H"},{"discipline":"300 Metres Hurdles (84.0cm)","disciplineCode":"300HY"},{"discipline":"400m hurdles (84.0cm)","disciplineCode":"400HY"},{"discipline":"400 Metres Hurdles","disciplineCode":"400H"},{"discipline":"400 Metres Hurdles Short Track","disciplineCode":"400Hsh"},{"discipline":"High Jump","disciplineCode":"HJ"},{"discipline":"Pole Vault","disciplineCode":"PV"},{"discipline":"Long Jump","disciplineCode":"LJ"},{"discipline":"Triple Jump","disciplineCode":"TJ"},{"discipline":"Shot Put","disciplineCode":"SP"},{"discipline":"Shot Put (6kg)","disciplineCode":"SPJ"},{"discipline":"Shot Put (5kg)","disciplineCode":"SPY"},{"discipline":"Shot Put (3kg)","disciplineCode":"SPYG"},{"discipline":"Shot Put (4kg)","disciplineCode":"SPYG4"},{"discipline":"Discus Throw","disciplineCode":"DT"},{"discipline":"Discus Throw (1.750kg)","disciplineCode":"DTJ"},{"discipline":"Discus Throw (1.500kg)","disciplineCode":"DTY"},{"discipline":"Hammer Throw","disciplineCode":"HT"},{"discipline":"Hammer Throw (6kg)","disciplineCode":"HTJ"},{"discipline":"Hammer Throw (5kg)","disciplineCode":"HTY"},{"discipline":"Hammer Throw (3kg)","disciplineCode":"HTYG"},{"discipline":"Javelin Throw","disciplineCode":"JT"},{"discipline":"Javelin Throw (700g)","disciplineCode":"JTY"},{"discipline":"Javelin Throw (500g)","disciplineCode":"JTYG"},{"discipline":"Pentathlon","disciplineCode":"PEN"},{"discipline":"Pentathlon Short Track","disciplineCode":"PENsh"},{"discipline":"Pentathlon Girls Short Track","disciplineCode":"PENGsh"},{"discipline":"Heptathlon U20 Short Track","disciplineCode":"HEPJsh"},{"discipline":"Heptathlon Short Track","disciplineCode":"HEPsh"},{"discipline":"Heptathlon","disciplineCode":"HEP"},{"discipline":"Heptathlon-100mH 76.2cm","disciplineCode":"HEPY"},{"discipline":"Heptathlon U18","disciplineCode":"HEPG"},{"discipline":"Heptathlon U18 Short Track","disciplineCode":"HEPBsh"},{"discipline":"Octathlon U16","disciplineCode":"OCT"},{"discipline":"Octathlon Boys","disciplineCode":"OCTY"},{"discipline":"Decathlon","disciplineCode":"DEC"},{"discipline":"Decathlon (62-84)","disciplineCode":"DEC6284"},{"discipline":"Decathlon U20","disciplineCode":"DECJ"},{"discipline":"Decathlon (1.06) U20","disciplineCode":"DECJO"},{"discipline":"Decathlon Boys","disciplineCode":"DECY"},{"discipline":"Mile Race Walk","disciplineCode":"MILEW"},{"discipline":"Mile Race Walk Short Track","disciplineCode":"MILEWsh"},{"discipline":"3000 Metres Race Walk","disciplineCode":"3KW"},{"discipline":"3000 Metres Race Walk Short Track","disciplineCode":"3KWsh"},{"discipline":"5000 Metres Race Walk","disciplineCode":"5KW"},{"discipline":"5000 Metres Race Walk Short Track","disciplineCode":"5KWsh"},{"discipline":"5 Kilometres Race Walk","disciplineCode":"5KR"},{"discipline":"10,000 Metres Race Walk","disciplineCode":"10KW"},{"discipline":"10,000 Metres Race Walk Short Track","disciplineCode":"10KWsh"},{"discipline":"10 Kilometres Race Walk","disciplineCode":"10KR"},{"discipline":"15 Kilometers Race Walk","disciplineCode":"15KR"},{"discipline":"20,000 Metres Race Walk","disciplineCode":"20KW"},{"discipline":"20 Kilometres Race Walk","disciplineCode":"20KR"},{"discipline":"2 Hours Race Walk","disciplineCode":"2HW"},{"discipline":"30,000 Metres Race Walk","disciplineCode":"30KW"},{"discipline":"30 Kilometres Race Walk","disciplineCode":"30KR"},{"discipline":"35 Kilometres Race Walk","disciplineCode":"35KR"},{"discipline":"50,000 Metres Race Walk","disciplineCode":"50KW"},{"discipline":"50 Kilometres Race Walk","disciplineCode":"50KR"},{"discipline":"4x100 Metres Relay","disciplineCode":"4X1"},{"discipline":"4x200 Metres Relay","disciplineCode":"4X2"},{"discipline":"4x200 Metres Relay Short Track","disciplineCode":"4X2sh"},{"discipline":"4x400 Metres Relay","disciplineCode":"4X4"},{"discipline":"4x400 Metres Relay Short Track","disciplineCode":"4X4sh"},{"discipline":"4x800 Metres Relay","disciplineCode":"4X8"},{"discipline":"4x800 Metres Relay Short Track","disciplineCode":"4X8sh"},{"discipline":"4xMile Relay","disciplineCode":"4XMILE"},{"discipline":"4xMile Relay Short Track","disciplineCode":"4XMILsh"},{"discipline":"4x1500 Metres Relay","disciplineCode":"4X15"},{"discipline":"Sprint Medley Relay","disciplineCode":"MEAD"},{"discipline":"8x100 Metres Relay","disciplineCode":"8X1"},{"discipline":"Road Relay","disciplineCode":"EKID"},{"discipline":"Distance Medley Relay","disciplineCode":"DISMEAD"},{"discipline":"Distance Medley Relay Short Track","disciplineCode":"DISMEsh"},{"discipline":"Cross Country Relay","disciplineCode":"MIXREL"},{"discipline":"2x2x400m Relay","disciplineCode":"2X2X4"},{"discipline":"Shuttle Hurdles","disciplineCode":"SHUTHUR"},{"discipline":"3x100 Metres Relay","disciplineCode":"3X1"},{"discipline":"Hour Race Walk","disciplineCode":"1HW"},{"discipline":"600 Metres Road","disciplineCode":"600R"},{"discipline":"Mile Road","disciplineCode":"1MR"},{"discipline":"5 Miles Road","disciplineCode":"5MR"},{"discipline":"10 Miles Road","disciplineCode":"10MR"},{"discipline":"8 Kilometres Road","disciplineCode":"8RR"},{"discipline":"Cross Country Senior Race","disciplineCode":"XSE"},{"discipline":"Cross Country U20 Race","disciplineCode":"XJ"},{"discipline":"Cross Country U23 Race","disciplineCode":"XU23"},{"discipline":"Cross Country Short Race","disciplineCode":"XC"},{"discipline":"Cross Country Long Race","disciplineCode":"XS"},{"discipline":"Cross Country 4000m","disciplineCode":"XC4KM"},{"discipline":"24 Hours","disciplineCode":"24H"},{"discipline":"Marathon Race Walk Mixed Relay","disciplineCode":"MARMXT"},{"discipline":"100m Amputee","disciplineCode":"100A"},{"discipline":"200m Amputee","disciplineCode":"200A"},{"discipline":"100m Blind","disciplineCode":"100B"},{"discipline":"200m Blind","disciplineCode":"200B"},{"discipline":"400m Blind","disciplineCode":"400B"},{"discipline":"400m Cerebral Palsy","disciplineCode":"400CP"},{"discipline":"800m Masters","disciplineCode":"800MA"},{"discipline":"800m Wheelchair","disciplineCode":"800W"},{"discipline":"1500m Wheelchair","disciplineCode":"1500W"},{"discipline":"100m Wheelchair","disciplineCode":"100W"},{"discipline":"800 Metres T54","disciplineCode":"800T54"},{"discipline":"Javelin Throw Wheelchair","disciplineCode":"JTW"},{"discipline":"400 Metres T53","disciplineCode":"400T53"},{"discipline":"400m Masters","disciplineCode":"400MA"},{"discipline":"200m Visually Impaired","disciplineCode":"200VI"},{"discipline":"200m Wheelchair","disciplineCode":"200W"},{"discipline":"Road Race","disciplineCode":"RR"}]
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true
}
}
3 changes: 3 additions & 0 deletions updateDisciplines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

curl -o src/disciplines.json --silent --show-error --fail https://worldathletics.pfingstsportfest.de/disciplines

0 comments on commit b8f63f0

Please sign in to comment.