对英雄联盟比赛预测(四)- 数据清洗

对英雄联盟比赛预测(四)- 数据清洗系列文章目录提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加例如:第一章Python机器学习入门之pandas的使用提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档文章

 

系列文章目录

对英雄联盟比赛预测(一)- 特征分析

对英雄联盟比赛预测(二)- 数据获取api分析

对英雄联盟比赛预测(三)- 数据获取Java实现

对英雄联盟比赛预测(四)- 数据清洗


 

 


前言

本文主要对前文获取的数据,做清洗,去除脏数据,并格式化。

文章三中最新代码:https://github.com/majixiang/riotgames-spider ,欢迎大家指正。


 

一、数据原型

通过前面第三篇文章,介绍从官网获取数据,本人已经获取了26万条数据,也就是13万场比赛,因这些数据都是json格式的,不适合后续处理,所以需要将这些数据合并成csv文件

对英雄联盟比赛预测(四)- 数据清洗

二、步骤

1. 引入相关依赖

项目使用gradle编译,commons-io用来读写文件,fastjson用来解析json,hutool用来生成csv文件流。

    compileOnly 'org.projectlombok:lombok:1.18.18'
    implementation 'org.apache.commons:commons-lang3:3.11'
    implementation 'commons-io:commons-io:2.6'
    implementation 'com.jayway.jsonpath:json-path:2.4.0'
    implementation 'com.alibaba:fastjson:1.2.75'
    implementation 'cn.hutool:hutool-all:5.5.7'

 

2. 相关实体类

实体类和文章三里一致,并新增一个Game类,用来存放csv的行数据,如下:


import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author jixiang.ma
 * @date 2021/2/4 11:39
 **/
@Getter
@Setter
@ToString
public class Game {
    private long gameId;
    private long gameCreation;
    private int gameDuration;
    private int queueId;
    private int mapId;
    private int seasonId;

    private int win;
    private int firstBlood;
    private int firstTower;
    private int firstInhibitor;
    private int firstBaron;
    private int firstDragon;
    private int firstRiftHerald;

    private int t1_towerKills;
    private int t1_inhibitorKills;
    private int t1_baronKills;
    private int t1_dragonKills;
    private int t1_vilemawKills;
    private int t1_riftHeraldKills;
    private int t1_dominionVictoryScore;

    // 总击杀数
    private int t1_kills;
    private int t1_deaths;
    private int t1_assists;
    // 整个团队的最大连杀数
    private int t1_largestKillingSpree;
    private int t1_largestMultiKill;
    private int t1_killingSprees;
    private int t1_longestTimeSpentLiving;
    //整个团队双杀的次数
    private int t1_doubleKills;
    private int t1_tripleKills;
    private int t1_quadraKills;
    private int t1_pentaKills;
    private int t1_unrealKills;
    // 团队总伤害
    private int t1_totalDamageDealt;
    // 魔法伤害
    private int t1_magicDamageDealt;
    // 物理伤害
    private int t1_physicalDamageDealt;
    // 真实伤害
    private int t1_trueDamageDealt;
    // 造成的最大伤害
    private int t1_largestCriticalStrike;
    // 对英雄的总伤害
    private int t1_totalDamageDealtToChampions;
    private int t1_magicDamageDealtToChampions;
    private int t1_physicalDamageDealtToChampions;
    private int t1_trueDamageDealtToChampions;
    private int t1_totalHeal;
    private int t1_totalUnitsHealed;
    private int t1_damageSelfMitigated;
    private int t1_damageDealtToObjectives;
    private int t1_damageDealtToTurrets;
    private int t1_visionScore;
    private int t1_timeCCingOthers;
    private int t1_totalDamageTaken;
    private int t1_magicalDamageTaken;
    private int t1_physicalDamageTaken;
    private int t1_trueDamageTaken;
    private int t1_goldEarned;
    private int t1_goldSpent;
    // 补兵数
    private int t1_totalMinionsKilled;
    // 野怪数
    private int t1_neutralMinionsKilled;
    private int t1_totalTimeCrowdControlDealt;
    private int t1_champLevel;
    private int t1_visionWardsBoughtInGame;
    private int t1_sightWardsBoughtInGame;

