feat: 优化数字处理逻辑,提升代码可读性和维护性;更新预约状态数据结构
This commit is contained in:
1 parent
8838b62e61
commit
2847b8359e
3 files changed
+143
-70
No files matched your search
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user