Skip to content

Commit

Permalink
Added Fotmob goalkeeper parsing support
Browse files Browse the repository at this point in the history
  • Loading branch information
This-Is-Ko committed Oct 9, 2023
1 parent 7a66b76 commit 56cc24c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 56cc24c

Please sign in to comment.