fix: Naho Eltern + Foto-Layout-Erkennung + Eltern-Fallback-Lookup
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user