def main(): files = [f for f in os.listdir('../../logs/extract') if 'shotchart_nbacom' in f] f = '2011-12-25_LAC@GS_shotchart_nbacom' gamedata = db.nba_query_dict("SELECT * FROM game WHERE id = 1267")[0] obj = ShotChart(f, gamedata) obj.test()
def getAwayFiveManUnit(self): result = db.nba_query_dict(""" SELECT * FROM playbyplay_espn WHERE game_id = %s ORDER BY period ASC, sec_elapsed_game ASC, play_num ASC """ % self.game_id) players = self._getCurrentPlayers(self.away_team) total_periods = self._getNumberOfPeriods() fiveman = self._guessFiveManUnits(result, total_periods, self.away_team, players) return fiveman
def main(): files = [f for f in os.listdir(LOGDIR_EXTRACT) if '2011-12' in f and 'boxscore' in f] f = '2012-01-18_OKC@WAS_boxscore_nbacom' gamedata = db.nba_query_dict("SELECT * FROM game where date_played <= '2012-02-10'") dbobj = db.Db(db.dbconn_nba) for game in gamedata: #print game['abbrev'] filename = game['abbrev'] + '_boxscore_nbacom' obj = CleanBoxScore(filename, game, dbobj) result = obj.getGameInfo()
def getAwayFiveManUnit(self): result = db.nba_query_dict( """ SELECT * FROM playbyplay_espn WHERE game_id = %s ORDER BY period ASC, sec_elapsed_game ASC, play_num ASC """ % self.game_id ) players = self._getCurrentPlayers(self.away_team) total_periods = self._getNumberOfPeriods() fiveman = self._guessFiveManUnits(result, total_periods, self.away_team, players) return fiveman
def main(): files = [ '2011-12-25_LAC@GS_shotchart_espn', '2011-12-25_MIA@DAL_shotchart_espn', '2011-12-25_BOS@NY_shotchart_espn', '2011-12-25_CHI@LAL_shotchart_espn', '2011-12-25_ORL@OKC_shotchart_espn' ] files = [f for f in os.listdir('../../logs/extract') if 'shotchart_espn' in f] f = '2011-12-25_LAC@GS_shotchart_espn' gamedata = db.nba_query_dict("SELECT * FROM game WHERE id = 1267")[0] obj = ShotChartEspn(f, gamedata) obj.cleanAll()
def main(): files = [ '2011-12-25_LAC@GS_shotchart_espn', '2011-12-25_MIA@DAL_shotchart_espn', '2011-12-25_BOS@NY_shotchart_espn', '2011-12-25_CHI@LAL_shotchart_espn', '2011-12-25_ORL@OKC_shotchart_espn' ] files = [ f for f in os.listdir('../../logs/extract') if 'shotchart_espn' in f ] f = '2011-12-25_LAC@GS_shotchart_espn' gamedata = db.nba_query_dict("SELECT * FROM game WHERE id = 1267")[0] obj = ShotChartEspn(f, gamedata) obj.cleanAll()
import fiveman from libscrape.config import db import unittest sample = db.nba_query_dict("SELECT * FROM game WHERE date_played <= '2011-02-20' ORDER BY RAND() LIMIT 10") #sample = db.nba_query_dict("SELECT * FROM game WHERE id = 666") class CheckFiveMan(unittest.TestCase): def setUp(self): self.objs = [fiveman.FiveMan(game['id'],game['away_team'],game['home_team'], game['date_played']) for game in sample] def testAllPlaysHaveFiveHomePlayers(self): for obj in self.objs: #print '%s vs %s' % (obj.away_team, obj.home_team) result = obj.getHomeFiveManUnit() print "game_id: %s, %s vs %s" % (obj.game_id, obj.away_team, obj.home_team) for period in result: for line in period: self.assertTrue(len(line[2]) <= 5, "play has greater than 5 players: play num: %s" % line[0]) def testAllPlaysHaveFiveAwayPlayers(self): for obj in self.objs: result = obj.getAwayFiveManUnit() print "game_id: %s, %s vs %s" % (obj.game_id, obj.away_team, obj.home_team)
def main(game_id=1500): gamedata = db.nba_query_dict("SELECT * FROM game WHERE id = %s" % game_id) obj = FiveMan(gamedata[0]) obj.go()
def chooseGames(game_ids): return db.nba_query_dict("SELECT * FROM game WHERE date_played BETWEEN '2011-02-02' AND '2011-02-26'")
def chooseGames(game_ids): return db.nba_query_dict("SELECT * FROM game WHERE id IN (%s)" % ','.join(map(str, game_ids)))
import fiveman from libscrape.config import db import unittest sample = db.nba_query_dict( "SELECT * FROM game WHERE date_played <= '2011-02-26' ORDER BY RAND() LIMIT 10" ) #sample = db.nba_query_dict("SELECT * FROM game WHERE id = 240") class CheckFiveMan(unittest.TestCase): def setUp(self): self.objs = [ fiveman.FiveMan(game['id'], game['away_team'], game['home_team'], game['date_played']) for game in sample ] def testAllPlaysHaveFiveHomePlayers(self): for obj in self.objs: result = obj.getHomeFiveManUnit() print "game_id: %s" % obj.game_id for period in result: for line in period: #print line self.assertEqual(len(line[2]), 5) def testAllPlaysHaveFiveAwayPlayers(self): for obj in self.objs: result = obj.getAwayFiveManUnit()
def chooseGames(game_ids): return db.nba_query_dict( "SELECT * FROM game WHERE date_played BETWEEN '2011-02-02' AND '2011-02-26'" )
def chooseGames(game_ids): return db.nba_query_dict("SELECT * FROM game WHERE id IN (%s)" % ','.join(map(str,game_ids)))