From 0c7390fab69f9a1f982806de044992e58736cf0f Mon Sep 17 00:00:00 2001 From: Jacob Brown Date: Mon, 6 Oct 2025 11:09:58 -0600 Subject: [PATCH] refactor: revert from value_reason to groundwater_level_reason --- core/lexicon.json | 49 +++++++++++++++++++-------------------- db/observation.py | 8 +++---- schemas/observation.py | 6 ++--- tests/conftest.py | 4 +--- tests/test_observation.py | 18 +++++++------- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/core/lexicon.json b/core/lexicon.json index 17f27765e..7ec56e369 100644 --- a/core/lexicon.json +++ b/core/lexicon.json @@ -20,7 +20,7 @@ {"name": "field_contact_role", "description": null}, {"name": "geochronology", "description": null}, {"name": "horizontal_datum", "description": null}, - {"name": "value_reason", "description": null}, + {"name": "groundwater_level_reason", "description": null}, {"name": "measurement_method", "description": null}, {"name": "monitoring_status", "description": null}, {"name": "observed_property", "description": null}, @@ -284,30 +284,29 @@ {"categories": ["thing_type"], "term": "perennial stream", "definition": "that has a continuous flow of water throughout the year, even during drier periods."}, {"categories": ["thing_type"], "term": "ephemeral stream", "definition": "a stream that flows only briefly during and after precipitation events"}, {"categories": ["thing_type"], "term": "meteorological station", "definition": "a station that measures the weather conditions at a particular location"}, - {"categories": ["value_reason"], "term": "Water level affected by atmospheric pressure", "definition": "Water level affected by atmospheric pressure"}, - {"categories": ["value_reason"], "term": "Water level was frozen (no level recorded).", "definition": "Water level was frozen (no level recorded)."}, - {"categories": ["value_reason"], "term": "Site was dry", "definition": "Site was dry"}, - {"categories": ["value_reason"], "term": "Site was flowing recently.", "definition": "Site was flowing recently."}, - {"categories": ["value_reason"], "term": "Site was flowing. Water level or head couldn't be measured w/out additional equipment.", "definition": "Site was flowing. Water level or head couldn't be measured w/out additional equipment."}, - {"categories": ["value_reason"], "term": "Nearby site that taps the same aquifer was flowing.", "definition": "Nearby site that taps the same aquifer was flowing."}, - {"categories": ["value_reason"], "term": "Nearby site that taps the same aquifer had been flowing recently.", "definition": "Nearby site that taps the same aquifer had been flowing recently."}, - {"categories": ["value_reason"], "term": "Recharge water was being injected into the aquifer at this site.", "definition": "Recharge water was being injected into the aquifer at this site."}, - {"categories": ["value_reason"], "term": "Recharge water was being injected into nearby site that taps the same aquifer.", "definition": "Recharge water was being injected into nearby site that taps the same aquifer."}, - {"categories": ["value_reason"], "term": "Water was cascading down the inside of the well.", "definition": "Water was cascading down the inside of the well."}, - {"categories": ["value_reason"], "term": "Water level was affected by brackish or saline water.", "definition": "Water level was affected by brackish or saline water."}, - {"categories": ["value_reason"], "term": "Well was not in hydraulic contact w/formation (from source other than defined in USGS C714 or C93).", "definition": "Well was not in hydraulic contact w/formation (from source other than defined in USGS C714 or C93)."}, - {"categories": ["value_reason"], "term": "Measurement was discontinued (no level recorded).", "definition": "Measurement was discontinued (no level recorded)."}, - {"categories": ["value_reason"], "term": "Obstruction was encountered in the well (no level recorded)", "definition": "Obstruction was encountered in the well (no level recorded)"}, - {"categories": ["value_reason"], "term": "Site was being pumped", "definition": "Site was being pumped"}, - {"categories": ["value_reason"], "term": "Site was pumped recently", "definition": "Site was pumped recently"}, - {"categories": ["value_reason"], "term": "Nearby site that taps the same aquifer was being pumped", "definition": "Nearby site that taps the same aquifer was being pumped"}, - {"categories": ["value_reason"], "term": "Nearby site that taps the same aquifer was pumped recently", "definition": "Nearby site that taps the same aquifer was pumped recently"}, - {"categories": ["value_reason"], "term": "Foreign substance present on the water surface", "definition": "Foreign substance present on the water surface"}, - {"categories": ["value_reason"], "term": "Well was destroyed (no subsequent water levels should be recorded)", "definition": "Well was destroyed (no subsequent water levels should be recorded)"}, - {"categories": ["value_reason"], "term": "Water level affected by stage in nearby surface-water site", "definition": "Water level affected by stage in nearby surface-water site"}, - {"categories": ["value_reason"], "term": "Other conditions exist that would affect the level (remarks)", "definition": "Other conditions exist that would affect the level (remarks)"}, - {"categories": ["value_reason"], "term": "Water level not affected by status", "definition": "Water level not affected by status"}, - {"categories": ["value_reason"], "term": "Observed value not affected", "definition": "Observed value not affected"}, + {"categories": ["groundwater_level_reason"], "term": "Water level affected by atmospheric pressure", "definition": "Water level affected by atmospheric pressure"}, + {"categories": ["groundwater_level_reason"], "term": "Water level was frozen (no level recorded).", "definition": "Water level was frozen (no level recorded)."}, + {"categories": ["groundwater_level_reason"], "term": "Site was dry", "definition": "Site was dry"}, + {"categories": ["groundwater_level_reason"], "term": "Site was flowing recently.", "definition": "Site was flowing recently."}, + {"categories": ["groundwater_level_reason"], "term": "Site was flowing. Water level or head couldn't be measured w/out additional equipment.", "definition": "Site was flowing. Water level or head couldn't be measured w/out additional equipment."}, + {"categories": ["groundwater_level_reason"], "term": "Nearby site that taps the same aquifer was flowing.", "definition": "Nearby site that taps the same aquifer was flowing."}, + {"categories": ["groundwater_level_reason"], "term": "Nearby site that taps the same aquifer had been flowing recently.", "definition": "Nearby site that taps the same aquifer had been flowing recently."}, + {"categories": ["groundwater_level_reason"], "term": "Recharge water was being injected into the aquifer at this site.", "definition": "Recharge water was being injected into the aquifer at this site."}, + {"categories": ["groundwater_level_reason"], "term": "Recharge water was being injected into nearby site that taps the same aquifer.", "definition": "Recharge water was being injected into nearby site that taps the same aquifer."}, + {"categories": ["groundwater_level_reason"], "term": "Water was cascading down the inside of the well.", "definition": "Water was cascading down the inside of the well."}, + {"categories": ["groundwater_level_reason"], "term": "Water level was affected by brackish or saline water.", "definition": "Water level was affected by brackish or saline water."}, + {"categories": ["groundwater_level_reason"], "term": "Well was not in hydraulic contact w/formation (from source other than defined in USGS C714 or C93).", "definition": "Well was not in hydraulic contact w/formation (from source other than defined in USGS C714 or C93)."}, + {"categories": ["groundwater_level_reason"], "term": "Measurement was discontinued (no level recorded).", "definition": "Measurement was discontinued (no level recorded)."}, + {"categories": ["groundwater_level_reason"], "term": "Obstruction was encountered in the well (no level recorded)", "definition": "Obstruction was encountered in the well (no level recorded)"}, + {"categories": ["groundwater_level_reason"], "term": "Site was being pumped", "definition": "Site was being pumped"}, + {"categories": ["groundwater_level_reason"], "term": "Site was pumped recently", "definition": "Site was pumped recently"}, + {"categories": ["groundwater_level_reason"], "term": "Nearby site that taps the same aquifer was being pumped", "definition": "Nearby site that taps the same aquifer was being pumped"}, + {"categories": ["groundwater_level_reason"], "term": "Nearby site that taps the same aquifer was pumped recently", "definition": "Nearby site that taps the same aquifer was pumped recently"}, + {"categories": ["groundwater_level_reason"], "term": "Foreign substance present on the water surface", "definition": "Foreign substance present on the water surface"}, + {"categories": ["groundwater_level_reason"], "term": "Well was destroyed (no subsequent water levels should be recorded)", "definition": "Well was destroyed (no subsequent water levels should be recorded)"}, + {"categories": ["groundwater_level_reason"], "term": "Water level affected by stage in nearby surface-water site", "definition": "Water level affected by stage in nearby surface-water site"}, + {"categories": ["groundwater_level_reason"], "term": "Other conditions exist that would affect the level (remarks)", "definition": "Other conditions exist that would affect the level (remarks)"}, + {"categories": ["groundwater_level_reason"], "term": "Water level not affected", "definition": "Water level not affected"}, {"categories": ["status"], "term": "Abandoned", "definition": "Abandoned"}, {"categories": ["status"], "term": "Active, pumping well", "definition": "Active, pumping well"}, {"categories": ["status"], "term": "Destroyed, exists but not usable", "definition": "Destroyed, exists but not usable"}, diff --git a/db/observation.py b/db/observation.py index 588b77d0a..ded414d28 100644 --- a/db/observation.py +++ b/db/observation.py @@ -59,10 +59,6 @@ class Observation(Base, AutoBaseMixin, ReleaseMixin): nullable=True, ) unit: Mapped[str] = lexicon_term(nullable=False) - value_reason: Mapped[str] = lexicon_term( - nullable=False, - comment="The reason describes everything that can effect the observation the moment a sample/observation is attempted (e.g. obstruction, dry well, equipment failure); a null value must have an associated reason in the same record. Factors preventing the obtainment of the observation from the beginning of the field event to attempted sampling/observation (e.g. flat tire, locked gate, destroyed well) are not recorded here but in the notes field of the FieldEvent table; in this situation no sample/observation should be recorded.", - ) notes: Mapped[str] = mapped_column(nullable=True) # groundwater @@ -71,6 +67,10 @@ class Observation(Base, AutoBaseMixin, ReleaseMixin): doc="Height of the measuring point above the ground surface in ft", info={"unit": "ft"}, ) + groundwater_level_reason: Mapped[str] = lexicon_term( + nullable=True, + comment="The reason describes everything that can effect the observation the moment a sample/observation is attempted (e.g. obstruction, dry well, equipment failure); a null value must have an associated reason in the same record. Factors preventing the obtainment of the observation from the beginning of the field event to attempted sampling/observation (e.g. flat tire, locked gate, destroyed well) are not recorded here but in the notes field of the FieldEvent table; in this situation no sample/observation should be recorded.", + ) # --- Relationships --- # Many-To-One: An Observation can be generated by one piece of Equipment. diff --git a/schemas/observation.py b/schemas/observation.py index 819547095..67fc247c2 100644 --- a/schemas/observation.py +++ b/schemas/observation.py @@ -64,11 +64,11 @@ class CreateBaseObservation(BaseCreateModel, ValidateObservation): release_status: str value: float | None unit: str | None - value_reason: str class CreateGroundwaterLevelObservation(CreateBaseObservation): measuring_point_height: float + groundwater_level_reason: str class CreateWaterChemistryObservation(CreateBaseObservation): @@ -86,11 +86,11 @@ class UpdateBaseObservation(BaseUpdateModel, ValidateObservation): release_status: str | None = None value: float | None | None = None unit: str | None = None - value_reason: str | None = None class UpdateGroundwaterLevelObservation(UpdateBaseObservation): measuring_point_height: float | None = None + groundwater_level_reason: str | None = None class UpdateWaterChemistryObservation(UpdateBaseObservation): @@ -106,12 +106,12 @@ class BaseObservationResponse(BaseResponseModel): release_status: str value: float | None unit: str - value_reason: str class GroundwaterLevelObservationResponse(BaseObservationResponse): depth_to_water_bgs: float | None measuring_point_height: float | None + groundwater_level_reason: str | None # NULL from legacy data @model_validator(mode="before") def calculate_depth_to_water_bgs(self: Self) -> Self: diff --git a/tests/conftest.py b/tests/conftest.py index 062cf5e9f..75dda1557 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -613,7 +613,7 @@ def groundwater_level_observation(sensor, groundwater_level_sample): value=10.0, unit="ft", measuring_point_height=5.0, - value_reason="Water level not affected by status", + groundwater_level_reason="Water level not affected", ) session.add(observation) session.commit() @@ -631,7 +631,6 @@ def water_chemistry_observation(sensor, water_chemistry_sample): release_status="draft", value=4.0, unit="dimensionless", - value_reason="Observed value not affected", ) session.add(observation) session.commit() @@ -649,7 +648,6 @@ def observation_to_delete(water_chemistry_sample, sensor): release_status="draft", value=4.0, unit="dimensionless", - value_reason="Observed value not affected", ) session.add(observation) session.commit() diff --git a/tests/test_observation.py b/tests/test_observation.py index ede2c90ca..12ff56e5c 100644 --- a/tests/test_observation.py +++ b/tests/test_observation.py @@ -55,7 +55,6 @@ def test_add_water_chemistry_observation(water_chemistry_sample, sensor): "sample_id": water_chemistry_sample.id, "sensor_id": sensor.id, "observed_property": "pH", - "value_reason": "Observed value not affected", } response = client.post("/observation/water-chemistry", json=payload) data = response.json() @@ -70,7 +69,6 @@ def test_add_water_chemistry_observation(water_chemistry_sample, sensor): assert data["sample_id"] == payload["sample_id"] assert data["sensor_id"] == payload["sensor_id"] assert data["observed_property"] == payload["observed_property"] - assert data["value_reason"] == payload["value_reason"] cleanup_post_test(Observation, data["id"]) @@ -83,7 +81,7 @@ def test_add_groundwater_level_observation(groundwater_level_sample, sensor): "measuring_point_height": 53, "sample_id": groundwater_level_sample.id, "sensor_id": sensor.id, - "value_reason": "Water level not affected by status", + "groundwater_level_reason": "Water level not affected", "observed_property": "groundwater level", "unit": "ft", } @@ -98,7 +96,7 @@ def test_add_groundwater_level_observation(groundwater_level_sample, sensor): assert data["value"] == payload["value"] assert data["measuring_point_height"] == payload["measuring_point_height"] assert data["sensor_id"] == payload["sensor_id"] - assert data["value_reason"] == payload["value_reason"] + assert data["groundwater_level_reason"] == payload["groundwater_level_reason"] assert data["observed_property"] == payload["observed_property"] assert ( data["depth_to_water_bgs"] @@ -275,7 +273,8 @@ def test_get_groundwater_level_observations(groundwater_level_observation): == groundwater_level_observation.release_status ) assert ( - data["items"][0]["value_reason"] == groundwater_level_observation.value_reason + data["items"][0]["groundwater_level_reason"] + == groundwater_level_observation.groundwater_level_reason ) assert data["items"][0]["value"] == groundwater_level_observation.value assert data["items"][0]["unit"] == groundwater_level_observation.unit @@ -288,9 +287,6 @@ def test_get_groundwater_level_observations(groundwater_level_observation): data["items"][0]["measuring_point_height"] == groundwater_level_observation.measuring_point_height ) - assert ( - data["items"][0]["value_reason"] == groundwater_level_observation.value_reason - ) def test_get_groundwater_level_observation_by_id(groundwater_level_observation): @@ -315,7 +311,10 @@ def test_get_groundwater_level_observation_by_id(groundwater_level_observation): == groundwater_level_observation.observed_property[colon_index + 1 :] ) assert data["release_status"] == groundwater_level_observation.release_status - assert data["value_reason"] == groundwater_level_observation.value_reason + assert ( + data["groundwater_level_reason"] + == groundwater_level_observation.groundwater_level_reason + ) assert data["value"] == groundwater_level_observation.value assert data["unit"] == groundwater_level_observation.unit assert ( @@ -327,7 +326,6 @@ def test_get_groundwater_level_observation_by_id(groundwater_level_observation): data["measuring_point_height"] == groundwater_level_observation.measuring_point_height ) - assert data["value_reason"] == groundwater_level_observation.value_reason def test_get_groundwater_level_observation_by_id_404_not_found(