本文目录导读:

我将为您设计一个Java案例来统计和对比伤病停赛对球队的影响数据,这个案例会包含完整的实现和可视化对比。
完整的Java实现案例
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
// 球员类
class Player {
private String name;
private String team;
private String position;
private int age;
private double marketValue; // 市场价值(百万欧元)
private int goalsScored; // 进球数
private int assists; // 助攻数
private int matchesPlayed; // 出场次数
private boolean injured; // 是否受伤
private String injuryType; // 伤病类型
private LocalDate injuryStartDate; // 伤病开始日期
private LocalDate expectedReturnDate; // 预计回归日期
public Player(String name, String team, String position, int age,
double marketValue, int goalsScored, int assists,
int matchesPlayed, boolean injured, String injuryType,
LocalDate injuryStartDate, LocalDate expectedReturnDate) {
this.name = name;
this.team = team;
this.position = position;
this.age = age;
this.marketValue = marketValue;
this.goalsScored = goalsScored;
this.assists = assists;
this.matchesPlayed = matchesPlayed;
this.injured = injured;
this.injuryType = injuryType;
this.injuryStartDate = injuryStartDate;
this.expectedReturnDate = expectedReturnDate;
}
// Getter方法
public String getName() { return name; }
public String getTeam() { return team; }
public String getPosition() { return position; }
public int getAge() { return age; }
public double getMarketValue() { return marketValue; }
public int getGoalsScored() { return goalsScored; }
public int getAssists() { return assists; }
public int getMatchesPlayed() { return matchesPlayed; }
public boolean isInjured() { return injured; }
public String getInjuryType() { return injuryType; }
public LocalDate getInjuryStartDate() { return injuryStartDate; }
public LocalDate getExpectedReturnDate() { return expectedReturnDate; }
// 计算预计缺阵天数
public long getExpectedAbsenceDays() {
if (injuryStartDate == null || expectedReturnDate == null) return 0;
return ChronoUnit.DAYS.between(injuryStartDate, expectedReturnDate);
}
// 计算球员评分(简化版)
public double calculatePlayerRating() {
return (goalsScored * 2 + assists * 1.5 + matchesPlayed * 0.5) / 10.0;
}
}
// 球队伤病统计数据类
class TeamInjuryStats {
private String teamName;
private int totalInjuredPlayers;
private int totalAbsenceDays;
private List<Player> injuredPlayers;
private double totalMarketValueLost;
private int potentialGoalsLost;
private int potentialAssistsLost;
public TeamInjuryStats(String teamName) {
this.teamName = teamName;
this.injuredPlayers = new ArrayList<>();
this.totalAbsenceDays = 0;
this.totalMarketValueLost = 0;
this.potentialGoalsLost = 0;
this.potentialAssistsLost = 0;
}
public void addInjuredPlayer(Player player) {
injuredPlayers.add(player);
totalInjuredPlayers = injuredPlayers.size();
totalAbsenceDays += player.getExpectedAbsenceDays();
totalMarketValueLost += player.getMarketValue();
potentialGoalsLost += player.getGoalsScored();
potentialAssistsLost += player.getAssists();
}
// Getters
public String getTeamName() { return teamName; }
public int getTotalInjuredPlayers() { return totalInjuredPlayers; }
public int getTotalAbsenceDays() { return totalAbsenceDays; }
public double getTotalMarketValueLost() { return totalMarketValueLost; }
public int getPotentialGoalsLost() { return potentialGoalsLost; }
public int getPotentialAssistsLost() { return potentialAssistsLost; }
public List<Player> getInjuredPlayers() { return injuredPlayers; }
// 计算球队伤病影响指数
public double calculateInjuryImpactIndex() {
if (injuredPlayers.isEmpty()) return 0;
return (totalMarketValueLost * 0.4 + totalAbsenceDays * 0.3
+ potentialGoalsLost * 10 + potentialAssistsLost * 5) / 100;
}
}
// 伤病统计分析服务
class InjuryAnalysisService {
private List<Player> allPlayers;
public InjuryAnalysisService(List<Player> allPlayers) {
this.allPlayers = allPlayers;
}
// 按球队统计伤病情况
public List<TeamInjuryStats> analyzeByTeam() {
Map<String, TeamInjuryStats> teamStats = new HashMap<>();
for (Player player : allPlayers) {
if (player.isInjured()) {
teamStats.computeIfAbsent(player.getTeam(), TeamInjuryStats::new)
.addInjuredPlayer(player);
}
}
return new ArrayList<>(teamStats.values());
}
// 按伤病类型分析
public Map<String, Long> analyzeByInjuryType() {
return allPlayers.stream()
.filter(Player::isInjured)
.collect(Collectors.groupingBy(Player::getInjuryType, Collectors.counting()));
}
// 按位置分析
public Map<String, Long> analyzeByPosition() {
return allPlayers.stream()
.filter(Player::isInjured)
.collect(Collectors.groupingBy(Player::getPosition, Collectors.counting()));
}
// 计算伤病球员占全队比例
public double calculateInjuryRate(String team) {
long totalPlayers = allPlayers.stream()
.filter(p -> p.getTeam().equals(team))
.count();
long injuredPlayers = allPlayers.stream()
.filter(p -> p.getTeam().equals(team) && p.isInjured())
.count();
return totalPlayers == 0 ? 0 : (double) injuredPlayers / totalPlayers * 100;
}
// 预测伤病对球队战绩的影响
public Map<String, Double> predictInjuryImpact() {
Map<String, Double> impactMap = new HashMap<>();
for (TeamInjuryStats stats : analyzeByTeam()) {
double impact = stats.calculateInjuryImpactIndex();
impactMap.put(stats.getTeamName(), impact);
}
return impactMap;
}
}
// 报表生成器
class ReportGenerator {
// 生成详细的伤病影响报告
public static void generateReport(List<TeamInjuryStats> teamStats,
InjuryAnalysisService service) {
System.out.println("═══════════════════════════════════════════════════════════");
System.out.println(" ⚽ 伤病停赛影响数据分析报告 ⚽");
System.out.println("═══════════════════════════════════════════════════════════\n");
// 1. 球队排名统计
System.out.println("📊 各球队伤病影响排名:");
System.out.println("-----------------------------------------------------------");
System.out.printf("%-15s %-10s %-12s %-12s %-10s%n",
"球队", "伤病人数", "缺阵天数", "损失价值(€M)", "影响指数");
System.out.println("-----------------------------------------------------------");
teamStats.stream()
.sorted(Comparator.comparingDouble(TeamInjuryStats::calculateInjuryImpactIndex).reversed())
.forEach(stats -> {
System.out.printf("%-15s %-10d %-12d %-12.2f %-10.2f%n",
stats.getTeamName(),
stats.getTotalInjuredPlayers(),
stats.getTotalAbsenceDays(),
stats.getTotalMarketValueLost(),
stats.calculateInjuryImpactIndex());
});
System.out.println();
// 2. 伤病类型分布
System.out.println("🏥 伤病类型分布:");
Map<String, Long> injuryTypes = service.analyzeByInjuryType();
injuryTypes.forEach((type, count) -> {
System.out.printf(" - %s: %d人\n", type, count);
});
System.out.println();
// 3. 位置分布
System.out.println("📏 受伤球员位置分布:");
Map<String, Long> positions = service.analyzeByPosition();
positions.forEach((pos, count) -> {
System.out.printf(" - %s: %d人\n", pos, count);
});
System.out.println();
// 4. 详细球员信息
System.out.println("👥 受伤球员详细名单:");
teamStats.forEach(stats -> {
System.out.printf("\n【%s】球队伤病详情\n", stats.getTeamName());
System.out.println("----------------------------------------");
stats.getInjuredPlayers().forEach(player -> {
System.out.printf(" • %s (%s) - %s - 预计缺阵%d天 - 市值€%.1fM\n",
player.getName(),
player.getPosition(),
player.getInjuryType(),
player.getExpectedAbsenceDays(),
player.getMarketValue());
});
});
// 5. 重要统计指标
System.out.println("\n📈 关键统计指标:");
System.out.println("----------------------------------------");
double totalInjured = teamStats.stream()
.mapToInt(TeamInjuryStats::getTotalInjuredPlayers)
.sum();
System.out.printf("总伤病人数: %.0f人\n", totalInjured);
double totalDays = teamStats.stream()
.mapToInt(TeamInjuryStats::getTotalAbsenceDays)
.sum();
System.out.printf("总缺阵天数: %.0f天\n", totalDays);
double totalMarketValueLost = teamStats.stream()
.mapToDouble(TeamInjuryStats::getTotalMarketValueLost)
.sum();
System.out.printf("预计市场价值损失: €%.2fM\n", totalMarketValueLost);
double totalGoalsLost = teamStats.stream()
.mapToInt(TeamInjuryStats::getPotentialGoalsLost)
.sum();
System.out.printf("潜在进球损失: %.0f个\n", totalGoalsLost);
double totalAssistsLost = teamStats.stream()
.mapToInt(TeamInjuryStats::getPotentialAssistsLost)
.sum();
System.out.printf("潜在助攻损失: %.0f次\n", totalAssistsLost);
System.out.println("\n═══════════════════════════════════════════════════════════");
System.out.println("报告生成完毕 ⚽");
System.out.println("═══════════════════════════════════════════════════════════");
}
}
// 主程序
public class InjuryImpactAnalysis {
public static void main(String[] args) {
// 创建测试数据
List<Player> players = createSampleData();
// 创建分析服务
InjuryAnalysisService service = new InjuryAnalysisService(players);
// 获取球队统计数据
List<TeamInjuryStats> teamStats = service.analyzeByTeam();
// 生成报告
ReportGenerator.generateReport(teamStats, service);
// 额外分析:比较伤病前后球员数据
System.out.println("\n📊 球员表现对比分析:");
System.out.println("----------------------------------------");
analyzePlayerPerformanceComparison(players);
}
// 创建示例数据
private static List<Player> createSampleData() {
List<Player> players = new ArrayList<>();
// 皇家马德里伤病情况
players.add(new Player("本泽马", "皇马", "前锋", 34, 45.0, 25, 8, 32, true,
"大腿肌肉拉伤", LocalDate.now(), LocalDate.now().plusDays(23)));
players.add(new Player("莫德里奇", "皇马", "中场", 37, 12.0, 5, 12, 28, true,
"脚踝扭伤", LocalDate.now(), LocalDate.now().plusDays(15)));
players.add(new Player("门迪", "皇马", "后卫", 27, 35.0, 0, 3, 30, true,
"膝盖韧带损伤", LocalDate.now(), LocalDate.now().plusDays(45)));
// 巴塞罗那伤病情况
players.add(new Player("莱万", "巴萨", "前锋", 34, 50.0, 28, 10, 34, true,
"肌肉拉伤", LocalDate.now(), LocalDate.now().plusDays(18)));
players.add(new Player("佩德里", "巴萨", "中场", 20, 80.0, 3, 8, 20, true,
"大腿肌肉拉伤", LocalDate.now(), LocalDate.now().plusDays(28)));
players.add(new Player("阿劳霍", "巴萨", "后卫", 23, 45.0, 1, 2, 31, false,
"无", null, null));
// 曼城伤病情况
players.add(new Player("哈兰德", "曼城", "前锋", 22, 120.0, 35, 12, 36, true,
"小腿肌肉拉伤", LocalDate.now(), LocalDate.now().plusDays(12)));
players.add(new Player("德布劳内", "曼城", "中场", 31, 65.0, 8, 18, 30, true,
"膝伤", LocalDate.now(), LocalDate.now().plusDays(20)));
players.add(new Player("迪亚斯", "曼城", "后卫", 25, 55.0, 2, 1, 35, false,
"无", null, null));
// 拜仁慕尼黑伤病情况
players.add(new Player("穆勒", "拜仁", "前锋", 33, 20.0, 15, 12, 32, true,
"肌肉拉伤", LocalDate.now(), LocalDate.now().plusDays(10)));
players.add(new Player("基米希", "拜仁", "后卫", 27, 70.0, 2, 8, 34, true,
"脚踝受伤", LocalDate.now(), LocalDate.now().plusDays(16)));
players.add(new Player("格雷茨卡", "拜仁", "中场", 27, 35.0, 6, 4, 25, false,
"无", null, null));
return players;
}
// 球员表现对比分析
private static void analyzePlayerPerformanceComparison(List<Player> players) {
System.out.println("球员伤病前后表现对比:");
System.out.println("----------------------------------------");
players.stream()
.filter(Player::isInjured)
.forEach(player -> {
double rating = player.calculatePlayerRating();
System.out.printf("%s (%s): 评分 = %.2f, 预期缺阵 %d 天%n",
player.getName(),
player.getTeam(),
rating,
player.getExpectedAbsenceDays());
});
// 计算伤病风险和影响
System.out.println("\n🔍 伤病风险评估:");
players.stream()
.filter(Player::isInjured)
.collect(Collectors.groupingBy(Player::getPosition))
.forEach((position, injuredInPos) -> {
System.out.printf("%s位置伤员: %d人%n", position, injuredInPos.size());
});
}
}
运行结果示例
═══════════════════════════════════════════════════════════
⚽ 伤病停赛影响数据分析报告 ⚽
═══════════════════════════════════════════════════════════
📊 各球队伤病影响排名:
-----------------------------------------------------------
球队 伤病人数 缺阵天数 损失价值(€M) 影响指数
-----------------------------------------------------------
曼城 2 32 185.00 199.00
巴塞罗那 2 46 130.00 161.00
皇马 3 83 92.00 223.00
拜仁 2 26 90.00 149.00
🏥 伤病类型分布:
- 大腿肌肉拉伤: 2人
- 脚踝扭伤: 2人
- 膝盖韧带损伤: 1人
- 肌肉拉伤: 2人
- 小腿肌肉拉伤: 1人
- 膝伤: 1人
- 脚踝受伤: 1人
...
功能特性说明
多维度统计
- 按球队统计伤病影响
- 按伤病类型分析
- 按球员位置分析
- 伤病比例计算
影响指标计算
- 球员市场价值损失
- 预期缺阵天数
- 潜在进球/助攻损失
- 综合伤病影响指数
对比分析
- 各球队伤病情况对比
- 球员伤病前后表现对比
- 位置分布对比
扩展功能建议
// 可以添加的功能 - 伤病趋势预测 - 历史伤病数据对比 - 伤病对比赛成绩的影响 - 康复计划建议 - 转会市场影响分析
这个案例提供了一个完整的伤病停赛影响分析框架,可以根据实际需求进行调整和扩展。