基本结构以及计算降雨栅格
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Schemas package - Pydantic数据模型
|
||||
"""
|
||||
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
降雨数据相关的Pydantic Schemas
|
||||
"""
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
class RainfallGridRequest(BaseModel):
|
||||
"""降雨栅格请求模型"""
|
||||
time: Optional[str] = Field(
|
||||
None,
|
||||
alias="time",
|
||||
description="查询时间 ISO格式,默认为当前时间(自动查询前12小时数据)",
|
||||
example="2024-01-01T12:00:00"
|
||||
)
|
||||
resolution: float = Field(
|
||||
0.01,
|
||||
alias="resolution",
|
||||
description="栅格分辨率(度)",
|
||||
gt=0,
|
||||
le=0.1
|
||||
)
|
||||
|
||||
class Config:
|
||||
populate_by_name = True # 允许同时使用字段名和别名
|
||||
|
||||
|
||||
class StationData(BaseModel):
|
||||
"""站点数据模型"""
|
||||
lon: float
|
||||
lat: float
|
||||
rainfall: float
|
||||
|
||||
|
||||
class GridMetadata(BaseModel):
|
||||
"""栅格元数据"""
|
||||
start_time: str
|
||||
end_time: str
|
||||
district_id: int
|
||||
resolution: float
|
||||
station_count: int
|
||||
grid_size: List[int]
|
||||
bounds: dict
|
||||
|
||||
|
||||
class RainfallGridResponse(BaseModel):
|
||||
"""降雨栅格响应模型 - 符合前端 ApiResponse 结构"""
|
||||
code: int = Field(200, description="状态码")
|
||||
message: str = Field(..., description="响应消息")
|
||||
data: Optional[dict] = Field(None, description="响应数据")
|
||||
|
||||
|
||||
class StationsResponse(BaseModel):
|
||||
"""站点数据响应模型 - 符合前端 ApiResponse 结构"""
|
||||
code: int = Field(200, description="状态码")
|
||||
message: str = Field(..., description="响应消息")
|
||||
data: List[StationData] = Field(default_factory=list, description="站点数据列表")
|
||||
Reference in New Issue
Block a user