Esempio n. 1
0
 def setUp(self):
     self.future_game_info = GameInfo(
         home_team='H',
         away_team='A',
         game_started=False,
         starts_at=datetime.now(timezone('EST')) + timedelta(days=1))
     self.finished_game_info = GameInfo(
         home_team='H',
         away_team='A',
         game_started=False,
         starts_at=datetime.now(timezone('EST')) - timedelta(days=1))
     self.lineup_optimizer = get_optimizer(Site.DRAFTKINGS,
                                           Sport.BASKETBALL)
     positions = ['PG', 'SG', 'SF', 'PF', 'C', 'PG/SG', 'SF/PF', 'C']
     self.active_players = create_players(positions,
                                          game_info=self.future_game_info,
                                          salary=5000,
                                          fppg=20)
     self.inactive_players = create_players(
         positions, game_info=self.finished_game_info, salary=4500, fppg=10)
     self.lineup_optimizer.load_players(self.active_players +
                                        self.inactive_players)
     self.lineup = Lineup([
         LineupPlayer(self.active_players[0], 'PG'),
         LineupPlayer(self.inactive_players[1], 'SG'),
         LineupPlayer(self.active_players[2], 'SF'),
         LineupPlayer(self.inactive_players[3], 'PF'),
         LineupPlayer(self.active_players[4], 'C'),
         LineupPlayer(self.inactive_players[5], 'G'),
         LineupPlayer(self.active_players[6], 'F'),
         LineupPlayer(self.inactive_players[7], 'UTIL'),
     ])
 def setUp(self):
     first_game_info = GameInfo('HOU', 'BOS', datetime.now(), False)
     second_game_info = GameInfo('CHI', 'NY', datetime.now(), False)
     self.players = [
         Player('1', '1', '1', ['SP', 'RP'], 'HOU',
                3000, 15, game_info=first_game_info),
         Player('2', '2', '2', ['SP', 'RP'], 'BOS',
                3000, 15, game_info=first_game_info),
         Player('3', '3', '3', ['C'], 'HOU', 3000,
                15, game_info=first_game_info),
         Player('4', '4', '4', ['1B'], 'BOS', 3000,
                15, game_info=first_game_info),
         Player('5', '5', '5', ['2B'], 'HOU', 3000,
                15, game_info=first_game_info),
         Player('6', '6', '6', ['3B'], 'BOS', 3000,
                15, game_info=first_game_info),
         Player('7', '7', '7', ['SS'], 'HOU', 3000,
                15, game_info=first_game_info),
         Player('8', '8', '8', ['OF'], 'BOS', 3000,
                15, game_info=first_game_info),
         Player('9', '9', '9', ['OF'], 'HOU', 3000,
                15, game_info=first_game_info),
         Player('10', '10', '10', ['OF'], 'BOS',
                3000, 15, game_info=first_game_info),
         Player('11', '11', '11', ['SP', 'RP'], 'CHI',
                3000, 5, game_info=second_game_info),
         Player('12', '12', '12', ['SP', 'RP'], 'NY',
                3000, 5, game_info=second_game_info),
     ]
     self.optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASEBALL)
     self.optimizer.load_players(self.players)
Esempio n. 3
0
 def _parse_game_info(self, row: Dict) -> Optional[GameInfo]:
     raw_game_info = row.get('Game Info')
     if not raw_game_info:
         return None
     if raw_game_info in ('In Progress', 'Final'):
         game_info = self._games.get((None, None))
         if not game_info:
             game_info = GameInfo(  # No game info provided, just mark game as started
                 home_team=None,
                 away_team=None,
                 starts_at=None,
                 game_started=True
             )
             self._games[(None, None)] = game_info
         return game_info
     try:
         teams, date, time, tz = raw_game_info.rsplit(' ', 3)
         away_team, home_team = teams.split('@')
         game_info = self._games.get((home_team, away_team))
         if game_info:
             return game_info
         starts_at = datetime.strptime(date + time, '%m/%d/%Y%I:%M%p').\
             replace(tzinfo=timezone(get_timezone()))
         game_info = GameInfo(
             home_team=home_team,
             away_team=away_team,
             starts_at=starts_at,
         )
         self._games[(home_team, away_team)] = game_info
         return game_info
     except ValueError:
         return None