    private int t2_towerKills;
    private int t2_inhibitorKills;
    private int t2_baronKills;
    private int t2_dragonKills;
    private int t2_vilemawKills;
    private int t2_riftHeraldKills;
    private int t2_dominionVictoryScore;

    // 总击杀数
    private int t2_kills;
    private int t2_deaths;
    private int t2_assists;
    // 整个团队的最大连杀数
    private int t2_largestKillingSpree;
    private int t2_largestMultiKill;
    private int t2_killingSprees;
    private int t2_longestTimeSpentLiving;
    //整个团队双杀的次数
    private int t2_doubleKills;
    private int t2_tripleKills;
    private int t2_quadraKills;
    private int t2_pentaKills;
    private int t2_unrealKills;
    // 团队总伤害
    private int t2_totalDamageDealt;
    // 魔法伤害
    private int t2_magicDamageDealt;
    // 物理伤害
    private int t2_physicalDamageDealt;
    // 真实伤害
    private int t2_trueDamageDealt;
    // 造成的最大伤害
    private int t2_largestCriticalStrike;
    // 对英雄的总伤害
    private int t2_totalDamageDealtToChampions;
    private int t2_magicDamageDealtToChampions;
    private int t2_physicalDamageDealtToChampions;
    private int t2_trueDamageDealtToChampions;
    private int t2_totalHeal;
    private int t2_totalUnitsHealed;
    private int t2_damageSelfMitigated;
    private int t2_damageDealtToObjectives;
    private int t2_damageDealtToTurrets;
    private int t2_visionScore;
    private int t2_timeCCingOthers;
    private int t2_totalDamageTaken;
    private int t2_magicalDamageTaken;
    private int t2_physicalDamageTaken;
    private int t2_trueDamageTaken;
    private int t2_goldEarned;
    private int t2_goldSpent;
    // 补兵数
    private int t2_totalMinionsKilled;
    // 野怪数
    private int t2_neutralMinionsKilled;
    private int t2_totalTimeCrowdControlDealt;
    private int t2_champLevel;
    private int t2_visionWardsBoughtInGame;
    private int t2_sightWardsBoughtInGame;

}

 

3. 清洗


import cn.hutool.Hutool;
import cn.hutool.core.text.csv.CsvUtil;
import cn.hutool.core.text.csv.CsvWriter;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import com.jayway.jsonpath.JsonPath;
import io.transwarp.entity.Match;
import io.transwarp.entity.MatchDetail;
import io.transwarp.entity.Participants;
import io.transwarp.entity.Win;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author jixiang.ma
 * @date 2021/2/4 10:15
 **/
