Skip to content

Commit 6d03bf4

Browse files
committed
fix(well inventory): use one mp height for thing and gwl
1 parent fe6cfbc commit 6d03bf4

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

services/well_inventory_csv.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,22 @@ def _add_csv_row(session: Session, group: Group, model: WellInventoryRow, user)
687687
}
688688
)
689689

690+
if (
691+
model.mp_height is not None
692+
and model.measuring_point_height_ft is not None
693+
and model.mp_height != model.measuring_point_height_ft
694+
):
695+
raise ValueError(
696+
"Conflicting values for measuring point height: mp_height and measuring_point_height_ft"
697+
)
698+
699+
if model.measuring_point_height_ft is not None:
700+
universal_mp_height = model.measuring_point_height_ft
701+
elif model.mp_height is not None:
702+
universal_mp_height = model.mp_height
703+
else:
704+
universal_mp_height = None
705+
690706
data = CreateWell(
691707
location_id=loc.id,
692708
group_id=group.id,
@@ -695,7 +711,7 @@ def _add_csv_row(session: Session, group: Group, model: WellInventoryRow, user)
695711
well_depth=model.total_well_depth_ft,
696712
well_depth_source=model.depth_source,
697713
well_casing_diameter=model.casing_diameter_ft,
698-
measuring_point_height=model.measuring_point_height_ft,
714+
measuring_point_height=universal_mp_height,
699715
measuring_point_description=model.measuring_point_description,
700716
well_completion_date=model.date_drilled,
701717
well_completion_date_source=model.completion_source,
@@ -839,7 +855,7 @@ def _add_csv_row(session: Session, group: Group, model: WellInventoryRow, user)
839855
value=model.depth_to_water_ft,
840856
unit="ft",
841857
observation_datetime=model.measurement_date_time,
842-
measuring_point_height=model.mp_height,
858+
measuring_point_height=universal_mp_height,
843859
groundwater_level_reason=(
844860
model.level_status.value
845861
if hasattr(model.level_status, "value")

tests/test_well_inventory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def test_well_inventory_db_contents_with_waterlevels(tmp_path):
482482
"sample_method": "Steel-tape measurement",
483483
"data_quality": "Water level accurate to within two hundreths of a foot",
484484
"water_level_notes": "Attempted measurement",
485-
"mp_height_ft": 2.5,
485+
"mp_height_ft": 3.5,
486486
"level_status": "Water level not affected",
487487
}
488488
)
@@ -670,7 +670,7 @@ def test_blank_depth_to_water_still_creates_water_level_records(tmp_path):
670670
"sample_method": "Steel-tape measurement",
671671
"data_quality": "Water level accurate to within two hundreths of a foot",
672672
"water_level_notes": "Attempted measurement",
673-
"mp_height_ft": 2.5,
673+
"mp_height_ft": 3.5,
674674
}
675675
)
676676

@@ -694,7 +694,7 @@ def test_blank_depth_to_water_still_creates_water_level_records(tmp_path):
694694
"2025-02-15T10:30:00Z"
695695
)
696696
assert observations[0].value is None
697-
assert observations[0].measuring_point_height == 2.5
697+
assert observations[0].measuring_point_height == 3.5
698698

699699

700700
def test_rerunning_same_well_inventory_csv_is_idempotent():

0 commit comments

Comments
 (0)