The timing system of a running club records each finish as a time in seconds, a bib number, the runner's name and their club. Names are typed in by volunteers and are sometimes misspelt, so the system identifies and orders finishes by time and bib only.
Write two classes:
Finish(time, bib, name, club=""):reprshows every field asname=value:Finish(time=61.2, bib=7, name='Ana', club='');- two finishes are equal when their
timeandbibare equal (the name and club do not matter); - finishes compare with
<,>,<=,>=bytime, and bybibwhen the times are equal, sosorted,minandmaxput them in finishing order.
Results(race), holding the race name and a listfinishesthat starts empty for each race:add(finish)appends a finish;podium()returns the names of the (up to) three best finishes, best first;clubs()returns a dictionary from each club to its number of finishes, with the clubs in alphabetical order;reprshows both fields:Results(race='5k', finishes=[...]).
The tests compare repr strings and use ==, sorted, min and max on your objects. The setup's parkrun(n, seed) generates n finishes.
Examples
Input: a, b, c = Finish(61.2, 7, "Ana"), Finish(59.8, 3, "Bo", "Harriers"), Finish(61.2, 2, "Cy")
repr(sorted([a, b, c])), a == Finish(61.2, 7, "Anna", "Striders"), max(a, b, c).name
Output: ("[Finish(time=59.8, bib=3, name='Bo', club='Harriers'), Finish(time=61.2, bib=2, name='Cy', club=''), Finish(time=61.2, bib=7, name='Ana', club='')]",
True, 'Ana')
Input: r = Results("5k"); r.add(Finish(1500.0, 11, "Dee", "Harriers")); repr(r), repr(Results("10k"))
Output: ("Results(race='5k', finishes=[Finish(time=1500.0, bib=11, name='Dee', club='Harriers')])",
"Results(race='10k', finishes=[])")
Constraints
- Up to
5000finishes per race; times are positive floats and bibs positive integers.
Goals
- Replace a hand-written `__init__`, `__repr__`, `__eq__` and `<` with `@dataclass`
- Choose which fields take part in comparisons with `field(compare=False)`
- Give every object its own list with `field(default_factory=list)`