public class DataClean {
    public static void main(String[] args) throws IOException {
        // json数据源
        String jsonPath = "E:\\data\\data\\";
        File jsonPathFile = new File(jsonPath);

        if (jsonPathFile.isDirectory()) {
            File[] files = jsonPathFile.listFiles();
            // 要输出的csv路径
            CsvWriter writer = CsvUtil.getWriter(new File("D:/games.csv"), Charset.forName("UTF-8"), true);
            writer.writeLine("gameId",
                    "gameCreation",
                    "gameDuration",
                    "queueId",
                    "mapId",
                    "seasonId",
                    "win",
                    "firstBlood",
                    "firstTower",
                    "firstInhibitor",
                    "firstBaron",
                    "firstDragon",
                    "firstRiftHerald",
                    "t1_towerKills",
                    "t1_inhibitorKills",
                    "t1_baronKills",
                    "t1_dragonKills",
                    "t1_riftHeraldKills",
                    "t1_dominionVictoryScore",
                    "t1_kills",
                    "t1_deaths",
                    "t1_assists",
                    "t1_largestKillingSpree",
                    "t1_largestMultiKill",
                    "t1_killingSprees",
                    "t1_longestTimeSpentLiving",
                    "t1_doubleKills",
                    "t1_tripleKills",
                    "t1_quadraKills",
                    "t1_pentaKills",
                    "t1_unrealKills",
                    "t1_totalDamageDealt",
                    "t1_magicDamageDealt",
                    "t1_physicalDamageDealt",
                    "t1_trueDamageDealt",
                    "t1_largestCriticalStrike",
                    "t1_totalDamageDealtToChampions",
                    "t1_magicDamageDealtToChampions",
                    "t1_physicalDamageDealtToChampion",
                    "t1_trueDamageDealtToChampions",
                    "t1_totalHeal",
                    "t1_totalUnitsHealed",
                    "t1_damageSelfMitigated",
                    "t1_damageDealtToObjectives",
                    "t1_damageDealtToTurrets",
                    "t1_visionScore",
                    "t1_timeCCingOthers",
                    "t1_totalDamageTaken",
                    "t1_magicalDamageTaken",
                    "t1_physicalDamageTaken",
                    "t1_trueDamageTaken",
                    "t1_goldEarned",
                    "t1_goldSpent",
                    "t1_totalMinionsKilled",
                    "t1_neutralMinionsKilled",
                    "t1_totalTimeCrowdControlDealt",
                    "t1_champLevel",
                    "t1_visionWardsBoughtInGame",
                    "t1_sightWardsBoughtInGame",


                    "t2_towerKills",
                    "t2_inhibitorKills",
                    "t2_baronKills",
                    "t2_dragonKills",
                    "t2_riftHeraldKills",
                    "t2_dominionVictoryScore",
                    "t2_kills",
                    "t2_deaths",
                    "t2_assists",
                    "t2_largestKillingSpree",
                    "t2_largestMultiKill",
                    "t2_killingSprees",
                    "t2_longestTimeSpentLiving",
                    "t2_doubleKills",
                    "t2_tripleKills",
                    "t2_quadraKills",
                    "t2_pentaKills",
                    "t2_unrealKills",
                    "t2_totalDamageDealt",
                    "t2_magicDamageDealt",
                    "t2_physicalDamageDealt",
                    "t2_trueDamageDealt",
                    "t2_largestCriticalStrike",
                    "t2_totalDamageDealtToChampions",
                    "t2_magicDamageDealtToChampions",
                    "t2_physicalDamageDealtToChampions",
                    "t2_trueDamageDealtToChampions",
                    "t2_totalHeal",
                    "t2_totalUnitsHealed",
                    "t2_damageSelfMitigated",
                    "t2_damageDealtToObjectives",
                    "t2_damageDealtToTurrets",
                    "t2_visionScore",
                    "t2_timeCCingOthers",
                    "t2_totalDamageTaken",
                    "t2_magicalDamageTaken",
                    "t2_physicalDamageTaken",
                    "t2_trueDamageTaken",
                    "t2_goldEarned",
                    "t2_goldSpent",
                    "t2_totalMinionsKilled",
                    "t2_neutralMinionsKilled",
                    "t2_totalTimeCrowdControlDealt",
                    "t2_champLevel",
                    "t2_visionWardsBoughtInGame",
                    "t2_sightWardsBoughtInGame");
            for (File file : files) {
                if (file.getName().contains("detail")) {
                    System.out.println("current file is : " + file.getName());
                    String data = FileUtils.readFileToString(file, Charset.forName("UTF-8"));
                    MatchDetail matchDetail = JSONObject.toJavaObject(JSONObject.parseObject(data), MatchDetail.class);
                    if(null == matchDetail.getGameId()) {
                        continue;
                    }
                    writer.writeLine(matchDetail.getGameId().toString(),
                            matchDetail.getGameCreation().toString(),
                            matchDetail.getGameDuration().toString(),
                            matchDetail.getQueueId().toString(),
                            matchDetail.getMapId().toString(),
                            matchDetail.getSeasonId().toString(),
                            getWin(matchDetail),
                            getFirstBlood(matchDetail),
                            getFirstTower(matchDetail),
                            getFirstInhibitor(matchDetail),
                            getFirstBaron(matchDetail),
                            getFirstDragon(matchDetail),
                            getFirstRiftHerald(matchDetail),
                            getTowerKills(matchDetail, 1),
                            getInhibitorKills(matchDetail, 1),
                            getBaronKills(matchDetail, 1),
                            getDragonKills(matchDetail, 1),
                            getRiftHeraldKills(matchDetail, 1),
                            getDominionVictoryScore(matchDetail, 1),
                            getKills(matchDetail, 1),
                            getDeaths(matchDetail, 1),
                            getAssists(matchDetail, 1),
                            getLargestKillingSpree(matchDetail, 1),
                            getLargestMultiKill(matchDetail, 1),
                            getKillSprees(matchDetail, 1),
                            getLongestTimeSpentLiving(matchDetail, 1),
                            getDoubleKills(matchDetail, 1),
                            getTripleKills(matchDetail, 1),
                            getQuadraKills(matchDetail, 1),
                            getPentaKills(matchDetail, 1),
                            getTotalDamageDealt(matchDetail, 1),
                            getMagicDamageDealt(matchDetail, 1),
                            getPhysicalDamageDealt(matchDetail, 1),
                            getTrueDamageDealt(matchDetail, 1),
                            getLargestCriticalStrike(matchDetail, 1),
                            getTotalDamageDealtToChampions(matchDetail, 1),
                            getMagicDamageDealtToChampions(matchDetail, 1),
                            getPhysicalDamageDealtToChampions(matchDetail, 1),
                            getTrueDamageDealtToChampions(matchDetail, 1),
                            getTotalHeal(matchDetail, 1),
                            getTotalUnitsHealed(matchDetail, 1),
                            getDamageSelfMitigated(matchDetail, 1),
                            getDamageDealtToObjectives(matchDetail, 1),
                            getDamageDealtToTurrets(matchDetail, 1),
                            getVisionScore(matchDetail, 1),
                            getTimeCCingOthers(matchDetail, 1),
                            getTotalDamageTaken(matchDetail, 1),
                            getMagicalDamageTaken(matchDetail, 1),
                            getPhysicalDamageTaken(matchDetail, 1),
                            getTrueDamageTaken(matchDetail, 1),
                            getGoldEarned(matchDetail, 1),
                            getGoldSpent(matchDetail, 1),
                            getTotalMinionsKilled(matchDetail, 1),
                            getNeutralMinionsKilled(matchDetail, 1),
                            getTotalTimeCrowdControlDealt(matchDetail, 1),
                            getChampLevel(matchDetail, 1),
                            getVisionWardsBoughtInGame(matchDetail, 1),
                            getSightWardsBoughtInGame(matchDetail, 1),

                            getTowerKills(matchDetail, 2),
                            getInhibitorKills(matchDetail, 2),
                            getBaronKills(matchDetail, 2),
                            getDragonKills(matchDetail, 2),
                            getRiftHeraldKills(matchDetail, 2),
                            getDominionVictoryScore(matchDetail, 2),
                            getKills(matchDetail, 2),
                            getDeaths(matchDetail, 2),
                            getAssists(matchDetail, 2),
                            getLargestKillingSpree(matchDetail, 2),
                            getLargestMultiKill(matchDetail, 2),
                            getKillSprees(matchDetail, 2),
                            getLongestTimeSpentLiving(matchDetail, 2),
                            getDoubleKills(matchDetail, 2),
                            getTripleKills(matchDetail, 2),
                            getQuadraKills(matchDetail, 2),
                            getPentaKills(matchDetail, 2),
                            getTotalDamageDealt(matchDetail, 2),
                            getMagicDamageDealt(matchDetail, 2),
                            getPhysicalDamageDealt(matchDetail, 2),
                            getTrueDamageDealt(matchDetail, 2),
                            getLargestCriticalStrike(matchDetail, 2),
                            getTotalDamageDealtToChampions(matchDetail, 2),
                            getMagicDamageDealtToChampions(matchDetail, 2),
                            getPhysicalDamageDealtToChampions(matchDetail, 2),
                            getTrueDamageDealtToChampions(matchDetail, 2),
                            getTotalHeal(matchDetail, 2),
                            getTotalUnitsHealed(matchDetail, 2),
                            getDamageSelfMitigated(matchDetail, 2),
                            getDamageDealtToObjectives(matchDetail, 2),
                            getDamageDealtToTurrets(matchDetail, 2),
                            getVisionScore(matchDetail, 2),
                            getTimeCCingOthers(matchDetail, 2),
                            getTotalDamageTaken(matchDetail, 2),
                            getMagicalDamageTaken(matchDetail, 2),
                            getPhysicalDamageTaken(matchDetail, 2),
                            getTrueDamageTaken(matchDetail, 2),
                            getGoldEarned(matchDetail, 2),
                            getGoldSpent(matchDetail, 2),
                            getTotalMinionsKilled(matchDetail, 2),
                            getNeutralMinionsKilled(matchDetail, 2),
                            getTotalTimeCrowdControlDealt(matchDetail, 2),
                            getChampLevel(matchDetail, 2),
                            getVisionWardsBoughtInGame(matchDetail, 2),
                            getSightWardsBoughtInGame(matchDetail, 2)
                    );
                }
            }
        }
    }

