Importer consumes conflict-decisions.json to un-quarantine (HUMANQUESTION D)
god maintains tools/import/conflict-decisions.json as Julian/his wife answer the D-conflicts. extract.py now consumes it (apply_conflict_decisions): for an animal matching normalize(name)+dob, it clears the conflict, marks resolvedByDecision, and — when the decision carries a `genotype` (breeder notation, parsed via genotype.py) and/or `farbschlag` — treats those as AUTHORITATIVE. Tolerates a missing/empty/garbled file. Genuinely-unresolved conflicts stay quarantined. Loader (ImportService): SourceAnimal.ResolvedByDecision flows through; the report surfaces Animals.ConflictsResolvedByDecision + a German note. Result on real data: the 2 current decisions (Firefly D-/PP, WildFire PP) un-quarantine → Konflikte 21 → 19. As god appends entries the count grows; nothing else needed from me. Tests: python test_extract (decision clears conflict + genotype authoritative + removes from conflicts list + tolerates missing file) and a C# loader test (a resolved animal loads and is counted). Folded into the EXTRACT-BANDS branch so the next re-extract applies band-aware Farbschlag + these decisions in one pass. No schema change (JSON DTO fields). python + dotnet 121/121 green; has-pending clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -834,6 +834,41 @@ def write_report(merged, conflicts, orphans, raw_count, litters, photo_count,
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------ main
|
||||
def apply_conflict_decisions(merged, conflicts, path):
|
||||
"""Consume human conflict resolutions (tools/import/conflict-decisions.json) so the wife's
|
||||
answers UN-QUARANTINE animals. Schema: {"resolutions":[{name, dob, decision, genotype?,
|
||||
farbschlag?, source}]}. Match = norm_name(name)+norm_dob(dob) (same identity as dedup). A
|
||||
matching animal: clear its conflict, mark resolvedByDecision; an explicit `genotype`
|
||||
(breeder notation) is parsed and becomes authoritative, `farbschlag` overrides too. Tolerates
|
||||
a missing/empty/garbled file. Returns the number of conflicts resolved. (god/HUMANQUESTION D.)"""
|
||||
decisions = {}
|
||||
try:
|
||||
with open(path, encoding="utf-8") as fh:
|
||||
for r in (json.load(fh).get("resolutions") or []):
|
||||
decisions[(norm_name(r.get("name", "")), norm_dob(r.get("dob", "")))] = r
|
||||
except (OSError, ValueError):
|
||||
return 0
|
||||
if not decisions:
|
||||
return 0
|
||||
|
||||
resolved = 0
|
||||
for a in merged:
|
||||
d = decisions.get((norm_name(a["name"]), norm_dob(a["dob"])))
|
||||
if not d:
|
||||
continue
|
||||
a["resolvedByDecision"] = True
|
||||
if d.get("genotype"):
|
||||
a["genotype"] = gt.parse(d["genotype"])
|
||||
if d.get("farbschlag"):
|
||||
a["farbschlag"] = d["farbschlag"]
|
||||
a["farbschlagVariants"] = [d["farbschlag"]]
|
||||
if a.get("conflict"):
|
||||
a["conflict"] = False
|
||||
conflicts[:] = [c for c in conflicts if c.get("id") != a["id"]]
|
||||
resolved += 1
|
||||
return resolved
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||||
@@ -868,6 +903,8 @@ def main():
|
||||
print(f"Wurfchronik: {len(litters)} Würfe")
|
||||
|
||||
merged, conflicts, orphans, zucht_splits = dedup(raw_animals)
|
||||
decisions_path = os.path.join(HERE, "conflict-decisions.json")
|
||||
resolved_by_decision = apply_conflict_decisions(merged, conflicts, decisions_path)
|
||||
match_stats = match_litters(merged, litters)
|
||||
photo_count = sum(len(a["photos"]) for a in merged)
|
||||
|
||||
@@ -884,7 +921,8 @@ def main():
|
||||
zucht_splits, match_stats)
|
||||
|
||||
print(f"\nRoh: {len(raw_animals)} → eindeutig: {len(merged)} "
|
||||
f"| Konflikte: {len(conflicts)} | Zucht-Splits: {len(zucht_splits)} "
|
||||
f"| Konflikte: {len(conflicts)} | per Entscheidung gelöst: {resolved_by_decision} "
|
||||
f"| Zucht-Splits: {len(zucht_splits)} "
|
||||
f"| Orphans: {len(orphans)} | Fotos: {photo_count}")
|
||||
print(f"Wurf-Verknüpfung: {match_stats['parents']} (Datum+Eltern), "
|
||||
f"{match_stats['dateOnly']} (nur Datum), {match_stats['ambiguous']} mehrdeutig "
|
||||
|
||||
Reference in New Issue
Block a user