Spaces:
Sleeping
Sleeping
File size: 1,002 Bytes
95cb050 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
"""
Pydantic models for API request/response validation
"""
from pydantic import BaseModel, field_validator
from typing import Optional
class SingleAssessment(BaseModel):
"""Model for single location vulnerability assessment request"""
latitude: float
longitude: float
height: Optional[float] = 0.0
basement: Optional[float] = 0.0
@field_validator('latitude')
@classmethod
def check_lat(cls, v: float) -> float:
if not -90 <= v <= 90:
raise ValueError('Latitude must be between -90 and 90')
return v
@field_validator('longitude')
@classmethod
def check_lon(cls, v: float) -> float:
if not -180 <= v <= 180:
raise ValueError('Longitude must be between -180 and 180')
return v
@field_validator('basement')
@classmethod
def check_basement(cls, v: float) -> float:
if v > 0:
raise ValueError('Basement height must be 0 or negative (e.g., -1, -2, -3)')
return v
|