    private static String getWin(MatchDetail matchDetail) {
        return Win.Win.equals(matchDetail.getTeams().get(0).getWin()) ? "1" : "2";
    }

    private static String getFirstBlood(MatchDetail matchDetail) {
        return matchDetail.getTeams().get(0).getFirstBlood() ? "1" : "2";
    }

    private static String getFirstTower(MatchDetail matchDetail) {
        return matchDetail.getTeams().get(0).getFirstTower() ? "1" : "2";
    }

    private static String getFirstInhibitor(MatchDetail matchDetail) {
        return matchDetail.getTeams().get(0).getFirstInhibitor() ? "1" : "2";
    }

    private static String getFirstBaron(MatchDetail matchDetail) {
        return matchDetail.getTeams().get(0).getFirstBaron() ? "1" : "2";
    }

    private static String getFirstDragon(MatchDetail matchDetail) {
        return matchDetail.getTeams().get(0).getFirstDragon() ? "1" : "2";
    }

    private static String getFirstRiftHerald(MatchDetail matchDetail) {
        return matchDetail.getTeams().get(0).getFirstRiftHerald() ? "1" : "2";
    }

    private static String getTowerKills(MatchDetail matchDetail, int team) {
        return matchDetail.getTeams().get(team - 1).getTowerKills() + "";
    }

