-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_model.py
51 lines (37 loc) · 1.08 KB
/
data_model.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from enum import StrEnum, auto
from pathlib import Path
from pydantic import BaseModel
class Group(StrEnum):
TREATMENT = auto()
CONTROL = auto()
class TopSoilOrganicCarbon(BaseModel):
"""Topsoil organic carbon weight measurements."""
measurement_value: float
measurement_name: str
measurement_year: str
measurement_depth: str
measurement_unit: str
group: Group
class TopSoilOrganicCarbonChange(BaseModel):
"""Change in topsoil organic carbon weight measurements."""
measurement_change_value: float
measurement_relative_to: str
measurement_name: str
measurement_year: str
measurement_depth: str
measurement_unit: str
class Location(BaseModel):
name: str
address: str
latitude: float
longitude: float
measurements: list[TopSoilOrganicCarbon | TopSoilOrganicCarbonChange]
class Paper(BaseModel):
title: str
authors: str
year: int
doi: str
locations: list[Location]
def save(self, path: Path) -> None:
with open(path, "w") as f:
f.write(self.model_dump_json(indent=2))