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:
# 如果有多段,优先选择较短的(倒计时)或较长的(价值)
# 这里返回最长的合理段(通常是价值)
+50 -7
View File
@@ -1,8 +1,51 @@
{
"updated_ts": 1767497510.8090184,
"reason": "startup_clear",
"room_pos": 0,
"current_room_title": "",
"current_room_title_raw": "",
"reservations": []
}
"updated_ts": 1767505629.8816812,
"reason": "record_reservation",
"room_pos": 3,
"current_room_title": "价小巫籽",
"current_room_title_raw": "价小_巫籽",
"reservations": [
{
"prize_value_yuan": 899.0,
"content": "",
"future_ts": 1767505783.05867,
"future_str": "2026-01-04 13:49:43",
"pos_seen": 3,
"room_title": "什小巫粘",
"room_title_raw": "什小,巫粘",
"created_ts": 1767505629.8782284,
"task_count": 2,
"time_text": "02:39",
"participants": 0,
"copies": 0
},
{
"prize_value_yuan": 6999.0,
"content": "",
"future_ts": 1767505850.730152,
"future_str": "2026-01-04 13:50:50",
"pos_seen": 0,
"room_title": "彩虹士加",
"room_title_raw": "彩虹士加",
"created_ts": 1767505551.1017678,
"task_count": 2,
"time_text": "05:05",
"participants": 0,
"copies": 0
},
{
"prize_value_yuan": 5999.0,
"content": "",
"future_ts": 1767506076.810189,
"future_str": "2026-01-04 13:54:36",
"pos_seen": 1,
"room_title": "刘佟柽佟",
"room_title_raw": "刘佟柽.佟",
"created_ts": 1767505578.9773765,
"task_count": 2,
"time_text": "08:23",
"participants": 0,
"copies": 0
}
]
}
+81 -59
View File
@@ -11,17 +11,19 @@ import sys
# 修复Windows控制台编码问题
if sys.platform == "win32":
try:
reconfigure_func = getattr(sys.stdout, 'reconfigure', None)
reconfigure_func = getattr(sys.stdout, "reconfigure", None)
if reconfigure_func:
reconfigure_func(encoding='utf-8')
reconfigure_func(encoding="utf-8")
except Exception:
pass
try:
import path_config
CONFIG_PATH = path_config.get_config_path()
except Exception:
import path_config
CONFIG_PATH = path_config.get_config_path()
@@ -35,101 +37,121 @@ def check_conflicts(cfg: dict) -> list:
join_ahead = int(cfg.get("high_value_fudai_join_ahead_seconds", 300) or 300)
if skip_lt >= skip_gt:
conflicts.append({
"type": "倒计时阈值冲突",
"message": f"倒计时小于阈值({skip_lt}秒) >= 倒计时大于阈值({skip_gt}秒),这会导致所有福袋都被过滤",
"params": {
"skip_if_countdown_lt_seconds": skip_lt,
"skip_if_countdown_gt_seconds": skip_gt,
conflicts.append(
{
"type": "倒计时阈值冲突",
"message": f"倒计时小于阈值({skip_lt}秒) >= 倒计时大于阈值({skip_gt}秒),这会导致所有福袋都被过滤",
"params": {
"skip_if_countdown_lt_seconds": skip_lt,
"skip_if_countdown_gt_seconds": skip_gt,
},
}
})
)
if join_ahead > skip_gt:
conflicts.append({
"type": "预约参与阈值冲突",
"message": f"预约参与阈值({join_ahead}秒) > 倒计时大于阈值({skip_gt}秒),高价值福袋即使剩余时间在预约阈值内也会被过滤",
"params": {
"high_value_fudai_join_ahead_seconds": join_ahead,
"skip_if_countdown_gt_seconds": skip_gt,
conflicts.append(
{
"type": "预约参与阈值冲突",
"message": f"预约参与阈值({join_ahead}秒) > 倒计时大于阈值({skip_gt}秒),高价值福袋即使剩余时间在预约阈值内也会被过滤",
"params": {
"high_value_fudai_join_ahead_seconds": join_ahead,
"skip_if_countdown_gt_seconds": skip_gt,
},
}
})
)
if join_ahead < skip_lt:
conflicts.append({
"type": "预约参与阈值冲突",
"message": f"预约参与阈值({join_ahead}秒) < 倒计时小于阈值({skip_lt}秒),可能导致高价值福袋在预约阈值内也被过滤",
"params": {
"high_value_fudai_join_ahead_seconds": join_ahead,
"skip_if_countdown_lt_seconds": skip_lt,
conflicts.append(
{
"type": "预约参与阈值冲突",
"message": f"预约参与阈值({join_ahead}秒) < 倒计时小于阈值({skip_lt}秒),可能导致高价值福袋在预约阈值内也被过滤",
"params": {
"high_value_fudai_join_ahead_seconds": join_ahead,
"skip_if_countdown_lt_seconds": skip_lt,
},
}
})
)
# 2. 检查参与人数参数冲突
min_participants = int(cfg.get("min_participants", 0) or 0)
max_participants = int(cfg.get("max_participants", 0) or 0)
if max_participants > 0 and min_participants > max_participants:
conflicts.append({
"type": "参与人数阈值冲突",
"message": f"最小参与人数({min_participants}) > 最大参与人数({max_participants}),这会导致所有福袋都被过滤",
"params": {
"min_participants": min_participants,
"max_participants": max_participants,
conflicts.append(
{
"type": "参与人数阈值冲突",
"message": f"最小参与人数({min_participants}) > 最大参与人数({max_participants}),这会导致所有福袋都被过滤",
"params": {
"min_participants": min_participants,
"max_participants": max_participants,
},
}
})
)
# 3. 检查价值参数冲突
min_value = float(cfg.get("min_prize_value_yuan", 0) or 0)
high_value_threshold = float(cfg.get("high_value_fudai_threshold_yuan", 1000) or 1000)
high_value_threshold = float(
cfg.get("high_value_fudai_threshold_yuan", 1000) or 1000
)
if high_value_threshold < min_value:
conflicts.append({
"type": "价值阈值冲突",
"message": f"高价值阈值({high_value_threshold}元) < 最小价值({min_value}元),高价值福袋可能被最小价值过滤掉",
"params": {
"high_value_fudai_threshold_yuan": high_value_threshold,
"min_prize_value_yuan": min_value,
conflicts.append(
{
"type": "价值阈值冲突",
"message": f"高价值阈值({high_value_threshold}元) < 最小价值({min_value}元),高价值福袋可能被最小价值过滤掉",
"params": {
"high_value_fudai_threshold_yuan": high_value_threshold,
"min_prize_value_yuan": min_value,
},
}
})
)
# 4. 检查高价值预约相关参数
high_value_enabled = bool(cfg.get("high_value_fudai_enabled", False))
if high_value_enabled and high_value_threshold <= 0:
conflicts.append({
"type": "高价值预约配置错误",
"message": f"已启用高价值预约,但高价值阈值({high_value_threshold}元) <= 0,预约功能无法正常工作",
"params": {
"high_value_fudai_enabled": high_value_enabled,
"high_value_fudai_threshold_yuan": high_value_threshold,
conflicts.append(
{
"type": "高价值预约配置错误",
"message": f"已启用高价值预约,但高价值阈值({high_value_threshold}元) <= 0,预约功能无法正常工作",
"params": {
"high_value_fudai_enabled": high_value_enabled,
"high_value_fudai_threshold_yuan": high_value_threshold,
},
}
})
)
# 5. 检查预约相关参数合理性
if high_value_enabled:
max_reservations = int(cfg.get("high_value_fudai_max_reservations", 5) or 5)
if max_reservations <= 0:
conflicts.append({
"type": "预约数量配置错误",
"message": f"最多记录数量({max_reservations}) <= 0,预约功能无法正常工作",
"params": {
"high_value_fudai_max_reservations": max_reservations,
conflicts.append(
{
"type": "预约数量配置错误",
"message": f"最多记录数量({max_reservations}) <= 0,预约功能无法正常工作",
"params": {
"high_value_fudai_max_reservations": max_reservations,
},
}
})
)
# 6. 检查福袋查找相关参数
fudai_icon_max_wait = float(cfg.get("fudai_icon_max_wait_seconds", 5.0) or 5.0)
fudai_icon_retry_delay = float(cfg.get("fudai_icon_retry_delay_seconds", 0.6) or 0.6)
fudai_icon_retry_delay = float(
cfg.get("fudai_icon_retry_delay_seconds", 0.6) or 0.6
)
if fudai_icon_max_wait < fudai_icon_retry_delay:
conflicts.append({
"type": "福袋查找参数不合理",
"message": f"最大等待时间({fudai_icon_max_wait}秒) < 重试延迟({fudai_icon_retry_delay}秒),可能导致只检测一次就放弃",
"params": {
"fudai_icon_max_wait_seconds": fudai_icon_max_wait,
"fudai_icon_retry_delay_seconds": fudai_icon_retry_delay,
conflicts.append(
{
"type": "福袋查找参数不合理",
"message": f"最大等待时间({fudai_icon_max_wait}秒) < 重试延迟({fudai_icon_retry_delay}秒),可能导致只检测一次就放弃",
"params": {
"fudai_icon_max_wait_seconds": fudai_icon_max_wait,
"fudai_icon_retry_delay_seconds": fudai_icon_retry_delay,
},
}
})
)
return conflicts