Esempio n. 4
0
 def import_players(self):
     players = []
     with open(self.filename, 'r') as csvfile:
         csv_data = csv.DictReader(csvfile, skipinitialspace=True)
         for row in csv_data:
             game_info = None
             try:
                 away_team, home_team = row.get('Game', '').split('@')
                 game_info = GameInfo(home_team, away_team, None, False)
             except ValueError:
                 pass
             try:
                 player = Player(row['ID'],
                                 row['First Name'],
                                 row['Last Name'],
                                 row['Position'].split('/'),
                                 row['Team'],
                                 float(row['Salary']),
                                 float(row['FPPG']),
                                 is_injured=True
                                 if row['Injury Status'].strip() else False,
                                 game_info=game_info,
                                 **self.get_player_extra(row))
             except KeyError:
                 raise LineupOptimizerIncorrectCSV
             players.append(player)
     return players
Esempio n. 5
0
 def import_players(self):
     players = []
     i = 0
     with open(self.filename, 'r') as csvfile:
         csv_data = csv.DictReader(csvfile, skipinitialspace=True)
         for row in csv_data:
             game_info = None
             try:
                 home_team = row["HomeTeam"]
                 away_team = row["AwayTeam"]
                 game_info = GameInfo(home_team, away_team, None, False)
             except ValueError:
                 pass
             try:
                 player = Player(row['Player ID'],
                                 row['Name'].split(" ")[0],
                                 row['Name'].split(" ")[1],
                                 [row['Position']] if not row['Position2']
                                 else [row['Position'], row['Position2']],
                                 row['Team'],
                                 float(row['Price']),
                                 float(row['Projection']),
                                 max_exposure=float(row['Max Exposure']),
                                 game_info=game_info)
             except KeyError:
                 raise LineupOptimizerIncorrectCSV
             i = i + 1
             players.append(player)
     return players
Esempio n. 6
0
 def import_players(self):
     games = {}  # type: Dict[Tuple[str, str], GameInfo]
     players = []
     with open(self.filename, 'r') as csvfile:
         csv_data = csv.DictReader(csvfile, skipinitialspace=True)
         for row in csv_data:
             player_id = self._process_cell(row['ID'])
             if not player_id:
                 continue
             try:
                 away_team, home_team = self._process_cell(
                     row.get('Game', '')).split('@')
                 game_info = games.get((home_team, away_team), None)
                 if not game_info:
                     game_info = GameInfo(home_team, away_team, None)
                     games[(home_team, away_team)] = game_info
             except ValueError:
                 game_info = None
             try:
                 player = Player(
                     player_id,
                     self._process_cell(row['First Name']),
                     self._process_cell(row['Last Name']),
                     self._process_cell(row['Position']).split('/'),
                     self._process_cell(row['Team']),
                     float(self._process_cell(row['Salary'])),
                     float(self._process_cell(row['FPPG'])),
                     is_injured=True
                     if self._process_cell(row['Injury Status']) else False,
                     game_info=game_info,
                     **self.get_player_extra(row))
             except KeyError:
                 raise LineupOptimizerIncorrectCSV
             players.append(player)
     return players
Esempio n. 7
0
 def import_players(self):
     players = []
     with open(self.filename, 'r') as csvfile:
         csv_data = csv.DictReader(csvfile, skipinitialspace=True)
         for row in csv_data:
             game_info = None
             try:
                 away_team, home_team = row.get('Game', '').split('@')
                 game_info = GameInfo(home_team, away_team, None, False)
             except ValueError:
                 pass
             try:
                 max_exposure = row.get('Max Exposure')
                 player = Player(
                     row['Id'],
                     row['First Name'],
                     row['Last Name'],
                     row['Position'].split('/'),
                     row['Team'],
                     float(row['Salary']),
                     float(row['FPPG']),
                     True if row['Injury Indicator'].strip() else False,
                     max_exposure=float(max_exposure.replace('%', ''))
                     if max_exposure else None,
                     game_info=game_info,
                 )
             except KeyError:
                 raise LineupOptimizerIncorrectCSV
             players.append(player)
     return players
