Skip to content

Commit 7ce9114

Browse files
committed
refactor: rename sample_type to activity_type
1 parent e259f72 commit 7ce9114

9 files changed

Lines changed: 79 additions & 64 deletions

File tree

api/observation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from services.observation_helper import (
4444
get_observations,
4545
observation_model_patcher,
46-
get_observation_of_a_sample_type_by_id,
46+
get_observation_of_an_activity_type_by_id,
4747
)
4848

4949
router = APIRouter(prefix="/observation", tags=["observation"])
@@ -184,7 +184,7 @@ async def get_groundwater_level_observation_by_id(
184184
user: amp_viewer_dependency,
185185
observation_id: int,
186186
) -> GroundwaterLevelObservationResponse:
187-
return get_observation_of_a_sample_type_by_id(
187+
return get_observation_of_an_activity_type_by_id(
188188
session=session,
189189
request=request,
190190
observation_id=observation_id,
@@ -231,7 +231,7 @@ async def get_water_chemistry_observation_by_id(
231231
user: amp_viewer_dependency,
232232
observation_id: int,
233233
) -> WaterChemistryObservationResponse:
234-
return get_observation_of_a_sample_type_by_id(
234+
return get_observation_of_an_activity_type_by_id(
235235
session=session,
236236
request=request,
237237
observation_id=observation_id,
@@ -276,7 +276,7 @@ async def get_geothermal_observation_by_id(
276276
user: amp_viewer_dependency,
277277
observation_id: int,
278278
) -> GeothermalObservationResponse:
279-
return get_observation_of_a_sample_type_by_id(
279+
return get_observation_of_an_activity_type_by_id(
280280
session=session, request=request, observation_id=observation_id
281281
)
282282

core/lexicon.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@
251251
{"categories": [{"name": "relation", "description": null}], "term": "OSEPOD", "definition": "NM OSE 'Point of Diversion' ID"},
252252
{"categories": [{"name": "relation", "description": null}], "term": "PLSS", "definition": "Public Land Survey System ID"},
253253

254-
{"categories": [{"name": "sample_type", "description": null}], "term": "groundwater level", "definition": "groundwater level"},
255-
{"categories": [{"name": "sample_type", "description": null}], "term": "water chemistry", "definition": "water chemistry"},
256-
{"categories": [{"name": "sample_type", "description": null}], "term": "geothermal", "definition": "geothermal"},
254+
{"categories": [{"name": "activity_type", "description": null}], "term": "groundwater level", "definition": "groundwater level"},
255+
{"categories": [{"name": "activity_type", "description": null}], "term": "water chemistry", "definition": "water chemistry"},
256+
{"categories": [{"name": "activity_type", "description": null}], "term": "geothermal", "definition": "geothermal"},
257257

258258
{"categories": [{"name": "sample_matrix", "description": null}], "term": "groundwater", "definition": "groundwater"},
259259

db/sample.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class Sample(Base, AutoBaseMixin, ReleaseMixin):
7979
default=0,
8080
comment="Identifier for duplicate samples (0 = original sample, not a duplicate, 1 = dup no.1, 2 = dup no.2, etc.).",
8181
)
82-
sample_type: Mapped[str] = lexicon_term(
82+
activity_type: Mapped[str] = lexicon_term(
8383
nullable=False,
84-
comment="The type of sample (e.g., 'geochemical', 'geothermal', 'groundwater').",
84+
comment="The type of sampling activity (e.g., 'geochemical', 'geothermal', 'groundwater level', 'water chemistry').",
8585
)
8686

8787
# --- Relationship Definitions ---

schemas/sample.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def convert_sample_date_to_utc(sample_date: AwareDatetime) -> AwareDatetime:
8787
# -------- CREATE ----------
8888
class CreateSample(BaseCreateModel, ValidateSample):
8989
thing_id: int
90-
sample_type: str
90+
activity_type: str
9191
field_sample_id: str
9292
sample_date: Annotated[AwareDatetime, PastDatetime()]
9393
sampler_name: str # REFACTOR TODO: update with enum/restricted values
@@ -118,7 +118,7 @@ class UpdateSample(BaseUpdateModel, ValidateSample):
118118
"""
119119

120120
thing_id: int | None = None # REFACTOR TODO: should users be able to change this?
121-
sample_type: str | None = None
121+
activity_type: str | None = None
122122
field_sample_id: str | None = None
123123
sample_date: Annotated[AwareDatetime, PastDatetime()] | None = None
124124
sampler_name: str | None = None # REFACTOR TODO: update with enum/restricted values
@@ -143,7 +143,7 @@ class UpdateSample(BaseUpdateModel, ValidateSample):
143143
# -------- RESPONSE ----------
144144
class SampleResponse(BaseResponseModel):
145145
thing: ThingResponse
146-
sample_type: str
146+
activity_type: str
147147
field_sample_id: str
148148
sample_date: AwareDatetime
149149
release_status: str

services/observation_helper.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
from services.query_helper import simple_get_by_id, order_sort_filter
2020

2121

22-
def get_sample_type_from_request(request: Request) -> str:
22+
def get_activity_type_from_request(request: Request) -> str:
2323
path = request.url.path
2424
path_components = path.split("/")
2525
if len(path_components) == 2:
2626
# no sample type specified in path
27-
sample_type_in_path = path_components[1]
27+
activity_type_in_path = path_components[1]
2828
if len(path_components) >= 3:
2929
# sample type specified in path
30-
sample_type_in_path = path_components[2]
30+
activity_type_in_path = path_components[2]
3131

32-
sample_type = sample_type_in_path.replace("-", " ")
33-
return sample_type
32+
activity_type = activity_type_in_path.replace("-", " ")
33+
return activity_type
3434

3535

3636
def get_observations(
@@ -54,7 +54,7 @@ def get_observations(
5454
Retrieve all observations
5555
"""
5656
sample_table_is_joined = False
57-
sample_type = get_sample_type_from_request(request)
57+
activity_type = get_activity_type_from_request(request)
5858

5959
sql = select(Observation)
6060
if thing_id is not None:
@@ -72,10 +72,10 @@ def get_observations(
7272
sql = sql.where(Observation.observation_datetime <= end_time)
7373

7474
# root of path is /observation
75-
if sample_type != "observation":
75+
if activity_type != "observation":
7676
if sample_table_is_joined is False:
7777
sql = sql.join(Sample, Sample.id == Observation.sample_id)
78-
sql = sql.where(Sample.sample_type == sample_type)
78+
sql = sql.where(Sample.activity_type == activity_type)
7979

8080
sql = order_sort_filter(sql, Observation, sort, order, filter_)
8181

@@ -85,35 +85,35 @@ def get_observations(
8585
return paginate(query=sql, conn=session)
8686

8787

88-
def verify_observed_property_corresponds_with_sample_type(
88+
def verify_observed_property_corresponds_with_activity_type(
8989
observation: Observation, request: Request
9090
):
91-
requested_sample_type = get_sample_type_from_request(request)
92-
actual_sample_type = observation.sample.sample_type
91+
requested_activity_type = get_activity_type_from_request(request)
92+
actual_activity_type = observation.sample.activity_type
9393

94-
if actual_sample_type != requested_sample_type:
94+
if actual_activity_type != requested_activity_type:
9595
raise PydanticStyleException(
9696
status_code=HTTP_404_NOT_FOUND,
9797
detail=[
9898
{
9999
"loc": ["path", "observation_id"],
100100
"type": "value_error",
101101
"input": {"observation_id": observation.id},
102-
"msg": f"Observation with ID {observation.id} is not a {requested_sample_type} observation. It is a {actual_sample_type} observation.",
102+
"msg": f"Observation with ID {observation.id} is not a {requested_activity_type} observation. It is a {actual_activity_type} observation.",
103103
}
104104
],
105105
)
106106

107107

108-
def get_observation_of_a_sample_type_by_id(
108+
def get_observation_of_an_activity_type_by_id(
109109
session: Session, request: Request, observation_id: int
110110
) -> Observation:
111111
"""
112112
Retrieve an observation by its ID.
113113
"""
114114
observation = simple_get_by_id(session, Observation, observation_id)
115115

116-
verify_observed_property_corresponds_with_sample_type(observation, request)
116+
verify_observed_property_corresponds_with_activity_type(observation, request)
117117

118118
return observation
119119

@@ -131,7 +131,7 @@ def observation_model_patcher(
131131
# simple_get_by_id raises HTTP_404_NOT_FOUND if the item is not found
132132
observation = simple_get_by_id(session, Observation, observation_id)
133133

134-
verify_observed_property_corresponds_with_sample_type(observation, request)
134+
verify_observed_property_corresponds_with_activity_type(observation, request)
135135

136136
for key, value in payload.model_dump(exclude_unset=True).items():
137137
setattr(observation, key, value)

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def groundwater_level_sample(water_well_thing, sensor):
464464
sample = Sample(
465465
sample_date="2025-01-01T00:00:00Z",
466466
thing_id=water_well_thing.id,
467-
sample_type="groundwater level",
467+
activity_type="groundwater level",
468468
sampler_name="Test Sampler",
469469
release_status="draft",
470470
field_sample_id=f"FS-{uuid.uuid4()}",
@@ -487,7 +487,7 @@ def water_chemistry_sample(water_well_thing, sensor):
487487
sample = Sample(
488488
sample_date="2025-01-01T00:00:00Z",
489489
thing_id=water_well_thing.id,
490-
sample_type="water chemistry",
490+
activity_type="water chemistry",
491491
sampler_name="Test Sampler",
492492
release_status="draft",
493493
field_sample_id=f"FS-{uuid.uuid4()}",
@@ -510,7 +510,7 @@ def geothermal_sample(water_well_thing, sensor):
510510
sample = Sample(
511511
sample_date="2025-01-01T00:00:00Z",
512512
thing_id=water_well_thing.id,
513-
sample_type="geothermal",
513+
activity_type="geothermal",
514514
sampler_name="Test Sampler",
515515
release_status="draft",
516516
field_sample_id=f"FS-{uuid.uuid4()}",
@@ -532,7 +532,7 @@ def second_sample(water_well_thing, sensor):
532532
with session_ctx() as session:
533533
sample = Sample(
534534
thing_id=water_well_thing.id,
535-
sample_type="groundwater level",
535+
activity_type="groundwater level",
536536
field_sample_id="FS-9999999",
537537
sample_date="2025-01-01T00:00:00Z",
538538
release_status="draft",

tests/test_observation.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_patch_groundwater_level_observation_404_not_found(
160160
assert data["detail"] == f"Observation with ID {bad_id} not found."
161161

162162

163-
def test_patch_groundwater_level_observation_404_wrong_sample_type(
163+
def test_patch_groundwater_level_observation_404_wrong_activity_type(
164164
water_chemistry_observation, geothermal_observation
165165
):
166166
for obs in water_chemistry_observation, geothermal_observation:
@@ -172,13 +172,13 @@ def test_patch_groundwater_level_observation_404_wrong_sample_type(
172172
data = response.json()
173173

174174
if obs.observed_property == "temperature":
175-
sample_type = "geothermal"
175+
activity_type = "geothermal"
176176
else:
177-
sample_type = "water chemistry"
177+
activity_type = "water chemistry"
178178

179179
assert (
180180
data["detail"][0]["msg"]
181-
== f"Observation with ID {obs.id} is not a groundwater level observation. It is a {sample_type} observation."
181+
== f"Observation with ID {obs.id} is not a groundwater level observation. It is a {activity_type} observation."
182182
)
183183

184184

@@ -206,7 +206,7 @@ def test_patch_water_chemistry_observation_404_not_found(water_chemistry_observa
206206
assert data["detail"] == f"Observation with ID {bad_id} not found."
207207

208208

209-
def test_patch_water_chemistry_observation_404_wrong_sample_type(
209+
def test_patch_water_chemistry_observation_404_wrong_activity_type(
210210
groundwater_level_observation, geothermal_observation
211211
):
212212
for obs in groundwater_level_observation, geothermal_observation:
@@ -216,13 +216,13 @@ def test_patch_water_chemistry_observation_404_wrong_sample_type(
216216
data = response.json()
217217

218218
if obs.observed_property == "temperature":
219-
sample_type = "geothermal"
219+
activity_type = "geothermal"
220220
else:
221-
sample_type = "groundwater level"
221+
activity_type = "groundwater level"
222222

223223
assert (
224224
data["detail"][0]["msg"]
225-
== f"Observation with ID {obs.id} is not a water chemistry observation. It is a {sample_type} observation."
225+
== f"Observation with ID {obs.id} is not a water chemistry observation. It is a {activity_type} observation."
226226
)
227227

228228

@@ -248,7 +248,7 @@ def test_patch_geothermal_observation_404_not_found(geothermal_observation):
248248
assert data["detail"] == f"Observation with ID {bad_id} not found."
249249

250250

251-
def test_patch_geothermal_observation_404_wrong_sample_type(
251+
def test_patch_geothermal_observation_404_wrong_activity_type(
252252
groundwater_level_observation, water_chemistry_observation
253253
):
254254
for obs in groundwater_level_observation, water_chemistry_observation:
@@ -258,13 +258,13 @@ def test_patch_geothermal_observation_404_wrong_sample_type(
258258
data = response.json()
259259

260260
if obs.observed_property == "groundwater level":
261-
sample_type = "groundwater level"
261+
activity_type = "groundwater level"
262262
else:
263-
sample_type = "water chemistry"
263+
activity_type = "water chemistry"
264264

265265
assert (
266266
data["detail"][0]["msg"]
267-
== f"Observation with ID {obs.id} is not a geothermal observation. It is a {sample_type} observation."
267+
== f"Observation with ID {obs.id} is not a geothermal observation. It is a {activity_type} observation."
268268
)
269269

270270

@@ -412,7 +412,7 @@ def test_get_groundwater_level_observation_by_id_404_not_found(
412412
assert data["detail"] == f"Observation with ID {bad_id} not found."
413413

414414

415-
def test_get_groundwater_level_observation_by_id_404_wrong_sample_type(
415+
def test_get_groundwater_level_observation_by_id_404_wrong_activity_type(
416416
water_chemistry_observation, geothermal_observation
417417
):
418418
for obs in water_chemistry_observation, geothermal_observation:
@@ -421,13 +421,13 @@ def test_get_groundwater_level_observation_by_id_404_wrong_sample_type(
421421
data = response.json()
422422

423423
if obs.observed_property == "temperature":
424-
actual_sample_type = "geothermal"
424+
actual_activity_type = "geothermal"
425425
else:
426-
actual_sample_type = "water chemistry"
426+
actual_activity_type = "water chemistry"
427427

428428
assert (
429429
data["detail"][0]["msg"]
430-
== f"Observation with ID {obs.id} is not a groundwater level observation. It is a {actual_sample_type} observation."
430+
== f"Observation with ID {obs.id} is not a groundwater level observation. It is a {actual_activity_type} observation."
431431
)
432432
assert data["detail"][0]["type"] == "value_error"
433433
assert data["detail"][0]["input"] == {"observation_id": obs.id}
@@ -569,7 +569,7 @@ def test_get_water_chemistry_observation_by_id_404_not_found(
569569
assert data["detail"] == f"Observation with ID {bad_id} not found."
570570

571571

572-
def test_get_water_chemistry_observation_by_id_404_wrong_sample_type(
572+
def test_get_water_chemistry_observation_by_id_404_wrong_activity_type(
573573
groundwater_level_observation, geothermal_observation
574574
):
575575
for obs in groundwater_level_observation, geothermal_observation:
@@ -578,13 +578,13 @@ def test_get_water_chemistry_observation_by_id_404_wrong_sample_type(
578578
data = response.json()
579579

580580
if obs.observed_property == "groundwater level":
581-
actual_sample_type = "groundwater level"
581+
actual_activity_type = "groundwater level"
582582
else:
583-
actual_sample_type = "geothermal"
583+
actual_activity_type = "geothermal"
584584

585585
assert (
586586
data["detail"][0]["msg"]
587-
== f"Observation with ID {obs.id} is not a water chemistry observation. It is a {actual_sample_type} observation."
587+
== f"Observation with ID {obs.id} is not a water chemistry observation. It is a {actual_activity_type} observation."
588588
)
589589
assert data["detail"][0]["type"] == "value_error"
590590
assert data["detail"][0]["input"] == {"observation_id": obs.id}
@@ -650,7 +650,7 @@ def test_get_geothermal_observation_by_id_404_not_found(geothermal_observation):
650650
assert data["detail"] == f"Observation with ID {bad_id} not found."
651651

652652

653-
def test_get_geothermal_observation_by_id_404_wrong_sample_type(
653+
def test_get_geothermal_observation_by_id_404_wrong_activity_type(
654654
water_chemistry_observation, groundwater_level_observation
655655
):
656656
for obs in water_chemistry_observation, groundwater_level_observation:
@@ -659,13 +659,13 @@ def test_get_geothermal_observation_by_id_404_wrong_sample_type(
659659
data = response.json()
660660

661661
if obs.observed_property == "groundwater level":
662-
actual_sample_type = "groundwater level"
662+
actual_activity_type = "groundwater level"
663663
else:
664-
actual_sample_type = "water chemistry"
664+
actual_activity_type = "water chemistry"
665665

666666
assert (
667667
data["detail"][0]["msg"]
668-
== f"Observation with ID {obs.id} is not a geothermal observation. It is a {actual_sample_type} observation."
668+
== f"Observation with ID {obs.id} is not a geothermal observation. It is a {actual_activity_type} observation."
669669
)
670670
assert data["detail"][0]["type"] == "value_error"
671671
assert data["detail"][0]["input"] == {"observation_id": obs.id}

0 commit comments

Comments
 (0)