Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion services/ngwmn_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ def make_waterlevels_response(point_id, db):
.order_by(NGWMNWaterLevels.date_measured)
.all()
)
# The daily *minimum* depth matches the legacy
# NMA_WaterLevelsContinuous_Pressure_Daily values (AMP's nightly job
# published the shallowest reading of each day), keeping the NGWMN
# record consistent with what was historically harvested.
pressure = (
db.query(
TransducerDailyData.point_id,
TransducerDailyData.date_measured,
TransducerDailyData.depth_to_water_bgs,
TransducerDailyData.depth_to_water_bgs_min,
)
.join(Thing, Thing.id == TransducerDailyData.thing_id)
.filter(
Expand Down
13 changes: 7 additions & 6 deletions tests/test_ngwmn_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ def ngwmn_merged_well():
session.flush()

transducer_readings = [
# 2024-03-15 daily avg 50.0: manual 47.50 is shallower and wins.
# 2024-03-15 daily min 49.0: manual 47.50 is shallower and wins.
("2024-03-15T06:00:00Z", 49.0),
("2024-03-15T18:00:00Z", 51.0),
# 2024-03-20 daily avg 30.0: transducer-only date.
# 2024-03-20 daily min 29.0: transducer-only date.
("2024-03-20T06:00:00Z", 29.0),
("2024-03-20T18:00:00Z", 31.0),
# 2024-04-01 daily avg 20.0: manual 33.00 is deeper and loses.
# 2024-04-01 daily min 19.0: manual 33.00 is deeper and loses.
("2024-04-01T06:00:00Z", 19.0),
("2024-04-01T18:00:00Z", 21.0),
]
Expand Down Expand Up @@ -380,8 +380,9 @@ def test_ngwmn_waterlevels_merges_manual_and_transducer(ngwmn_merged_well):
assert first.findtext("MeasurementMonth") == "3"
assert first.findtext("MeasurementDay") == "15"

# Transducer-only date: daily average is emitted.
assert second.findtext("DepthFromLandSurfaceData") == "30.00"
# Transducer-only date: the daily minimum is emitted, matching the
# legacy NMA_WaterLevelsContinuous_Pressure_Daily statistic.
assert second.findtext("DepthFromLandSurfaceData") == "29.00"
assert second.findtext("MeasuringMethod") == "Pressure Transducer"
assert second.findtext("WaterLevelUnits") == "ft bgs"
assert second.findtext("WaterLevelAccuracy") == "0.02 ft"
Expand All @@ -390,7 +391,7 @@ def test_ngwmn_waterlevels_merges_manual_and_transducer(ngwmn_merged_well):

# Same-date overlap where the manual reading is deeper: transducer wins
# and the manual record is dropped.
assert third.findtext("DepthFromLandSurfaceData") == "20.00"
assert third.findtext("DepthFromLandSurfaceData") == "19.00"
assert third.findtext("MeasuringMethod") == "Pressure Transducer"
assert third.findtext("MeasurementMonth") == "4"
assert third.findtext("MeasurementDay") == "1"
Expand Down
Loading