-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #332 from zwebb2/wnba
added support for wnba basketball
- Loading branch information
Showing
13 changed files
with
604 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
'nfl' : 'ffl', | ||
'nba' : 'fba', | ||
'nhl' : 'fhl', | ||
'mlb' : 'flb' | ||
'mlb' : 'flb', | ||
'wnba' : 'wfba' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
__all__ = ['League', | ||
'Team', | ||
'Player', | ||
'Matchup', | ||
] | ||
|
||
from .league import League | ||
from .team import Team | ||
from .player import Player | ||
from .matchup import Matchup | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from .constant import ACTIVITY_MAP | ||
|
||
class Activity(object): | ||
def __init__(self, data, player_map, get_team_data): | ||
self.actions = [] # List of tuples (Team, action, player) | ||
self.date = data['date'] | ||
for msg in data['messages']: | ||
team = '' | ||
action = 'UNKNOWN' | ||
player = '' | ||
msg_id = msg['messageTypeId'] | ||
if msg_id == 244: | ||
team = get_team_data(msg['from']) | ||
elif msg_id == 239: | ||
team = get_team_data(msg['for']) | ||
else: | ||
team = get_team_data(msg['to']) | ||
if msg_id in ACTIVITY_MAP: | ||
action = ACTIVITY_MAP[msg_id] | ||
if msg['targetId'] in player_map: | ||
player = player_map[msg['targetId']] | ||
self.actions.append((team, action, player)) | ||
|
||
def __repr__(self): | ||
return 'Activity(' + ' '.join("(%s,%s,%s)" % tup for tup in self.actions) + ')' | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from .constant import POSITION_MAP, PRO_TEAM_MAP, STATS_MAP | ||
from .player import Player | ||
from datetime import datetime, timedelta | ||
|
||
class BoxPlayer(Player): | ||
'''player with extra data from a matchup''' | ||
def __init__(self, data, pro_schedule, year): | ||
super(BoxPlayer, self).__init__(data, year) | ||
self.slot_position = 'FA' | ||
self.pro_opponent = "None" # professional team playing against | ||
self.game_played = 100 # 0-100 for percent of game played | ||
self.points = 0 | ||
self.points_breakdown = {} | ||
|
||
if 'lineupSlotId' in data: | ||
self.slot_position = POSITION_MAP[data['lineupSlotId']] | ||
|
||
player = data['playerPoolEntry']['player'] if 'playerPoolEntry' in data else data['player'] | ||
if player['proTeamId'] in pro_schedule: | ||
(opp_id, date) = pro_schedule[player['proTeamId']] | ||
self.game_played = 100 if datetime.now() > datetime.fromtimestamp(date/1000.0) + timedelta(hours=3) else 0 | ||
self.pro_opponent = PRO_TEAM_MAP[opp_id] | ||
|
||
player_stats = player.get('stats', []) | ||
for stats in player_stats: | ||
stats_breakdown = stats.get('appliedStats') or stats.get('stats', {}) | ||
breakdown = {STATS_MAP.get(k, k):v for (k,v) in stats_breakdown.items()} | ||
points = round(stats.get('appliedTotal', 0), 2) | ||
self.points = points | ||
self.points_breakdown = breakdown | ||
|
||
def __repr__(self): | ||
return f'Player({self.name}, points:{self.points})' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from .box_player import BoxPlayer | ||
|
||
class BoxScore(object): | ||
''' ''' | ||
def __init__(self, data, pro_schedule, by_matchup, year): | ||
self.winner = data.get('winner', 'UNDECIDED') | ||
self.home_team = data['home']['teamId'] | ||
self.home_projected = -1 # week is over/not set | ||
roster_key = 'rosterForMatchupPeriod' if by_matchup else 'rosterForCurrentScoringPeriod' | ||
# TODO combine home and away logic into common function | ||
home_roster = data['home'].get(roster_key, {}) | ||
if 'totalPointsLive' in data['home'] and by_matchup: | ||
self.home_score = round(data['home']['totalPointsLive'], 2) | ||
self.home_projected = round(data['home'].get('totalProjectedPointsLive', -1), 2) | ||
else: | ||
self.home_score = round(home_roster.get('appliedStatTotal', 0), 2) | ||
self.home_lineup = [BoxPlayer(player, pro_schedule, year) for player in home_roster.get('entries', [])] | ||
|
||
# For Leagues with bye weeks | ||
self.away_team = 0 | ||
self.away_score = 0 | ||
self.away_lineup = [] | ||
self.away_projected = -1 # week is over/not set | ||
if 'away' in data: | ||
self.away_team = data['away']['teamId'] | ||
away_roster = data['away'].get(roster_key, {}) | ||
if 'totalPointsLive' in data['away'] and by_matchup: | ||
self.away_score = round(data['away']['totalPointsLive'], 2) | ||
self.away_projected = round(data['away'].get('totalProjectedPointsLive', -1), 2) | ||
else: | ||
self.away_score = round(away_roster.get('appliedStatTotal', 0), 2) | ||
self.away_lineup = [BoxPlayer(player, pro_schedule, year) for player in away_roster.get('entries', [])] | ||
|
||
def __repr__(self): | ||
away_team = self.away_team or "BYE" | ||
home_team = self.home_team or "BYE" | ||
return f'Box Score({away_team} at {home_team})' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
POSITION_MAP = { | ||
0: 'PG', | ||
1: 'SG', | ||
2: 'SF', | ||
3: 'PF', | ||
4: 'C', | ||
5: 'G', | ||
6: 'F', | ||
7: 'SG/SF', | ||
8: 'G/F', | ||
9: 'PF/C', | ||
10: 'F/C', | ||
11: 'UT', | ||
12: 'BE', | ||
13: 'IR', | ||
14: '', | ||
15: 'Rookie', | ||
# reverse | ||
'PG': 0, | ||
'SG': 1, | ||
'SF': 2, | ||
'PF': 3, | ||
'C': 4, | ||
'G': 5, | ||
'F': 6, | ||
'SG/SF': 7, | ||
'G/F': 8, | ||
'PF/C': 9, | ||
'F/C': 10, | ||
'UT': 11, | ||
'BE': 12, | ||
'IR': 13, | ||
'Rookie': 15 | ||
} | ||
|
||
PRO_TEAM_MAP = { | ||
0: 'FA', | ||
3: 'Dal', | ||
5: 'Ind', | ||
6: 'LA', | ||
8: 'Min', | ||
9: 'NY', | ||
11: 'Phx', | ||
14: 'Sea', | ||
16: 'Wsh', | ||
17: 'LV', | ||
18: 'Conn', | ||
19: 'Chi', | ||
20: 'Atl', | ||
} | ||
|
||
STATS_MAP = { | ||
'0': 'PTS', | ||
'1': 'BLK', | ||
'2': 'STL', | ||
'3': 'AST', | ||
'4': 'OREB', | ||
'5': 'DREB', | ||
'6': 'REB', | ||
'7': '', | ||
'8': '', | ||
'9': 'PF', | ||
'10': '', | ||
'11': 'TO', | ||
'12': '', | ||
'13': 'FGM', | ||
'14': 'FGA', | ||
'15': 'FTM', | ||
'16': 'FTA', | ||
'17': '3PTM', | ||
'18': '3PTA', | ||
'19': 'FG%', | ||
'20': 'FT%', | ||
'21': '3PT%', | ||
'22': '', | ||
'23': '', | ||
'24': '', | ||
'25': '', | ||
'26': '', | ||
'27': '', | ||
'28': 'MPG', | ||
'29': '', | ||
'30': '', | ||
'31': '', | ||
'32': '', | ||
'33': '', | ||
'34': '', | ||
'35': '', | ||
'36': '', | ||
'37': '', | ||
'38': '', | ||
'39': '', | ||
'40': 'MIN', | ||
'41': 'GS', | ||
'42': 'GP', | ||
'43': '', | ||
'44': '', | ||
'45': '', | ||
} | ||
|
||
STAT_ID_MAP = { | ||
'10': 'projected', | ||
'01': 'last_7', | ||
'02': 'last_15', | ||
'03': 'last_30' | ||
} | ||
|
||
ACTIVITY_MAP = { | ||
178: 'FA ADDED', | ||
180: 'WAIVER ADDED', | ||
179: 'DROPPED', | ||
181: 'DROPPED', | ||
239: 'DROPPED', | ||
244: 'TRADED', | ||
'FA': 178, | ||
'WAIVER': 180, | ||
'TRADED': 244 | ||
} |
Oops, something went wrong.