feat: 优化数字处理逻辑,提升代码可读性和维护性;更新预约状态数据结构

This commit is contained in:
Your Name committed 2026-01-04 15:07:49 +08:00
1 parent 8838b62e61
commit 2847b8359e
3 files changed
+143 -70

No files matched your search

+12 -4
View File
@@ -1916,8 +1916,12 @@ class underlying_operations:
# 保留小数点(包括全角/中文标点归一化为英文点)以便调试时看到如 24.9 这样的值
digits_result = ""
if text:
t_norm = str(text).replace("。", ".").replace(",", ".").replace(".", ".")
digits_result = "".join(ch for ch in t_norm if ch.isdigit() or ch == ".")
t_norm = (
str(text).replace("。", ".").replace(",", ".").replace(".", ".")
)
digits_result = "".join(
ch for ch in t_norm if ch.isdigit() or ch == "."
)
extra_info_dict = {
"mode": change_color,
@@ -1978,7 +1982,9 @@ class underlying_operations:
# 同时准备两种数字抽取结果:
# 1) digits_only: 仅数字(用于倒计时/位置等只需整数的场景)
# 2) digits: 允许小数点(用于金额/带小数的数值),并规范化常见全角标点
text_norm = str(text).replace("。", ".").replace(",", ".").replace(".", ".")
text_norm = (
str(text).replace("。", ".").replace(",", ".").replace(".", ".")
)
digits_only = "".join(ch for ch in text_norm if ch.isdigit())
digits = "".join(ch for ch in text_norm if ch.isdigit() or ch == ".")
@@ -1997,7 +2003,9 @@ class underlying_operations:
# 对于倒计时,选择1-2位的数字段
# 这里先返回所有数字,让调用方处理
# 但优先选择较短的段(1-6位),忽略小数点长度影响
reasonable_segments = [s for s in digit_segments if 1 <= len(s.replace('.', '')) <= 6]
reasonable_segments = [
s for s in digit_segments if 1 <= len(s.replace(".", "")) <= 6
]
if reasonable_segments:
# 如果有多段,优先选择较短的(倒计时)或较长的(价值)
# 这里返回最长的合理段(通常是价值)