IMPORT-POLISH v2: 3 Korrekturen nach god-Review
FIX-1 ZUCHT: apply_conflict_decisions/apply_dob_remaps matchen jetzt auf das VOLLE canon_pair-Tupel (nameCanon, zuchtCanon, dob) wenn die Decision eine Zucht traegt; Fallback name-only wenn keine Zucht. C3-Regel gewahrt: gleicher Name+DOB, andere Zucht -> kein Hit. Neuer Regression-Test: Luna ZdkC-Decision trifft nur luna-kc, nicht luna-bf (andere Zucht). FIX-2 MERGE: dedup() waehlt das spezifischste Genotyp (fewest '?' alleles) als sekundaeren Tiebreaker nach locus-count. CC schlaegt C-, Gg schlaegt G- unabhaengig von der Reihenfolge. 3 neue Merge-Tests (C- first/CC first/G-vsGg). FIX-3 BACKFILL allDbNormToGid: ResolveParentForBackfill prueft jetzt BEIDE Quellen: (a) createdAnimalByName (aktiver Lauf) und (b) allDbNormToGid (alle DB-Tiere). Decktt den kritischen Fall: Elterntier in fruehrem Lauf geladen, in diesem Lauf absent vom Extract. Neuer 3-Lauf-SQLite-Test: Lauf 1 null-Vater, Lauf 2 laedt Vater, Lauf 3 backfillt via allDbNormToGid. Gate: 125/125 C#-Tests, Python ALL PASS, has-pending-model-changes=No. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -135,6 +135,30 @@ check("FIX-1: v.d. decision also matches 'von den' record (both spellings match)
|
||||
try: os.remove(dec_vd)
|
||||
except OSError: pass
|
||||
|
||||
# FIX-1 C3-rule: same name+DOB, two Zuchten -> decision hits ONLY the correct Zucht (C3 isolation)
|
||||
dec_c3 = os.path.join(tempfile.gettempdir(), "decisions-c3.json")
|
||||
_json.dump({"resolutions": [
|
||||
# Decision only for Luna from ZdkC, NOT Luna from Black Forest
|
||||
{"name": "Luna von den Kleinen Chaoten", "dob": "01.01.2020",
|
||||
"decision": "D-locus = DD", "genotype": "aa CC DD ee gg PP spsp rere", "source": "test"},
|
||||
]}, open(dec_c3, "w", encoding="utf-8"))
|
||||
merged_c3 = [
|
||||
{"id": "luna-kc", "name": "Luna von den Kleinen Chaoten", "dob": "01.01.2020",
|
||||
"conflict": True, "farbschlag": "", "death": "",
|
||||
"genotype": {"mapped8locus": {"D": ["D","?"]}, "rawGenotype": "D-", "unmappedTokens": []}},
|
||||
{"id": "luna-bf", "name": "Luna of Black Forest", "dob": "01.01.2020",
|
||||
"conflict": True, "farbschlag": "", "death": "",
|
||||
"genotype": {"mapped8locus": {"D": ["D","?"]}, "rawGenotype": "D-", "unmappedTokens": []}},
|
||||
]
|
||||
conflicts_c3 = [{"id": "luna-kc"}, {"id": "luna-bf"}]
|
||||
n_c3 = e.apply_conflict_decisions(merged_c3, conflicts_c3, dec_c3)
|
||||
check("FIX-1 C3: decision hits only the correct Zucht (luna-kc resolved)", n_c3 == 1)
|
||||
check("FIX-1 C3: luna-kc conflict cleared (correct Zucht)", merged_c3[0]["conflict"] is False)
|
||||
check("FIX-1 C3: luna-bf conflict NOT cleared (different Zucht)", merged_c3[1]["conflict"] is True)
|
||||
check("FIX-1 C3: conflicts list has only luna-bf left", len(conflicts_c3) == 1 and conflicts_c3[0]["id"] == "luna-bf")
|
||||
try: os.remove(dec_c3)
|
||||
except OSError: pass
|
||||
|
||||
# --- correctDob: a wrong-birthdate duplicate is remapped BEFORE dedup so it merges ---
|
||||
dec2 = os.path.join(tempfile.gettempdir(), "decisions-dob.json")
|
||||
_json.dump({"resolutions": [
|
||||
@@ -192,6 +216,49 @@ check("c[h] vs c[chm] (different modifiers, both specified) -> conflict",
|
||||
check("identical genotypes -> no conflict",
|
||||
not e._genotype_conflict([{"A": ["A", "a"]}, {"A": ["A", "a"]}]))
|
||||
|
||||
# FIX-2 MERGE: specific allele must survive the merge regardless of which variant comes first.
|
||||
# dedup() picks the most specific genotype (fewest '?' alleles); C- vs CC -> CC must win.
|
||||
def _minimal_animal(name, dob, mapped):
|
||||
"""Build a minimal raw animal dict suitable for dedup()."""
|
||||
from genotype import parse as gparse
|
||||
raw = " ".join(f"{l}{''.join(a)}" for l, pa in mapped.items() for a in [pa])
|
||||
return {
|
||||
"name": name, "dob": dob, "death": "", "gender": None,
|
||||
"farbschlag": "", "breeder": "", "zucht": "", "parentRefs": [],
|
||||
"photos": [], "sourceFiles": ["test.xlsx"], "tags": [],
|
||||
"deaf": None, "conflict": False,
|
||||
"genotype": {"mapped8locus": mapped, "rawGenotype": raw, "unmappedTokens": []},
|
||||
"_gen": 0, "_col": 5, "_row": 10, "_file": "test.xlsx",
|
||||
"_zucht": "",
|
||||
}
|
||||
|
||||
# Order A: C- first, CC second
|
||||
animals_merge_a = [
|
||||
_minimal_animal("TestTier", "01.01.2020", {"C": ["C", "?"]}), # C-
|
||||
_minimal_animal("TestTier", "01.01.2020", {"C": ["C", "C"]}), # CC
|
||||
]
|
||||
merged_ma, _, _, _ = e.dedup(animals_merge_a)
|
||||
check("FIX-2 merge A (C- first): result has CC not C-",
|
||||
merged_ma[0]["genotype"]["mapped8locus"].get("C") == ["C", "C"])
|
||||
|
||||
# Order B: CC first, C- second (must give same result)
|
||||
animals_merge_b = [
|
||||
_minimal_animal("TestTier2", "02.02.2020", {"C": ["C", "C"]}), # CC
|
||||
_minimal_animal("TestTier2", "02.02.2020", {"C": ["C", "?"]}), # C-
|
||||
]
|
||||
merged_mb, _, _, _ = e.dedup(animals_merge_b)
|
||||
check("FIX-2 merge B (CC first): result has CC not C-",
|
||||
merged_mb[0]["genotype"]["mapped8locus"].get("C") == ["C", "C"])
|
||||
|
||||
# G- vs Gg: Gg must win
|
||||
animals_merge_g = [
|
||||
_minimal_animal("TestGGerbil", "03.03.2020", {"G": ["G", "?"]}), # G-
|
||||
_minimal_animal("TestGGerbil", "03.03.2020", {"G": ["G", "g"]}), # Gg
|
||||
]
|
||||
merged_mg, _, _, _ = e.dedup(animals_merge_g)
|
||||
check("FIX-2 merge G (G- vs Gg): Gg wins",
|
||||
merged_mg[0]["genotype"]["mapped8locus"].get("G") == ["G", "g"])
|
||||
|
||||
# --- FIX-4: Skarlett parse artifact — trailing "/ +YEAR" stripped from geno, death captured ---
|
||||
dob4, death4, geno4 = e.parse_detail("Skarlett,*17.04.2016, aa C- DD ee Gg PP spsp rere / +2018")
|
||||
check("FIX-4: '/ +YEAR' artifact stripped from geno tail",
|
||||
|
||||
Reference in New Issue
Block a user