Skip to content

Commit cadf0d2

Browse files
authored
Merge pull request #217 from UW-Macrostrat/interchange-schema
adding /dev/interchange-data/ routes to api v3
2 parents eab031e + 440ac6a commit cadf0d2

File tree

6 files changed

+436
-0
lines changed

6 files changed

+436
-0
lines changed

services/api-v3/api/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import api.routes.security
1111
from api.database import connect_engine, dispose_engine
12+
from api.routes.dev import dev_router
1213
from api.routes.ingest import router as ingest_router
1314
from api.routes.object import router as object_router
1415
from api.routes.sources import router as sources_router
@@ -46,6 +47,8 @@ async def setup_engine(a: FastAPI):
4647
app.include_router(object_router)
4748
app.include_router(ingest_router)
4849
app.include_router(sources_router)
50+
app.include_router(dev_router)
51+
4952

5053
if __name__ == "__main__":
5154
uvicorn.run(
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
from datetime import datetime
2+
from enum import Enum
3+
from typing import Literal, Optional
4+
5+
from pydantic import BaseModel
6+
7+
8+
class Location(BaseModel):
9+
"""
10+
Location model representing a geographical location with latitude and longitude.
11+
"""
12+
13+
latitude: float
14+
longitude: float
15+
elevation: Optional[float] = None
16+
radius: Optional[float] = None
17+
# A description of the location
18+
description: Optional[str] = None
19+
closest_place: Optional[str] = None
20+
gps_accuracy: Optional[float] = None
21+
22+
23+
class IdentifiedModel(BaseModel):
24+
id: int
25+
26+
27+
class Photo(IdentifiedModel):
28+
"""
29+
A photo.
30+
"""
31+
32+
# URL at which the photo should be fetchable
33+
url: str
34+
width: int
35+
height: int
36+
checksum: str
37+
38+
39+
class BeddingFacing(Enum):
40+
upright = "upright"
41+
overturned = "overturned"
42+
unknown = "unknown"
43+
44+
45+
class PlanarOrientation(BaseModel):
46+
strike: float
47+
dip: float
48+
facing: BeddingFacing = BeddingFacing.upright
49+
notes: Optional[str] = None
50+
associated: list["Orientation"] = []
51+
52+
53+
class LinearOrientation(BaseModel):
54+
plunge: float
55+
trend: float
56+
notes: Optional[str] = None
57+
58+
59+
class Texture(BaseModel):
60+
name: str
61+
62+
63+
Orientation = PlanarOrientation | LinearOrientation
64+
65+
66+
class GeologicAgeInterval(IdentifiedModel):
67+
name: str
68+
t_age: Optional[float] = None
69+
b_age: Optional[float] = None
70+
71+
72+
class Lithology(IdentifiedModel):
73+
name: str
74+
parents: Optional[list[int]] = None
75+
color: Optional[str] = None
76+
pattern: Optional[str] = None
77+
78+
79+
class LithodemeType(Enum):
80+
Formation = "formation"
81+
Member = "member"
82+
Group = "group"
83+
Supergroup = "supergroup"
84+
Batholith = "batholith"
85+
Pluton = "pluton"
86+
Bed = "bed"
87+
Flow = "flow"
88+
Terrace = "terrace"
89+
Intrusion = "intrusion"
90+
...
91+
92+
93+
class LithodemeName(GeologicAgeInterval):
94+
"""A lithodeme or stratigraphic unit name"""
95+
96+
parent: Optional[int] = None
97+
type: LithodemeType
98+
t_interval: Optional[float] = None
99+
b_interval: Optional[float] = None
100+
101+
102+
class RockUnit(IdentifiedModel):
103+
name: str
104+
abbreviation: Optional[str] = None
105+
liths: list[Lithology] = []
106+
age: Optional[GeologicAgeInterval] = None
107+
entity: Optional[LithodemeName] = None
108+
109+
110+
class Fossil(IdentifiedModel):
111+
description: str
112+
taxa: Optional[str] = None
113+
114+
115+
AnyData = Orientation | Photo | RockUnit | Texture | Lithology | Fossil
116+
117+
118+
class Observation(BaseModel):
119+
notes: Optional[str] = None
120+
data: AnyData
121+
122+
123+
class Person(IdentifiedModel):
124+
name: str
125+
email: Optional[str] = None
126+
orcid: Optional[str] = None
127+
institution: Optional[str] = None
128+
gravatar: Optional[str] = None
129+
130+
131+
class Sample(IdentifiedModel):
132+
"""
133+
A sample of a rock or sediment
134+
"""
135+
136+
name: str
137+
description: Optional[str] = None
138+
sample_type: Literal["rock", "sediment", "soil", "water"]
139+
igsn: Optional[str] = None
140+
collected: datetime
141+
142+
143+
class SocialInfo(BaseModel):
144+
likes: int
145+
comments: int
146+
rating: Optional[int] = None
147+
148+
149+
class FieldSite(BaseModel):
150+
"""
151+
A site of with associated field observations
152+
"""
153+
154+
id: int | str
155+
name: Optional[str] = None
156+
location: Location
157+
created: datetime
158+
updated: datetime
159+
observations: list[Observation] = []
160+
samples: list[Sample] = []
161+
photos: list[Photo] = []
162+
notes: Optional[str] = None
163+
social: Optional[SocialInfo] = None
164+
children: Optional[list["FieldSite"]] = None
165+
contributors: Optional[list[Person]] = None

services/api-v3/api/routes/__init__.py

Whitespace-only changes.

services/api-v3/api/routes/dev.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from api.routes.dev_routes.interchange_data import interchange_router
2+
from fastapi import APIRouter
3+
4+
dev_router = APIRouter(prefix="/dev", tags=["dev"])
5+
dev_router.include_router(interchange_router)

services/api-v3/api/routes/dev_routes/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)