Files
Jyotisha/scripts/report_render/evidence_grade.py

248 lines
12 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Per-claim evidence-grade caps for the report reading (`report_evidence_grade_v1`).
Astrologer 2026-11-12 (her repo 8aaf6099, handoff/2026-11-12/preset_q3 §1.3–1.4
and §5.2): the backend fixes each conclusion's required dependencies by route
and claim type, computes a grade ceiling from a six-axis evidence ledger, and the
model may only write at or below it. Grades are not probabilities.
| Grade | Meaning in this contract |
|---|---|
| A | strongly and independently validated on a defined case set (never reached here) |
| B | matching cases plus several independent methods agree (never reached here) |
| C | sourced and computable, but not calibrated on matching cases |
| D | a dependency the conclusion needs is missing, undecidable or in open conflict |
No conclusion in a report has matching external cases (event calibration is
`not_done` everywhere), so the ceiling is C at best. A conclusion falls to D when
a *required* layer of its route is missing, failed, withheld, or sits within the
birth-time tolerance of an ascendant change in a varga it needs. A missing layer
that only the route's checklist names (``checked``) is recorded in the ledger and
must be disclosed; it does not by itself make the conclusion D, because an
unrelated missing technique must not drag valid conclusions down (§5.2).
Dependencies follow her `references/strict-workflow-router.md` §2–§7 mandatory
modules. The split into ``required`` and ``checked`` is the product's v1 reading
of that list and is listed for her review.
"""
from __future__ import annotations
from typing import Any
GRADE_CONTRACT = "report_evidence_grade_v1"
GRADE_ORDER = ("A", "B", "C", "D")
# Product policy, versioned: how far the true birth instant may sit from the
# recorded one. A minute-confirmed record is taken as +/- 1 minute; an
# unconfirmed one has no stated tolerance, so the local boundary is not checked.
PRECISION_POLICY = "birth_record_minute_v1"
CONFIRMED_TOLERANCE_MINUTES = 1.0
MISSING_STATES = {"blocked", "withheld", "missing", "calculation_failed", "missing_input", "not_computed"}
# Dependency kinds:
# ("p", domain, id) domain participation row
# ("s", id) shared technique row
# ("v", code) varga ascendant boundary relative to the birth-time tolerance
# ("t", key) timing / transit / annual block present
# Each claim type: route (her router section), section ids it may appear in,
# required deps (missing -> D) and checked deps (missing -> disclosed only).
CLAIM_TYPES: dict[str, dict[str, Any]] = {
"character_structure": {
"route": "full-reading-strict §2",
"sections": ("overview", "character"),
"required": [("v", "D1"), ("s", "functional")],
"checked": [("s", "d9"), ("v", "D9"), ("s", "shadbala"), ("s", "avastha"), ("s", "dispositor_chain")],
},
"career_promise": {
"route": "career-timing-strict §3",
"sections": ("overview", "career"),
"required": [("v", "D1"), ("s", "functional"), ("p", "career", "D10"), ("v", "D10")],
"checked": [("s", "d9"), ("p", "career", "AmK"), ("p", "career", "AK"), ("p", "career", "Karakamsha"),
("p", "career", "A10"), ("p", "career", "AL"), ("s", "shadbala"), ("s", "ashtakavarga"),
("s", "dispositor_chain"), ("p", "career", "D1_D9_D10"), ("s", "argala")],
},
"wealth_earning": {
"route": "finance-timing-strict §5",
"sections": ("overview", "wealth"),
"required": [("v", "D1"), ("s", "functional"), ("p", "wealth", "D2"), ("v", "D2")],
"checked": [("p", "wealth", "D11"), ("p", "wealth", "A2"), ("p", "wealth", "A11"), ("p", "wealth", "D10"),
("p", "wealth", "A10"), ("s", "shadbala"), ("s", "ashtakavarga"), ("s", "argala")],
},
"wealth_retention": {
"route": "finance-timing-strict §5",
"sections": ("overview", "wealth"),
"required": [("v", "D1"), ("s", "functional"), ("p", "wealth", "D2"), ("v", "D2")],
"checked": [("p", "wealth", "A2"), ("s", "shadbala"), ("s", "ashtakavarga"), ("s", "argala")],
},
"relationship_structure": {
"route": "relationship-timing-strict §4",
"sections": ("overview", "love"),
"required": [("v", "D1"), ("s", "functional"), ("p", "marriage", "D9_7"), ("v", "D9")],
"checked": [("p", "marriage", "UL"), ("p", "marriage", "A7"), ("p", "marriage", "DK"),
("p", "marriage", "Vivah"), ("s", "shadbala")],
},
"health_pressure": {
"route": "health-timing-strict §7",
"sections": ("overview", "health"),
"required": [("v", "D1"), ("s", "functional"), ("p", "health", "D6"), ("v", "D6")],
"checked": [("p", "health", "D8"), ("v", "D8"), ("p", "health", "D30"), ("v", "D30"),
("p", "health", "drekkana22"), ("s", "shadbala")],
},
"health_obstruction": {
"route": "health-timing-strict §7 + badhaka-obstacle-planet-guide.md §二",
"sections": ("health",),
"required": [("v", "D1"), ("p", "health", "Badhaka")],
"checked": [],
},
"timing_window": {
"route": "event-timing-strict §6",
"sections": ("overview", "career", "wealth", "love", "health", "now"),
"required": [("s", "vimshottari"), ("s", "narayana"), ("t", "transits")],
"checked": [("t", "annual"), ("t", "double_transit"), ("s", "yogini"), ("s", "kp")],
},
}
GRADED_SECTIONS = ("character", "career", "wealth", "love", "health", "now")
def _dep_id(dep: tuple) -> str:
return ":".join(str(part) for part in dep)
def _participation(facts: dict, domain: str, item_id: str) -> str:
rows = ((facts.get("domains") or {}).get(domain) or {}).get("participation") or []
for row in rows:
if isinstance(row, dict) and row.get("id") == item_id:
return str(row.get("state") or "missing")
return "missing"
def _shared(facts: dict, item_id: str) -> str:
for row in facts.get("shared_techniques") or []:
if isinstance(row, dict) and row.get("id") == item_id:
return str(row.get("state") or "missing")
return "missing"
def _varga_boundary(facts: dict, code: str) -> tuple[str, dict[str, Any]]:
precision = facts.get("birth_precision") or {}
margin = (precision.get("ascendant_margins") or {}).get(code)
if not facts.get("minute_confirmed"):
return "not_evaluated", {"policy": PRECISION_POLICY, "reason": "birth time not confirmed to the minute"}
if not isinstance(margin, dict):
return "missing", {"policy": PRECISION_POLICY, "reason": "no ascendant margin for this varga"}
nearest = min(float(margin.get("before_minutes", 0)), float(margin.get("after_minutes", 0)))
detail = {"policy": PRECISION_POLICY, "nearest_change_minutes": nearest,
"tolerance_minutes": CONFIRMED_TOLERANCE_MINUTES}
return ("clear_at_tolerance" if nearest > CONFIRMED_TOLERANCE_MINUTES else "boundary_sensitive"), detail
def _block_state(facts: dict, key: str) -> str:
if key == "transits":
return "executed" if (facts.get("transits") or {}).get("planets") else "missing"
if key == "annual":
annual = facts.get("annual") or {}
return "missing" if annual.get("status") == "blocked" or not annual else "executed"
if key == "double_transit":
double = (facts.get("transits") or {}).get("double_transit") or {}
return "executed" if double.get("checked_houses") else "missing"
return "missing"
def _parameter_sensitive(facts: dict) -> set[str]:
listed = (facts.get("blocked_states") or {}).get("parameter_sensitive") or []
out = {str(item) for item in listed}
narayana_status = ((facts.get("timing") or {}).get("narayana") or {}).get("status")
if narayana_status in {"partial", "partial_verified", "parameter_sensitive", "conditional"}:
out.add("narayana")
return out
def _evaluate(facts: dict, dep: tuple, sensitive: set[str]) -> dict[str, Any]:
kind = dep[0]
detail: dict[str, Any] = {}
if kind == "p":
state = _participation(facts, dep[1], dep[2])
elif kind == "s":
state = _shared(facts, dep[1])
if dep[1] in sensitive and state == "executed":
state = "parameter_sensitive"
elif kind == "v":
state, detail = _varga_boundary(facts, dep[1])
else:
state = _block_state(facts, dep[1])
return {"id": _dep_id(dep), "state": state, **({"detail": detail} if detail else {})}
def _is_missing(row: dict) -> bool:
return row["state"] in MISSING_STATES or row["state"] == "boundary_sensitive"
def _contradictions(facts: dict) -> list[dict[str, Any]]:
functional = facts.get("functional") or {}
return [row for row in functional.get("natural_vs_functional_conflicts") or [] if isinstance(row, dict)]
def claim_grade(facts: dict, claim_type: str) -> dict[str, Any]:
spec = CLAIM_TYPES[claim_type]
sensitive = _parameter_sensitive(facts)
required = [_evaluate(facts, dep, sensitive) for dep in spec["required"]]
checked = [_evaluate(facts, dep, sensitive) for dep in spec["checked"]]
missing_required = [row["id"] for row in required if _is_missing(row)]
must_disclose = [row["id"] for row in checked if _is_missing(row)]
sensitive_rows = [row["id"] for row in required + checked if row["state"] == "parameter_sensitive"]
boundary_rows = []
for row in required + checked:
if row["id"].startswith("v:"):
details = {key: value for key, value in row["detail"].items() if key != "policy"}
state = "clear" if row["state"] == "clear_at_tolerance" else row["state"]
boundary_rows.append({"id": row["id"], "state": state, **details})
precision = facts.get("birth_precision") or {}
purpose = precision.get("purpose_stability") or "not_evaluated"
if claim_type == "timing_window" and purpose == "stable":
purpose = "not_evaluated"
if purpose != "stable":
must_disclose.append("purpose_stability_not_evaluated")
cap = "D" if missing_required else "C"
reasons = (
[f"required dependency unavailable: {item}" for item in missing_required]
or ["no matching external cases: event calibration not done"]
)
return {
"route": spec["route"],
"sections": list(spec["sections"]),
"cap": cap,
"reasons": reasons,
"required": required,
"checked": checked,
"must_disclose": must_disclose,
"parameter_sensitive": sensitive_rows,
# Six axes (§5.2) plus the local boundary check.
"ledger": {
"case_fit": "none",
"method_maturity": "source_bounded" if not missing_required else "dependency_missing",
"independent_agreement": "not_assessed",
"purpose_stability": purpose,
"boundary_check": {"policy": PRECISION_POLICY, "rows": boundary_rows},
"external_calculation_check": "not_done",
"contradiction": [f"{row.get('planet')}: natural {row.get('natural')} / functional {row.get('functional')}"
for row in _contradictions(facts)],
},
}
def evidence_grades(facts: dict) -> dict[str, Any]:
"""The per-claim ceilings the reading must respect."""
return {
"contract": GRADE_CONTRACT,
"precision_policy": PRECISION_POLICY,
"grade_order": list(GRADE_ORDER),
"graded_sections": list(GRADED_SECTIONS),
"claims": {name: claim_grade(facts, name) for name in CLAIM_TYPES},
}
def grade_allowed(grade: str, cap: str) -> bool:
"""A grade may equal its ceiling or be weaker (later in GRADE_ORDER)."""
return GRADE_ORDER.index(grade) >= GRADE_ORDER.index(cap)