Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9432f88
Unify read csv approaches
kbighorse Nov 27, 2025
5db6964
Formatting changes
kbighorse Nov 27, 2025
fe6f50c
Un-ignore features; add features for location and well dates
kbighorse Nov 27, 2025
738c1ef
Remove features we won't keep
kbighorse Nov 27, 2025
9532632
Formatting changes
kbighorse Nov 27, 2025
ac04b26
Add features that describe post-migration behaviors
kbighorse Nov 27, 2025
952c5db
Rename `inventoried_on` to `legacy_start_date` since it won't continu…
kbighorse Nov 27, 2025
dbfc8ef
Add new fields to unit tests
kbighorse Nov 27, 2025
5d51954
Create test_transfer_legacy_dates.py
kbighorse Nov 27, 2025
8beca4e
Merge branch 'timestamp_proposal' of https://github.com/DataIntegrati…
kbighorse Nov 27, 2025
687fb4a
Support changes in unit tests for thing and transfer script
kbighorse Nov 27, 2025
6552bc0
Implement changes in db and schemas
kbighorse Nov 27, 2025
08fb221
Implement changes in transfer scripts
kbighorse Nov 27, 2025
47aad3f
Address measuring point bug
kbighorse Nov 27, 2025
546b701
Formatting changes
kbighorse Nov 27, 2025
7339290
Merge branch 'staging' into timestamp_proposal
kbighorse Dec 2, 2025
306dabc
Formatting changes
kbighorse Dec 3, 2025
d8167a7
Resolve test failures
kbighorse Dec 3, 2025
de1e5cb
Update column name in BDD tests
kbighorse Dec 3, 2025
0397891
Merge branch 'timestamp_proposal' of https://github.com/DataIntegrati…
kbighorse Dec 3, 2025
a9293bb
Formatting changes
kbighorse Dec 3, 2025
dc7a31b
Remove `well_completed_on`
kbighorse Dec 3, 2025
f011226
Formatting changes
kbighorse Dec 3, 2025
f021c4b
Replace `legacy_` prefix with `nma_`
kbighorse Dec 3, 2025
2e33f83
Remove legacy fields from `UpdateLocation` schema
kbighorse Dec 3, 2025
aef077b
Formatting changes
kbighorse Dec 3, 2025
960e6e2
Merge branch 'timestamp_proposal' of https://github.com/DataIntegrati…
kbighorse Dec 3, 2025
6258e7d
DRY up the mock lexicon mapper into a fixture
kbighorse Dec 3, 2025
d3c5401
Merge branch 'timestamp_proposal' of https://github.com/DataIntegrati…
kbighorse Dec 3, 2025
fd4562a
Replace legacy python timestamp call with current implementation
kbighorse Dec 3, 2025
5b1a07d
Preserve timezone in comparison
kbighorse Dec 3, 2025
b92a986
Make features more human-readable
kbighorse Dec 3, 2025
94addc7
Formatting changes
kbighorse Dec 3, 2025
0b4d77d
Simulate CSV rows more effiiently
kbighorse Dec 3, 2025
2d12844
Replace `legacy_` in method names
kbighorse Dec 3, 2025
d9fe6f0
Merge branch 'timestamp_proposal' of https://github.com/DataIntegrati…
kbighorse Dec 3, 2025
8c96e72
Increase code test coverage
kbighorse Dec 3, 2025
48f503d
Enforce timezone info on `created_at`
kbighorse Dec 3, 2025
43a8c5f
Ignore test coverage artifacts
kbighorse Dec 3, 2025
0272990
Delete .coverage
kbighorse Dec 3, 2025
f0e730c
Remove noisy EOF
kbighorse Dec 3, 2025
070fcba
Simplify error message
kbighorse Dec 3, 2025
f3e9587
Remove unnecessary conditionals
kbighorse Dec 3, 2025
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
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ dist/
wheels/
*.egg-info

# Test coverage reports
*.cover
.coverage
.coverage.*
htmlcov/
coverage.xml

