Add Claude Haiku baseline

Port the display reader from the web server's rowing module as a second
extraction method: send the whole photo to claude-haiku-4-5 and ask for
elapsed time and distance as JSON. The prompt, model and reply parsing
are unchanged; what is new is reading from a file, converting the reply
to WorkoutStats so both methods produce the same rows, and accepting
ANTHROPIC_API_KEY as well as CLAUDE_API_KEY.

Select it with 'rowing-stats --method haiku'. The anthropic SDK is an
optional extra, imported only when the baseline is used, so the OCR
pipeline still installs and runs without it or an API key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-09 11:49:13 +01:00
co-authored by Claude Opus 5.5
parent 685ee9bf3d
commit e2330c6f77
9 changed files with 443 additions and 10 deletions
+15 -2
View File
@@ -21,6 +21,10 @@ Each photo goes through four stages, one module each under `src/rowing_stats/`:
`pipeline.py` chains the stages for one file, and `cli.py` runs it over many files and writes text, JSON or CSV.
### Haiku baseline
`haiku_baseline.py` is the alternative the pipeline is measured against: send the whole photo to Claude Haiku 4.5 with a short prompt asking for the elapsed time and distance as JSON. There is no display detection or preprocessing. It reads only those two fields, makes one paid API call per photo, and needs a network connection and an API key, which is the trade-off the local pipeline exists to avoid. Both methods produce the same output rows, so their CSVs can be compared directly.
## Running it
You need Python 3.10 or newer and the [Tesseract](https://tesseract-ocr.github.io/tessdoc/Installation.html) binary on your `PATH` (`apt install tesseract-ocr`, `brew install tesseract`, or `pacman -S tesseract tesseract-data-eng`).
@@ -38,6 +42,13 @@ rowing-stats --format csv -o stats.csv photos/ # text (default), json or csv
rowing-stats --debug-dir debug photos/ # also save each stage's image
```
To run the Haiku baseline instead, install its extra dependency and set `ANTHROPIC_API_KEY` (or `CLAUDE_API_KEY`):
```sh
pip install -r requirements-baseline.txt
rowing-stats --method haiku --format csv -o baseline.csv photos/
```
Example:
```console
@@ -52,7 +63,7 @@ $ rowing-stats --format json photos/IMG_5414.JPEG
]
```
Fields that could not be read are left out (empty in CSV). A file that cannot be processed is reported on stderr and skipped, and the exit code is 1 if any file failed. If Tesseract itself is missing the run stops immediately.
Fields that could not be read are left out (empty in CSV). A file that cannot be processed is reported on stderr and skipped, and the exit code is 1 if any file failed. If Tesseract itself is missing, or the baseline has no API key, the run stops immediately.
The same pipeline is available from Python:
@@ -76,7 +87,7 @@ pip install -r requirements-dev.txt
pytest
```
The tests cover the parsing and cleaning logic, image loading failures (missing, corrupt and truncated files), display detection on synthetic images, and the CLI's output and exit codes. Tesseract is stubbed out in all but one test, which runs the real pipeline on a sample photo and is skipped if Tesseract is not installed.
The tests cover the parsing and cleaning logic, image loading failures (missing, corrupt and truncated files), display detection on synthetic images, and the CLI's output and exit codes. Tesseract is stubbed out in all but one test, which runs the real pipeline on a sample photo and is skipped if Tesseract is not installed. The baseline's tests use a fake Anthropic client, so no test makes an API call or needs a key.
## Limitations
@@ -97,6 +108,8 @@ The causes, roughly in order of impact:
- **Global thresholding.** A single Otsu threshold turns glare and shadow gradients into solid black patches that hide digits.
- **Heuristic parsing.** An unlabelled five-digit number is assumed to be the projected distance, which is wrong when it is really the distance with its `m` label missed.
The Haiku baseline has not yet been run over the sample photos, so there are no baseline numbers to set against the table above.
Other known gaps:
- Only the PM5's default workout screens are handled. Fields are matched by label, so other display modes (watts, force curve, pace boat) are ignored.