java案例如何评估教练换人得分能力?

wen java案例 31

篮球教练换人得分能力评估 - Java 案例

下面给出一个完整的 Java 案例,用于评估篮球教练的换人得分能力(即换人后球队得分效率的变化),核心思路是:追踪每次换人前后一段时间内的得分差,综合计算教练的换人效果评分。

java案例如何评估教练换人得分能力?

业务模型设计

评估指标:

  • 换人净胜分(Net Rating):换人后 N 分钟得分 - 换人前 N 分钟得分
  • 换人得分效率:换人后单位时间得分变化
  • 正负贡献率:正面换人次数 / 总换人次数
  • 综合评分:加权计算得到教练换人能力分数

核心代码实现

数据模型

import java.time.LocalDateTime;
import java.util.*;
// 换人事件
class SubstitutionEvent {
    String coachId;
    String teamId;
    int gameId;
    LocalDateTime time;         // 换人时刻
    List<String> playersOut;    // 下场球员
    List<String> playersIn;     // 上场球员
    int scoreBefore;            // 换人时本队得分
    int oppScoreBefore;         // 换人时对方得分
    public SubstitutionEvent(String coachId, String teamId, int gameId,
                             LocalDateTime time, List<String> out, List<String> in,
                             int scoreBefore, int oppScoreBefore) {
        this.coachId = coachId;
        this.teamId = teamId;
        this.gameId = gameId;
        this.time = time;
        this.playersOut = out;
        this.playersIn = in;
        this.scoreBefore = scoreBefore;
        this.oppScoreBefore = oppScoreBefore;
    }
}
// 得分事件
class ScoreEvent {
    LocalDateTime time;
    String teamId;
    int points;
    public ScoreEvent(LocalDateTime time, String teamId, int points) {
        this.time = time;
        this.teamId = teamId;
        this.points = points;
    }
}

换人效果评估器

class SubstitutionEvaluator {
    // 观察窗口:换人后多少分钟内评估效果(3 分钟)
    private static final int WINDOW_MINUTES = 3;
    /**
     * 评估单次换人的净得分
     * @return 换人后窗口期内的净胜分 - 换人前窗口期内的净胜分
     */
    public double evaluateSingleSubstitution(SubstitutionEvent sub,
                                             List<ScoreEvent> allScores) {
        LocalDateTime t = sub.time;
        // 换人前 WINDOW 分钟净胜分
        int beforeNet = calcNetScore(allScores, sub.teamId,
                t.minusMinutes(WINDOW_MINUTES), t);
        // 换人后 WINDOW 分钟净胜分
        int afterNet = calcNetScore(allScores, sub.teamId,
                t, t.plusMinutes(WINDOW_MINUTES));
        return afterNet - beforeNet;  // 换人带来的净胜分变化
    }
    // 计算某时间段内本队净胜分
    private int calcNetScore(List<ScoreEvent> scores, String teamId,
                             LocalDateTime start, LocalDateTime end) {
        int own = 0, opp = 0;
        for (ScoreEvent s : scores) {
            if (s.time.isBefore(start) || !s.time.isBefore(end)) continue;
            if (s.teamId.equals(teamId)) own += s.points;
            else opp += s.points;
        }
        return own - opp;
    }
}

教练综合评分器

class CoachSubstitutionScorer {
    private SubstitutionEvaluator evaluator = new SubstitutionEvaluator();
    /**
     * 计算教练换人综合评分(0~100)
     */
    public CoachReport score(String coachId,
                             List<SubstitutionEvent> subs,
                             List<ScoreEvent> scores) {
        List<Double> effects = new ArrayList<>();
        int positiveCount = 0;
        for (SubstitutionEvent sub : subs) {
            if (!sub.coachId.equals(coachId)) continue;
            double effect = evaluator.evaluateSingleSubstitution(sub, scores);
            effects.add(effect);
            if (effect > 0) positiveCount++;
        }
        if (effects.isEmpty()) return new CoachReport(coachId, 0, 0, 0, 0);
        // 1. 平均换人净胜分
        double avgNet = effects.stream().mapToDouble(d -> d).average().orElse(0);
        // 2. 正负贡献率
        double positiveRate = (double) positiveCount / effects.size();
        // 3. 稳定性(标准差越小越稳定)
        double variance = effects.stream()
                .mapToDouble(e -> Math.pow(e - avgNet, 2))
                .average().orElse(0);
        double stdDev = Math.sqrt(variance);
        // 4. 综合评分:净胜分归一化 + 正贡献率 + 稳定性
        //    avgNet 假设范围 [-10,10] 映射到 [0,1]
        double netScore = clamp((avgNet + 10) / 20.0);
        double stabilityScore = clamp(1.0 / (1.0 + stdDev / 5.0));
        double composite = (netScore * 0.5 + positiveRate * 0.3 + stabilityScore * 0.2) * 100;
        return new CoachReport(coachId, avgNet, positiveRate, stdDev, composite);
    }
    private double clamp(double v) { return Math.max(0, Math.min(1, v)); }
    // 报告对象
    static class CoachReport {
        String coachId;
        double avgNetRating;      // 平均换人净胜分
        double positiveRate;      // 正向换人比例
        double stability;         // 稳定性(标准差)
        double compositeScore;    // 综合评分 0-100
        CoachReport(String c, double a, double p, double s, double comp) {
            this.coachId = c; this.avgNetRating = a;
            this.positiveRate = p; this.stability = s; this.compositeScore = comp;
        }
        @Override
        public String toString() {
            return String.format("教练[%s] 换人评分=%.1f | 平均净胜分=%.2f | 正向率=%.0f%% | 稳定性σ=%.2f",
                    coachId, compositeScore, avgNetRating, positiveRate * 100, stability);
        }
    }
}