# Virtual environments
.venv
requirements.txt
Expand All @@ -25,11 +32,11 @@ launcher.sh
gcs_credentials.json
transfers/data/assets*
transfers/data/nma_csv_cache/*
transfers/data/*.csv
transfers/transfer*.log
transfer*.log
transfers/data/nma_csv_cache/*
!transfers/data/nma_csv_cache/.gitkeep
tests/features/*.feature
transfers/metrics/*
transfers/logs/*
run_bdd-local.sh
Expand Down
13 changes: 13 additions & 0 deletions db/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
String,
ForeignKey,
DateTime,
Date,
func,
Text,
)
Expand Down Expand Up @@ -61,6 +62,18 @@ class Location(Base, AutoBaseMixin, ReleaseMixin, NotesMixin, DataProvenanceMixi
nma_notes_location: Mapped[str] = mapped_column(Text, nullable=True)
nma_coordinate_notes: Mapped[str] = mapped_column(Text, nullable=True)

# --- AMPAPI Date Fields (Migration-Only, Read-Only Post-Migration) ---
nma_date_created: Mapped[datetime.date] = mapped_column(
Date,
nullable=True,
comment="Original AMPAPI DateCreated (read-only, populated only during migration)",
)
nma_site_date: Mapped[datetime.date] = mapped_column(
Date,
nullable=True,
comment="Original AMPAPI SiteDate (read-only, populated only during migration)",
)

# --- Relationship Definitions ---
thing_associations: Mapped[list["LocationThingAssociation"]] = relationship(
back_populates="location", cascade="all, delete-orphan"
Expand Down
11 changes: 11 additions & 0 deletions schemas/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
from datetime import date
from typing import List

from geoalchemy2 import WKBElement
Expand Down Expand Up @@ -106,6 +107,9 @@ class GeoJSONProperties(BaseModel):
default_factory=GeoJSONUTMCoordinates
)
notes: list[NoteResponse] = []
# AMPAPI date fields (read-only, populated only during migration)
nma_date_created: date | None = None
nma_site_date: date | None = None

model_config = ConfigDict(
from_attributes=True,
Expand Down Expand Up @@ -150,6 +154,9 @@ def populate_fields(cls, data: Any) -> Any:
data_dict["properties"]["notes"] = data_dict.get("notes")
data_dict["properties"]["elevation"] = convert_m_to_ft(elevation_m)
data_dict["properties"]["elevation_method"] = data_dict.get("elevation_method")
# populate AMPAPI date fields
data_dict["properties"]["nma_date_created"] = data_dict.get("nma_date_created")
data_dict["properties"]["nma_site_date"] = data_dict.get("nma_site_date")

# populate UTM coordinates
point_utm_zone_13n_wkt = transform_srid(
Expand Down Expand Up @@ -181,6 +188,10 @@ class LocationResponse(BaseResponseModel):
county: str | None
quad_name: str | None

# AMPAPI date fields (read-only, populated only during migration, not in Create/Update schemas)
nma_date_created: date | None = None
nma_site_date: date | None = None

@field_validator("point", mode="before")
def point_to_wkt(cls, value):
if isinstance(value, WKBElement):
Expand Down
1 change: 1 addition & 0 deletions schemas/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
from datetime import date
from typing import List

from pydantic import BaseModel, model_validator, Field, field_validator
Expand Down
94 changes: 94 additions & 0 deletions tests/features/post-migration-legacy-data-retrieval.feature

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this file go into the repo OcotilloBDD rather than here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Move most features in OcotilloBDD into this repo going forward.

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Feature: Post-Migration AMPAPI Date Field Retrieval
As a data manager
After migrating data from AMPAPI to NMSampleLocations
I want to verify that all AMPAPI temporal information is preserved and queryable
So that no historical context is lost

Background:
Given a functioning api
And the AMPAPI data has been migrated to the database

# Location AMPAPI Date Lookups (Read-Only Fields)

Scenario: Retrieve location with both AMPAPI date fields via API
Given a location exists with:
| field | value |
| nma_date_created | 2014-04-03 |
| nma_site_date | 2002-12-10 |
When I retrieve that location via the API
Then the response should include nma_date_created as "2014-04-03"
And the response should include nma_site_date as "2002-12-10"
And the time gap should be approximately 11.3 years

Scenario: Retrieve location with large time gap (54 years)
Given a location exists with:
| field | value |
| nma_date_created | 2008-05-28 |
| nma_site_date | 1954-05-01 |
When I retrieve that location via the API
Then the response should include nma_date_created as "2008-05-28"
And the response should include nma_site_date as "1954-05-01"
And the time gap should be approximately 54 years

Scenario: List all locations includes AMPAPI date fields
Comment thread
kbighorse marked this conversation as resolved.
Given 5 locations exist with various AMPAPI dates
Comment thread
kbighorse marked this conversation as resolved.
Comment thread
kbighorse marked this conversation as resolved.
When I GET /location to list all locations
Then each location should have a date created field
And each location should have a site date field
And some locations should have null site date

Scenario: Filter locations by AMPAPI site date range
Given locations exist with nma_site_date ranging from 1950 to 2024
When I filter locations where nma_site_date is between "2000-01-01" and "2010-12-31"
Then the response should only include locations with site date in that decade
And locations with site date before 2000 should not be included
And locations with site date after 2010 should not be included

Scenario: Query location by nma_date_created
Given 3 locations exist with nma_date_created "2014-04-03"
And 2 locations exist with nma_date_created "2017-12-06"
When I query for locations with nma_date_created "2014-04-03"
Then the response should include exactly 3 locations
And all should have nma_date_created "2014-04-03"

# Data Quality Validation

Scenario: Verify migration preserved expected percentage of AMPAPI dates
Given 100 locations were migrated
And 9 of them had non-null SiteDate in AMPAPI
When I query the migrated locations
Then 9% should have non-null nma_site_date
And 100% should have non-null nma_date_created

# Audit Trail Verification

Scenario: AMPAPI dates preserved alongside audit timestamps
Given a location was migrated with AMPAPI dates
When I retrieve that location
Then it should have created_at (new system timestamp from migration)
And it should have nma_date_created (original AMPAPI DateCreated)
And it should have nma_site_date (original AMPAPI SiteDate)
And all three timestamps should be independently queryable
And created_at should be a recent timestamp
And nma_date_created should be an older date

# Edge Cases

Scenario: Location where SiteDate is later than DateCreated (data anomaly)
Given a location exists with:
| field | value |
| nma_date_created | 2010-01-15 |
| nma_site_date | 2015-06-20 |
When I retrieve that location
Then nma_date_created should be "2010-01-15"
And nma_site_date should be "2015-06-20"
And the system should accept this without error

Scenario: Location with only nma_date_created (no nma_site_date)
Given a location exists with:
| field | value |
| nma_date_created | 2014-10-17 |
| nma_site_date | null |
When I retrieve that location
Then nma_date_created should be "2014-10-17"
And nma_site_date should be null
Loading
Loading