Files
skipredictor/LESSONS.md
T
2026-03-13 15:10:37 +01:00

5.6 KiB

Webcam Historical Download Validation - 2026-03-13

What went wrong: Historical webcam downloads were saved directly from historico-webcams/... page URLs, which can return HTML wrappers instead of binary images.

Root cause: The collector assumed the historical page URL always returned raw image bytes and did not validate payload type before running YOLO analysis.

Prevention rule: In this repository, historical webcam ingestion must resolve the real image URL through webcams/historico.php?showimg=1... and reject HTML payloads before saving .jpg files.

Example: In [collect_historical_webcams.py](/home/dasemu/Hacking/Darío Sevilla/skipredictor/scripts/collect_historical_webcams.py), process_day() now uses _resolve_historical_image_url() and _download_image_bytes(); HTML payloads are discarded and the day is stored as unknown.

Files affected: scripts/collect_historical_webcams.py, tests/test_collect_historical_webcams.py


Deployment Assumptions - 2026-03-12

What went wrong: I assumed the Telegram bot running on the server might differ from the repository after seeing a schema mismatch between the bot code and the predictions JSON.

Root cause: I inferred deployment drift before exhausting the simpler explanation: the repository bot itself still expected the old JSON schema and would therefore fail even when code and server were synchronized. I also failed to apply the repository-specific operating assumption that production runs on the server unless the user explicitly says otherwise.

Prevention rule: In this repository, unless the user explicitly says otherwise, assume production deployment lives on the server even if development happens locally. When the user states the server and repo are synchronized, treat that as the default assumption and first verify whether the bug is reproducible directly from the checked-in code before attributing it to deployment drift.

Example: The production JSON at /opt/skipredictor/data/processed/predictions_latest.json on the server contained valid predictions under stations, and the checked-in [telegram_bot.py](/home/dasemu/Hacking/Darío Sevilla/skipredictor/bot/telegram_bot.py) still expected top-level station keys plus legacy fields like station_open_probability, while [collect_daily_data.py](/home/dasemu/Hacking/Darío Sevilla/skipredictor/scripts/collect_daily_data.py) writes predictions under stations with fields such as open_probability and km_open.

Files affected: bot/telegram_bot.py, scripts/collect_daily_data.py


Migration Scope - 2026-03-13

What went wrong: I started a database migration while preserving compatibility fallbacks to the previous CSV/JSON storage flow.

Root cause: I optimized for low-risk rollout instead of following the user's explicit migration intent. In this repository, that creates extra complexity and leaves ambiguous sources of truth.

Prevention rule: When the user asks for a migration in this repo and does not request coexistence, implement a single authoritative path after the migration. Do not keep legacy file fallbacks unless the user asks for a transitional phase.

Example: The SQLite migration must make the bot, the daily pipeline, and model training read from the database directly instead of keeping fallbacks to data/processed/predictions_latest.json or data/processed/dataset_featured.csv.

Files affected: bot/telegram_bot.py, scripts/collect_daily_data.py, ml/train_model.py


Git - 2026-03-13

What went wrong: Worktree creation and cleanup were mismanaged, leading to confusion between the main directory and the worktree. Changes were applied to the main directory instead of the newly created worktree, and branch deletion failed because the worktree was still active.

Root cause: Lack of a strict "switch directory" step, incorrect order in the cleanup process, and creating worktrees outside the repository root.

Prevention rule: Before using a worktree:

  1. Always create the worktree inside a .tmp/ directory within the repository (e.g., .tmp/feature-name).
  2. Always cd into the new worktree directory immediately after creation.
  3. Perform all edits and commits inside the worktree.
  4. To clean up:
    • Return to the main directory: cd -
    • Remove the worktree: git worktree remove .tmp/<path>
    • Then, and only then, delete the branch: git branch -d <branch>

Example:

# Correct flow:
git worktree add .tmp/new-feature -b feature-branch
cd .tmp/new-feature
# ... do work, add, commit ...
cd -
git merge feature-branch
git worktree remove .tmp/new-feature
git branch -d feature-branch

Files affected:


Execution Context - 2026-03-13

What went wrong: I continued running environment/bootstrap commands inside a secondary worktree after the user explicitly asked to run them in the main repository checkout.

Root cause: I treated the worktree isolation choice as more important than the user's concrete execution context instruction.

Prevention rule: In this repository, if the user explicitly says to execute locally in main, run the operational commands in the main checkout even if a worktree exists for development or review work.

Example: After the user asked to run ./start.sh, scripts/build_full_dataset.py, and scripts/collect_daily_data.py locally, those commands had to be executed in /home/dasemu/Hacking/Darío Sevilla/skipredictor, not in /home/dasemu/Hacking/Darío Sevilla/skipredictor-db-migration.

Files affected: