Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aec217b
feat: at mp height & description to well transfer
jacob-a-brown Nov 11, 2025
505ae6e
feat: add well status and monitoring status to well transfer
jacob-a-brown Nov 11, 2025
8107e7c
feat: validate measuring point height for a well
jacob-a-brown Nov 11, 2025
647dc70
refactor: fix erase/rebuild for tests
jacob-a-brown Nov 12, 2025
ddf6436
Merge branch 'bdms-221' into bdms-221-jab-transfer-updates
jacob-a-brown Nov 12, 2025
10ec9ec
Merge branch 'bdms-221-jab-updates-to-pass-tests' into bdms-221-jab-t…
jacob-a-brown Nov 12, 2025
0bccd4f
note: add note for AMMP review
jacob-a-brown Nov 12, 2025
54c24e8
Merge branch 'bdms-221-jab-updates-to-pass-tests' into bdms-221-jab-t…
jacob-a-brown Nov 12, 2025
f2f5e27
refactor: make well validations more readable
jacob-a-brown Nov 12, 2025
85761c0
Merge branch 'bdms-221-jab-updates-to-pass-tests' into bdms-221-jab-t…
jacob-a-brown Nov 12, 2025
771dff4
refactor: update transfer script for monitoring frequency history table
jacob-a-brown Nov 12, 2025
ef1a4c8
refactor: update for measuring point history table
jacob-a-brown Nov 12, 2025
cabac98
feat: set group_type based off of wells' monitoring status
jacob-a-brown Nov 12, 2025
a795783
Merge branch 'bdms-221-jab-updates-to-pass-tests' into bdms-221-jab-t…
jacob-a-brown Nov 12, 2025
34856d5
Merge branch 'bdms-221-jab-updates-to-pass-tests' into bdms-221-jab-t…
jacob-a-brown Nov 12, 2025
e78a963
Merge branch 'bdms-221' into bdms-221-jab-transfer-updates
jacob-a-brown Nov 13, 2025
b22619c
fix: import retrieve_latest_polymorphic_record from correct place
jacob-a-brown Nov 13, 2025
c80d4a3
Merge branch 'bdms-221-jab-updates-to-pass-tests' into bdms-221-jab-t…
jacob-a-brown Nov 17, 2025
15116e7
Merge branch 'bdms-221-jab-updates-to-pass-tests' into bdms-221-jab-t…
jacob-a-brown Nov 17, 2025
ef016da
WIP: use data provenance table in transfers
jacob-a-brown Nov 18, 2025
cfc4e8f
fix: convert ngvd29 to navd88 for elevation where applicable
jacob-a-brown Nov 18, 2025
3e5a8f0
Merge branch 'bdms-221' into bdms-221-jab-transfer-updates
jacob-a-brown Nov 18, 2025
df238fa
refactor: address PR comments
jacob-a-brown Nov 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/lexicon.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@
{"categories": ["group_type"], "term": "Historical", "definition": "A group of `Things` that share a common historical attribute. E.g., 'Wells drilled before 1950', 'Legacy Wells (Pre-1990)'."},
{"categories": ["monitoring_frequency"], "term": "Monthly", "definition": "Location is monitored on a monthly basis."},
{"categories": ["monitoring_frequency"], "term": "Bimonthly", "definition": "Location is monitored every two months."},
{"categories": ["monitoring_frequency"], "term": "Bimonthly reported", "definition": "Location is monitored every two months and reported to NMBGMR."},
{"categories": ["monitoring_frequency"], "term": "Quarterly", "definition": "Location is monitored on a quarterly basis."},
{"categories": ["monitoring_frequency"], "term": "Biannual", "definition": "Location is monitored twice a year."},
{"categories": ["monitoring_frequency"], "term": "Annual", "definition": "Location is monitored once a year."},
Expand Down
52 changes: 37 additions & 15 deletions schemas/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,41 @@ class ValidateWell(BaseModel):
well_depth: float | None = None # in feet
hole_depth: float | None = None # in feet
well_casing_depth: float | None = None # in feet
measuring_point_height: float | None = None # in feet

@model_validator(mode="after")
def check_depths(self):
if (
self.hole_depth is not None
and self.well_depth is not None
and self.well_depth > self.hole_depth
):
raise ValueError("well depth must be less than than or equal to hole depth")
elif (
self.hole_depth is not None
and self.well_casing_depth is not None
and self.well_casing_depth > self.hole_depth
):
raise ValueError(
"well casing depth must be less than or equal to hole depth"
)
def validate_values(self):
if self.hole_depth is not None:
if self.well_depth is not None and self.well_depth > self.hole_depth:
raise ValueError(
"well depth must be less than than or equal to hole depth"
)
elif (
self.well_casing_depth is not None
and self.well_casing_depth > self.hole_depth
):
raise ValueError(
"well casing depth must be less than or equal to hole depth"
)

