Skip to content

Commit 9e4f368

Browse files
committed
fix: update measuring point height handling and add tests for assumed values
1 parent 5f11251 commit 9e4f368

4 files changed

Lines changed: 71 additions & 5 deletions

File tree

db/measuring_point_history.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from typing import TYPE_CHECKING
1616

17-
from sqlalchemy import Integer, ForeignKey, Date, Text, Numeric, Boolean
17+
from sqlalchemy import Integer, ForeignKey, Date, Text, Numeric, Boolean, false
1818
from sqlalchemy.orm import relationship, Mapped, mapped_column
1919

2020
from db.base import Base, AutoBaseMixin, ReleaseMixin
@@ -44,7 +44,7 @@ class MeasuringPointHistory(Base, AutoBaseMixin, ReleaseMixin):
4444
Boolean,
4545
nullable=False,
4646
default=False,
47-
server_default="false",
47+
server_default=false(),
4848
comment="True when measuring point height is assumed/defaulted rather than explicitly measured.",
4949
)
5050
measuring_point_description: Mapped[str] = mapped_column(

tests/test_thing.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
viewer_function,
2626
amp_viewer_function,
2727
)
28-
from db import Thing, WellScreen, ThingIdLink
28+
from db import Thing, WellScreen, ThingIdLink, MeasuringPointHistory
29+
from db.engine import session_ctx
2930
from main import app
3031
from schemas import DT_FMT
3132
from schemas.location import LocationResponse
@@ -190,6 +191,65 @@ def test_add_water_well_with_measuring_point(location, group):
190191
cleanup_post_test(Thing, data["id"])
191192

192193

194+
def test_add_water_well_missing_measuring_point_height_sets_assumed(location, group):
195+
payload = {
196+
"location_id": location.id,
197+
"group_id": group.id,
198+
"release_status": "draft",
199+
"name": "Test Well Missing MP Height",
200+
}
201+
202+
response = client.post("/thing/water-well", json=payload)
203+
assert response.status_code == 201
204+
data = response.json()
205+
assert data["measuring_point_height"] == 0
206+
assert data["measuring_point_height_is_assumed"] is True
207+
208+
with session_ctx() as session:
209+
mph = (
210+
session.query(MeasuringPointHistory)
211+
.filter(
212+
MeasuringPointHistory.thing_id == data["id"],
213+
MeasuringPointHistory.end_date.is_(None),
214+
)
215+
.one()
216+
)
217+
assert float(mph.measuring_point_height) == 0.0
218+
assert mph.measuring_point_height_is_assumed is True
219+
220+
cleanup_post_test(Thing, data["id"])
221+
222+
223+
def test_add_water_well_explicit_measuring_point_height_not_assumed(location, group):
224+
payload = {
225+
"location_id": location.id,
226+
"group_id": group.id,
227+
"release_status": "draft",
228+
"name": "Test Well Explicit MP Height",
229+
"measuring_point_height": 2.5,
230+
}
231+
232+
response = client.post("/thing/water-well", json=payload)
233+
assert response.status_code == 201
234+
data = response.json()
235+
assert data["measuring_point_height"] == 2.5
236+
assert data["measuring_point_height_is_assumed"] is False
237+
238+
with session_ctx() as session:
239+
mph = (
240+
session.query(MeasuringPointHistory)
241+
.filter(
242+
MeasuringPointHistory.thing_id == data["id"],
243+
MeasuringPointHistory.end_date.is_(None),
244+
)
245+
.one()
246+
)
247+
assert float(mph.measuring_point_height) == 2.5
248+
assert mph.measuring_point_height_is_assumed is False
249+
250+
cleanup_post_test(Thing, data["id"])
251+
252+
193253
@pytest.mark.skip("Needs to be updated per changes made from feature files")
194254
def test_add_water_well_409_bad_group_id(location):
195255
bad_group_id = 9999

tests/transfers/test_contact_with_multiple_wells.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
def _run_contact_transfer(pointids: list[str]):
2424
wt = WellTransferer(pointids=pointids)
25-
wt.transfer()
25+
wt.transfer_parallel()
2626

2727
ct = ContactTransfer(pointids=pointids)
2828
ct.transfer()

transfers/util.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,17 @@ def estimate_measuring_point_height(
106106
) -> tuple[float, str, datetime | None, datetime | None]:
107107
mph = row.MPHeight
108108
mph_desc = row.MeasuringPoint
109+
# Treat NaN as missing the same as None.
110+
if notna(mph):
111+
mph_is_missing = False
112+
else:
113+
mph = None
114+
mph_is_missing = True
109115
try:
110116
df = self._grouped.get_group(row.PointID)
111117
except KeyError:
112118
df = None
113-
if mph is None:
119+
if mph_is_missing:
114120
if self.verbose:
115121
logger.info(
116122
f"No MPHeight found for PointID: {row.PointID}. Estimating from measurements."

0 commit comments

Comments
 (0)