python案例对这次中柱射门是否感到惋惜?

wen python案例 3

下面给你一个可运行的 Python 案例:

python案例对这次中柱射门是否感到惋惜?

from dataclasses import dataclass
@dataclass
class Shot:
    hit_post: bool
    on_target: bool
    expected_goal: float  # 预期进球值 xG,0~1
    minute: int
    score_diff: int  # 己方比分 - 对方比分
def regret_level(shot: Shot) -> dict:
    """
    计算对一次射门的惋惜程度。
    返回:分数、等级、原因
    """
    score = 0.0
    reasons = []
    if shot.hit_post:
        score += 50
        reasons.append("中柱,距离进球极近")
    if shot.on_target:
        score += 15
        reasons.append("射正,机会质量不低")
    score += shot.expected_goal * 20
    if shot.expected_goal >= 0.3:
        reasons.append("预期进球值较高")
    if shot.minute >= 85:
        score += 10
        reasons.append("发生在比赛末段,机会更珍贵")
    if shot.score_diff <= 0:
        score += 10
        reasons.append("比分胶着或落后,错失机会代价更大")
    score = min(score, 100)
    if score >= 80:
        level = "非常惋惜"
    elif score >= 60:
        level = "比较惋惜"
    elif score >= 40:
        level = "有点惋惜"
    else:
        level = "不太惋惜"
    return {
        "score": round(score, 1),
        "level": level,
        "reasons": reasons
    }
# 假设这次中柱射门:中柱、射正、xG=0.35、第88分钟、比分0:0
shot = Shot(hit_post=True, on_target=True, expected_goal=0.35, minute=88, score_diff=0)
result = regret_level(shot)
print(result)

输出示例:

{'score': 92.0, 'level': '非常惋惜', 'reasons': ['中柱,距离进球极近', '射正,机会质量不低', '预期进球值较高', '发生在比赛末段,机会更珍贵', '比分胶着或落后,错失机会代价更大']}

如果这次射门是中柱 + 射正 + xG 不低 + 发生在关键时段 + 比分胶着,那用这个模型判断,结论会是:非常惋惜。
如果你把具体比赛信息发我,比如第几分钟、比分、xG、是否射正,我可以帮你代入算一个更贴合的“惋惜指数”。

上一篇python案例认为这次远射能打破僵局吗?

下一篇当前分类已是最新一篇

抱歉,评论功能暂时关闭!