get_double_gameweeks
Identify upcoming Premier League gameweeks where teams play multiple matches to optimize Fantasy Premier League team selection and transfer strategy.
Instructions
Get information about upcoming double gameweeks where teams play multiple times
Args:
num_gameweeks: Number of upcoming gameweeks to check (default: 5)
Returns:
Information about double gameweeks and affected teams
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| num_gameweeks | No |
Implementation Reference
- The main handler function that implements the logic to identify and return upcoming double gameweeks where teams have multiple fixtures. It fetches necessary API data, analyzes fixtures per gameweek, counts fixtures per team, and collects gameweeks with teams having more than one fixture.async def get_double_gameweeks(num_gameweeks: int = 5) -> List[Dict[str, Any]]: """ Identify upcoming double gameweeks where teams have multiple fixtures. Args: num_gameweeks: Number of upcoming gameweeks to analyze Returns: List of double gameweeks with affected teams """ # Get gameweek data all_gameweeks = await api.get_gameweeks() all_fixtures = await api.get_fixtures() team_data = await api.get_teams() # Get current gameweek current_gw = None for gw in all_gameweeks: if gw.get("is_current", False) or gw.get("is_next", False): current_gw = gw break if not current_gw: return [] current_gw_id = current_gw["id"] # Limit to specified number of upcoming gameweeks upcoming_gameweeks = [gw for gw in all_gameweeks if gw["id"] >= current_gw_id and gw["id"] < current_gw_id + num_gameweeks] # Map team IDs to names team_map = {t["id"]: t for t in team_data} # Results to return double_gameweeks = [] # Analyze each upcoming gameweek for gameweek in upcoming_gameweeks: gw_id = gameweek["id"] # Get fixtures for this gameweek gw_fixtures = [f for f in all_fixtures if f.get("event") == gw_id] # Count fixtures per team team_fixture_count = {} for fixture in gw_fixtures: home_team = fixture.get("team_h") away_team = fixture.get("team_a") team_fixture_count[home_team] = team_fixture_count.get(home_team, 0) + 1 team_fixture_count[away_team] = team_fixture_count.get(away_team, 0) + 1 # Identify teams with multiple fixtures (double gameweek) teams_with_doubles = [] for team_id, count in team_fixture_count.items(): if count > 1: team = team_map.get(team_id, {}) teams_with_doubles.append({ "id": team_id, "name": team.get("name", f"Team {team_id}"), "short_name": team.get("short_name", ""), "fixture_count": count }) # If teams have double gameweek, add to results if teams_with_doubles: double_gameweeks.append({ "gameweek": gw_id, "name": gameweek.get("name", f"Gameweek {gw_id}"), "teams_with_doubles": teams_with_doubles, "count": len(teams_with_doubles) }) return double_gameweeks