chore: bootstrap Claude setup

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5 committed 2026-10-18 15:02:48 +02:00
1 parent b4453917dc
commit d99aed9a3c
12 files changed
+175 -7

No files matched your search

+196
View File
@@ -0,0 +1,196 @@
# SkiPredictor Operations Guide
This guide covers common administrative and maintenance tasks for the SkiPredictor system.
## Architecture
Single unified process: FastAPI + APScheduler + Telegram Bot (in-process).
**Scheduled tasks:**
- Standard (5h, 10h, 15h): archive forecasts, collect weather, generate predictions
- Extended (20h): same + webcam snapshot + crowd analysis + actuals scraping
- Training (Sunday 21h): retrain ML models
**Single source of truth:** `current_forecasts` / `past_forecasts` tables in SQLite.
## Database Management
The authoritative data source is the SQLite database at `data/processed/skipredictor.db`.
### Inspecting latest predictions
```bash
sqlite3 data/processed/skipredictor.db "SELECT * FROM current_forecasts ORDER BY station_id, prediction_date LIMIT 10;"
```
### Checking system status via CLI
```bash
.venv/bin/python -c "from storage import SQLiteStore; s=SQLiteStore(); print(f'DB Size: {s.db_path.stat().st_size/1024/1024:.2f} MB')"
```
## Setup (first time)
```bash
./setup.sh
```
This creates a venv, installs dependencies, downloads historical data, trains models, and collects webcam snapshots.
## Starting the unified daemon
```bash
source .venv/bin/activate
export TELEGRAM_BOT_TOKEN='your_token'
export JWT_SECRET_KEY='your_secret'
export ADMIN_TELEGRAM_IDS='123456789,987654321' # Optional: comma-separated admin user IDs
uvicorn app.main:app --host 0.0.0.0 --port 8000
```
This starts FastAPI (REST API), APScheduler (scheduled tasks), and the Telegram bot (in-process polling).
## Manual Forecast Cycles
### Run a full prediction cycle now
```bash
.venv/bin/python scripts/collect_daily_data.py
```
### Scrape today's actual results
```bash
.venv/bin/python data_sources/station_scraper.py
```
## ML Model Operations
### Force manual retraining
```bash
.venv/bin/python scripts/retrain_model.py
```
### Inspecting model metrics
```bash
sqlite3 data/processed/skipredictor.db "SELECT metrics_json FROM training_runs ORDER BY completed_at DESC LIMIT 1;"
```
## Telegram Bot
### Running the bot standalone (dev)
```bash
export TELEGRAM_BOT_TOKEN='your_token'
.venv/bin/python -m bot.telegram_bot
```
## Troubleshooting
### Missing forecasts?
1. Check `data/pipeline.log`.
2. Verify Open-Meteo connectivity: `curl "https://api.open-meteo.com/v1/forecast?latitude=43.05&longitude=-5.77&daily=snowfall_sum"`
3. Ensure models exist in `ml/models/`.
### Bot not responding?
1. Check if the bot is active via `GET /api/v1/status`.
2. Ensure `TELEGRAM_BOT_TOKEN` is correctly exported in the environment.
3. Check uvicorn logs for bot startup errors.
## Telegram Bot Commands
### User Commands
- `/start` — Welcome message with brief description
- `/help` — List all available commands
- `/hoy` — All three stations' forecast for today
- `/manana` — All three stations' forecast for tomorrow
- `/tresdias` — All three stations' forecasts for next 3 days
- `/semana` — All three stations' forecasts for next 7 days
- `/suscribir` — Subscribe to daily 20:00 push notifications (tomorrow's forecast)
- `/desuscribir` — Unsubscribe from push notifications
### Push Notifications System
Users who execute `/suscribir` receive automated daily predictions via push notification at 20:00 Madrid time.
**How it works:**
1. User sends `/suscribir` → subscriber entry created in `notification_subscribers` table
2. At 20:00 daily, the extended task broadcasts tomorrow's forecast to all active subscribers
3. If a user blocks the bot (Telegram API returns "Forbidden"), their subscription is automatically deactivated
**Database table:**
```
notification_subscribers:
- telegram_chat_id (UNIQUE)
- telegram_username (optional)
- subscribed_at (ISO timestamp)
- active (0 or 1)
```
## Admin Accuracy Reports
When `ADMIN_TELEGRAM_IDS` environment variable is set, the system sends daily accuracy reports to designated admins at 20:00.
**How it works:**
1. Extract yesterday's 20:00 prediction for today from `past_forecasts`
2. Compare against today's actual station data in `historical_actuals`
3. Compute divergence metrics:
- `open_status_match`: Did prediction match actual open/closed?
- `open_prob_error`: |predicted_probability - actual_status|
- `km_error`: |predicted_km - actual_km|
- `km_error_pct`: percentage error for km
4. Compute 30-day accumulated accuracy
5. Format report in Spanish with station breakdowns
6. Send via Telegram to each admin ID
**Report includes:**
- Per-station accuracy with match status (✅/❌)
- km prediction error
- Daily summary (% open accuracy, avg km error)
- 30-day accumulated statistics
**Setup:**
```bash
export ADMIN_TELEGRAM_IDS='123456789,987654321'
```
## Weather Data Enhancements
### New Forecast Fields
All forecasts now include two new fields:
- **`sky_condition`**: Derived from WMO weather code, values: `"soleado"`, `"parcialmente nublado"`, `"nublado"`, `"niebla"`, `"nublado con nieve"`, `"tormenta"`, `"desconocido"`
- **`snow_type`**: Inferred from temperature + snowfall or from Infonieve historical data, values: `"polvo"`, `"húmeda"`, `"dura"`, `"primavera"`, `"artificial"`, `"costra"`, `"desconocido"`
These fields appear in:
- REST API responses (forecast endpoints)
- Telegram bot messages (displayed as "Cielo:" and "Tipo de nieve:")
- SQLite `current_forecasts` and `past_forecasts` tables
### Data Source
- **Weather codes** come from Open-Meteo (WMO standard codes)
- **Snow type** primarily from Infonieve's `calidadnieve` column when available; otherwise inferred from temperature and snowfall conditions
## Database Schema Updates
### New Table: `notification_subscribers`
```sql
CREATE TABLE notification_subscribers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
telegram_chat_id INTEGER UNIQUE NOT NULL,
telegram_username TEXT,
subscribed_at TEXT NOT NULL,
active INTEGER DEFAULT 1
);
```
### Updated Tables: `current_forecasts`, `past_forecasts`
New columns added:
- `sky_condition TEXT` — Sky condition label
- `snow_type TEXT` — Snow type/quality label
- `weather_code INTEGER` — WMO weather code (raw)
Example query to inspect new fields:
```bash
sqlite3 data/processed/skipredictor.db \
"SELECT station_id, prediction_date, open_probability, sky_condition, snow_type
FROM current_forecasts
ORDER BY station_id, prediction_date;"
```