"""Cas C et D avec direction : astre brillant compatible selon les règles v2 (agrégats seulement)."""
import json, sys, collections
import run as R1, run_v2 as V2
_c, rows, _ = R1.build()
cd = [r for r in rows if r["cls"] in ("C", "D") and r["az"] is not None]
out = collections.Counter(); per_cls = collections.Counter(); priv = []
for r in cd:
    c = V2.v2_candidates(r)
    comp = [x for x in c if V2.compatible(x)]
    k = comp[0]["name"] if comp else "aucun astre brillant compatible"
    out[k] += 1; per_cls[(r["cls"], bool(comp))] += 1
    if comp:
        priv.append({"case": r["case"], "cls": r["cls"], "year": r["year"], "dep": r["dep"], "cand": comp[0]["name"], "az_diff": comp[0]["az_diff"], "el": comp[0]["el"]})
json.dump({"n": len(cd), "kinds": dict(out), "per_cls": [[a, b, n] for (a, b), n in per_cls.items()], "list_private": priv}, sys.stdout, ensure_ascii=False)
