-
Notifications
You must be signed in to change notification settings - Fork 4
BDMS-609: Add support for legacy SiteNotes handling #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ef96f7b
b533da4
a58fc75
e6a8f21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| Contact, | ||
| FieldEventParticipant, | ||
| Parameter, | ||
| Notes, | ||
| ) | ||
| from db.engine import session_ctx | ||
| from transfers.transferer import Transferer | ||
|
|
@@ -158,6 +159,7 @@ def _transfer_hook(self, session: Session) -> None: | |
| "observations_created": 0, | ||
| "contacts_created": 0, | ||
| "contacts_reused": 0, | ||
| "notes_created": 0, | ||
| } | ||
|
|
||
| gwd = self.cleaned_df.groupby(["PointID"]) | ||
|
|
@@ -396,6 +398,38 @@ def _transfer_hook(self, session: Session) -> None: | |
| session.execute(insert(Observation), observation_rows) | ||
| stats["observations_created"] += len(observation_rows) | ||
|
|
||
| # Site Notes (legacy) | ||
| # If there are duplicate notes for a single point ID, we only create one note. | ||
| # However, if some duplicates are "time stamped" (meaning they are attached to | ||
| # rows with different dates), we should ideally preserve that context. | ||
| # The current implementation prepends the date to the note content | ||
| # to ensure that duplicate content from different dates remains distinct. | ||
| unique_notes: dict[str, datetime] = {} | ||
| for prep in prepared_rows: | ||
| if hasattr(prep["row"], "SiteNotes") and prep["row"].SiteNotes: | ||
| content = str(prep["row"].SiteNotes).strip() | ||
| if content: | ||
| dt = prep["dt_utc"] | ||
| # We keep all notes that have different content OR different dates | ||
| # Actually, if content is same but date is different, we want to see it. | ||
| # So we key by (content, date) | ||
| key = (content, dt.date()) | ||
| if key not in unique_notes: | ||
| unique_notes[key] = dt | ||
|
|
||
| for (content, _), dt in unique_notes.items(): | ||
| date_prefix = dt.strftime("%Y-%m-%d") | ||
| session.add( | ||
| Notes( | ||
| target_table="thing", | ||
| target_id=thing_id, | ||
| note_type="Site Notes (legacy)", | ||
| content=f"{date_prefix}: {content}", | ||
| release_status="public", | ||
| ) | ||
| ) | ||
| stats["notes_created"] += 1 | ||
|
Comment on lines
+401
to
+431
|
||
|
|
||
| session.commit() | ||
| session.expunge_all() | ||
| stats["groups_processed"] += 1 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
site_noteswas added to the response schema with an empty-list default, but there are existing API/BDD checks for other note arrays (e.g.,general_notes,sampling_procedure_notes) and none validate thatsite_notesis always present and is[]when empty (per Issue #549 acceptance criteria). Please add/extend an API test to assert the field is included and defaults to an empty list when no notes exist.