个人长报告同盘同日重试改为秒回
完整数据版在版本号明确时复用当天的结果。渲染快捷算法留下但默认关闭,本机只快了大约两成。 Co-Authored-By: Grok (agent loop)
This commit is contained in:
co-authored by
Grok (agent loop)
parent
66cd60081f
commit
69c739fbee
@@ -7,9 +7,15 @@ It only changes reader-facing labels; it does not alter calculation payloads.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
try:
|
||||
from scripts.report_perf_flags import report_render_fast_enabled
|
||||
except ModuleNotFoundError: # pragma: no cover - direct scripts/ execution
|
||||
from report_perf_flags import report_render_fast_enabled
|
||||
|
||||
|
||||
# Bilingual planet tokens from yoga combination text, longest first.
|
||||
# Dignity is glued on with no space ("木星Jupiterexalted"), so the long form
|
||||
@@ -131,6 +137,11 @@ def translate_zh_glued_phrases(text: str) -> str:
|
||||
return text
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=512)
|
||||
def _natural_language_term_pattern(raw: str, plural: str) -> re.Pattern:
|
||||
return re.compile(rf"(?<![A-Za-z0-9_]){re.escape(raw)}{plural}(?![A-Za-z0-9_])")
|
||||
|
||||
|
||||
def replace_natural_language_term(text: str, raw: str, public: str) -> str:
|
||||
"""Replace one glossary term in prose only.
|
||||
|
||||
@@ -141,7 +152,14 @@ def replace_natural_language_term(text: str, raw: str, public: str) -> str:
|
||||
if not text or not raw:
|
||||
return text
|
||||
plural = "s?" if re.search(r"[A-Za-z]$", raw) and not raw.endswith("s") else ""
|
||||
pattern = re.compile(rf"(?<![A-Za-z0-9_]){re.escape(raw)}{plural}(?![A-Za-z0-9_])")
|
||||
if report_render_fast_enabled():
|
||||
# Case-sensitive literal. If it is absent, split-and-join would return
|
||||
# the same bytes, so the compile and the scan can be skipped.
|
||||
if raw not in text:
|
||||
return text
|
||||
pattern = _natural_language_term_pattern(raw, plural)
|
||||
else:
|
||||
pattern = re.compile(rf"(?<![A-Za-z0-9_]){re.escape(raw)}{plural}(?![A-Za-z0-9_])")
|
||||
parts = re.split(r"(`[^`]*`)", text)
|
||||
return "".join(
|
||||
part if index % 2 else pattern.sub(public, part)
|
||||
@@ -555,12 +573,98 @@ def _restore_zh_nakshatra_glosses(markdown: str) -> str:
|
||||
)
|
||||
|
||||
|
||||
# Every AD/PD hit contains these literals. Patterns stay case-sensitive.
|
||||
_ZH_AD_DENSITY_RE = re.compile(
|
||||
r"(.+?)主大运中的(.+?)子运,会把(.+?)的自然主题带入当前阶段。"
|
||||
)
|
||||
_ZH_PD_DENSITY_RE = re.compile(
|
||||
r"(.+?)子运中的(.+?)次子运,会在(.+?)背景下呈现(.+?)的短周期结果。"
|
||||
)
|
||||
_ZH_AD_ANCHORS = ("主大运中的", "子运,会把", "的自然主题带入当前阶段。")
|
||||
_ZH_PD_ANCHORS = ("次子运,会在", "背景下呈现", "的短周期结果。")
|
||||
_EN_MD_HEADING_RE = re.compile(r"^#{2,4}\s+(.+?\bMaha Dasha\b.*)$")
|
||||
_EN_AD_DENSITY_RE = re.compile(
|
||||
r"The Antar Dasha of (.+?) activates (.+?)'s natural themes inside the broader Maha Dasha of (.+?)\."
|
||||
)
|
||||
_EN_PD_DENSITY_RE = re.compile(
|
||||
r"In the Pratyantar Dasha of (.+?) in the Antar Dasha of (.+?), (.+?)'s significations give the short-period result inside the (.+?) background\."
|
||||
)
|
||||
_EN_AD_ANCHORS = (
|
||||
"The Antar Dasha of ",
|
||||
" activates ",
|
||||
"'s natural themes inside the broader Maha Dasha of ",
|
||||
)
|
||||
_EN_PD_ANCHORS = (
|
||||
"In the Pratyantar Dasha of ",
|
||||
" in the Antar Dasha of ",
|
||||
"'s significations give the short-period result inside the ",
|
||||
" background.",
|
||||
)
|
||||
|
||||
|
||||
def _line_has_anchors(line: str, anchors: tuple[str, ...]) -> bool:
|
||||
return all(anchor in line for anchor in anchors)
|
||||
|
||||
|
||||
def _thicken_zh_dasha_density_fast(markdown: str) -> str:
|
||||
"""Same AD/PD inserts as the legacy scan, without searching inert lines."""
|
||||
lines = markdown.splitlines()
|
||||
out: list[str] = []
|
||||
for index, line in enumerate(lines):
|
||||
out.append(line)
|
||||
# Both patterns are case-sensitive and every hit contains these literals.
|
||||
ad_possible = _line_has_anchors(line, _ZH_AD_ANCHORS)
|
||||
pd_possible = _line_has_anchors(line, _ZH_PD_ANCHORS)
|
||||
if not ad_possible and not pd_possible:
|
||||
continue
|
||||
lookahead = "\n".join(lines[index + 1:index + 6])
|
||||
if "这一子运不是单独结论" in lookahead or "这个次子运只承担短周期细化" in lookahead:
|
||||
continue
|
||||
if ad_possible:
|
||||
ad_match = _ZH_AD_DENSITY_RE.search(line)
|
||||
if ad_match:
|
||||
md_lord, ad_lord, theme_lord = ad_match.groups()
|
||||
out.extend([
|
||||
"",
|
||||
(
|
||||
f"这一子运不是单独结论,而是把{theme_lord}的自然象征放进{md_lord}主大运的背景里筛选。"
|
||||
f"阅读时先看{ad_lord}本身的落宫、守护宫、尊贵状态与星宿,再看它和主大运星之间是否互相支持。"
|
||||
),
|
||||
"",
|
||||
(
|
||||
"若同一宫位或同一行星在分盘、Ashtakavarga、年度盘和行运中重复出现,"
|
||||
"该主题的可见度会提高;若这些层彼此冲突,则应把结果视为阶段性倾向,而不是孤立断语。"
|
||||
),
|
||||
])
|
||||
continue
|
||||
if pd_possible:
|
||||
pd_match = _ZH_PD_DENSITY_RE.search(line)
|
||||
if pd_match:
|
||||
ad_lord, pd_lord, md_lord, theme_lord = pd_match.groups()
|
||||
out.extend([
|
||||
"",
|
||||
(
|
||||
f"这个次子运只承担短周期细化:{pd_lord}会把{theme_lord}的具体征象带入{ad_lord}子运,"
|
||||
f"并受{md_lord}主背景限制。"
|
||||
),
|
||||
"",
|
||||
(
|
||||
"因此这里优先用于判断事情推进的节奏、触发点和轻重缓急;实际领域仍需回到本命落宫、"
|
||||
"分盘重复、年度盘和当前行运共同核对。"
|
||||
),
|
||||
])
|
||||
continue
|
||||
return "\n".join(out)
|
||||
|
||||
|
||||
def _thicken_zh_dasha_density(markdown: str) -> str:
|
||||
"""Restore reader-facing density for translated AD/PD prose.
|
||||
|
||||
This adds reading instructions tied to already-present fields. It does not
|
||||
introduce new predictions or alter dates.
|
||||
"""
|
||||
if report_render_fast_enabled():
|
||||
return _thicken_zh_dasha_density_fast(markdown)
|
||||
lines = markdown.splitlines()
|
||||
out: list[str] = []
|
||||
for index, line in enumerate(lines):
|
||||
@@ -941,9 +1045,64 @@ def normalize_en_markdown_terms(markdown: str) -> str:
|
||||
return apply_en_residual_han(_thicken_en_dasha_density(text))
|
||||
|
||||
|
||||
def _thicken_en_dasha_density_fast(markdown: str) -> str:
|
||||
"""Same English AD inserts as the legacy scan, without searching inert lines."""
|
||||
lines = markdown.splitlines()
|
||||
out: list[str] = []
|
||||
current_md = None
|
||||
ad_context_added = False
|
||||
for index, line in enumerate(lines):
|
||||
md_heading = _EN_MD_HEADING_RE.match(line)
|
||||
if md_heading:
|
||||
next_md = md_heading.group(1)
|
||||
if next_md != current_md:
|
||||
current_md = next_md
|
||||
ad_context_added = False
|
||||
out.append(line)
|
||||
# Both patterns are case-sensitive and every hit contains these literals.
|
||||
ad_possible = _line_has_anchors(line, _EN_AD_ANCHORS)
|
||||
pd_possible = _line_has_anchors(line, _EN_PD_ANCHORS)
|
||||
if not ad_possible and not pd_possible:
|
||||
continue
|
||||
lookahead = "\n".join(lines[index + 1:index + 6])
|
||||
if (
|
||||
"This Antar Dasha is not read as a standalone verdict" in lookahead
|
||||
or "This Pratyantar Dasha is the short-cycle refinement" in lookahead
|
||||
):
|
||||
continue
|
||||
if ad_possible:
|
||||
ad_match = _EN_AD_DENSITY_RE.search(line)
|
||||
if ad_match and not ad_context_added:
|
||||
ad_lord, theme_lord, md_lord = ad_match.groups()
|
||||
out.extend([
|
||||
"",
|
||||
(
|
||||
f"This Antar Dasha is not read as a standalone verdict. It places {theme_lord}'s "
|
||||
f"natural significations inside the background of the {md_lord} Maha Dasha, then "
|
||||
f"filters them through {ad_lord}'s house placement, house ownership, dignity, "
|
||||
"nakshatra lord, conjunctions, and divisional-chart repetition."
|
||||
),
|
||||
"",
|
||||
(
|
||||
"When the same planet or house repeats through divisional charts, Ashtakavarga, "
|
||||
"annual factors, and transits, the theme becomes more visible. When those layers "
|
||||
"conflict, the result should be read as a staged tendency rather than an isolated statement."
|
||||
),
|
||||
])
|
||||
ad_context_added = True
|
||||
continue
|
||||
if pd_possible and _EN_PD_DENSITY_RE.search(line):
|
||||
# The row already contains the concrete PD lord and timing context.
|
||||
# Keep it, but do not append the same methodology paragraph per node.
|
||||
continue
|
||||
return "\n".join(out)
|
||||
|
||||
|
||||
def _thicken_en_dasha_density(markdown: str) -> str:
|
||||
"""Add chapter-level AD context without repeating boilerplate on every PD row."""
|
||||
|
||||
if report_render_fast_enabled():
|
||||
return _thicken_en_dasha_density_fast(markdown)
|
||||
lines = markdown.splitlines()
|
||||
out: list[str] = []
|
||||
current_md = None
|
||||
|
||||
Reference in New Issue
Block a user