Skip to content

Commit ae81a04

Browse files
author
amosbastian
committed
Fix versus team handling
1 parent 39749c6 commit ae81a04

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

FPLbot/utils.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ def find_player(player_name):
417417
except IndexError:
418418
logger.error(f"Player {player_name} could not be found!")
419419
return None
420+
420421
return player
421422

422423

@@ -449,32 +450,34 @@ def get_relevant_fixtures(player, team_name=None):
449450
"""Return all fixtures that the player has played for his current team
450451
(optionally) against the given team.
451452
"""
452-
fixture_ids = [result["id"] for result in database.results.find()]
453-
454453
fixtures = [
455454
fixture for fixture in player["understat_history"]
456455
if (to_fpl_team(fixture["h_team"].lower()) in fpl_team_names or
457456
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
459458
]
460459

461460
if team_name:
462461
fixtures = [
463462
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()
466465
]
467466

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
469468
# fixtures played vs. them for his current team.
470469
if len(fixtures) > 10:
471470
fixtures = [
472471
fixture for fixture in fixtures
473472
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())
476475
]
477476
]
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]
478481

479482
return fixtures
480483

comment_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
---
66

7-
^Made ^by ^[esoemah](https://www.reddit.com/message/compose/?to=esoemah). ^Source: ^https://github.com/amosbastian/FPLbot
7+
^Made ^by ^[/u/esoemah](https://www.reddit.com/message/compose/?to=esoemah). ^Source: ^https://github.com/amosbastian/FPLbot

post_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
---
1616

17-
^Made ^by ^[esoemah](https://www.reddit.com/message/compose/?to=esoemah). ^Source: ^https://github.com/amosbastian/FPLbot
17+
^Made ^by ^[/u/esoemah](https://www.reddit.com/message/compose/?to=esoemah). ^Source: ^https://github.com/amosbastian/FPLbot

0 commit comments

Comments
 (0)