标出研究章和 PyJHora 的已知差别(#92)。

10 张虚构盘逐体系对照。不一致的方法在标题下写明差在哪一类。本命 Tithi 顺行一致,逆行没有公开函数。Windows 上 1970 年以前的日出不再用 fromtimestamp。

自测:合同与研究章测试通过;200 张英文扫描约 1956 秒通过。未跑全量 pytest、快速门和前端。

Co-Authored-By: Grok (agent loop)
This commit is contained in:
jesse-ux
2026-10-23 22:29:52 +08:00
co-authored by Grok (agent loop)
parent e586886196
commit a757af6b4e
10 changed files with 1196 additions and 35 deletions
+52 -1
View File
@@ -6,9 +6,11 @@ on the packet, and they are not sent to chat cards or rectification.
from __future__ import annotations
import json
import logging
import re
from datetime import datetime, timedelta, timezone
from pathlib import Path
logger = logging.getLogger(__name__)
@@ -291,7 +293,56 @@ def _chapter(title: str, language: str, body: str) -> str:
def _family_block(title: str, language: str, body: str) -> str:
return f"## {title}\n\n{BANNER[language]}\n\n{body.strip()}"
note = _pyjhora_note(title, language)
text = f"## {title}\n\n{BANNER[language]}"
if note:
text += "\n\n" + note
if body.strip():
text += "\n\n" + body.strip()
return text
_PYJHORA_NOTES: dict | None = None
def _pyjhora_notes() -> dict:
"""Committed offline comparison. Missing or unread JSON adds no label."""
global _PYJHORA_NOTES
if _PYJHORA_NOTES is None:
path = Path(__file__).resolve().parents[2] / "docs" / "tasks" / "research-timing-pyjhora-20261023.json"
notes: dict[tuple[str, str], str] = {}
try:
payload = json.loads(path.read_text(encoding="utf-8"))
except (OSError, json.JSONDecodeError):
payload = {}
systems = payload.get("systems") if isinstance(payload, dict) else None
for item in (systems or {}).values():
if not isinstance(item, dict) or item.get("status") != "不一致":
continue
zh = str(item.get("heading_zh") or "")
en = str(item.get("heading_en") or "")
category = str(item.get("category") or "")
category_en = str(item.get("category_en") or "")
match = item.get("match") or "exact"
if zh and category:
notes[("zh", zh, match)] = f"与 PyJHora 不一致:差在 {category}"
if en and category_en:
notes[("en", en, match)] = f"Differs from PyJHora: {category_en}"
_PYJHORA_NOTES = notes
return _PYJHORA_NOTES
def _pyjhora_note(title: str, language: str) -> str:
best = ""
found = ""
for (lang, heading, match), sentence in _pyjhora_notes().items():
if lang != language or not heading:
continue
if title == heading or (match == "prefix" and title.startswith(heading + " ")):
if len(heading) >= len(best):
best = heading
found = sentence
return found
def _heading(key: str, language: str) -> str:
+16 -1
View File
@@ -24,6 +24,21 @@ except ImportError: # pragma: no cover - package import
_STEP = 0.125
_BISECTIONS = 45
_TOLERANCE = 1e-6
_UNIX_EPOCH_JD = 2440587.5
def _utc_from_jd(jd: float) -> datetime:
"""UTC from a Julian day. Windows ``fromtimestamp`` rejects instants before 1970."""
unix = (float(jd) - _UNIX_EPOCH_JD) * 86400.0
seconds = int(unix)
micros = int(round((unix - seconds) * 1_000_000))
if micros >= 1_000_000:
seconds += 1
micros -= 1_000_000
elif micros < 0:
seconds -= 1
micros += 1_000_000
return datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=seconds, microseconds=micros)
def find_returns(
@@ -248,7 +263,7 @@ def hindu_solar_events(moment: datetime, latitude: float, longitude: float) -> l
flags=flags,
)
if status == 0 and jd <= times[0] < jd + 1:
stamp = datetime.fromtimestamp((times[0] - 2440587.5) * 86400, timezone.utc)
stamp = _utc_from_jd(times[0])
events.append({"event": name, "datetime_utc": stamp.isoformat()})
events.sort(key=lambda row: row["datetime_utc"])
return events