@@ -417,6 +417,7 @@ def find_player(player_name):
417
417
except IndexError :
418
418
logger .error (f"Player { player_name } could not be found!" )
419
419
return None
420
+
420
421
return player
421
422
422
423
@@ -449,32 +450,34 @@ def get_relevant_fixtures(player, team_name=None):
449
450
"""Return all fixtures that the player has played for his current team
450
451
(optionally) against the given team.
451
452
"""
452
- fixture_ids = [result ["id" ] for result in database .results .find ()]
453
-
454
453
fixtures = [
455
454
fixture for fixture in player ["understat_history" ]
456
455
if (to_fpl_team (fixture ["h_team" ].lower ()) in fpl_team_names or
457
456
to_fpl_team (fixture ["a_team" ].lower ()) in fpl_team_names ) and
458
- int (fixture ["time" ]) > 0 and fixture [ "id" ] in fixture_ids
457
+ int (fixture ["time" ]) > 0
459
458
]
460
459
461
460
if team_name :
462
461
fixtures = [
463
462
fixture for fixture in fixtures
464
- if team_name == fixture ["h_team" ].lower () or
465
- team_name == fixture ["a_team" ].lower ()
463
+ if team_name . lower () == fixture ["h_team" ].lower () or
464
+ team_name . lower () == fixture ["a_team" ].lower ()
466
465
]
467
466
468
- # Player probably played for the given team before, so only include
467
+ # Player could've played for the given team before, so only include
469
468
# fixtures played vs. them for his current team.
470
469
if len (fixtures ) > 10 :
471
470
fixtures = [
472
471
fixture for fixture in fixtures
473
472
if player ["team" ].lower () in [
474
- to_fpl_team (fixture ["h_team" ].lower ()),
475
- to_fpl_team (fixture ["a_team" ].lower ())
473
+ to_fpl_team (fixture ["h_team" ].lower ()),
474
+ to_fpl_team (fixture ["a_team" ].lower ())
476
475
]
477
476
]
477
+ else :
478
+ # If comparing player vs. player, then only include this season.
479
+ fixture_ids = [result ["id" ] for result in database .results .find ()]
480
+ fixture = [f for f in fixtures if f ["id" ] in fixture_ids ]
478
481
479
482
return fixtures
480
483
0 commit comments