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
49 changes: 24 additions & 25 deletions core/lexicon.json
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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"},
Expand Down
8 changes: 4 additions & 4 deletions db/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions schemas/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
18 changes: 8 additions & 10 deletions tests/test_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"])

Expand All @@ -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",
}
Expand All @@ -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"]
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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 (
Expand All @@ -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(
Expand Down
Loading