mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 15:26:15 +00:00
docs: update API, deployment, and lessons for the new backend
- 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.
This commit is contained in:
1 parent
b5b62e582e
commit
e952cea417
7 files changed
+281
-279
No files matched your search
+86
-103
@@ -6,6 +6,50 @@ All responses use JSON. Dates use ISO 8601 format (`YYYY-MM-DD`). Timestamps use
|
||||
|
||||
---
|
||||
|
||||
## Authentication
|
||||
|
||||
All endpoints except `/health`, `/auth/register`, and `/auth/login` require a valid JWT bearer token.
|
||||
|
||||
### `POST /api/v1/auth/register`
|
||||
|
||||
Create a new user account.
|
||||
|
||||
**Request Body:**
|
||||
```json
|
||||
{
|
||||
"email": "user@example.com",
|
||||
"password": "securepassword123"
|
||||
}
|
||||
```
|
||||
|
||||
**Response 201:**
|
||||
```json
|
||||
{
|
||||
"id": 1,
|
||||
"email": "user@example.com"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `POST /api/v1/auth/login`
|
||||
|
||||
Obtain a JWT token valid for 14 days. Uses OAuth2 Password Flow (form data).
|
||||
|
||||
**Request Body (form-data):**
|
||||
- `username`: email
|
||||
- `password`: password
|
||||
|
||||
**Response 200:**
|
||||
```json
|
||||
{
|
||||
"access_token": "eyJhbG...",
|
||||
"token_type": "bearer"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Stations
|
||||
|
||||
### `GET /api/v1/stations`
|
||||
@@ -25,26 +69,6 @@ List all tracked ski stations with metadata.
|
||||
"altitude": 1505,
|
||||
"wind_closure_threshold_kmh": 80,
|
||||
"min_snow_depth_cm": 30
|
||||
},
|
||||
{
|
||||
"station_id": "sanisidro",
|
||||
"name": "San Isidro",
|
||||
"max_km": 31.0,
|
||||
"latitude": 43.07,
|
||||
"longitude": -5.37,
|
||||
"altitude": 1500,
|
||||
"wind_closure_threshold_kmh": 80,
|
||||
"min_snow_depth_cm": 30
|
||||
},
|
||||
{
|
||||
"station_id": "fuentes",
|
||||
"name": "Fuentes de Invierno",
|
||||
"max_km": 8.6,
|
||||
"latitude": 43.08,
|
||||
"longitude": -5.93,
|
||||
"altitude": 1500,
|
||||
"wind_closure_threshold_kmh": 80,
|
||||
"min_snow_depth_cm": 30
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -78,22 +102,9 @@ Get the latest forecast for **all stations**. Returns today + next 7 days per st
|
||||
"weather_summary": "Nieve ligera, -2°C, viento 25 km/h",
|
||||
"rule_notes": [],
|
||||
"prediction_source": "hybrid"
|
||||
},
|
||||
{
|
||||
"date": "2026-03-14",
|
||||
"open_probability": 0.72,
|
||||
"open_label": "Abierta",
|
||||
"km_open": 15.0,
|
||||
"max_km": 22.0,
|
||||
"crowd_level": "high",
|
||||
"weather_summary": "Soleado, 3°C, viento 15 km/h",
|
||||
"rule_notes": ["Fin de semana + nieve reciente"],
|
||||
"prediction_source": "hybrid"
|
||||
}
|
||||
]
|
||||
},
|
||||
"sanisidro": { "...same structure..." },
|
||||
"fuentes": { "...same structure..." }
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -107,7 +118,7 @@ Get the latest forecast for **all stations**. Returns today + next 7 days per st
|
||||
|
||||
### `GET /api/v1/forecast/{station_id}`
|
||||
|
||||
Get the latest forecast for a **single station**. Same structure as above but only one station.
|
||||
Get the latest forecast for a **single station**.
|
||||
|
||||
**Path parameters:**
|
||||
- `station_id`: `pajares` | `sanisidro` | `fuentes`
|
||||
@@ -119,26 +130,7 @@ Get the latest forecast for a **single station**. Same structure as above but on
|
||||
"run_hour": 10,
|
||||
"station_id": "pajares",
|
||||
"name": "Valgrande-Pajares",
|
||||
"days": [
|
||||
{
|
||||
"date": "2026-03-13",
|
||||
"open_probability": 0.85,
|
||||
"open_label": "Abierta",
|
||||
"km_open": 18.5,
|
||||
"max_km": 22.0,
|
||||
"crowd_level": "medium",
|
||||
"weather_summary": "Nieve ligera, -2°C, viento 25 km/h",
|
||||
"rule_notes": [],
|
||||
"prediction_source": "hybrid"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**Response 404:**
|
||||
```json
|
||||
{
|
||||
"detail": "Station 'xyz' not found. Valid: pajares, sanisidro, fuentes"
|
||||
"days": [ ... ]
|
||||
}
|
||||
```
|
||||
|
||||
@@ -182,7 +174,7 @@ Get past forecast runs (archived when a new run replaces them).
|
||||
|
||||
### `GET /api/v1/health`
|
||||
|
||||
Health check endpoint.
|
||||
Public health check endpoint.
|
||||
|
||||
**Response 200:**
|
||||
```json
|
||||
@@ -196,7 +188,7 @@ Health check endpoint.
|
||||
|
||||
### `GET /api/v1/status`
|
||||
|
||||
System status: last forecast run, next scheduled run, model info.
|
||||
System status: last forecast run, next scheduled run, model info, bot status.
|
||||
|
||||
**Response 200:**
|
||||
```json
|
||||
@@ -206,9 +198,9 @@ System status: last forecast run, next scheduled run, model info.
|
||||
"last_training_run": "2026-03-10T03:00:00+01:00",
|
||||
"next_training_run": "2026-03-17T03:00:00+01:00",
|
||||
"models": {
|
||||
"station_open": "RandomForestClassifier",
|
||||
"km_open": "GradientBoostingRegressor",
|
||||
"crowd_level": "LGBMClassifier"
|
||||
"station_open": "station_open",
|
||||
"km_open": "km_open",
|
||||
"crowd_level": "crowd_level"
|
||||
},
|
||||
"telegram_bot_active": true,
|
||||
"stations_count": 3,
|
||||
@@ -218,59 +210,50 @@ System status: last forecast run, next scheduled run, model info.
|
||||
|
||||
---
|
||||
|
||||
## Schedule (internal, not exposed as API)
|
||||
## Internal Schedule
|
||||
|
||||
The backend orchestrates these tasks internally:
|
||||
The backend (FastAPI + APScheduler) orchestrates these tasks internally:
|
||||
|
||||
| Hour (Europe/Madrid) | Task |
|
||||
|---|---|
|
||||
| 00:00 | Forecast run: today + 7 days |
|
||||
| 05:00 | Forecast run: today + 7 days |
|
||||
| 10:00 | Forecast run: today + 7 days |
|
||||
| 15:00 | Forecast run: tomorrow + 6 days (skip today) |
|
||||
| 20:00 | Forecast run: tomorrow + 6 days (skip today) + scrape today's actual |
|
||||
| Weekly (Monday 03:00) | ML model retraining |
|
||||
|
||||
Each forecast run:
|
||||
1. Archives current forecasts → `past_forecasts` table
|
||||
2. Fetches fresh weather data from Open-Meteo
|
||||
3. Generates new predictions via HybridPredictor
|
||||
4. Stores in `current_forecasts` table
|
||||
| 15:00 | Forecast run: tomorrow + 6 days |
|
||||
| 20:00 | Forecast run: tomorrow + 6 days |
|
||||
| Weekly (Mon 03:00) | ML model retraining |
|
||||
|
||||
---
|
||||
|
||||
## Database Tables (new/modified)
|
||||
## Storage Schema (SQLite)
|
||||
|
||||
### `current_forecasts`
|
||||
Active predictions served by the API.
|
||||
### `users`
|
||||
| Column | Type |
|
||||
|---|---|
|
||||
| id | INTEGER PK |
|
||||
| email | TEXT UNIQUE |
|
||||
| password_hash | TEXT |
|
||||
| created_at | TEXT |
|
||||
| last_login_at | TEXT |
|
||||
|
||||
| Column | Type | Description |
|
||||
|---|---|---|
|
||||
| id | INTEGER PK | Auto-increment |
|
||||
| generated_at | TEXT | When this forecast was created |
|
||||
| run_hour | INTEGER | Hour of the run (0, 5, 10, 15, 20) |
|
||||
| station_id | TEXT | pajares/sanisidro/fuentes |
|
||||
| prediction_date | TEXT | The date being predicted |
|
||||
| open_probability | REAL | 0.0 - 1.0 |
|
||||
| km_open | REAL | Predicted km open |
|
||||
| crowd_level | TEXT | low/medium/high |
|
||||
| weather_summary | TEXT | Human-readable weather |
|
||||
| rule_notes_json | TEXT | JSON array of rule notes |
|
||||
| prediction_source | TEXT | rules/ml/hybrid |
|
||||
### `current_forecasts` / `past_forecasts`
|
||||
| Column | Type |
|
||||
|---|---|
|
||||
| generated_at | TEXT |
|
||||
| run_hour | INTEGER |
|
||||
| station_id | TEXT |
|
||||
| prediction_date | TEXT |
|
||||
| open_probability | REAL |
|
||||
| km_open | REAL |
|
||||
| crowd_level | TEXT |
|
||||
| weather_summary | TEXT |
|
||||
| rule_notes_json | TEXT |
|
||||
| prediction_source | TEXT |
|
||||
|
||||
### `past_forecasts`
|
||||
Archived forecasts (same schema as `current_forecasts`).
|
||||
|
||||
### `historical_actuals`
|
||||
Actual station data scraped from infonieve at 20:00.
|
||||
|
||||
| Column | Type | Description |
|
||||
|---|---|---|
|
||||
| id | INTEGER PK | Auto-increment |
|
||||
| date | TEXT | The actual date |
|
||||
| station_id | TEXT | pajares/sanisidro/fuentes |
|
||||
| open_status | INTEGER | 0 or 1 |
|
||||
| km_open | REAL | Actual km open |
|
||||
| lifts_open | INTEGER | Number of lifts open |
|
||||
| snow_depth | REAL | Snow depth cm |
|
||||
| scraped_at | TEXT | When data was scraped |
|
||||
### `training_runs`
|
||||
| Column | Type |
|
||||
|---|---|
|
||||
| id | INTEGER PK |
|
||||
| completed_at | TEXT |
|
||||
| metrics_json | TEXT |
|
||||
| parameters_json | TEXT |
|
||||
Reference in new issue
Block a user