Files
skipredictor/API_SPEC.md
T
dasemu b4453917dc docs: update documentation for new features and recent changes
- 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
2026-03-17 18:26:06 +01:00

274 lines
5.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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",
"sky_condition": "nublado",
"snow_type": "húmeda",
"weather_summary": "Nublado | Tª -2–2 °C | Nieve 5 cm | Lluvia 2.0 mm | Rachas 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 |
| sky_condition | TEXT |
| snow_type | TEXT |
| weather_code | INTEGER |
| weather_summary | TEXT |
| rule_notes_json | TEXT |
| prediction_source | TEXT |
### `notification_subscribers`
| Column | Type |
|---|---|
| id | INTEGER PK |
| telegram_chat_id | INTEGER UNIQUE |
| telegram_username | TEXT |
| subscribed_at | TEXT |
| active | INTEGER |
### `training_runs`
| Column | Type |
|---|---|
| id | INTEGER PK |
| completed_at | TEXT |
| metrics_json | TEXT |
| parameters_json | TEXT |