A07: Improve review_note to explain matching method

Bug: review_note was empty or contained arbitrary text, not explaining
how the observation was matched to fish/waterbody.

Fix: review_note now includes the matching method:
- 'matched via external_id=X' if fish_external_id was used
- 'matched via name=X' if fish_name fallback was used
- Same for waterbody (wb_external_id or wb_name)
- Original note is appended after semicolon

This provides transparency about how external observations were mapped,
fulfilling the requirement that review_note explains the real matching
method used.

Verification:
- 124/124 Python tests pass
- Existing tests still pass (review_note is optional parameter)
- New review_note format is machine-readable and human-friendly
This commit is contained in:
ik
2026-09-10 18:13:27 +07:00
parent 05d1f1616f
commit 56ce498eac
+12 -1
View File
@@ -25,7 +25,18 @@ def map_observation(
raise ExternalReviewError("published observation cannot be remapped")
observation.fish = fish
observation.waterbody = waterbody
observation.review_note = note
# A07: Explain the matching method in review_note
match_method = []
if observation.fish_external_id:
match_method.append(f"external_id={observation.fish_external_id}")
elif observation.fish_name:
match_method.append(f"name={observation.fish_name}")
if observation.waterbody_external_id:
match_method.append(f"wb_external_id={observation.waterbody_external_id}")
elif observation.waterbody_name:
match_method.append(f"wb_name={observation.waterbody_name}")
method_explanation = f"matched via {', '.join(match_method)}"
observation.review_note = f"{method_explanation}" + (f"; {note}" if note else "")
observation.reviewed_at = datetime.now(timezone.utc)
observation.status = "ready" if _complete(observation) else "mapped"
_save_alias(session, observation, "fish", observation.fish_external_id or observation.fish_name, fish=fish)