Events & Time¶
Events¶
Event is a 90+ member enum; each member is a (distance, stroke,
course) tuple, named <STROKE>_<DISTANCE>_<COURSE> for individual events (e.g.
FREE_100_SCY) and <STROKE>_<DISTANCE>_RELAY_<COURSE> for relays (e.g.
MEDLEY_400_RELAY_LCM). Members compare in declaration order, so sorted(...) yields a
natural event ordering.
- Components:
event.distance,event.stroke(Stroke),event.course(Course). - Lookup:
Event.find(distance, stroke, course)→ the matchingEventorNone. - Relays:
event.is_relay(),event.leg_distance(),event.leg_strokes(), andevent.leg_event(order)— the individual event swum on a given leg (1–4). This is what lets a relay leg sort alongside flat-start swims of the same individual event.
Time¶
Time stores centiseconds: int and formats as [M:]SS.HH. See the
data-model guide for usage; the full API is below.
event
¶
Swimming event representation as (distance, stroke, course).
Event
¶
Bases: Enum
A unique swimming event represented by a (distance, stroke, course) tuple.
Supports declaration-order comparison. Members are named with uppercase patterns
using abbreviated stroke names, e.g. <STROKE>_<DISTANCE>_<COURSE> (for individual
events like FREE_50_SCY) or <STROKE>_<DISTANCE>_RELAY_<COURSE> (for relays like
MEDLEY_200_RELAY_LCM).
find
classmethod
¶
Resolve an event by components, or None if none matches.
is_relay
¶
leg_distance
¶
Calculate the per-leg distance (total distance divided by 4).
Returns:
| Type | Description |
|---|---|
int
|
The distance of a single leg in the relay. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the event is an individual swim rather than a relay. |
Source code in src/tunas/event.py
leg_strokes
¶
leg_strokes() -> list[Stroke]
Get the ordered sequence of strokes swum on the four legs of this relay.
Returns:
| Type | Description |
|---|---|
list[Stroke]
|
A list of four |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the event is an individual swim rather than a relay. |
Source code in src/tunas/event.py
leg_event
¶
leg_event(order: int) -> Event
Resolve the individual Event swum on a specific relay leg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
int
|
The 1-based leg position (must be between 1 and 4). |
required |
Returns:
| Type | Description |
|---|---|
Event
|
The corresponding individual |
Raises:
| Type | Description |
|---|---|
ValueError
|
If this is an individual event, or if |
Source code in src/tunas/event.py
time
¶
Immutable swim time value type with centisecond precision.
Time
dataclass
¶
An immutable, hashable swim time with centisecond precision.
Stored internally as a non-negative centiseconds integer. Faster times compare
as less than slower times (i.e. smaller values indicate faster swims). Supports
addition and subtraction between Time instances.
String formatting returns "M:SS.HH" if the time is at least one minute, or
"SS.HH" if under a minute. The formatted string zero-pads seconds and hundredths
but does not pad the minute component.
Attributes:
| Name | Type | Description |
|---|---|---|
centiseconds |
int
|
Duration of the swim in hundredths of a second. |
total_seconds
property
¶
The whole time expressed as seconds (centiseconds / 100).
parse
classmethod
¶
parse(s: str) -> Time
Parse a swim-time string formatted as [M:]SS.HH (the minutes part is optional).
Strips leading/trailing whitespace. Tolerates 1- or 2-digit minutes and
seconds; fractions of a second are taken to centisecond precision, with
any extra digits rounded to the nearest hundredth (e.g. "1:04.875" ->
1:04.88).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
The time string to parse (e.g., |
required |
Returns:
| Type | Description |
|---|---|
Time
|
A new |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string is empty, lacks a decimal point, contains non-numeric digits, or has more than two segments separated by colons. |