Skip to content

Commit 8dec2bc

Browse files
fmt
1 parent b800f65 commit 8dec2bc

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

pypsdm/db/weather/models.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from geoalchemy2 import Geometry, WKBElement
66
from shapely import Point
77
from shapely.geometry.base import BaseGeometry
8-
from shapely.wkb import loads
9-
from shapely.wkb import dumps
8+
from shapely.wkb import dumps, loads
109
from sqlalchemy import Column
1110
from sqlmodel import Field, SQLModel
1211

@@ -62,6 +61,7 @@ def name_mapping():
6261

6362
class Coordinate(SQLModel, table=True):
6463
"""Represents a geographical coordinate."""
64+
6565
id: int = Field(default=None, primary_key=True)
6666

6767
# Use Geometry for storing WKB data (binary format)
@@ -88,7 +88,6 @@ def point(self) -> BaseGeometry:
8888
coordinate = self.coordinate
8989
return loads(coordinate)
9090

91-
9291
@property
9392
def latitude(self) -> float:
9493
return self.point.y
@@ -106,12 +105,12 @@ def x(self) -> float:
106105
return self.point.x
107106

108107
@staticmethod
109-
def from_xy(id: int, x: float, y: float) -> 'Coordinate':
108+
def from_xy(id: int, x: float, y: float) -> "Coordinate":
110109
point = Point(x, y)
111110
wkb_data = dumps(point)
112111
return Coordinate(id=id, coordinate=wkb_data)
113112

114113
@staticmethod
115-
def from_hex(id: int, wkb_hex: str) -> 'Coordinate':
114+
def from_hex(id: int, wkb_hex: str) -> "Coordinate":
116115
bytes = binascii.unhexlify(wkb_hex)
117-
return Coordinate(id=id, coordinate=bytes)
116+
return Coordinate(id=id, coordinate=bytes)

tests/db/weather/test_weather_models.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from datetime import datetime
22

33
import pytest
4-
from sqlalchemy import text, select
4+
from sqlalchemy import select, text
55

6-
from pypsdm.db.weather.models import WeatherValue, Coordinate
6+
from pypsdm.db.weather.models import Coordinate, WeatherValue
77

88

99
@pytest.mark.docker_required
@@ -14,13 +14,15 @@ def test_create_coordinate(db_session):
1414
coord_2 = Coordinate.from_xy(2, 7.46, 51.5)
1515
coordinates: list[Coordinate] = coordinates + [coord_1, coord_2]
1616

17-
query = text("""
17+
query = text(
18+
"""
1819
INSERT INTO coordinate (id, coordinate)
1920
VALUES (:id, ST_SetSRID(ST_GeomFromWKB(:geom), 4326));
20-
""")
21+
"""
22+
)
2123

2224
for coord in coordinates:
23-
db_session.execute(query, {'id': coord.id, 'geom': coord.coordinate})
25+
db_session.execute(query, {"id": coord.id, "geom": coord.coordinate})
2426
db_session.commit()
2527

2628
first_coordinate: Coordinate = db_session.get(Coordinate, 1)
@@ -43,12 +45,14 @@ def test_create_weather_value(db_session):
4345
"""Test creating a weather value."""
4446
berlin = Coordinate.from_xy(id=1, x=13.405, y=52.52)
4547

46-
query = text("""
48+
query = text(
49+
"""
4750
INSERT INTO coordinate (id, coordinate)
4851
VALUES (:id, ST_SetSRID(ST_GeomFromWKB(:geom), 4326));
49-
""")
52+
"""
53+
)
5054

51-
db_session.execute(query, {'id': berlin.id, 'geom': berlin.coordinate})
55+
db_session.execute(query, {"id": berlin.id, "geom": berlin.coordinate})
5256
db_session.commit()
5357

5458
now = datetime.now()

0 commit comments

Comments
 (0)