From 56cc24cf9245441d9d663d67218cf67bbb1f12ed Mon Sep 17 00:00:00 2001 From: This-Is-Ko <52279273+This-Is-Ko@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:06:14 +1100 Subject: [PATCH] Added Fotmob goalkeeper parsing support --- .../datasource/FotmobDataSource.java | 23 +++++++++++++++++++ .../models/PlayerMatchPerformanceStats.java | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/main/java/com/ko/footballupdater/datasource/FotmobDataSource.java b/src/main/java/com/ko/footballupdater/datasource/FotmobDataSource.java index 70ced5b..1749cfa 100644 --- a/src/main/java/com/ko/footballupdater/datasource/FotmobDataSource.java +++ b/src/main/java/com/ko/footballupdater/datasource/FotmobDataSource.java @@ -41,6 +41,7 @@ public class FotmobDataSource implements DataSourceParser { private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); private final String BASEURL = "https://www.fotmob.com"; private final String API_MATCH_BASE_URL = "/api/matchDetails?matchId="; + private final String GOALKEEPER_FOTMOB_STRING_SHORT = "GK"; @Override public PlayerMatchPerformanceStats parsePlayerMatchData(Player player, Document document) { @@ -156,6 +157,28 @@ private PlayerMatchPerformanceStats checkPlayerAndParse(Player player, JsonNode } } + // Separate stats required for goalkeepers + if (GOALKEEPER_FOTMOB_STRING_SHORT.equals(playerEntry.get("positionStringShort").asText())) { + // Goalkeepers only contain top stats + if (topStats == null) { + return null; + } + return new PlayerMatchPerformanceStats(dataSourceSiteName, + match, + getStatIntegerOrDefault(topStats, "Minutes played", 0), + getStatIntegerOrDefault(topStats, "Touches", 0), + getStatStringOrDefault(topStats, "Accurate passes", "0"), + getStatStringOrDefault(topStats, "Accurate long balls", "0"), + getStatIntegerOrDefault(topStats, "Goals conceded", 0), + getStatStringOrDefault(topStats, "Saves", "0"), + getStatIntegerOrDefault(topStats, "Punches", 0), + getStatIntegerOrDefault(topStats, "Throws", 0), + getStatIntegerOrDefault(topStats, "High claim", 0), + getStatIntegerOrDefault(topStats, "Recoveries", 0) + ); + } + + // Outfield players require all stats if (topStats == null || attackStats == null || defenseStats == null || duelsStats == null) { return null; } diff --git a/src/main/java/com/ko/footballupdater/models/PlayerMatchPerformanceStats.java b/src/main/java/com/ko/footballupdater/models/PlayerMatchPerformanceStats.java index 9628a37..29a1acf 100644 --- a/src/main/java/com/ko/footballupdater/models/PlayerMatchPerformanceStats.java +++ b/src/main/java/com/ko/footballupdater/models/PlayerMatchPerformanceStats.java @@ -44,6 +44,7 @@ public class PlayerMatchPerformanceStats { private Integer passesAttempted; private Float passesSuccessPercentage; private String passingAccuracyAll; + private String longBallAccuracyAll; private Integer progressivePasses; private Integer passesIntoFinalThird; private Integer carries; @@ -55,6 +56,11 @@ public class PlayerMatchPerformanceStats { private Integer gkGoalsAgainst; private Integer gkSaves; private Float gkSavePercentage; + private String gkSavesAll; + private Integer gkPunches; + private Integer gkThrows; + private Integer gkHighClaim; + private Integer gkRecoveries; private Integer gkPenaltiesAttemptedAgainst; private Integer gkPenaltiesScoredAgainst; private Integer gkPenaltiesSaved; @@ -64,6 +70,23 @@ public PlayerMatchPerformanceStats(DataSourceSiteName dataSourceSiteName) { this.dataSourceSiteName = dataSourceSiteName; } + // Used by FOTMOB goalkeepers + public PlayerMatchPerformanceStats(DataSourceSiteName dataSourceSiteName, Match match, Integer minutesPlayed, Integer touches, String passingAccuracyAll, String longBallAccuracyAll, Integer gkGoalsAgainst, String gkSavesAll, Integer gkPunches, Integer gkThrows, Integer gkHighClaim, Integer gkRecoveries) { + this.dataSourceSiteName = dataSourceSiteName; + this.match = match; + this.minutesPlayed = minutesPlayed; + this.touches = touches; + this.passingAccuracyAll = passingAccuracyAll; + this.longBallAccuracyAll = longBallAccuracyAll; + this.gkGoalsAgainst = gkGoalsAgainst; + this.gkSavesAll = gkSavesAll; + this.gkPunches = gkPunches; + this.gkThrows = gkThrows; + this.gkHighClaim = gkHighClaim; + this.gkRecoveries = gkRecoveries; + } + + // Used by FOTMOB outfield players public PlayerMatchPerformanceStats(DataSourceSiteName dataSourceSiteName, Match match, Integer minutesPlayed, Integer goals, Integer assists, Integer shots, Integer shotsBlocked, Integer fouls, Integer fouled, Integer offsides, String crossingAccuracyAll, Integer dispossessed, Integer touches, String tacklingSuccessAll, Integer defensiveActions, Integer recoveries, Integer duelsWon, Integer duelsLost, Integer groundDuelsWon, Integer aerialDuelsWon, Integer chancesCreatedAll, String passingAccuracyAll, Integer passesIntoFinalThird, String carriesSuccessAll) { this.dataSourceSiteName = dataSourceSiteName; this.match = match;