From 5f56bf23378dacd3c5a2381ceb4feafe44ca4be7 Mon Sep 17 00:00:00 2001 From: Kai Koehler Date: Thu, 22 Aug 2024 16:04:00 -0700 Subject: [PATCH] Pydantic avro schema storage --- src/sasquatchbackpack/schemas/__init__.py | 1 + src/sasquatchbackpack/schemas/usgs.avsc | 1 - src/sasquatchbackpack/schemas/usgs.py | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/sasquatchbackpack/schemas/__init__.py delete mode 100644 src/sasquatchbackpack/schemas/usgs.avsc create mode 100644 src/sasquatchbackpack/schemas/usgs.py diff --git a/src/sasquatchbackpack/schemas/__init__.py b/src/sasquatchbackpack/schemas/__init__.py new file mode 100644 index 0000000..2b72230 --- /dev/null +++ b/src/sasquatchbackpack/schemas/__init__.py @@ -0,0 +1 @@ +"""Avro schemas.""" diff --git a/src/sasquatchbackpack/schemas/usgs.avsc b/src/sasquatchbackpack/schemas/usgs.avsc deleted file mode 100644 index a2c158c..0000000 --- a/src/sasquatchbackpack/schemas/usgs.avsc +++ /dev/null @@ -1 +0,0 @@ -{"namespace": "$namespace", "name": "$topic_name", "type": "record", "description": "Collection of earthquakes near the summit", "fields": [{"name": "timestamp", "type": "long"}, {"name": "id", "type": "string", "description": "unique earthquake id"}, {"name": "latitude", "type": "float", "units": "Degrees"}, {"name": "longitude", "type": "float", "units": "Degrees"}, {"name": "depth", "type": "float", "units": "Km"}, {"name": "magnitude", "type": "float", "units": "Richter Magnitudes"}]} \ No newline at end of file diff --git a/src/sasquatchbackpack/schemas/usgs.py b/src/sasquatchbackpack/schemas/usgs.py new file mode 100644 index 0000000..6b79afc --- /dev/null +++ b/src/sasquatchbackpack/schemas/usgs.py @@ -0,0 +1,17 @@ +"""USGS Schemas.""" + +from dataclasses import dataclass, field + +from dataclasses_avroschema import AvroModel + + +@dataclass +class EarthquakeSchema(AvroModel): + """USGS Earthquake schema.""" + + timestamp: int + id: str = field(metadata={"description": "unique earthquake id"}) + latitude: float = field(metadata={"units": "degree"}) + longitude: float = field(metadata={"units": "degree"}) + depth: float = field(metadata={"units": "km"}) + magnitude: float = field(metadata={"units": "u.richter_magnitudes"})