if self.measuring_point_height is not None:
if (
self.hole_depth is not None
and self.measuring_point_height >= self.hole_depth
):
raise ValueError("measuring point height must be less than hole depth")
elif (
self.well_casing_depth is not None
and self.measuring_point_height >= self.well_casing_depth
):
raise ValueError(
"measuring point height must be less than well casing depth"
)
elif (
self.well_depth is not None
and self.measuring_point_height >= self.well_depth
):
raise ValueError("measuring point height must be less than well depth")

return self

Expand Down Expand Up @@ -106,6 +124,10 @@ class CreateWell(CreateBaseThing, ValidateWell):
default=None, gt=0, description="Well casing depth in feet"
)
well_casing_materials: list[CasingMaterial] | None = None
measuring_point_height: float = Field(
ge=0, description="Measuring point height in feet"
)
measuring_point_description: str | None


class CreateSpring(CreateBaseThing):
Expand Down
20 changes: 20 additions & 0 deletions services/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ def get_epqs_elevation_from_point(lon: float, lat: float) -> float | None:
return data["value"]


def convert_ngvd29_to_navd88(
elevation_ngvd29: float, longitude: float, latitude: float
) -> float:
url = "https://geodesy.noaa.gov/api/ncat/llh"
params = {
"lat": latitude,
"lon": longitude,
"inDatum": "nad83(2011)",
"outDatum": "nad83(2011)",
"inVertDatum": "ngvd29",
"outVertDatum": "navd88",
"orthoHt": elevation_ngvd29,
}
response = httpx.get(url, params=params)
data = response.json()

elevation_navd88 = data.get("destOrthoht")
return elevation_navd88


def retrieve_latest_polymorphic_history_table_record(
target_record: DeclarativeBase,
polymorphic_relationship: str,
Expand Down
24 changes: 24 additions & 0 deletions tests/test_thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ def test_validate_hole_depth_casing_depth():
ValidateWell(hole_depth=100.0, well_casing_depth=110.0)


def test_validate_mp_height_hole_depth():
with pytest.raises(
ValueError,
match="measuring point height must be less than hole depth",
):
ValidateWell(hole_depth=100.0, measuring_point_height=110.0)


def test_validate_mp_height_well_depth():
with pytest.raises(
ValueError,
match="measuring point height must be less than well depth",
):
ValidateWell(well_depth=100.0, measuring_point_height=105.0)


def test_validate_mp_height_well_casing_depth():
with pytest.raises(
ValueError,
match="measuring point height must be less than well casing depth",
):
ValidateWell(well_casing_depth=100.0, measuring_point_height=105.0)


# POST tests ===================================================================


Expand Down
26 changes: 26 additions & 0 deletions transfers/group_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from db.engine import session_ctx
from transfers.util import read_csv
from transfers.logger import logger
from services.util import retrieve_latest_polymorphic_history_table_record


def transfer_groups(
Expand All @@ -44,7 +45,32 @@ def transfer_groups(
logger.info(
f"Adding {len(records)} things to group {group.name}, prefix {prefix}"
)
group_is_monitoring_plan = False
for record in records:
# set the group_type to Monitoring Plan if at least one well is currently monitored
if not group_is_monitoring_plan:
if record.status_history:
monitoring_status = [
sh
for sh in record.status_history
if sh.status_type == "Monitoring Status"
]
if monitoring_status:
monitoring_status = retrieve_latest_polymorphic_history_table_record(
record,
"status_history",
"Monitoring Status",
)
if (
monitoring_status.status_value
== "Currently monitored"
):
group_is_monitoring_plan = True
group.group_type = "Monitoring Plan"
logger.info(
f" Setting group {group.name} type to Monitoring Plan based on thing {record.name}"
)

gta = GroupThingAssociation(group=group, thing=record)
session.add(gta)
group.thing_associations.append(gta)
Expand Down
17 changes: 15 additions & 2 deletions transfers/thing_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@

from db import LocationThingAssociation
from services.thing_helper import add_thing
from transfers.util import make_location, read_csv, replace_nans
from transfers.util import (
make_location,
make_location_data_provenance,
read_csv,
replace_nans,
)
from transfers.logger import logger


Expand Down Expand Up @@ -49,7 +54,15 @@ def transfer_thing(session: Session, site_type: str, make_payload, limit=None) -
session.commit()

try:
location = make_location(row)
location, elevation_method = make_location(row)
session.add(location)
session.flush()
data_provenances = make_location_data_provenance(
row, location, elevation_method
)
for dp in data_provenances:
session.add(dp)

payload = make_payload(row)
thing_type = payload.pop("thing_type")
thing = add_thing(session, payload, thing_type=thing_type)
Expand Down
Loading
Loading