fix: Naho Eltern + Foto-Layout-Erkennung + Eltern-Fallback-Lookup
Some checks failed
CI / Backend Tests (.NET) (push) Successful in 1m2s
CI / Frontend Tests (Node/Vite) (push) Successful in 9m34s
CI / Docker Build & Push (push) Failing after 9s

This commit is contained in:
2026-06-21 22:55:50 +02:00
parent 41ff973f9a
commit cb2ee03a14
4 changed files with 81 additions and 4 deletions

View File

@@ -111,10 +111,15 @@ def main():
# Index animals for fast lookup by slug ID and by normalized name+dob
animal_by_id = {a["id"]: a for a in animals}
animal_by_name_dob = {}
animal_by_name = {}
for a in animals:
key = (ex.norm_name(a["name"]), ex.norm_dob(a["dob"]))
if key[0] and key[1]:
animal_by_name_dob.setdefault(key, []).append(a)
nk = ex.norm_name(a["name"])
if nk:
animal_by_name.setdefault(nk, []).append(a)
# 2. Extract and resolve unique Contacts (Breeders & Zuchten)
print("Extracting unique contacts...")
@@ -163,8 +168,36 @@ def main():
l_parents = litter_parent_map.setdefault(l_id, [None, None]) # [father, mother]
for p_ref in a.get("parentRefs", []):
p_key = (ex.norm_name(p_ref["name"]), ex.norm_dob(p_ref["dob"]))
p_dob = ex.norm_dob(p_ref.get("dob", ""))
p_key = (ex.norm_name(p_ref["name"]), p_dob)
p_candidates = animal_by_name_dob.get(p_key, [])
if not p_candidates:
# Fallback to name-only lookup when parent DOB is empty/not found
p_norm = ex.norm_name(p_ref["name"])
candidates = animal_by_name.get(p_norm, [])
if candidates:
offspring_dob_str = parse_date_only(a["dob"])
if offspring_dob_str:
try:
o_dob = datetime.strptime(offspring_dob_str, "%Y-%m-%d")
valid_candidates = []
for cand in candidates:
cand_dob_str = parse_date_only(cand["dob"])
if cand_dob_str:
try:
c_dob = datetime.strptime(cand_dob_str, "%Y-%m-%d")
if c_dob < o_dob:
valid_candidates.append(cand)
except ValueError:
valid_candidates.append(cand)
else:
valid_candidates.append(cand)
if valid_candidates:
p_candidates = [valid_candidates[0]]
except ValueError:
p_candidates = [candidates[0]]
else:
p_candidates = [candidates[0]]
if p_candidates:
p_guid = animal_guid_map[p_candidates[0]["id"]]
if p_ref["roleGuess"] == "father":