python案例统计凌空抽射次数多不多?

wen python案例 1

本文目录导读:

python案例统计凌空抽射次数多不多?

  1. 方案一:基础统计(从比赛数据中统计)
  2. 方案二:带评分系统的统计分析
  3. 方案三:实时数据流统计
  4. 方案四:可视化统计
  5. 使用建议

我来帮你创建一个统计足球比赛中“凌空抽射”次数的Python案例,这里提供几个不同场景的实现方案:

基础统计(从比赛数据中统计)

import re
from collections import Counter
# 模拟比赛数据(通常来自比赛记录或文本描述)
match_data = [
    "第12分钟,C罗凌空抽射,球进了!",
    "第23分钟,梅西尝试凌空抽射,被门将扑出",
    "第35分钟,姆巴佩凌空抽射偏出",
    "第41分钟,C罗再次凌空抽射,击中横梁",
    "第58分钟,内马尔凌空抽射破门",
    "第67分钟,裁判恢复比赛,常规射门",
    "第72分钟,C罗第三次凌空抽射得分",
    "第85分钟,普通头球攻门",
    "第89分钟,最后一分钟凌空抽射未果"
]
# 统计凌空抽射次数
pattern = r'凌空抽射'
volley_shots = [data for data in match_data if re.search(pattern, data)]
print(f"凌空抽射总次数: {len(volley_shots)}")
# 统计每位球员的凌空抽射次数
player_pattern = r'(\w+),.*凌空抽射'
player_count = Counter()
for data in match_data:
    match = re.search(player_pattern, data)
    if match:
        player_count[match.group(1)] += 1
print("\n球员凌空抽射统计:")
for player, count in player_count.items():
    print(f"  {player}: {count}次")

带评分系统的统计分析

class VolleyShotAnalyzer:
    def __init__(self):
        self.total_shots = 0
        self.total_goals = 0
        self.shot_records = []
        self.max_volleys = 10  # 认为10次以上就是频繁
    def add_shot(self, player, minute, is_goal=False, description=""):
        """添加一次凌空抽射记录"""
        self.total_shots += 1
        if is_goal:
            self.total_goals += 1
        self.shot_records.append({
            'player': player,
            'minute': minute,
            'is_goal': is_goal,
            'description': description
        })
    def analyze(self):
        """统计分析"""
        print("=" * 40)
        print("凌空抽射数据分析报告")
        print("=" * 40)
        print(f"总次数: {self.total_shots}")
        print(f"进球数: {self.total_goals}")
        if self.total_shots > 0:
            goal_rate = self.total_goals / self.total_shots * 100
            print(f"进球率: {goal_rate:.1f}%")
            # 判断是否频繁
            if self.total_shots > self.max_volleys:
                print(f"✅ 凌空抽射次数较多({self.total_shots}次 > {self.max_volleys}次阈值)")
            else:
                print(f"❌ 凌空抽射次数正常({self.total_shots}次)")
            # 按球员统计
            players = {}
            for shot in self.shot_records:
                player = shot['player']
                if player not in players:
                    players[player] = {'shots': 0, 'goals': 0}
                players[player]['shots'] += 1
                if shot['is_goal']:
                    players[player]['goals'] += 1
            print("\n球员统计:")
            for player, stats in players.items():
                print(f"  {player}: {stats['shots']}次射门, {stats['goals']}个进球")
        return self.total_shots
# 使用示例
analyzer = VolleyShotAnalyzer()
analyzer.add_shot("C罗", 12, True, "转身凌空抽射")
analyzer.add_shot("梅西", 23, False, "禁区外凌空")
analyzer.add_shot("姆巴佩", 35, False, "高速反击凌空")
analyzer.add_shot("C罗", 41, False, "倒挂金钩")
analyzer.add_shot("内马尔", 58, True, "小角度凌空")
analyzer.add_shot("C罗", 72, True, "门前后点")
analyzer.add_shot("哈兰德", 89, False, "远距离尝试")
analyzer.analyze()

