Skip to content

Commit daa6e91

Browse files
committed
GLIDE data validators
1 parent 96a4428 commit daa6e91

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

pystac_monty/validators/glide.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
import logging
22
from typing import Optional
33

4-
from pydantic import BaseModel
4+
from pydantic import BaseModel, Field, ConfigDict
55

66
logger = logging.getLogger(__name__)
77
logging.basicConfig(level=logging.INFO)
88
logger.setLevel(logging.INFO)
99

10+
class BaseModelWithExtra(BaseModel):
11+
model_config = ConfigDict(extra="ignore")
1012

11-
class GlideSetValidator(BaseModel):
12-
comments: str
13-
year: int
13+
14+
class GlideSetValidator(BaseModelWithExtra):
15+
comments: Optional[str]
16+
year: int # Restricting reasonable year range
1417
docid: int
15-
latitude: float
16-
homeless: int
17-
source: str
18-
idsource: str
19-
killed: int
20-
affected: int
21-
duration: int
18+
latitude: float = Field(..., ge=-90, le=90)
19+
longitude: float = Field(..., ge=-180, le=180)
20+
homeless: int = Field(..., ge=0)
21+
source: Optional[str]
22+
idsource: Optional[str]
23+
killed: int = Field(..., ge=0)
24+
affected: int = Field(..., ge=0)
25+
duration: int = Field(..., ge=0)
2226
number: str
23-
injured: int
24-
month: int
27+
injured: int = Field(..., ge=0)
28+
month: int = Field(..., ge=1, le=12)
2529
geocode: str
26-
location: str
30+
location: Optional[str]
2731
magnitude: str
28-
time: Optional[str] = None
29-
id: Optional[str] = None
30-
event: str
31-
day: int
32-
status: str
33-
longitude: float
32+
time: Optional[str]
33+
id: Optional[str]
34+
event: str # Ensuring event is uppercase letters
35+
day: int = Field(..., ge=1, le=31)
36+
status: str
3437

3538
@classmethod
3639
def validate_event(cls, data: dict) -> bool:

0 commit comments

Comments
 (0)