Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
456 lines
24 KiB
Python
456 lines
24 KiB
Python
"""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 or withheld, or when the D1
|
||
ascendant changes inside the checked birth-time range. Another varga's ascendant
|
||
changing inside that range does not lower the ceiling (BUG-2013): paragraphs that
|
||
use that varga carry one local line instead, see ``boundary_dependence``. 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. Ashtakavarga outside career and wealth
|
||
is auxiliary only (her 2026-11-19 ruling 8, ``AUXILIARY_ONLY``).
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import re
|
||
from typing import Any
|
||
|
||
from .birth_precision_window import (
|
||
CONFIRMED_TOLERANCE_MINUTES, DEFAULT_WINDOW_SCENARIO, DEFAULT_WINDOW_SOURCE, TOLERANCE_KIND,
|
||
WINDOW_POLICY, crosses_birth_window, report_birth_window,
|
||
)
|
||
|
||
try:
|
||
from scripts.consult_card_domain_facts import PRECISION_VARGA
|
||
except ModuleNotFoundError: # pragma: no cover - direct scripts/ execution path
|
||
from consult_card_domain_facts import PRECISION_VARGA
|
||
|
||
GRADE_CONTRACT = "report_evidence_grade_v1"
|
||
GRADE_ORDER = ("A", "B", "C", "D")
|
||
# Keep the minute-confirmed policy and ledger shape for existing reports.
|
||
PRECISION_POLICY = "birth_record_minute_v1"
|
||
|
||
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).
|
||
#
|
||
# BUG-1993: 原值: ("s", "ashtakavarga") 只在事业、财富三类的 checked 里;
|
||
# 新值: 性格、感情、健康压力、应期四类的 checked 也列它;
|
||
# 原因: 她的 strict-workflow-router.md §2 共用基线把 Shadbala 和 Ashtakavarga 并列("when a claim
|
||
# depends on planetary strength or transit strength"),事实包也给每个领域的宫位和行星带了八分法分值,
|
||
# 原表只把 Shadbala 列进了这几类。段落照事实包写出「第七宫八分法 30」就因引用不在允许范围整节被扣。
|
||
# 它是 checked:缺失只需披露,不改变等级上限。
|
||
#
|
||
# BUG-2019(占星师 2026-11-19 上线前答复第 8 条,取代上面「待她过目」的状态):数值可以核对,推论不全面放开。
|
||
# 感情:辅助;健康压力:条件性辅助;时间窗口:必须结合实际行运、周期;性格:不从分数推人格标签。
|
||
# 落到程序里是一条规则:这四类里八分法只算辅助依据(``auxiliary``),段落必须同时引用该结论类型的另一项
|
||
# 非辅助依赖(时间窗口的其它依赖全是周期和行运),否则这条引用按「不在允许范围」处理:去掉这一句或这一段,
|
||
# 不扣整节。事业、财富三类不受这条限制。哪张盘、哪个参照点、是否削减等口径随事实包里的八分法数据走,这里不新增判据。
|
||
# BUG-2021(占星师 2026-11-17 第二批回复第 4、5 项):AL 起第 2 宫、第 11 宫是财富的主要证据
|
||
# (Arudha 的财富与收益视角,与本命第 2、11 宫并列,互不否决),事实包的财富领域已有 AL2、AL11 两行派生计算。
|
||
# 原值:财富两类结论的依赖里没有它们,正文写到「AL 起第 11 宫」时别名 AL 只对得上事业的 p:career:AL,
|
||
# 这句话按「不在允许范围」被去掉(BUG-2013 复测、BUG-2019 遗留)。
|
||
# 新值:获得收入可引用 AL2、AL11,留住收入可引用 AL2(与 A2 / A11 在两类里的分法相同)。
|
||
# 它们列在 checked:没算出来只披露「派生未计算」,不让等级降为 D(她写明互不否决)。别名沿用 AL。
|
||
AUXILIARY_ONLY: dict[str, tuple[tuple, ...]] = {
|
||
"character_structure": (("s", "ashtakavarga"),),
|
||
"relationship_structure": (("s", "ashtakavarga"),),
|
||
"health_pressure": (("s", "ashtakavarga"),),
|
||
"timing_window": (("s", "ashtakavarga"),),
|
||
}
|
||
|
||
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", "ashtakavarga"), ("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"), ("p", "wealth", "AL2"), ("p", "wealth", "AL11"),
|
||
("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"), ("p", "wealth", "AL2"), ("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"), ("s", "ashtakavarga")],
|
||
},
|
||
"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"), ("s", "ashtakavarga")],
|
||
},
|
||
"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"), ("s", "ashtakavarga")],
|
||
},
|
||
}
|
||
|
||
GRADED_SECTIONS = ("character", "career", "wealth", "love", "health", "now")
|
||
|
||
DEPENDENCY_ALIASES = {
|
||
"s:functional": ("功能吉凶",), "s:d9": ("九分盘尊贵度", "九分盘", "Navamsha", "D9"),
|
||
"s:shadbala": ("Shadbala", "六力"),
|
||
"s:avastha": ("Avastha", "星曜状态"), "s:dispositor_chain": ("定位星链",),
|
||
"s:ashtakavarga": ("Ashtakavarga", "八分法", "SAV"), "s:argala": ("Argala",),
|
||
"s:vimshottari": ("Vimshottari", "大运", "小运", "次小运"),
|
||
"s:narayana": ("Narayana", "纳拉亚纳"), "s:yogini": ("Yogini",), "s:kp": ("KP", "KP 判宫"),
|
||
"t:transits": ("过境", "行运"), "t:annual": ("年盘",),
|
||
"t:double_transit": ("Double Transit", "双行运", "双重行运", "双星过境"),
|
||
"p:career:AmK": ("AmK",), "p:career:AK": ("AK",), "p:career:Karakamsha": ("Karakamsha",),
|
||
"p:career:A10": ("A10",), "p:career:AL": ("AL",),
|
||
"p:wealth:A2": ("A2",), "p:wealth:A11": ("A11",), "p:wealth:A10": ("A10",),
|
||
"p:wealth:AL2": ("AL",), "p:wealth:AL11": ("AL",),
|
||
"p:marriage:D9_7": ("九分盘第七宫", "九分盘", "Navamsha", "D9"),
|
||
"p:marriage:UL": ("UL",), "p:marriage:A7": ("A7",),
|
||
"p:marriage:DK": ("DK",), "p:marriage:Vivah": ("Vivah",),
|
||
"p:health:drekkana22": ("第22个Drekkana", "第22个三分盘"),
|
||
"p:health:Badhaka": ("Badhaka", "阻碍宫", "阻碍宫主"),
|
||
"v:D1": ("D1", "本命盘"), "v:D2": ("D2", "财富分盘"),
|
||
"v:D6": ("D6", "健康分盘"), "v:D9": ("D9", "九分盘", "Navamsha"),
|
||
"v:D10": ("D10", "事业分盘"),
|
||
}
|
||
_VARGA_CODE = re.compile(r"D(?:[1-9]|[1-5]\d|60)\Z")
|
||
|
||
|
||
# BUG-2013 (占星师 2026-11-19 第 4、5、6 条): a varga ascendant that changes inside the checked range
|
||
# no longer blanks the whole conclusion type. The conclusion type keeps its ceiling; only a paragraph
|
||
# that actually uses that varga (its ascendant, houses or lordships) is boundary-dependent and carries
|
||
# one local line. Which dependency uses which varga is read off the dependency id itself, so nothing
|
||
# is added to the astrologer's route lists. D1 is the exception: every house in the report hangs on
|
||
# it, so a D1 ascendant inside the range still makes the conclusion D.
|
||
BOUNDARY_CONTRACT = "report_boundary_dependence_v1"
|
||
OTHER_SIDE_NOT_EVALUATED = "not_evaluated"
|
||
# BUG-2028(占星师 2026-11-19 分层答复):原值「另一情景下,该项结论及时间窗口尚未评估。」;新值用日常话。
|
||
# 分盘、秒数等细节留在 boundary.vargas 里,不进读者那一句。
|
||
OTHER_SIDE_LINE_ZH = "另一种情况下的结论还没有评估。"
|
||
# BUG-2028:她 2026-11-19 第 18 条给了新的 A–D 标准(逐条断言的依据充分度,案例验证另列),尚未实现。
|
||
# 现有结果(缺必需依据为 D,否则为 C)标成旧算法,以后的新等级不会和它混在一起。
|
||
GRADE_ALGORITHM = "v1_legacy"
|
||
_DEP_VARGA = re.compile(r"(?<![A-Za-z0-9])[Dd](\d{1,2})(?![0-9])")
|
||
VARGA_LABELS_ZH = {
|
||
"D1": "本命盘(D1)", "D2": "财富分盘(D2,日月两分 Hora)", "D6": "健康分盘(D6)", "D8": "D8 分盘",
|
||
"D9": "九分盘(D9)", "D10": "事业分盘(D10)", "D30": "D30 分盘",
|
||
}
|
||
|
||
|
||
def dependency_vargas(dep_id: str) -> list[str]:
|
||
"""Varga codes a dependency id is tied to: v:D10, p:career:D10, p:marriage:D9_7, s:d9 …"""
|
||
return sorted({f"D{int(number)}" for number in _DEP_VARGA.findall(dep_id.split(":", 1)[-1])},
|
||
key=lambda code: int(code[1:]))
|
||
|
||
|
||
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"):
|
||
window = report_birth_window(precision.get("window"), minute_confirmed=False)
|
||
detail = {"policy": WINDOW_POLICY, **window}
|
||
if code in PRECISION_VARGA:
|
||
return "not_evaluated", {**detail, "reason": "birth time not confirmed to the minute"}
|
||
if not isinstance(margin, dict) or any(margin.get(side) is None for side in ("before_minutes", "after_minutes")):
|
||
return "missing", {**detail, "reason": "no ascendant margin for this varga"}
|
||
before = float(margin["before_minutes"])
|
||
after = float(margin["after_minutes"])
|
||
detail.update(before_change_minutes=before, after_change_minutes=after, nearest_change_minutes=min(before, after))
|
||
crosses = crosses_birth_window(before, after, window)
|
||
return ("boundary_sensitive" if crosses else "clear_at_tolerance"), detail
|
||
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, "tolerance_kind": TOLERANCE_KIND}
|
||
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:
|
||
# 原值: 任何分盘上升在范围内换座都算缺失,整类结论降为 D
|
||
# 新值: 只有 D1 仍算缺失;其余分盘换座改为「依赖边界」,由用到它的段落带一句局部说明
|
||
# 原因: BUG-2013,占星师 2026-11-19 第 4 条:不能把事业、财富整节停掉
|
||
return row["state"] in MISSING_STATES or (row["state"] == "boundary_sensitive" and row["id"] == "v:D1")
|
||
|
||
|
||
def _is_boundary(row: dict) -> bool:
|
||
return row["state"] == "boundary_sensitive" and row["id"] != "v:D1"
|
||
|
||
|
||
def _seconds(minutes: object) -> int | None:
|
||
return max(1, round(float(minutes) * 60)) if isinstance(minutes, (int, float)) else None
|
||
|
||
|
||
def boundary_dependence(facts: dict) -> dict[str, Any]:
|
||
"""Vargas whose ascendant differs in another birth scenario, and the dependency ids tied to them."""
|
||
precision = facts.get("birth_precision") or {}
|
||
margins = precision.get("ascendant_margins") or {}
|
||
window = precision.get("window") or {}
|
||
deps = {dep for spec in CLAIM_TYPES.values() for field in ("required", "checked") for dep in spec[field]}
|
||
codes = sorted({code for dep in deps for code in dependency_vargas(_dep_id(dep))}, key=lambda code: int(code[1:]))
|
||
vargas: dict[str, dict[str, Any]] = {}
|
||
for code in codes:
|
||
if code == "D1":
|
||
continue
|
||
state, _detail = _varga_boundary(facts, code)
|
||
if state != "boundary_sensitive":
|
||
continue
|
||
margin = margins.get(code) if isinstance(margins.get(code), dict) else {}
|
||
before, after = margin.get("before_minutes"), margin.get("after_minutes")
|
||
before = before if isinstance(before, (int, float)) else None
|
||
after = after if isinstance(after, (int, float)) else None
|
||
checked = report_birth_window(window, minute_confirmed=bool(facts.get("minute_confirmed")))
|
||
# The side whose change actually falls inside the checked range; the nearer one if both do.
|
||
inside = [(distance, side) for distance, side in ((before, "earlier"), (after, "later"))
|
||
if distance is not None and crosses_birth_window(
|
||
distance if side == "earlier" else None, distance if side == "later" else None, checked)]
|
||
earlier = min(inside)[1] == "earlier" if inside else before is not None and (after is None or before <= after)
|
||
vargas[code] = {
|
||
"kind": "sensitivity_range" if facts.get("minute_confirmed") else "birth_window",
|
||
"label_zh": VARGA_LABELS_ZH.get(code, f"{code} 分盘"),
|
||
"direction": "earlier" if earlier else "later",
|
||
# Birth-clock seconds to the nearest ascendant change, never arc minutes.
|
||
"birth_time_seconds": _seconds(before if earlier else after),
|
||
"other_side": OTHER_SIDE_NOT_EVALUATED,
|
||
}
|
||
chosen = window.get("chosen_line_charts") if window.get("source") == "rectified_range" else None
|
||
computed = window.get("chosen_line_charts_other_side_computed") or []
|
||
for code in chosen or []:
|
||
if code in vargas or not isinstance(code, str) or not _VARGA_CODE.fullmatch(code):
|
||
continue
|
||
vargas[code] = {
|
||
"kind": "chosen_line",
|
||
"label_zh": VARGA_LABELS_ZH.get(code, f"{code} 分盘"),
|
||
# The report writes one reading, so the conclusion on the other side is not evaluated
|
||
# even where the other side's chart was computed (BUG-2018 `other_side_computed`).
|
||
"other_side_chart_computed": code in computed,
|
||
"other_side": OTHER_SIDE_NOT_EVALUATED,
|
||
}
|
||
refs = {}
|
||
for dep in sorted(deps):
|
||
tied = [code for code in dependency_vargas(_dep_id(dep)) if code in vargas]
|
||
if tied:
|
||
refs[_dep_id(dep)] = tied
|
||
return {
|
||
"contract": BOUNDARY_CONTRACT,
|
||
"tolerance": {"kind": TOLERANCE_KIND, "minutes": CONFIRMED_TOLERANCE_MINUTES,
|
||
"recording_method": "not_modelled"},
|
||
"other_side_line_zh": OTHER_SIDE_LINE_ZH,
|
||
"vargas": vargas,
|
||
"refs": refs,
|
||
}
|
||
|
||
|
||
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)]
|
||
boundary_dependent = [row["id"] for row in required + checked if _is_boundary(row)]
|
||
must_disclose.extend(boundary_dependent)
|
||
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 (precision.get("window") or {}).get("source") == DEFAULT_WINDOW_SOURCE:
|
||
purpose = DEFAULT_WINDOW_SCENARIO
|
||
must_disclose.append(DEFAULT_WINDOW_SCENARIO)
|
||
else:
|
||
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,
|
||
# BUG-2019: ids that may only accompany another, non-auxiliary dependency of this claim type.
|
||
"auxiliary": [_dep_id(dep) for dep in AUXILIARY_ONLY.get(claim_type, ())],
|
||
"boundary_dependent": boundary_dependent,
|
||
"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(facts), "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 _precision_policy(facts: dict) -> str:
|
||
return PRECISION_POLICY if facts.get("minute_confirmed") else WINDOW_POLICY
|
||
|
||
|
||
def _dependency_catalog(facts: dict) -> dict[str, dict[str, Any]]:
|
||
deps = {dep for spec in CLAIM_TYPES.values() for field in ("required", "checked") for dep in spec[field]}
|
||
for domain, row in (facts.get("domains") or {}).items():
|
||
if not isinstance(row, dict) or not isinstance(charts := row.get("varga_charts"), dict):
|
||
continue
|
||
for code, chart in charts.items():
|
||
if isinstance(code, str) and _VARGA_CODE.fullmatch(code) and isinstance(chart, dict):
|
||
deps.add(("v", code))
|
||
if _participation(facts, domain, code) != "missing":
|
||
deps.add(("p", domain, code))
|
||
sensitive = _parameter_sensitive(facts)
|
||
catalog = {}
|
||
for dep in sorted(deps):
|
||
row = _evaluate(facts, dep, sensitive)
|
||
code = dep[-1]
|
||
varga_alias = (code,) if dep[0] == "v" or (dep[0] == "p" and code != "D1" and _VARGA_CODE.fullmatch(code)) else ()
|
||
aliases = DEPENDENCY_ALIASES.get(row["id"], varga_alias)
|
||
catalog[row["id"]] = {"state": row["state"], "aliases": list(aliases)}
|
||
return catalog
|
||
|
||
|
||
def evidence_grades(facts: dict) -> dict[str, Any]:
|
||
"""The per-claim ceilings the reading must respect."""
|
||
return {
|
||
"contract": GRADE_CONTRACT,
|
||
"grade_algorithm": GRADE_ALGORITHM,
|
||
"precision_policy": _precision_policy(facts),
|
||
"grade_order": list(GRADE_ORDER),
|
||
"graded_sections": list(GRADED_SECTIONS),
|
||
"claims": {name: claim_grade(facts, name) for name in CLAIM_TYPES},
|
||
"dependency_catalog": _dependency_catalog(facts),
|
||
"boundary": boundary_dependence(facts),
|
||
}
|
||
|
||
|
||
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)
|