def get(self, option, name): try: stats = pd.read_csv( FILE_DIR + '/nbastats/static/data/players_{}.csv'.format(option), index_col='PLAYER') except IOError as e: raise tornado.web.HTTPError(500) player = utility.url_to_name( name) # convert from url-friendly to formal name img_src = stats.ix[player]['IMG'] # get player headshot address if not img_src: img_src = None # handle missing img url, currently do nothing. Can use a default image instead years = stats.ix[player]['YEARS'].strip().split() last_year = years[-1] # display most recent year stats for the player try: stats = pd.read_csv( FILE_DIR + '/nbastats/static/data/stats_{}.csv'.format(last_year), index_col='PLAYER') except IOError: raise tornado.web.HTTPError(500) self.write( rendering.render_player(player, stats, years, last_year, option, img_src, TEMPLATE_DIR, 'player.html'))
def test_lebron(self): urls = [ 'lebron-james', 'tracy-mcgrady', 'antonio-mcdyess', 'desagana-diop' ] names = [ 'LeBron James', 'Tracy McGrady', 'Antonio McDyess', 'DeSagana Diop' ] for i in xrange(len(urls)): self.assertEqual(url_to_name(urls[i]), names[i])
def get(self, option, name, year): try: stats = pd.read_csv(FILE_DIR + '/nbastats/static/data/players_{}.csv'.format(option), index_col='PLAYER') except IOError: raise tornado.web.HTTPError(500) player = utility.url_to_name(name) # convert from url-friendly to formal name img_src = stats.ix[player]['IMG'] # get player headshot address years = stats.ix[player]['YEARS'].strip().split() try: stats = pd.read_csv(FILE_DIR + '/nbastats/static/data/stats_{}.csv'.format(year), index_col='PLAYER') except IOError: raise tornado.web.HTTPError(500) self.write(rendering.render_player(player, stats, years, year, option, img_src, TEMPLATE_DIR, 'player.html'))
def get(self, option, name): try: stats = pd.read_csv(FILE_DIR + '/nbastats/static/data/players_{}.csv'.format(option), index_col='PLAYER') except IOError as e: raise tornado.web.HTTPError(500) player = utility.url_to_name(name) # convert from url-friendly to formal name img_src = stats.ix[player]['IMG'] # get player headshot address if not img_src: img_src = None # handle missing img url, currently do nothing. Can use a default image instead years = stats.ix[player]['YEARS'].strip().split() last_year = years[-1] # display most recent year stats for the player try: stats = pd.read_csv(FILE_DIR + '/nbastats/static/data/stats_{}.csv'.format(last_year), index_col='PLAYER') except IOError: raise tornado.web.HTTPError(500) self.write(rendering.render_player(player, stats, years, last_year, option, img_src, TEMPLATE_DIR, 'player.html'))
def get(self, option, name, year): try: stats = pd.read_csv( FILE_DIR + '/nbastats/static/data/players_{}.csv'.format(option), index_col='PLAYER') except IOError: raise tornado.web.HTTPError(500) player = utility.url_to_name( name) # convert from url-friendly to formal name img_src = stats.ix[player]['IMG'] # get player headshot address years = stats.ix[player]['YEARS'].strip().split() try: stats = pd.read_csv( FILE_DIR + '/nbastats/static/data/stats_{}.csv'.format(year), index_col='PLAYER') except IOError: raise tornado.web.HTTPError(500) self.write( rendering.render_player(player, stats, years, year, option, img_src, TEMPLATE_DIR, 'player.html'))
def test_dash(self): urls = ['darius-johnson-odom', 'al-farouq-aminu'] names = ['Darius Johnson-Odom', 'Al-Farouq Aminu'] for i in xrange(len(urls)): self.assertEqual(url_to_name(urls[i]), names[i])
def test_normal(self): urls = ['steve-nash', 'kobe-bryant', 'yao-ming'] names = ['Steve Nash', 'Kobe Bryant', 'Yao Ming'] for i in xrange(len(urls)): self.assertEqual(url_to_name(urls[i]), names[i])
def test_iii(self): self.assertEqual(url_to_name('john-lucas-iii'), 'John Lucas III')
def test_apostrophe(self): urls = ["shaq-o'neal", "terry-o'quinn"] names = ["Shaq O'Neal", "Terry O'Quinn"] for i in xrange(len(urls)): self.assertEqual(url_to_name(urls[i]), names[i])
def test_lebron(self): urls = ['lebron-james', 'tracy-mcgrady', 'antonio-mcdyess', 'desagana-diop'] names = ['LeBron James', 'Tracy McGrady', 'Antonio McDyess', 'DeSagana Diop'] for i in xrange(len(urls)): self.assertEqual(url_to_name(urls[i]), names[i])