Retrieve the matches for the selected leagues and seasons. Parameters ---------- include_matches_without_data : bool By default matches with and without data are returned. If False, will only return matches with data. force_cache : bool
(
self, include_matches_without_data: bool = True, force_cache: bool = False
)
| 178 | return df.loc[valid_seasons] |
| 179 | |
| 180 | def read_schedule( |
| 181 | self, include_matches_without_data: bool = True, force_cache: bool = False |
| 182 | ) -> pd.DataFrame: |
| 183 | """Retrieve the matches for the selected leagues and seasons. |
| 184 | |
| 185 | Parameters |
| 186 | ---------- |
| 187 | include_matches_without_data : bool |
| 188 | By default matches with and without data are returned. |
| 189 | If False, will only return matches with data. |
| 190 | |
| 191 | force_cache : bool |
| 192 | By default no cached data is used for the current season. |
| 193 | If True, will force the use of cached data anyway. |
| 194 | |
| 195 | Returns |
| 196 | ------- |
| 197 | pd.DataFrame |
| 198 | """ |
| 199 | df_seasons = self.read_seasons() |
| 200 | |
| 201 | matches = [] |
| 202 | |
| 203 | for (league, season), league_season in df_seasons.iterrows(): |
| 204 | league_id = league_season["league_id"] |
| 205 | season_id = league_season["season_id"] |
| 206 | url = league_season["url"] |
| 207 | |
| 208 | is_current_season = not self._is_complete(league, season) |
| 209 | no_cache = is_current_season and not force_cache |
| 210 | |
| 211 | data = self._read_league_season(url, league_id, season_id, no_cache) |
| 212 | |
| 213 | matches_data = data["datesData"] |
| 214 | for match in matches_data: |
| 215 | match_id = _as_int(match["id"]) |
| 216 | has_home_xg = match["xG"]["h"] not in ("0", None) |
| 217 | has_away_xg = match["xG"]["a"] not in ("0", None) |
| 218 | has_data = has_home_xg or has_away_xg |
| 219 | matches.append( |
| 220 | { |
| 221 | "league_id": league_id, |
| 222 | "league": league, |
| 223 | "season_id": season_id, |
| 224 | "season": season, |
| 225 | "game_id": match_id, |
| 226 | "date": match["datetime"], |
| 227 | "home_team_id": _as_int(match["h"]["id"]), |
| 228 | "away_team_id": _as_int(match["a"]["id"]), |
| 229 | "home_team": _as_str(match["h"]["title"]), |
| 230 | "away_team": _as_str(match["a"]["title"]), |
| 231 | "away_team_code": match["a"]["short_title"], |
| 232 | "home_team_code": match["h"]["short_title"], |
| 233 | "home_goals": _as_int(match["goals"]["h"]), |
| 234 | "away_goals": _as_int(match["goals"]["a"]), |
| 235 | "home_xg": _as_float(match["xG"]["h"]), |
| 236 | "away_xg": _as_float(match["xG"]["a"]), |
| 237 | "is_result": _as_bool(match["isResult"]), |
no test coverage detected