**Motivations:** - Implémenter le workflow complet de démonstration Collatz (commandes.md) - Permettre la reprise après interruption au palier D20 **Evolutions:** - Scripts 01-12 et run-full-workflow alignés sur commandes.md sections 1-10 - collatz_recover_noyau.py : recréation de noyau_post_D20 à partir du CSV candidats - Option --resume-from D20 dans collatz_k_pipeline pour reprendre sans recalculer D18-D19-F15 - Détection automatique : si candidats_D20 existe sans noyau_post_D20, récupération puis poursuite - Filtres --cible=critique et --modulo dans collatz_fusion_pipeline - ROOT par défaut = collatz_k_scripts (plus data/source vide) **Pages affectées:** - .gitignore (__pycache__, out/) - applications/collatz/collatz_k_scripts/*.py - applications/collatz/scripts/*.sh - applications/collatz/scripts/README.md
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
collatz_generate_full_certificate.py
|
|
|
|
Load all certificat_*.json files, merge into single JSON:
|
|
{clauses: [...], depth: N, ...}
|
|
|
|
Usage:
|
|
python collatz_generate_full_certificate.py --certificats-dir DIR --output JSON_PATH
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def load_and_merge(certificats_dir: Path) -> dict:
|
|
"""Load all certificat_*.json and merge clauses."""
|
|
all_clauses: list = []
|
|
max_depth = 0
|
|
extra_keys: dict = {}
|
|
|
|
for p in sorted(certificats_dir.glob("certificat_*.json")):
|
|
data = json.loads(p.read_text(encoding="utf-8"))
|
|
clauses = data.get("clauses", data.get("closed", []))
|
|
all_clauses.extend(clauses)
|
|
max_depth = max(max_depth, data.get("depth", 0))
|
|
for k, v in data.items():
|
|
if k not in ("clauses", "closed", "depth") and k not in extra_keys:
|
|
extra_keys[k] = v
|
|
|
|
result: dict = {"clauses": all_clauses, "depth": max_depth, **extra_keys}
|
|
return result
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(
|
|
description="Merge all certificat JSON files into one full certificate"
|
|
)
|
|
parser.add_argument("--certificats-dir", required=True, help="Directory containing certificat_*.json")
|
|
parser.add_argument("--output", required=True, help="Output JSON path")
|
|
args = parser.parse_args()
|
|
|
|
cert_dir = Path(args.certificats_dir)
|
|
if not cert_dir.is_dir():
|
|
raise SystemExit(f"Not a directory: {cert_dir}")
|
|
|
|
merged = load_and_merge(cert_dir)
|
|
|
|
out_path = Path(args.output)
|
|
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
out_path.write_text(json.dumps(merged, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|