import collections import csv import json import sys log_path, gt_path = sys.argv[1], sys.argv[2] pred, times = {}, [] with open(log_path, encoding="utf-8") as f: for r in csv.DictReader(f): pred[r["photo"]] = {k.lower().strip(): int(v) for k, v in json.loads(r["counts"]).items()} times.append(float(r["analysis_s"])) truth = collections.defaultdict(dict) with open(gt_path, encoding="utf-8-sig") as f: for r in csv.DictReader(f): truth[r["photo"]][r["product"].lower().strip()] = int(r["facings_reels"]) pairs = exact = 0 abs_err = tp = pred_total = true_total = 0 per_product = collections.defaultdict(lambda: [0, 0, 0]) # vrais, prédits, erreur absolue missing = [] for photo, t in truth.items(): if photo not in pred: missing.append(photo) continue p = pred[photo] for prod in set(t) | set(p): tv, pv = t.get(prod, 0), p.get(prod, 0) pairs += 1 exact += tv == pv abs_err += abs(tv - pv) tp += min(tv, pv) pred_total += pv true_total += tv per_product[prod][0] += tv per_product[prod][1] += pv per_product[prod][2] += abs(tv - pv) print(f"Photos non analysées : {missing}" if missing else "Toutes les photos de la vérité terrain ont été analysées.") print(f"\nCouples (photo, produit) évalués : {pairs}") print(f"Comptage exact : {exact / pairs:.1%}") print(f"Erreur absolue moyenne : {abs_err / pairs:.2f} facing(s)") print(f"Précision des facings : {tp / max(pred_total, 1):.1%}") print(f"Rappel des facings : {tp / max(true_total, 1):.1%}") print(f"Temps d'analyse moyen : {sum(times) / len(times):.2f} s par photo") print("\nPar produit (vrais / prédits / erreur absolue) :") for prod, (tv, pv, e) in sorted(per_product.items(), key=lambda x: -x[1][2]): print(f" {prod:30s} {tv:4d} {pv:4d} {e:4d}")