Repository navigation
refactor: define every sport once, in a catalogue - #28
Merged
Merged
Conversation
What differs between sports lived in seven places: an alias table in each of the three parsers, and the pace list, cadence unit, labels, colours and order in the frontend. Adding a sport meant finding all of them. app/services/sports.py now holds one entry per sport: label, pace or speed, cadence unit, colour slot, and per-format file aliases. The parsers look sports up there, GET /api/sports serves it, and the dashboard loads it at startup and reads it everywhere. No behaviour change: the new lookup was checked against the old tables for every alias. A backend test keeps the frontend tests' copy of the catalogue in step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 1 of supporting more sports, strength first. What differs between sports was spread over seven places:
formatters.js(which also decided the cadence unit), labels made by capitalising the key, colours intheme.js, and the sport order inSportBreakdown.jsx.Adding a sport meant finding all of them. Now it's one entry.
What changes
Backend
app/services/sports.py: oneSportper sport, with key, label,paceorspeed, cadence unit, palette colour slot, and its FIT, TCX and GPX aliases. Aliases are per format, because Strava's GPX9means a run and nothing says it does in TCX.sport_from_file(format, declared). An unknown name is still kept as written (rowingstaysrowing), and no name at all isother, as before.GET /api/sports: the catalogue in display order, without the file aliases.scripts/export_sports.py: writes the catalogue for the frontend tests, no database needed.Frontend
src/sports.jsregistry, loaded byApptogether with the profile before anything renders. If the catalogue can't be loaded, the app shows the same "Cannot reach the API" screen as for the profile.formatters.js(pace or speed, cadence unit, label),theme.js(sportColor) andSportBreakdown(order) read from it. A sport the catalogue doesn't list reads by speed, in the "other" colour, under its own name, which matches the old behaviour.SPORT_ORDERintheme.jsis renamedPALETTE_SLOTS, since it orders colour slots, not sports.Docs: README (API table, a new "Adding a sport" section, layout, the out-of-date test counts) and a new "Sports" section in
docs/DESIGN.md.No behaviour change
None, padded, mixed-case and unknown values. 0 mismatches out of 56.SPORT_ORDERrename.SPORT_ORDER(indexOfreturned -1). It now has its own place after hiking.Keeping the frontend tests honest
The frontend tests run without a server, so they read a copy of the catalogue (
frontend/tests/sports.json).test_the_frontend_tests_use_the_real_cataloguefails as soon as that copy differs from what the API serves, so the copy can't quietly become a second definition.python -m scripts.export_sportsregenerates it.Checks
tests/test_sports.py), coverage 96.7% (catalogue and route 100%).adding a sport > needs nothing but a catalogue entry: a sport defined only in the catalogue gets its label, pace, cadence unit, colour and order. One earlier full run on this machine had a single timeout inDashboardRecords; it passed alone twice and in the next two full runs.Next
Step 2: strength as the first sport without distance (FIT
training/strength_training), using this catalogue.