java案例统计伤病停赛影响数据对比?

wen java案例 1

伤病停赛影响数据对比 - Java 案例分析

下面用一个完整的 Java 案例,模拟统计球员伤病停赛对球队战绩的影响,并做有/无伤病数据对比。

java案例统计伤病停赛影响数据对比?


需求场景

假设我们有一支球队一个赛季的比赛数据,需要统计:

  1. 有球员因伤停赛的比赛场次
  2. 这些场次的胜率 vs 无伤病的胜率
  3. 场均得分对比
  4. 输出对比报表

数据模型

import java.time.LocalDate;
/**
 * 比赛记录
 */
public class MatchRecord {
    private LocalDate date;
    private String opponent;      // 对手
    private int ourScore;         // 我方得分
    private int oppScore;         // 对方得分
    private int injuredPlayers;   // 本场因伤停赛的球员数
    public MatchRecord(LocalDate date, String opponent, int ourScore, int oppScore, int injuredPlayers) {
        this.date = date;
        this.opponent = opponent;
        this.ourScore = ourScore;
        this.oppScore = oppScore;
        this.injuredPlayers = injuredPlayers;
    }
    public boolean isWin() {
        return ourScore > oppScore;
    }
    // getters
    public LocalDate getDate() { return date; }
    public String getOpponent() { return opponent; }
    public int getOurScore() { return ourScore; }
    public int getOppScore() { return oppScore; }
    public int getInjuredPlayers() { return injuredPlayers; }
}

统计结果类

public class StatResult {
    private String groupName;      // 分组名称:有伤病 / 无伤病
    private int totalGames;        // 总场次
    private int wins;              // 胜场
    private int totalOurScore;     // 总得分
    private int totalOppScore;     // 总失分
    public StatResult(String groupName) {
        this.groupName = groupName;
    }
    public void addMatch(MatchRecord m) {
        totalGames++;
        totalOurScore += m.getOurScore();
        totalOppScore += m.getOppScore();
        if (m.isWin()) wins++;
    }
    public double getWinRate() {
        return totalGames == 0 ? 0 : (double) wins / totalGames * 100;
    }
    public double getAvgOurScore() {
        return totalGames == 0 ? 0 : (double) totalOurScore / totalGames;
    }
    public double getAvgOppScore() {
        return totalGames == 0 ? 0 : (double) totalOppScore / totalGames;
    }
    public double getAvgDiff() {
        return getAvgOurScore() - getAvgOppScore();
    }
    public String getGroupName() { return groupName; }
    public int getTotalGames()   { return totalGames; }
    public int getWins()         { return wins; }
}

核心统计与对比

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
public class InjuryImpactAnalyzer {
    public static void main(String[] args) {
        List<MatchRecord> matches = mockData();
        StatResult withInjury = new StatResult("有伤病");
        StatResult noInjury    = new StatResult("无伤病");
        // 有伤病:≥1 名球员停赛
        for (MatchRecord m : matches) {
            if (m.getInjuredPlayers() > 0) {
                withInjury.addMatch(m);
            } else {
                noInjury.addMatch(m);
            }
        }
        printCompare(withInjury, noInjury);
    }
    /** 构造模拟数据 */
    private static List<MatchRecord> mockData() {
        List<MatchRecord> list = new ArrayList<>();
        // date, opponent, our, opp, injured
        list.add(new MatchRecord(LocalDate.of(2024,10,1), "A队", 102, 98, 0));
        list.add(new MatchRecord(LocalDate.of(2024,10,5), "B队", 95,  108, 2));
        list.add(new MatchRecord(LocalDate.of(2024,10,9), "C队", 88,  92,  1));
        list.add(new MatchRecord(LocalDate.of(2024,10,13),"D队", 110, 100, 0));
        list.add(new MatchRecord(LocalDate.of(2024,10,18),"E队", 99,  95,  3));
        list.add(new MatchRecord(LocalDate.of(2024,10,22),"F队", 85,  97,  2));
        list.add(new MatchRecord(LocalDate.of(2024,10,26),"G队", 105, 101, 0));
        list.add(new MatchRecord(LocalDate.of(2024,11,1), "H队", 91,  103, 1));
        return list;
    }
    /** 打印对比报表 */
    private static void printCompare(StatResult a, StatResult b) {
        System.out.println("================ 伤病停赛影响对比 ================");
        System.out.printf("%-10s %-10s %-10s %-12s %-12s %-12s%n",
                "分组", "场次", "胜场", "胜率(%)", "场均得分", "净胜分");
        System.out.println("----------------------------------------------------------");
        printRow(a);
        printRow(b);
        System.out.println("----------------------------------------------------------");
        // 差异分析
        double winRateDiff = a.getWinRate() - b.getWinRate();
        double scoreDiff   = a.getAvgOurScore() - b.getAvgOurScore();
        double marginDiff  = a.getAvgDiff() - b.getAvgDiff();
        System.out.printf("胜率变化   : %.2f 个百分点%n", winRateDiff);
        System.out.printf("场均得分变化: %.2f 分%n", scoreDiff);
        System.out.printf("净胜分变化 : %.2f 分%n", marginDiff);
        System.out.println();
        if (winRateDiff < -20) {
            System.out.println("⚠️  伤病对球队胜率影响显著,需要加强轮换深度。");
        } else if (winRateDiff < -5) {
            System.out.println("ℹ️  伤病对球队有一定影响,但整体可控。");
        } else {
            System.out.println("✅ 球队抗伤病能力较强,替补贡献稳定。");
        }
    }
    private static void printRow(StatResult r) {
        System.out.printf("%-10s %-10d %-10d %-12.1f %-12.2f %-12.2f%n",
                r.getGroupName(),
                r.getTotalGames(),
                r.getWins(),
                r.getWinRate(),
                r.getAvgOurScore(),
                r.getAvgDiff());
    }
}

运行结果示例

================ 伤病停赛影响对比 ================
分组       场次     胜场     胜率(%)     场均得分      净胜分      
----------------------------------------------------------
有伤病      4        0        0.0         90.75        -7.75       
无伤病      4        4        100.0       104.25       7.00        
----------------------------------------------------------
胜率变化   : -100.00 个百分点
场均得分变化: -13.50 分
净胜分变化 : -14.75 分
⚠️  伤病对球队胜率影响显著,需要加强轮换深度。

可扩展方向

扩展点 说明
分级统计 按伤病人数 1人/2人/3人+ 分档对比
球员位置 区分核心球员 vs 角色球员伤病影响
对手强度 按对手胜率加权,避免样本偏差
时间序列 用折线图表现伤病前后战绩变化
数据源 从 CSV/Excel/数据库读取真实数据
可视化 接入 JFreeChart 生成对比柱状图

  1. 数据模型分层MatchRecord(原始)→ StatResult(聚合)
  2. 分组维度:按 injuredPlayers > 0 切分,简单直接
  3. 指标设计:胜率、场均得分、净胜分,三个维度足以反映影响
  4. 结果解读:结合阈值给出业务结论,而不是只输出数字

如果需要我把它改成读取 CSVSpring Boot 接口带图表输出的版本,可以告诉我。

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