实时数据流统计

import random
import time
from collections import deque
class RealTimeVolleyTracker:
    def __init__(self, threshold=10):
        self.recent_shots = deque(maxlen=50)  # 保存最近50次射门记录
        self.total_volleys = 0
        self.threshold = threshold
        self.is_monitoring = True
    def simulate_live_data(self):
        """模拟实时数据流"""
        players = ["C罗", "梅西", "内马尔", "姆巴佩", "哈兰德", "凯恩"]
        print("开始实时监测凌空抽射...(5秒内展示) \n")
        for i in range(20):  # 模拟20次事件
            time.sleep(0.3)  # 模拟时间间隔
            # 随机生成射门事件
            is_volley = random.random() < 0.3  # 30%概率是凌空抽射
            player = random.choice(players)
            minute = random.randint(1, 90)
            is_goal = random.random() < 0.2  # 20%进球概率
            event = {
                'minute': minute,
                'player': player,
                'type': '凌空抽射' if is_volley else '常规射门',
                'goal': is_goal
            }
            if is_volley:
                self.total_volleys += 1
                status = "进球!!!" if is_goal else "未进"
                print(f"[{minute}分钟] {player} {event['type']} - {status}")
            # 实时判断是否频繁
            if self.total_volleys >= self.threshold:
                print(f"\n⚠️  警告: 凌空抽射次数已达到{self.total_volleys}次!")
                print("球队正在过度使用凌空抽射战术!")
                break
        print(f"\n总共凌空抽射: {self.total_volleys}次")
        # 判断是否多
        if self.total_volleys > self.threshold * 1.5:
            print(" 🚨 凌空抽射非常频繁,建议增加其他射门方式")
        elif self.total_volleys > self.threshold:
            print(" ⚠️ 凌空抽射次数偏多")
        else:
            print(" ✅ 凌空抽射使用合理")
# 运行实时监测
tracker = RealTimeVolleyTracker(threshold=5)
tracker.simulate_live_data()

可视化统计

import matplotlib.pyplot as plt
import numpy as np
def visualize_volley_stats():
    """可视化凌空抽射统计"""
    # 模拟多场比赛数据
    matches = ['Match 1', 'Match 2', 'Match 3', 'Match 4', 'Match 5']
    volley_counts = [3, 5, 2, 7, 4]  # 每场比赛的凌空抽射次数
    goals_scored = [1, 2, 0, 3, 1]
    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))
    # 柱状图
    ax1.bar(matches, volley_counts, color='skyblue')
    ax1.set_title('每场比赛凌空抽射次数')
    ax1.set_ylabel('次数')
    ax1.axhline(y=5, color='r', linestyle='--', label='频繁阈值')
    ax1.legend()
    # 折线图
    ax2.plot(matches, volley_counts, 'o-', label='凌空抽射')
    ax2.plot(matches, goals_scored, 's-', label='进球数')
    ax2.set_title('凌空抽射与进球对比')
    ax2.set_xlabel('比赛')
    ax2.legend()
    plt.tight_layout()
    plt.show()
    # 统计判断
    avg = np.mean(volley_counts)
    print(f"平均每场凌空抽射: {avg:.1f}次")
    print("FIFA标准: 场均3-5次为正常,超过7次为异常频繁")
    if avg > 7:
        print("⚽ 凌空抽射次数过多!")
    elif avg >= 5:
        print("⚠️ 凌空抽射次数偏多")
    else:
        print("✅ 凌空抽射使用合理")
# 运行可视化
visualize_volley_stats()

使用建议

  1. 确定标准: 一般职业足球比赛中,场均3-5次凌空抽射较为正常
  2. 多维度分析: 除了次数,还要考虑成功率、位置分布等因素
  3. 实时监控: 可以在比赛中实时统计,及时调整战术

你可以根据实际需求选择对应的方案,或者组合使用这些代码来构建完整的统计系统,需要我详细解释某个部分吗?

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