mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 15:26:15 +00:00
- Updated API_SPEC.md with JWT auth and storage schema. - Updated DEPLOYMENT.md for the new uvicorn-based setup. - Added LESSONS.md pattern for worktree management. - Included new README, TODO, and OPERATIONS files.
91 lines
2.5 KiB
Markdown
91 lines
2.5 KiB
Markdown
# Ski Predictor - Deployment and Operations Guide
|
|
|
|
## Quick Start
|
|
|
|
```bash
|
|
git clone https://git.dariosevilla.es/dasemu/skipredictor.git
|
|
cd skipredictor
|
|
./start.sh --cron --collect-now --bot
|
|
```
|
|
|
|
## Requirements
|
|
|
|
- Python 3.11+
|
|
- ~2 GB disk (YOLO model downloads on first run)
|
|
- Internet access (Open-Meteo API, infonieve.es scraping, Telegram API)
|
|
- **Environment Variables**:
|
|
- `TELEGRAM_BOT_TOKEN`: Required for the Telegram bot.
|
|
- `JWT_SECRET_KEY`: Required for the FastAPI backend authentication.
|
|
|
|
## ML Training
|
|
|
|
### First-time training (full historical dataset)
|
|
|
|
This downloads 16+ seasons of station data from infonieve.es, fetches matching historical weather from Open-Meteo, builds features, and trains all 3 models:
|
|
|
|
```bash
|
|
# 1. Download historical station data from infonieve.es
|
|
.venv/bin/python data_sources/infonieve_historical.py
|
|
|
|
# 2. Build the full dataset (weather + station merge) and train models
|
|
.venv/bin/python scripts/build_full_dataset.py
|
|
```
|
|
|
|
Output:
|
|
- `data/processed/skipredictor.db`: SQLite database with all data.
|
|
- `ml/models/*.joblib`: Trained models.
|
|
|
|
### Retraining with accumulated data
|
|
|
|
```bash
|
|
.venv/bin/python scripts/retrain_model.py
|
|
```
|
|
|
|
## FastAPI Backend & Scheduler
|
|
|
|
The backend uses FastAPI and includes an internal APScheduler to run forecast cycles at 00, 05, 10, 15, and 20:00 (Europe/Madrid), and a weekly retrain on Mondays at 03:00. It also manages the Telegram bot as a subprocess.
|
|
|
|
### Running the Backend
|
|
|
|
```bash
|
|
export TELEGRAM_BOT_TOKEN='...'
|
|
export JWT_SECRET_KEY='...'
|
|
.venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port 8000
|
|
```
|
|
|
|
### Systemd Service Setup
|
|
|
|
Create `/etc/systemd/system/skipredictor.service`:
|
|
|
|
```ini
|
|
[Unit]
|
|
Description=SkiPredictor Backend & Bot
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=dasemu
|
|
WorkingDirectory=/path/to/skipredictor
|
|
Environment=TELEGRAM_BOT_TOKEN=your_token
|
|
Environment=JWT_SECRET_KEY=your_secret
|
|
ExecStart=/path/to/skipredictor/.venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port 8000
|
|
Restart=on-failure
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
```
|
|
|
|
## Legacy Cron Jobs (Optional)
|
|
|
|
If you prefer not to use the internal scheduler, you can still use standard cron jobs for daily collection and retraining. See [OPERATIONS.md](OPERATIONS.md) for details.
|
|
|
|
## Monitoring
|
|
|
|
- **Logs**: `data/pipeline.log`, `data/retrain.log`, `data/bot.log`.
|
|
- **API Status**: `GET /api/v1/status` (requires auth).
|
|
- **Health**: `GET /api/v1/health` (public).
|
|
|
|
## Project Structure
|
|
|
|
*See [README.md](README.md) for the full directory tree.*
|