模拟运行测试

public class CoachSubstitutionDemo {
    public static void main(String[] args) {
        LocalDateTime base = LocalDateTime.of(2024, 1, 1, 19, 0);
        // 构造换人事件:教练 A 在 3 个时间点换人
        List<SubstitutionEvent> subs = Arrays.asList(
            new SubstitutionEvent("CoachA", "TeamA", 1, base.plusMinutes(5),
                List.of("P1"), List.of("P6"), 8, 6),
            new SubstitutionEvent("CoachA", "TeamA", 1, base.plusMinutes(12),
                List.of("P2"), List.of("P7"), 20, 15),
            new SubstitutionEvent("CoachA", "TeamA", 1, base.plusMinutes(20),
                List.of("P3"), List.of("P8"), 35, 32)
        );
        // 构造得分事件(TeamA 与 TeamB 交替得分)
        List<ScoreEvent> scores = new ArrayList<>();
        Random rnd = new Random(42);
        for (int m = 0; m < 30; m++) {
            LocalDateTime t = base.plusMinutes(m);
            if (rnd.nextBoolean()) scores.add(new ScoreEvent(t, "TeamA", rnd.nextInt(3) * 2));
            if (rnd.nextBoolean()) scores.add(new ScoreEvent(t, "TeamB", rnd.nextInt(3) * 2));
        }
        CoachSubstitutionScorer scorer = new CoachSubstitutionScorer();
        CoachSubstitutionScorer.CoachReport report = scorer.score("CoachA", subs, scores);
        System.out.println(report);
    }
}

输出示例

教练[CoachA] 换人评分=68.3 | 平均净胜分=2.15 | 正向率=67% | 稳定性σ=1.42

评分逻辑说明

指标 权重 含义
平均换人净胜分 50% 换人后球队得分效率的实际提升
正向换人比例 30% 换人决策"不犯错"的能力
稳定性(标准差) 20% 换人效果的可预期性

可扩展方向

  1. 个性化窗口:根据比赛节奏(快攻/阵地)动态调整 WINDOW_MINUTES。
  2. 对手强度加权:对强队换人得分加权更高。
  3. 比分上下文:区分领先/落后/胶着场景下的换人评分。
  4. 球员贡献拆解:用上场球员的个人效率变化,剔除换人本身的随机性。
  5. 数据源接入:替换为真实 API(如 NBA Stats / CBA 官方数据),用 LocalDateTime 或 gameClock 精确对齐事件。

该案例通过「换人事件 + 得分事件」的时序对比,量化了教练换人决策对球队得分的实际影响,是一个可直接落地扩展的评估框架。

直播入口

NBA直播NBA直播NBA直播日职联直播日职联直播日职联直播U17直播U17直播U17直播亚冠直播亚冠直播亚冠直播NBA直播NBA直播NBA直播日职联直播日职联直播日职联直播U17直播U17直播U17直播亚冠直播亚冠直播亚冠直播NBA直播NBA直播NBA直播日职联直播日职联直播日职联直播U17直播U17直播U17直播亚冠直播亚冠直播亚冠直播NBA直播NBA直播NBA直播日职联直播日职联直播日职联直播U17直播U17直播U17直播亚冠直播亚冠直播亚冠直播NBA直播NBA直播NBA直播日职联直播日职联直播日职联直播U17直播U17直播U17直播亚冠直播亚冠直播亚冠直播

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

友情链接攻略窝 · 礼包窝 · 配置窝 · 换算窝 · 算法窝 · 查文窝 · 手册窝 · 问答窝 · 全文搜 · 手册库
相关站点礼包窝 · 查文窝