    private static String getInhibitorKills(MatchDetail matchDetail, int team) {
        return matchDetail.getTeams().get(team - 1).getTowerKills() + "";
    }

    private static String getBaronKills(MatchDetail matchDetail, int team) {
        return matchDetail.getTeams().get(team - 1).getBaronKills() + "";
    }

    private static String getDragonKills(MatchDetail matchDetail, int team) {
        return matchDetail.getTeams().get(team - 1).getDragonKills() + "";
    }

    private static String getRiftHeraldKills(MatchDetail matchDetail, int team) {
        return matchDetail.getTeams().get(team - 1).getRiftHeraldKills() + "";
    }

    private static String getDominionVictoryScore(MatchDetail matchDetail, int team) {
        return matchDetail.getTeams().get(team - 1).getDominionVictoryScore() + "";
    }

    private static String getKills(MatchDetail matchDetail, int team) {
        int totalKills = filter(matchDetail, team).mapToInt(p -> p.getStats().getKills()).sum();
        return totalKills + "";
    }

    private static String getDeaths(MatchDetail matchDetail, int team) {
        int totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getDeaths()).sum();
        return totalDeaths + "";
    }

    private static String getAssists(MatchDetail matchDetail, int team) {
        int totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getAssists()).sum();
        return totalDeaths + "";
    }

    private static String getLargestKillingSpree(MatchDetail matchDetail, int team) {
        int totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getLargestKillingSpree()).max().orElse(0);
        return totalDeaths + "";
    }

    private static String getLargestMultiKill(MatchDetail matchDetail, int team) {
        int totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getLargestMultiKill()).max().orElse(0);
        return totalDeaths + "";
    }

    private static String getKillSprees(MatchDetail matchDetail, int team) {
        int totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getKillingSprees()).max().orElse(0);
        return totalDeaths + "";
    }

    private static String getLongestTimeSpentLiving(MatchDetail matchDetail, int team) {
        int totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getLongestTimeSpentLiving()).max().orElse(0);
        return totalDeaths + "";
    }

    private static String getDoubleKills(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getDoubleKills()).sum();
        return totalDeaths + "";
    }

    private static String getTripleKills(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTripleKills()).sum();
        return totalDeaths + "";
    }

    private static String getQuadraKills(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTripleKills()).sum();
        return totalDeaths + "";
    }

    private static String getPentaKills(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getPentaKills()).sum();
        return totalDeaths + "";
    }

    private static String getTotalDamageDealt(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTotalDamageDealt()).sum();
        return totalDeaths + "";
    }

    private static String getMagicDamageDealt(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getMagicDamageDealt()).sum();
        return totalDeaths + "";
    }

    private static String getPhysicalDamageDealt(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getPhysicalDamageDealt()).sum();
        return totalDeaths + "";
    }

    private static String getTrueDamageDealt(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTrueDamageDealt()).sum();
        return totalDeaths + "";
    }

    private static String getLargestCriticalStrike (MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getLargestCriticalStrike()).sum();
        return totalDeaths + "";
    }

    private static String getTotalDamageDealtToChampions(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTotalDamageDealtToChampions()).sum();
        return totalDeaths + "";
    }

    private static String getMagicDamageDealtToChampions(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getMagicDamageDealtToChampions()).sum();
        return totalDeaths + "";
    }

    private static String getPhysicalDamageDealtToChampions(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getPhysicalDamageDealtToChampions()).sum();
        return totalDeaths + "";
    }

    private static String getTrueDamageDealtToChampions (MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTrueDamageDealtToChampions()).sum();
        return totalDeaths + "";
    }

    private static String getTotalHeal(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTotalHeal()).sum();
        return totalDeaths + "";
    }

    private static String getTotalUnitsHealed(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTotalUnitsHealed()).sum();
        return totalDeaths + "";
    }

    private static String getDamageSelfMitigated (MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getDamageSelfMitigated()).sum();
        return totalDeaths + "";
    }

    private static String getDamageDealtToObjectives(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getDamageDealtToObjectives()).sum();
        return totalDeaths + "";
    }

    private static String getDamageDealtToTurrets (MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getDamageDealtToTurrets()).sum();
        return totalDeaths + "";
    }

    private static String getVisionScore(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getVisionScore()).sum();
        return totalDeaths + "";
    }

    private static String getTimeCCingOthers(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTimeCCingOthers()).sum();
        return totalDeaths + "";
    }

    private static String getTotalDamageTaken(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTotalDamageTaken()).sum();
        return totalDeaths + "";
    }

    private static String getMagicalDamageTaken(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getMagicalDamageTaken()).sum();
        return totalDeaths + "";
    }

    private static String getPhysicalDamageTaken(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getPhysicalDamageTaken()).sum();
        return totalDeaths + "";
    }

    private static String getTrueDamageTaken(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTrueDamageTaken()).sum();
        return totalDeaths + "";
    }

    private static String getGoldEarned(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getGoldEarned()).sum();
        return totalDeaths + "";
    }

    private static String getGoldSpent(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getGoldSpent()).sum();
        return totalDeaths + "";
    }

    private static String getTotalMinionsKilled(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTotalMinionsKilled()).sum();
        return totalDeaths + "";
    }

    private static String getNeutralMinionsKilled(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getNeutralMinionsKilled()).sum();
        return totalDeaths + "";
    }

    private static String getTotalTimeCrowdControlDealt(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getTotalTimeCrowdControlDealt()).sum();
        return totalDeaths + "";
    }

    private static String getChampLevel (MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getChampLevel()).sum();
        return totalDeaths + "";
    }

    private static String getVisionWardsBoughtInGame(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getVisionWardsBoughtInGame()).sum();
        return totalDeaths + "";
    }

    private static String getSightWardsBoughtInGame(MatchDetail matchDetail, int team) {
        long totalDeaths = filter(matchDetail, team).mapToInt(p -> p.getStats().getSightWardsBoughtInGame()).sum();
        return totalDeaths + "";
    }


    private static Stream<Participants> filter(MatchDetail matchDetail, int team) {
        return matchDetail.getParticipants().stream()
                .filter(participants -> {
                    if (participants.getTeamId() == (team * 100)) {
                        return true;
                    } else {
                        return false;
                    }
                });
    }
}

 

4. 结果

经过清洗后,最终生成了一个116186行数据的csv文件

对英雄联盟比赛预测(四)- 数据清洗


总结

本文主要讲述从前文获得的json文件,清洗后转换成方便后续使用的csv文件。

 

下一节将介绍预测中的特征工程。

今天的文章对英雄联盟比赛预测(四)- 数据清洗分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/67785.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注