Move the five top-level scripts into src/rowing_stats, one module per pipeline stage, behind a single 'rowing-stats' command with a subcommand each (crop, classify, ocr, claude, tune). Add type hints throughout, packaging metadata, pinned requirements files, and a test suite. Failures are now typed exceptions under RowingStatsError instead of prints, None returns and sys.exit: unreadable or missing images, photos with no detectable screen, a missing tesseract binary, tesseract failures, unusable Claude replies, and missing optional dependencies, model weights or API credentials. Each command reports a bad file and carries on, stops once on a setup problem, and returns a non-zero exit code when something failed. Crops, classifier labels and OCR votes are unchanged. Other changes: - crop.find_screen takes a CropParams, so the tuner searches the real detection code instead of a copy of it. - OCR validation scores only images that have a reference reading; images without one were counted as wrong. - 'classify train --data-dir train/' works with the repository layout (it looked for train/train), and the CNN weights path defaults to the committed screen_classifier_model.pth instead of a missing model.pth. - The CNN is loaded once per run rather than once per image. - ocr and claude can write their readings with --output. - crop no longer defaults to /mnt/user-data paths. - Pure vote-counting moved to parsing.py; the unused 'expected' argument that let a caller steer the vote is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
33 lines
884 B
Python
33 lines
884 B
Python
from pathlib import Path
|
|
|
|
import cv2
|
|
import numpy as np
|
|
import pytest
|
|
|
|
REPO = Path(__file__).parent.parent
|
|
|
|
|
|
@pytest.fixture
|
|
def photo() -> np.ndarray:
|
|
"""A synthetic photo: dark wall, one bright 'screen' with digits on it."""
|
|
image = np.full((600, 800, 3), 40, dtype=np.uint8)
|
|
cv2.rectangle(image, (300, 200), (500, 380), (220, 220, 220), thickness=-1)
|
|
for row, text in enumerate(["30:06", "7283", "2:04"]):
|
|
cv2.putText(image, text, (320, 250 + row * 50), cv2.FONT_HERSHEY_SIMPLEX,
|
|
1.2, (20, 20, 20), 3)
|
|
return image
|
|
|
|
|
|
@pytest.fixture
|
|
def photo_path(tmp_path: Path, photo: np.ndarray) -> Path:
|
|
path = tmp_path / "IMG_0001.jpg"
|
|
cv2.imwrite(str(path), photo)
|
|
return path
|
|
|
|
|
|
@pytest.fixture
|
|
def corrupt_path(tmp_path: Path) -> Path:
|
|
path = tmp_path / "corrupt.jpg"
|
|
path.write_text("this is not a JPEG")
|
|
return path
|