feat(report): replace the reader edition with the full-data report
Generate the full-data edition (pl9_personal_long_report.v4) and remove the reader edition. English still contains Han, so the API withholds it (BUG-1272, investigating). This commit is not pushed to staging.
This commit is contained in:
@@ -14,10 +14,20 @@ from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
try:
|
||||
from scripts.pl9_full_data_export import (
|
||||
FULL_DATA_EDITION,
|
||||
REPORT_VERSION_FULL,
|
||||
render_full_data_markdown,
|
||||
)
|
||||
from scripts.reader_appendix_language import clean_reader_appendix_markdown
|
||||
from scripts.reader_dasha_applicability import render_dasha_applicability
|
||||
from scripts.report_density_packet import report_density_packet
|
||||
except ModuleNotFoundError: # pragma: no cover - direct scripts/ execution path
|
||||
from pl9_full_data_export import (
|
||||
FULL_DATA_EDITION,
|
||||
REPORT_VERSION_FULL,
|
||||
render_full_data_markdown,
|
||||
)
|
||||
from reader_appendix_language import clean_reader_appendix_markdown
|
||||
from reader_dasha_applicability import render_dasha_applicability
|
||||
from report_density_packet import report_density_packet
|
||||
@@ -27,9 +37,7 @@ class ProfessionalReportReferenceInputError(ValueError):
|
||||
"""The professional-reference request is outside the public contract."""
|
||||
|
||||
|
||||
READER_MAIN_EDITION = "reader_main"
|
||||
REFERENCE_EDITION = "reference"
|
||||
REPORT_VERSION_READER = "pl9_personal_long_report.v3"
|
||||
|
||||
|
||||
def _normalize_edition(value: Any) -> str:
|
||||
@@ -40,9 +48,11 @@ def _normalize_edition(value: Any) -> str:
|
||||
normalized = value.strip()
|
||||
if normalized in {"", REFERENCE_EDITION, "professional_reference"}:
|
||||
return REFERENCE_EDITION
|
||||
if normalized == READER_MAIN_EDITION:
|
||||
return READER_MAIN_EDITION
|
||||
raise ProfessionalReportReferenceInputError("edition must be reference or reader_main")
|
||||
if normalized == "reader_main":
|
||||
raise ProfessionalReportReferenceInputError("edition reader_main has been removed; use full_data")
|
||||
if normalized == FULL_DATA_EDITION:
|
||||
return FULL_DATA_EDITION
|
||||
raise ProfessionalReportReferenceInputError("edition must be reference or full_data")
|
||||
|
||||
|
||||
def _normalize_format(value: Any) -> str:
|
||||
@@ -102,14 +112,12 @@ def _english_edition(packet: dict, include_fact_tables: bool) -> dict[str, Any]:
|
||||
"""
|
||||
try:
|
||||
from scripts.pl9_reader_english import HAN, _public_wording_en
|
||||
from scripts.pl9_reader_export import _pl9_export_markdown_for_edition
|
||||
except ModuleNotFoundError: # pragma: no cover - direct scripts/ execution path
|
||||
from pl9_reader_english import HAN, _public_wording_en
|
||||
from pl9_reader_export import _pl9_export_markdown_for_edition
|
||||
try:
|
||||
english = copy.deepcopy(packet)
|
||||
english["report_language"] = "en"
|
||||
markdown = _pl9_export_markdown_for_edition(english, READER_MAIN_EDITION)
|
||||
markdown = render_full_data_markdown(english)
|
||||
applicability = (
|
||||
_public_wording_en(render_dasha_applicability(copy.deepcopy(packet), language="en"))
|
||||
if include_fact_tables else None
|
||||
@@ -170,8 +178,8 @@ def build_professional_report_reference(handler, body: dict[str, Any], *, engine
|
||||
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 != READER_MAIN_EDITION):
|
||||
raise ProfessionalReportReferenceInputError("languages requires format markdown and edition reader_main")
|
||||
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)
|
||||
full_reading = handler._compute_full_reading_for_thematic(birth)
|
||||
@@ -185,30 +193,26 @@ def build_professional_report_reference(handler, body: dict[str, Any], *, engine
|
||||
except ValueError as exc:
|
||||
raise ProfessionalReportReferenceInputError(str(exc)) from exc
|
||||
|
||||
if edition == READER_MAIN_EDITION and isinstance(packet, dict):
|
||||
if edition == FULL_DATA_EDITION and isinstance(packet, dict):
|
||||
packet = dict(packet)
|
||||
packet["report_version"] = REPORT_VERSION_READER
|
||||
packet["report_version"] = REPORT_VERSION_FULL
|
||||
if output_format == "markdown":
|
||||
if edition == READER_MAIN_EDITION:
|
||||
try:
|
||||
from scripts.pl9_reader_export import _pl9_export_markdown_for_edition
|
||||
except ModuleNotFoundError: # pragma: no cover - direct scripts/ execution path
|
||||
from pl9_reader_export import _pl9_export_markdown_for_edition
|
||||
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 {}
|
||||
markdown = _pl9_export_markdown_for_edition(packet, READER_MAIN_EDITION)
|
||||
markdown = render_full_data_markdown(packet)
|
||||
else:
|
||||
markdown = resolved_engine.render_pl9_markdown(packet)
|
||||
return {
|
||||
"format": "markdown",
|
||||
"edition": edition,
|
||||
"report_version": REPORT_VERSION_READER if edition == READER_MAIN_EDITION else packet.get("report_version"),
|
||||
"report_version": REPORT_VERSION_FULL if edition == FULL_DATA_EDITION else packet.get("report_version"),
|
||||
"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 {}),
|
||||
**(english if edition == READER_MAIN_EDITION and "en" in languages else {}),
|
||||
**(english if edition == FULL_DATA_EDITION and "en" in languages else {}),
|
||||
}
|
||||
return {
|
||||
"format": "json",
|
||||
|
||||
Reference in New Issue
Block a user