mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 15:26:15 +00:00
REST API serving forecast data with HS256 JWT auth (14-day tokens).
Public: /health, /auth/register, /auth/login.
Protected: /stations, /forecast, /forecast/history, /forecast/{id}, /status.
Includes APScheduler for periodic forecasts and Telegram bot subprocess.
112 lines
2.6 KiB
Python
112 lines
2.6 KiB
Python
"""Pydantic response models for the SkiPredictor REST API."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# -- Stations ---------------------------------------------------------------
|
|
|
|
class StationInfo(BaseModel):
|
|
station_id: str
|
|
name: str
|
|
max_km: float
|
|
latitude: float
|
|
longitude: float
|
|
altitude: int
|
|
wind_closure_threshold_kmh: int
|
|
min_snow_depth_cm: int
|
|
|
|
|
|
class StationsResponse(BaseModel):
|
|
stations: list[StationInfo]
|
|
|
|
|
|
# -- Forecasts ---------------------------------------------------------------
|
|
|
|
class DayForecast(BaseModel):
|
|
date: str
|
|
open_probability: float | None = None
|
|
open_label: str | None = None
|
|
km_open: float | None = None
|
|
max_km: float | None = None
|
|
crowd_level: str | None = None
|
|
weather_summary: str | None = None
|
|
rule_notes: list[str] = Field(default_factory=list)
|
|
prediction_source: str | None = None
|
|
|
|
|
|
class StationForecast(BaseModel):
|
|
station_id: str
|
|
name: str
|
|
days: list[DayForecast]
|
|
|
|
|
|
class ForecastAllResponse(BaseModel):
|
|
generated_at: str | None = None
|
|
run_hour: int | None = None
|
|
stations: dict[str, StationForecast]
|
|
|
|
|
|
class ForecastStationResponse(BaseModel):
|
|
generated_at: str | None = None
|
|
run_hour: int | None = None
|
|
station_id: str
|
|
name: str
|
|
days: list[DayForecast]
|
|
|
|
|
|
# -- Forecast history --------------------------------------------------------
|
|
|
|
class ForecastHistoryRun(BaseModel):
|
|
generated_at: str
|
|
run_hour: int
|
|
prediction_date: str
|
|
station_id: str
|
|
open_probability: float | None = None
|
|
km_open: float | None = None
|
|
crowd_level: str | None = None
|
|
prediction_source: str | None = None
|
|
|
|
|
|
class ForecastHistoryResponse(BaseModel):
|
|
total: int
|
|
limit: int
|
|
offset: int
|
|
runs: list[ForecastHistoryRun]
|
|
|
|
|
|
# -- System ------------------------------------------------------------------
|
|
|
|
class HealthResponse(BaseModel):
|
|
status: str
|
|
timestamp: str
|
|
|
|
|
|
class StatusResponse(BaseModel):
|
|
last_forecast_run: str | None = None
|
|
next_forecast_run: str | None = None
|
|
last_training_run: str | None = None
|
|
next_training_run: str | None = None
|
|
models: dict[str, str] = Field(default_factory=dict)
|
|
telegram_bot_active: bool = False
|
|
stations_count: int = 0
|
|
database_size_mb: float = 0.0
|
|
|
|
|
|
# -- Auth -------------------------------------------------------------------
|
|
|
|
class UserCreate(BaseModel):
|
|
email: str = Field(..., min_length=3)
|
|
password: str = Field(..., min_length=8)
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
id: int
|
|
email: str
|
|
|
|
|
|
class TokenResponse(BaseModel):
|
|
access_token: str
|
|
token_type: str = "bearer"
|