(job_id, result_payload: dict, images_a_payload: list, images_b_payload: list, threshold_value: float, mode_value: str)
| 19412 | return str(v).encode("latin-1", "ignore").decode("latin-1") |
| 19413 | |
| 19414 | def _build_face_report(job_id, result_payload: dict, images_a_payload: list, images_b_payload: list, threshold_value: float, mode_value: str): |
| 19415 | try: |
| 19416 | face_dir = Path(tempfile.gettempdir()) / "intelosint_face" |
| 19417 | face_dir.mkdir(parents=True, exist_ok=True) |
| 19418 | report_dir = face_dir / job_id |
| 19419 | report_dir.mkdir(parents=True, exist_ok=True) |
| 19420 | saved_inputs = [] |
| 19421 | for idx, raw in enumerate(images_a_payload or [], start=1): |
| 19422 | p = report_dir / f"input_A_{idx:02d}.jpg" |
| 19423 | if _dataurl_to_temp_file(str(raw), p): |
| 19424 | h = _compute_face_hashes(p) |
| 19425 | saved_inputs.append({ |
| 19426 | "side": "A", |
| 19427 | "index": idx, |
| 19428 | "path": p, |
| 19429 | "name": p.name, |
| 19430 | "hashes": h, |
| 19431 | "size": p.stat().st_size if p.exists() else 0 |
| 19432 | }) |
| 19433 | for idx, raw in enumerate(images_b_payload or [], start=1): |
| 19434 | p = report_dir / f"input_B_{idx:02d}.jpg" |
| 19435 | if _dataurl_to_temp_file(str(raw), p): |
| 19436 | h = _compute_face_hashes(p) |
| 19437 | saved_inputs.append({ |
| 19438 | "side": "B", |
| 19439 | "index": idx, |
| 19440 | "path": p, |
| 19441 | "name": p.name, |
| 19442 | "hashes": h, |
| 19443 | "size": p.stat().st_size if p.exists() else 0 |
| 19444 | }) |
| 19445 | |
| 19446 | report_path = face_dir / f"{job_id}_face_report.pdf" |
| 19447 | summary = result_payload.get("summary") or {} |
| 19448 | provider = str(summary.get("provider", "arcface")).strip().lower() |
| 19449 | if provider in {"uk", "uk-face", "uk-recognition", "ukface", "uk_face"}: |
| 19450 | provider_label = "UK Face Recognition" |
| 19451 | else: |
| 19452 | provider_label = "ArcFace" |
| 19453 | matches = result_payload.get("matches") or [] |
| 19454 | matrix = result_payload.get("matrix") or [] |
| 19455 | annotated_a = result_payload.get("annotated_a") or "" |
| 19456 | annotated_b = result_payload.get("annotated_b") or "" |
| 19457 | top_pairs = result_payload.get("top_pair_icons") or [] |
| 19458 | |
| 19459 | rg = ReportGenerator() |
| 19460 | pdf = FPDF() |
| 19461 | rg._pdf_cover(pdf, "CScorza Report", "Face Recognition") |
| 19462 | rg._pdf_notes_page(pdf, "Note Tab Face (Pagina 2)", [ |
| 19463 | "Confronto biometrico basato su similarita vettoriale.", |
| 19464 | "Il punteggio indica probabilita statistica, non identificazione certa." |
| 19465 | ]) |
| 19466 | pdf.add_page() |
| 19467 | pdf.set_auto_page_break(auto=True, margin=12) |
| 19468 | def _cellln(text, h=6, align="L", border=0): |
| 19469 | pdf.cell(0, h, _latin1(text), border=border, align=align, new_x=XPos.LMARGIN, new_y=YPos.NEXT) |
| 19470 | |
| 19471 | def _mcline(text, h=6): |
no test coverage detected