Skip to content

Commit

Permalink
fix for finished gameweek
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmadden86 committed Oct 22, 2019
1 parent 9607731 commit da5c281
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 8 additions & 2 deletions fpl/fpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ async def get_player(self, player_id, players=None, gameweek=None, include_summa

return Player(player, self.session)

async def get_players(self, player_ids=None, include_summary=False, include_live=None,
async def get_players(self, player_ids=None, include_summary=False, include_live=False,
return_json=False):
"""Returns either a list of *all* players, or a list of players whose
IDs are in the given ``player_ids`` list.
Expand All @@ -287,8 +287,14 @@ async def get_players(self, player_ids=None, include_summary=False, include_live
if not player_ids:
player_ids = [player["id"] for player in players.values()]

current_gameweek_id = getattr(self, "current_gameweek")
gameweeks = getattr(self, "events")
current_gameweek = gameweeks[current_gameweek_id]
current_gameweek_finished = current_gameweek["finished"]
include_live = include_live and not current_gameweek_finished

if include_live:
gameweek = await self.get_gameweek(getattr(self, "current_gameweek"), include_live=True)
gameweek = await self.get_gameweek(current_gameweek_id, include_live=include_live)

tasks = [asyncio.ensure_future(
self.get_player(
Expand Down
2 changes: 2 additions & 0 deletions fpl/models/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(self, player_information, session):
self._session = session
for k, v in player_information.items():
setattr(self, k, v)
self.did_not_play = False
self.live_score = getattr(self, "event_points")

@property
async def games_played(self):
Expand Down
8 changes: 4 additions & 4 deletions fpl/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,19 @@ async def get_live_score(self, players):

captain = next(pick["element"] for pick in picks if pick["is_captain"])
try:
vice_captain = next(
pick["element"] for pick in picks if pick["is_vice_captain"] and pick["multiplier"] == 1)
# only if multiplier == 1, i.e. vice-captain not already applied by FPL
vice_captain = next(pick["element"] for pick in picks if pick["is_vice_captain"])
except StopIteration:
vice_captain = None

captain_points = players[captain].live_score
if captain in subs_out and vice_captain:
if captain in subs_out + subs:
captain_points = players[vice_captain].live_score

if active_chip == "3xc": # for triple captain chip
captain_points *= 2

print(sum(first_xi_live_scores), captain_points, points_hit)

return sum(first_xi_live_scores) + captain_points - points_hit

async def get_live_total_points(self, players):
Expand Down

0 comments on commit da5c281

Please sign in to comment.