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.
260 lines
5.0 KiB
Markdown
260 lines
5.0 KiB
Markdown
# SkiPredictor API Specification v1
|
|
|
|
Base URL: `/api/v1`
|
|
|
|
All responses use JSON. Dates use ISO 8601 format (`YYYY-MM-DD`). Timestamps use ISO 8601 with timezone (`YYYY-MM-DDTHH:MM:SS+HH:MM`).
|
|
|
|
---
|
|
|
|
## 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`
|
|
|
|
List all tracked ski stations with metadata.
|
|
|
|
**Response 200:**
|
|
```json
|
|
{
|
|
"stations": [
|
|
{
|
|
"station_id": "pajares",
|
|
"name": "Valgrande-Pajares",
|
|
"max_km": 22.0,
|
|
"latitude": 43.05,
|
|
"longitude": -5.77,
|
|
"altitude": 1505,
|
|
"wind_closure_threshold_kmh": 80,
|
|
"min_snow_depth_cm": 30
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Forecasts
|
|
|
|
### `GET /api/v1/forecast`
|
|
|
|
Get the latest forecast for **all stations**. Returns today + next 7 days per station.
|
|
|
|
**Response 200:**
|
|
```json
|
|
{
|
|
"generated_at": "2026-03-13T10:00:00+01:00",
|
|
"run_hour": 10,
|
|
"stations": {
|
|
"pajares": {
|
|
"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"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
**Notes:**
|
|
- `open_label`: `"Abierta"` (>=0.70), `"Probable apertura"` (>=0.40), `"Cerrada"` (<0.40)
|
|
- At run hours 15 and 20, `days[0]` is tomorrow (today is omitted)
|
|
- At run hours 00, 05, and 10, `days[0]` is today
|
|
|
|
---
|
|
|
|
### `GET /api/v1/forecast/{station_id}`
|
|
|
|
Get the latest forecast for a **single station**.
|
|
|
|
**Path parameters:**
|
|
- `station_id`: `pajares` | `sanisidro` | `fuentes`
|
|
|
|
**Response 200:**
|
|
```json
|
|
{
|
|
"generated_at": "2026-03-13T10:00:00+01:00",
|
|
"run_hour": 10,
|
|
"station_id": "pajares",
|
|
"name": "Valgrande-Pajares",
|
|
"days": [ ... ]
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### `GET /api/v1/forecast/history`
|
|
|
|
Get past forecast runs (archived when a new run replaces them).
|
|
|
|
**Query parameters:**
|
|
- `station_id` (optional): filter by station
|
|
- `date_from` (optional): earliest prediction date (`YYYY-MM-DD`)
|
|
- `date_to` (optional): latest prediction date (`YYYY-MM-DD`)
|
|
- `limit` (optional, default 50, max 200): number of runs to return
|
|
- `offset` (optional, default 0): pagination offset
|
|
|
|
**Response 200:**
|
|
```json
|
|
{
|
|
"total": 150,
|
|
"limit": 50,
|
|
"offset": 0,
|
|
"runs": [
|
|
{
|
|
"generated_at": "2026-03-13T05:00:00+01:00",
|
|
"run_hour": 5,
|
|
"prediction_date": "2026-03-13",
|
|
"station_id": "pajares",
|
|
"open_probability": 0.85,
|
|
"km_open": 18.5,
|
|
"crowd_level": "medium",
|
|
"prediction_source": "hybrid"
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## System
|
|
|
|
### `GET /api/v1/health`
|
|
|
|
Public health check endpoint.
|
|
|
|
**Response 200:**
|
|
```json
|
|
{
|
|
"status": "ok",
|
|
"timestamp": "2026-03-13T10:15:00+01:00"
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### `GET /api/v1/status`
|
|
|
|
System status: last forecast run, next scheduled run, model info, bot status.
|
|
|
|
**Response 200:**
|
|
```json
|
|
{
|
|
"last_forecast_run": "2026-03-13T10:00:00+01:00",
|
|
"next_forecast_run": "2026-03-13T15:00:00+01:00",
|
|
"last_training_run": "2026-03-10T03:00:00+01:00",
|
|
"next_training_run": "2026-03-17T03:00:00+01:00",
|
|
"models": {
|
|
"station_open": "station_open",
|
|
"km_open": "km_open",
|
|
"crowd_level": "crowd_level"
|
|
},
|
|
"telegram_bot_active": true,
|
|
"stations_count": 3,
|
|
"database_size_mb": 8.1
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Internal Schedule
|
|
|
|
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 |
|
|
| 20:00 | Forecast run: tomorrow + 6 days |
|
|
| Weekly (Mon 03:00) | ML model retraining |
|
|
|
|
---
|
|
|
|
## Storage Schema (SQLite)
|
|
|
|
### `users`
|
|
| Column | Type |
|
|
|---|---|
|
|
| id | INTEGER PK |
|
|
| email | TEXT UNIQUE |
|
|
| password_hash | TEXT |
|
|
| created_at | TEXT |
|
|
| last_login_at | TEXT |
|
|
|
|
### `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 |
|
|
|
|
### `training_runs`
|
|
| Column | Type |
|
|
|---|---|
|
|
| id | INTEGER PK |
|
|
| completed_at | TEXT |
|
|
| metrics_json | TEXT |
|
|
| parameters_json | TEXT |
|