个人长报告同盘同日重试改为秒回
完整数据版在版本号明确时复用当天的结果。渲染快捷算法留下但默认关闭,本机只快了大约两成。 Co-Authored-By: Grok (agent loop)
This commit is contained in:
co-authored by
Grok (agent loop)
parent
66cd60081f
commit
69c739fbee
@@ -8,6 +8,9 @@ calculation, and delegates packet assembly/rendering to ``jyotish_engine``.
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from datetime import datetime
|
||||
from importlib import import_module
|
||||
from types import SimpleNamespace
|
||||
@@ -32,6 +35,11 @@ except ModuleNotFoundError: # pragma: no cover - direct scripts/ execution path
|
||||
from reader_dasha_applicability import render_dasha_applicability
|
||||
from report_density_packet import report_density_packet
|
||||
|
||||
try:
|
||||
from scripts.report_perf_flags import report_reference_cache_enabled
|
||||
except ModuleNotFoundError: # pragma: no cover - direct scripts/ execution path
|
||||
from report_perf_flags import report_reference_cache_enabled
|
||||
|
||||
|
||||
class ProfessionalReportReferenceInputError(ValueError):
|
||||
"""The professional-reference request is outside the public contract."""
|
||||
@@ -187,18 +195,49 @@ def _export_args(birth: dict[str, Any]) -> SimpleNamespace:
|
||||
return SimpleNamespace(**payload)
|
||||
|
||||
|
||||
def build_professional_report_reference(handler, body: dict[str, Any], *, engine=None) -> dict[str, Any]:
|
||||
"""Build one JSON or Markdown response from one reused full-reading result."""
|
||||
if not isinstance(body, dict):
|
||||
raise ProfessionalReportReferenceInputError("request body must be an object")
|
||||
output_format = _normalize_format(body.get("format"))
|
||||
edition = _normalize_edition(body.get("edition"))
|
||||
packs = _normalize_packs(body.get("packs"))
|
||||
languages = _normalize_languages(body.get("languages"))
|
||||
if languages and (output_format != "markdown" or edition != FULL_DATA_EDITION):
|
||||
raise ProfessionalReportReferenceInputError("languages requires format markdown and edition full_data")
|
||||
def _load_report_cache():
|
||||
try:
|
||||
from scripts import consult_full_data_cache as cache
|
||||
except ModuleNotFoundError: # pragma: no cover - direct scripts/ execution path
|
||||
import consult_full_data_cache as cache
|
||||
return cache
|
||||
|
||||
birth = handler._high_rigor_birth_payload(body)
|
||||
|
||||
def _report_cache_sha() -> str:
|
||||
return os.environ.get("GITHUB_SHA") or ""
|
||||
|
||||
|
||||
def _report_cache_identity(
|
||||
birth: dict[str, Any],
|
||||
output_format: str,
|
||||
edition: str,
|
||||
packs: list[str],
|
||||
languages: list[str],
|
||||
include_fact_tables: bool,
|
||||
sha: str,
|
||||
) -> dict[str, Any]:
|
||||
return {
|
||||
"birth": birth,
|
||||
"format": output_format,
|
||||
"edition": edition,
|
||||
"packs": list(packs),
|
||||
"languages": list(languages),
|
||||
"include_fact_tables": include_fact_tables,
|
||||
"report_version": REPORT_VERSION_FULL,
|
||||
"github_sha": sha,
|
||||
}
|
||||
|
||||
|
||||
def _assemble_professional_report_reference(
|
||||
handler,
|
||||
birth: dict[str, Any],
|
||||
output_format: str,
|
||||
edition: str,
|
||||
packs: list[str],
|
||||
languages: list[str],
|
||||
include_fact_tables: bool,
|
||||
engine,
|
||||
) -> dict[str, Any]:
|
||||
full_reading = handler._compute_full_reading_for_thematic(birth)
|
||||
resolved_engine = engine or _load_engine()
|
||||
try:
|
||||
@@ -217,7 +256,7 @@ def build_professional_report_reference(handler, body: dict[str, Any], *, engine
|
||||
if edition == FULL_DATA_EDITION:
|
||||
# English renders from its own deep copy first, so nothing the Chinese
|
||||
# renderer does to the packet can reach it (and vice versa).
|
||||
english = _english_edition(packet, body.get("include_fact_tables") is True) if "en" in languages else {}
|
||||
english = _english_edition(packet, include_fact_tables) if "en" in languages else {}
|
||||
markdown = render_full_data_markdown(packet)
|
||||
else:
|
||||
markdown = resolved_engine.render_pl9_markdown(packet)
|
||||
@@ -228,7 +267,7 @@ def build_professional_report_reference(handler, body: dict[str, Any], *, engine
|
||||
"markdown": markdown,
|
||||
**({"fact_table_packet": report_density_packet(packet),
|
||||
"reader_dasha_applicability": clean_reader_appendix_markdown(render_dasha_applicability(packet))}
|
||||
if body.get("include_fact_tables") is True else {}),
|
||||
if include_fact_tables else {}),
|
||||
**(english if edition == FULL_DATA_EDITION and "en" in languages else {}),
|
||||
}
|
||||
return {
|
||||
@@ -236,3 +275,49 @@ def build_professional_report_reference(handler, body: dict[str, Any], *, engine
|
||||
"edition": edition,
|
||||
"report": packet,
|
||||
}
|
||||
|
||||
|
||||
def build_professional_report_reference(handler, body: dict[str, Any], *, engine=None) -> dict[str, Any]:
|
||||
"""Build one JSON or Markdown response from one reused full-reading result."""
|
||||
if not isinstance(body, dict):
|
||||
raise ProfessionalReportReferenceInputError("request body must be an object")
|
||||
output_format = _normalize_format(body.get("format"))
|
||||
edition = _normalize_edition(body.get("edition"))
|
||||
packs = _normalize_packs(body.get("packs"))
|
||||
languages = _normalize_languages(body.get("languages"))
|
||||
if languages and (output_format != "markdown" or edition != FULL_DATA_EDITION):
|
||||
raise ProfessionalReportReferenceInputError("languages requires format markdown and edition full_data")
|
||||
|
||||
birth = handler._high_rigor_birth_payload(body)
|
||||
include_fact_tables = body.get("include_fact_tables") is True
|
||||
sha = _report_cache_sha()
|
||||
use_cache = (
|
||||
report_reference_cache_enabled()
|
||||
and output_format == "markdown"
|
||||
and edition == FULL_DATA_EDITION
|
||||
and sha not in ("", "unknown")
|
||||
)
|
||||
if not use_cache:
|
||||
return _assemble_professional_report_reference(
|
||||
handler, birth, output_format, edition, packs, languages, include_fact_tables, engine,
|
||||
)
|
||||
identity = _report_cache_identity(
|
||||
birth, output_format, edition, packs, languages, include_fact_tables, sha,
|
||||
)
|
||||
started = time.perf_counter()
|
||||
|
||||
def builder(_identity: dict[str, Any]) -> dict[str, Any]:
|
||||
return _assemble_professional_report_reference(
|
||||
handler, birth, output_format, edition, packs, languages, include_fact_tables, engine,
|
||||
)
|
||||
|
||||
cached = _load_report_cache().get_or_build(
|
||||
identity,
|
||||
builder,
|
||||
cache_name="report_reference_cache",
|
||||
json_default=str,
|
||||
)
|
||||
elapsed_ms = int(round((time.perf_counter() - started) * 1000))
|
||||
state = "hit" if cached["hit"] else "miss"
|
||||
print(f"[report-reference-cache] {state} elapsed_ms={elapsed_ms}", file=sys.stderr)
|
||||
return cached["packet"]
|
||||
|
||||
Reference in New Issue
Block a user