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

@@ -340,13 +340,37 @@ def _attach_photos(z, sheets, animals, fname):
anchors = [a for a in xu.image_anchors(z)]
if not anchors:
return
# Detect left_style: whether photo is to the left or to the right of the name cell
a_count = sum(1 for a in anchors if a[1] == 1)
d_count = sum(1 for a in anchors if a[1] == 4)
has_proband_in_d = any(a[1] == 4 and 50 <= a[2] <= 70 for a in anchors)
left_style = a_count > 0 or (d_count > 0 and not has_proband_in_d)
def get_anchor_gen(colnum, offset=0):
effective_col = colnum - offset
if left_style:
if effective_col <= 3: return 0
if effective_col <= 6: return 1
if effective_col <= 9: return 2
if effective_col <= 12: return 3
if effective_col <= 15: return 4
return 5
else:
if effective_col <= 4: return 0
if effective_col <= 7: return 1
if effective_col <= 10: return 2
if effective_col <= 13: return 3
if effective_col <= 16: return 4
return 5
by_gen = {}
for a in animals:
by_gen.setdefault(a["_gen"], []).append(a)
media_dir = os.path.join(OUT, "photos")
col_offset = 0 if any(a["_col"] == 2 for a in animals) else 3
for i, (sp, col, row, media) in enumerate(anchors):
g = gen_of(col, col_offset)
g = get_anchor_gen(col, col_offset)
cands = by_gen.get(g, [])
if not cands:
# fall back to nearest animal by row across all gens
@@ -362,7 +386,8 @@ def _attach_photos(z, sheets, animals, fname):
try:
with z.open(media) as src, open(os.path.join(OUT, rel), "wb") as dst:
shutil.copyfileobj(src, dst)
target["photos"].append(rel)
if rel not in target["photos"]:
target["photos"].append(rel)
except KeyError:
pass