def run(): logging.basicConfig(level=logging.INFO) a = NBAComAgent(db=True, safe=False) fla = FantasyLabsNBAAgent(db=True, safe=False) # update players logging.info('start update players') a.commonallplayers('2015-16') logging.info('completed update players') # Update cs_player_gamelogs table through yesterday's games logging.info('start update player_gamelogs') a.cs_player_gamelogs('2015-16') logging.info('end update player_gamelogs') # Update cs_playerstats table through yesterday's games logging.info('start update playerstats') a.cs_playerstats('2015-16') logging.info('end update playerstats') # Update cs_team_gamelogs table through yesterday's games logging.info('start update team_gamelogs') a.cs_team_gamelogs('2015-16') logging.info('end update team_gamelogs') # Update cs_teamstats table through yesterday's games logging.info('start update teamstats') a.cs_teamstats('2015-16') logging.info('end update teamstats') # Get models and salaries from today's games # insert salaries into database logging.info('start update models') players, pp_players = fla.today_models(insert_db=True) logging.info('end update models') # insert models into database # TODO: preprocess_models + insert models code return players, pp_players
class FantasyLabsNBAAgent_test(unittest.TestCase): def setUp(self): self.a = FantasyLabsNBAAgent(db=True, use_cache=True) def test_init(self): adb = FantasyLabsNBAAgent(db=True) self.assertIsNotNone(adb.db) asafe = FantasyLabsNBAAgent(safe=True) self.assertIsNotNone(adb.safe) asafe = FantasyLabsNBAAgent(use_cache=True) self.assertIsNotNone(adb.scraper) def test_past_day_models(self): delta = random.choice(range(1,7)) d = dt.datetime.today() - dt.timedelta(delta) fmt = site_format('fl') models, pp_models = self.a.past_day_models(model_day=dt.datetime.strftime(d, fmt)) logging.debug('there are {0} models'.format(len(models))) self.assertIsInstance(models, list) self.assertTrue(len(models) > 0) model = random.choice(models) self.assertIsInstance(model, dict) self.assertIn('Salary', model) pp_model = random.choice(pp_models) self.assertIsInstance(pp_model, dict) self.assertIn('salary', pp_model) def test_range_models(self): fmt = site_format('fl') delta = random.choice(range(7,14)) range_start = dt.datetime.today() - dt.timedelta(delta) range_end = range_start + dt.timedelta(2) models, pp_models = self.a.range_models(range_start=dt.datetime.strftime(range_start, fmt), range_end=dt.datetime.strftime(range_end, fmt)) logging.debug('there are {0} models'.format(len(models))) self.assertIsInstance(models, list) self.assertTrue(len(models) > 0) model = random.choice(models) self.assertIsInstance(model, dict) self.assertIn('Salary', model) pp_model = random.choice(pp_models) self.assertIsInstance(pp_model, dict) self.assertIn('salary', pp_model) def test_today_models(self): models, pp_models = self.a.today_models() logging.debug('there are {0} models'.format(len(models))) self.assertIsInstance(models, list) self.assertTrue(len(models) > 0) model = random.choice(models) self.assertIsInstance(model, dict) self.assertIn('Salary', model) pp_model = random.choice(pp_models) self.assertIsInstance(pp_model, dict) self.assertIn('salary', pp_model)