From f681adae99ddde4920f02002a9bde9fe43b9c381 Mon Sep 17 00:00:00 2001 From: Doug Rickert Date: Tue, 25 Sep 2018 21:26:10 -0600 Subject: [PATCH] Fixed issue where inactive members from past seasons messed up power rankings --- CHANGELOG.md | 4 ++++ espnff/league.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf450b6..9f84317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Patched +- Fixed issue where inactive members from past seasons messed up +power rankings + ### Patched - Fixed output for possibility the attribute doesn't exist in the API diff --git a/espnff/league.py b/espnff/league.py index 3cbe808..08dcd88 100644 --- a/espnff/league.py +++ b/espnff/league.py @@ -87,10 +87,19 @@ def power_rankings(self, week): teams_sorted = sorted(self.teams, key=lambda x: x.team_id, reverse=False) + # deleted members from previous years still hold a team_id, so + # create a new mapping of team id to dominance matrix row/column + matrix_position_map = {} + count = 0 + for team in teams_sorted: + matrix_position_map[team.team_id] = count + count += 1 + + # loop through our teams and create a matrix of wins for team in teams_sorted: wins = [0]*32 for mov, opponent in zip(team.mov[:week], team.schedule[:week]): - opp = int(opponent.team_id)-1 + opp = matrix_position_map[opponent.team_id] if mov > 0: wins[opp] += 1 win_matrix.append(wins)