Esempio n. 8
0
 def _parse_game_info(self, row):
     game_info = row.get('Game Info')
     if not game_info:
         return
     if game_info in ('In Progress', 'Final'):
         return GameInfo(  # No game info provided, just mark game as started
             home_team='',
             away_team='',
             starts_at='',
             game_started=True)
     try:
         teams, date, time, tz = game_info.rsplit(' ', 3)
         away_team, home_team = teams.upper().split('@')
         starts_at = datetime.strptime(date + time, '%m/%d/%Y%I:%M%p').\
             replace(tzinfo=timezone(self.DEFAULT_TIMEZONE))
         return GameInfo(home_team=home_team,
                         away_team=away_team,
                         starts_at=starts_at,
                         game_started=False)
     except ValueError:
         return
Esempio n. 9
0
 def _parse_game_info(self, row):
     game_info = row.get('Game Info')
     if not game_info:
         return
     if game_info in ('In Progress', 'Final'):
         return GameInfo(  # No game info provided, just mark game as started
             home_team='',
             away_team='',
             starts_at='',
             game_started=True)
     try:
         teams, date = game_info.split(' ', 1)
         away_team, home_team = teams.split('@')
         starts_at = datetime.strptime(date.replace(
             ' ET', ''), '%m/%d/%Y %I:%M%p').replace(tzinfo=timezone('EST'))
         return GameInfo(home_team=home_team,
                         away_team=away_team,
                         starts_at=starts_at,
                         game_started=False)
     except ValueError:
         return
 def setUp(self):
     self.players = load_players()
     self.first_team = 'TEST 1'
     self.second_team = 'TEST 2'
     self.game_info = GameInfo(self.first_team, self.second_team, datetime.now(), False)
     self.extra_players = [
         Player('1', '1', '1', ['PG'], self.first_team, 3000, 100, game_info=self.game_info),
         Player('2', '2', '2', ['SG'], self.first_team, 3000, 100, game_info=self.game_info),
         Player('3', '3', '3', ['SF'], self.second_team, 3000, 1, game_info=self.game_info),
         Player('4', '4', '4', ['PF'], self.second_team, 3000, 1, game_info=self.game_info),
     ]
     self.optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASKETBALL)
     self.optimizer.load_players(self.players + self.extra_players)
Esempio n. 11
0
 def setUp(self):
     self.players = load_players()
     self.optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASKETBALL)
     self.optimizer.settings.max_from_one_team = 4
     self.home_team = 'Home'
     self.away_team = 'Away'
     self.game_info = GameInfo(
         home_team=self.home_team,
         away_team=self.away_team,
         starts_at=None,
     )
     self.game_players = [
         Player('1', '1', '1', ['PG'], self.home_team, 1000, 3, game_info=self.game_info),
         Player('2', '2', '2', ['SG'], self.home_team, 1000, 3, game_info=self.game_info),
         Player('3', '3', '3', ['C'], self.home_team, 1000, 3, game_info=self.game_info),
         Player('4', '4', '4', ['SG'], self.away_team, 1000, 1, game_info=self.game_info),
         Player('5', '5', '5', ['SF'], self.away_team, 1000, 1, game_info=self.game_info),
         Player('6', '6', '6', ['PF'], self.away_team, 1000, 1, game_info=self.game_info),
     ]
     self.optimizer.player_pool.load_players(self.players + self.game_players)
Esempio n. 12
0
 def _row_to_player(self, row: Dict) -> Player:
     game_info = None
     try:
         away_team, home_team = row.get('Game', '').split('@')
         game_info = GameInfo(home_team, away_team, None, False)
     except ValueError:
         pass
     try:
         player = Player(row['Id'],
                         row['First Name'],
                         row['Last Name'],
                         row['Position'].split('/'),
                         row['Team'],
                         float(row['Salary']),
                         float(row['FPPG']),
                         True if row['Injury Indicator'].strip() else False,
                         game_info=game_info,
                         **self.get_player_extra(row))
     except KeyError:
         raise LineupOptimizerIncorrectCSV
     return player