- Remove references to deprecated bot commands (/pajares, /sanisidro, /fuentes, /all) - Document new /suscribir and /desuscribir subscription commands - Add push notification system description and usage - Document admin accuracy reports with environment variable setup - Add sky_condition and snow_type fields to API spec and database schema - Update scheduled task description (training day changed from Monday to Sunday) - Add notification_subscribers table to schema - Update DEPLOYMENT.md with ADMIN_TELEGRAM_IDS environment variable - Mark completed milestones in TODO.md
6.2 KiB
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
sqlite3 data/processed/skipredictor.db "SELECT * FROM current_forecasts ORDER BY station_id, prediction_date LIMIT 10;"
Checking system status via CLI
.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)
./setup.sh
This creates a venv, installs dependencies, downloads historical data, trains models, and collects webcam snapshots.
Starting the unified daemon
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
.venv/bin/python scripts/collect_daily_data.py
Scrape today's actual results
.venv/bin/python data_sources/station_scraper.py
ML Model Operations
Force manual retraining
.venv/bin/python scripts/retrain_model.py
Inspecting model metrics
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)
export TELEGRAM_BOT_TOKEN='your_token'
.venv/bin/python -m bot.telegram_bot
Troubleshooting
Missing forecasts?
- Check
data/pipeline.log. - Verify Open-Meteo connectivity:
curl "https://api.open-meteo.com/v1/forecast?latitude=43.05&longitude=-5.77&daily=snowfall_sum" - Ensure models exist in
ml/models/.
Bot not responding?
- Check if the bot is active via
GET /api/v1/status. - Ensure
TELEGRAM_BOT_TOKENis correctly exported in the environment. - 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:
- User sends
/suscribir→ subscriber entry created innotification_subscriberstable - At 20:00 daily, the extended task broadcasts tomorrow's forecast to all active subscribers
- 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:
- Extract yesterday's 20:00 prediction for today from
past_forecasts - Compare against today's actual station data in
historical_actuals - 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
- Compute 30-day accumulated accuracy
- Format report in Spanish with station breakdowns
- 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:
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_forecastsandpast_forecaststables
Data Source
- Weather codes come from Open-Meteo (WMO standard codes)
- Snow type primarily from Infonieve's
calidadnievecolumn when available; otherwise inferred from temperature and snowfall conditions
Database Schema Updates
New Table: notification_subscribers
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 labelsnow_type TEXT— Snow type/quality labelweather_code INTEGER— WMO weather code (raw)
Example query to inspect new fields:
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;"