Skip to content

feat: type Event.distance as float for non-integer distances - #29

Open
fsalum wants to merge 1 commit into
SwimComm:masterfrom
fsalum:feat/distance-raw
Open

feat: type Event.distance as float for non-integer distances#29
fsalum wants to merge 1 commit into
SwimComm:masterfrom
fsalum:feat/distance-raw

Conversation

@fsalum

@fsalum fsalum commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

The E1/F1 distance field (6 chars) can contain non-integer values — for example, "2.4" representing 2.4 miles in open-water meets. safe_cast(int, "2.4") raises ValueError and falls back to int() = 0, permanently losing the original value.

Per review, this PR types Event.distance as float (rather than adding a parallel distance_raw) and parses it with safe_cast(float, ...), so non-integer distances survive the parse.

Changes

  • schemas.py: Event.distance is now float. get_or_create_event's distance param is typed float.
  • e_event_parsers.py / f_relay_parsers.py: distance = safe_cast(float, extract(line, 16, 6)).

Compatibility

This is an API-compatible but data-changing release: integer distances now come through as floats (100100.0), and callers that previously read distance as an int (e.g. keying events on it) should coerce. Blank/non-numeric fields still yield 0.0. Worth a major version bump.

Tests

  • Float distance ("2.4"distance=2.4)
  • Integer distance ("1000"distance=1000.0)
  • Blank distance → distance=0.0
  • Relay F1 float distance (same pattern)

All 116 tests pass.

@egelja egelja left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch! Can we instead update distance to a float? That's relatively backwards compatible, and more accurately represents the data

@fsalum

fsalum commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Good catch! Can we instead update distance to a float? That's relatively backwards compatible, and more accurately represents the data

I'm only a bit hesitant to that because it would affect anybody using the library, they will start seeing some events with 2.4 FR swimming that is not pool but open water events. Worth perhaps bumping the version to 3.0 (backwards compatible but the data changed).

Let me know if you still want that and I'm fine updating it.

@egelja

egelja commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Yep, I'm fine with bumping. Let's do it!

The E1/F1 distance field (6 chars) can contain non-integer values — e.g.
"2.4" for 2.4 miles in open-water meets. safe_cast(int, "2.4") raised
ValueError and fell back to int() = 0, permanently losing the value.

Type Event.distance as float and parse it with safe_cast(float, ...) so
these distances survive. Integer distances now come through as floats
(100 -> 100.0); this is an API-compatible data change, so callers reading
distance as an int should coerce. Blank/non-numeric fields still yield 0.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@fsalum
fsalum force-pushed the feat/distance-raw branch from f3b553d to 34cb26f Compare August 16, 2026 23:14
@fsalum fsalum changed the title feat: expose distance_raw on Event for non-integer distance recovery feat: type Event.distance as float for non-integer distances Aug 16, 2026
@fsalum

fsalum commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Updated.

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.

2 participants