def import_tournament(type, path, bracket, region, name): config = Config() mongo_client = MongoClient(host=config.get_mongo_url()) if type == 'tio': scraper = TioScraper(path, bracket) elif type =='challonge': scraper = ChallongeScraper(path) else: click.echo("Illegal type") dao = Dao(region, mongo_client=mongo_client) player_map = get_player_alias_to_id_map(scraper, dao) # TODO pass in a map of overrides for specific players tournament = Tournament.from_scraper(type, scraper, player_map, region) if name: tournament.name = name dao.insert_tournament(tournament) click.echo("Generating new ranking...") rankings.generate_ranking(dao) click.echo("Done!")
def import_tournament(type, path, bracket, region, name): config = Config() mongo_client = MongoClient(host=config.get_mongo_url()) if type == 'tio': scraper = TioScraper.from_file(path, bracket) elif type == 'challonge': scraper = ChallongeScraper(path) else: click.echo("Illegal type") dao = Dao(region, mongo_client=mongo_client) player_map = get_player_alias_to_id_map(scraper, dao) # TODO pass in a map of overrides for specific players tournament = Tournament.from_scraper(type, scraper, player_map, region) if name: tournament.name = name dao.insert_tournament(tournament) click.echo("Generating new ranking...") rankings.generate_ranking(dao) click.echo("Done!")
def test_generate_rankings_diff_against_tournament(self): now = datetime(2013, 11, 25) rankings.generate_ranking(self.dao, now=now, day_limit=45, num_tourneys=1, tournament_to_diff=self.tournament_2) ranking = self.dao.get_latest_ranking() ranking_list = ranking.ranking self.assertEquals(len(ranking_list), 3) entry = ranking_list[0] self.assertEquals(entry.rank, 1) self.assertEquals(entry.player, self.player_1_id) self.assertAlmostEquals(entry.rating, 6.857, delta=delta) self.assertEquals(entry.previous_rank, None) entry = ranking_list[1] self.assertEquals(entry.rank, 2) self.assertEquals(entry.player, self.player_4_id) self.assertAlmostEquals(entry.rating, -.800, delta=delta, msg="" + str(entry.player)) self.assertEquals(entry.previous_rank, 2) entry = ranking_list[2] self.assertEquals(entry.rank, 3) self.assertEquals(entry.player, self.player_2_id) self.assertAlmostEquals(entry.rating, -1.349, delta=delta) self.assertEquals(entry.previous_rank, 3)
def test_generate_rankings_excluded_for_inactivity(self): now = datetime(2013, 11, 25) rankings.generate_ranking(self.dao, now=now, day_limit=45, num_tourneys=1) ranking = self.dao.get_latest_ranking() ranking_list = ranking.ranking self.assertEquals(len(ranking_list), 3) entry = ranking_list[0] self.assertEquals(entry.rank, 1) self.assertEquals(entry.player, self.player_1_id) self.assertAlmostEquals(entry.rating, 6.857, delta=delta) entry = ranking_list[1] self.assertEquals(entry.rank, 2) self.assertEquals(entry.player, self.player_4_id) self.assertAlmostEquals(entry.rating, -.800, delta=delta, msg="" + str(entry.player)) entry = ranking_list[2] self.assertEquals(entry.rank, 3) self.assertEquals(entry.player, self.player_2_id) self.assertAlmostEquals(entry.rating, -1.349, delta=delta)
def setUp(self): self.mongo_client_patcher = patch('server.mongo_client', new=mongomock.MongoClient()) self.mongo_client = self.mongo_client_patcher.start() server.app.config['TESTING'] = True self.app = server.app.test_client() self.norcal_region = Region('norcal', 'Norcal') self.texas_region = Region('texas', 'Texas') Dao.insert_region(self.norcal_region, self.mongo_client) Dao.insert_region(self.texas_region, self.mongo_client) self.norcal_dao = Dao(NORCAL_REGION_NAME, mongo_client=self.mongo_client) self.texas_dao = Dao(TEXAS_REGION_NAME, mongo_client=self.mongo_client) self._import_files() now = datetime(2014, 11, 1) rankings.generate_ranking(self.norcal_dao, now=now) rankings.generate_ranking(self.texas_dao, now=now) self.user_id = 'asdf' self.user_full_name = 'full name' self.user_admin_regions = ['norcal', 'nyc'] self.user = User(self.user_id, self.user_admin_regions, full_name=self.user_full_name) self.norcal_dao.insert_user(self.user)
def test_generate_rankings_excluded_for_inactivity(self, mock_datetime): now = datetime(2013, 11, 25) mock_datetime.now.return_value = now rankings.generate_ranking(self.dao) ranking = self.dao.get_latest_ranking() ranking_list = ranking.ranking self.assertEquals(len(ranking_list), 3) entry = ranking_list[0] self.assertEquals(entry.rank, 1) self.assertEquals(entry.player, self.player_1_id) self.assertAlmostEquals(entry.rating, 6.857, delta=delta) entry = ranking_list[1] self.assertEquals(entry.rank, 2) self.assertEquals(entry.player, self.player_4_id) self.assertAlmostEquals(entry.rating, -.800, delta=delta) entry = ranking_list[2] self.assertEquals(entry.rank, 3) self.assertEquals(entry.player, self.player_2_id) self.assertAlmostEquals(entry.rating, -1.349, delta=delta)
def test_generate_rankings_excluded_for_inactivity(self): now = datetime(2013, 11, 25) rankings.generate_ranking(self.dao, now=now, day_limit=45, num_tourneys=1) ranking = self.dao.get_latest_ranking() ranking_list = ranking.ranking self.assertEquals(len(ranking_list), 2) entry = ranking_list[0] self.assertEquals(entry.rank, 1) self.assertEquals(entry.player, self.player_1_id) self.assertAlmostEquals(entry.rating, 6.857, delta=delta) ''' entry = ranking_list[1] self.assertEquals(entry.rank, 2) self.assertEquals(entry.player, self.player_5_id) self.assertAlmostEquals(entry.rating, -.800, delta=delta, msg="" + str(entry.player)) ''' entry = ranking_list[1] self.assertEquals(entry.rank, 2) self.assertEquals(entry.player, self.player_2_id) self.assertAlmostEquals(entry.rating, -1.349, delta=delta)
def import_tournament(type, path, bracket, region, name): config = parse_config() username = config.get('database', 'user') host = config.get('database', 'host') auth_db = config.get('database', 'auth_db') password = getpass.getpass() mongo_client = MongoClient(host='mongodb://%s:%s@%s/%s' % (username, password, host, auth_db)) if type == 'tio': scraper = TioScraper(path, bracket) elif type =='challonge': scraper = ChallongeScraper(path) else: click.echo("Illegal type") dao = Dao(region, mongo_client=mongo_client) import_players(scraper, dao) tournament = Tournament.from_scraper(type, scraper, dao) if name: tournament.name = name dao.insert_tournament(tournament) click.echo("Generating new ranking...") rankings.generate_ranking(dao) click.echo("Done!")
def post(self, region): dao = Dao(region, mongo_client=mongo_client) user = get_user_from_access_token(request.headers, dao) if not is_user_admin_for_region(user, region): return 'Permission denied', 403 # we pass in now so we can mock it out in tests now = datetime.now() rankings.generate_ranking(dao, now=now) return self.get(region)
def setUp(self): self.mongo_client_patcher = patch('server.mongo_client', new=mongomock.MongoClient()) self.mongo_client = self.mongo_client_patcher.start() server.app.config['TESTING'] = True self.app = server.app.test_client() self.norcal_dao = Dao(NORCAL_REGION_NAME, mongo_client=self.mongo_client, new=True) self.texas_dao = Dao(TEXAS_REGION_NAME, mongo_client=self.mongo_client, new=True) self._import_files() rankings.generate_ranking(self.norcal_dao) rankings.generate_ranking(self.texas_dao)
def post(self, region): dao = get_dao(region) auth_user(request, dao) parser = reqparse.RequestParser() \ .add_argument('ranking_activity_day_limit', type=str) \ .add_argument('ranking_num_tourneys_attended', type=str) \ .add_argument('tournament_qualified_day_limit', type=str) args = parser.parse_args() # we pass in now so we can mock it out in tests now = datetime.now() try: try: ranking_num_tourneys_attended = int( args['ranking_num_tourneys_attended']) ranking_activity_day_limit = int( args['ranking_activity_day_limit']) tournament_qualified_day_limit = int( args['tournament_qualified_day_limit']) # TODO Get stored rankings from the db dao.update_region_ranking_criteria( region.lower(), ranking_num_tourneys_attended=ranking_num_tourneys_attended, ranking_activity_day_limit=ranking_activity_day_limit, tournament_qualified_day_limit= tournament_qualified_day_limit) print 'Running rankings. day_limit: ' + str(ranking_activity_day_limit) + \ ' and num_tourneys: ' + str(ranking_num_tourneys_attended) + \ ' and tournament_qualified_day_limit: ' + \ str(tournament_qualified_day_limit) rankings.generate_ranking( dao, now=now, day_limit=ranking_activity_day_limit, num_tourneys=ranking_num_tourneys_attended, tournament_qualified_day_limit= tournament_qualified_day_limit) except: rankings.generate_ranking(dao, now=now) except Exception as e: print str(e) err('There was an error updating rankings') return self.get(region)
def post(self, region): dao = get_dao(region) auth_user(request, dao) parser = reqparse.RequestParser() \ .add_argument('ranking_activity_day_limit', type=str) \ .add_argument('ranking_num_tourneys_attended', type=str) \ .add_argument('tournament_qualified_day_limit', type=str) args = parser.parse_args() # we pass in now so we can mock it out in tests now = datetime.now() try: try: ranking_num_tourneys_attended = int( args['ranking_num_tourneys_attended']) ranking_activity_day_limit = int( args['ranking_activity_day_limit']) tournament_qualified_day_limit = int( args['tournament_qualified_day_limit']) # TODO Get stored rankings from the db dao.update_region_ranking_criteria( region.lower(), ranking_num_tourneys_attended=ranking_num_tourneys_attended, ranking_activity_day_limit=ranking_activity_day_limit, tournament_qualified_day_limit=tournament_qualified_day_limit) print 'Running rankings. day_limit: ' + str(ranking_activity_day_limit) + \ ' and num_tourneys: ' + str(ranking_num_tourneys_attended) + \ ' and tournament_qualified_day_limit: ' + \ str(tournament_qualified_day_limit) rankings.generate_ranking(dao, now=now, day_limit=ranking_activity_day_limit, num_tourneys=ranking_num_tourneys_attended, tournament_qualified_day_limit=tournament_qualified_day_limit) except: rankings.generate_ranking(dao, now=now) except Exception as e: print str(e) err('There was an error updating rankings') return self.get(region)
def post(self, region): dao = Dao(region, mongo_client=mongo_client) args = rankings_criteria_get_parser.parse_args() if not dao: return 'Dao not found', 404 user = get_user_from_request(request, dao) if not user: return 'Permission denied', 403 if not is_user_admin_for_region(user, region): return 'Permission denied', 403 # we pass in now so we can mock it out in tests now = datetime.now() try: try: ranking_num_tourneys_attended = int(args['ranking_num_tourneys_attended']) ranking_activity_day_limit = int(args['ranking_activity_day_limit']) tournament_qualified_day_limit = int(args['tournament_qualified_day_limit']) tournament_id_to_diff = ObjectId(args['tournament_id_to_diff']) #TODO Get stored rankings from the db dao.update_region_ranking_criteria(region.lower(), ranking_num_tourneys_attended=ranking_num_tourneys_attended, ranking_activity_day_limit=ranking_activity_day_limit, tournament_qualified_day_limit=tournament_qualified_day_limit) print 'Running rankings. day_limit: ' + str(ranking_activity_day_limit) + ' and num_tourneys: ' \ + str(ranking_num_tourneys_attended) + ' and tournament_qualified_day_limit: ' + str(tournament_qualified_day_limit) tournament_to_diff = dao.get_tournament_by_id(tournament_id_to_diff) rankings.generate_ranking(dao, now=now, day_limit=ranking_activity_day_limit, num_tourneys=ranking_num_tourneys_attended, tournament_qualified_day_limit=tournament_qualified_day_limit, tournament_to_diff=tournament_to_diff) except: rankings.generate_ranking(dao, now=now) except Exception as e: print str(e) return 'There was an error updating rankings', 400 return self.get(region)
def bulk_import(path, region): config = parse_config() username = config.get('database', 'user') host = config.get('database', 'host') auth_db = config.get('database', 'auth_db') password = getpass.getpass() mongo_client = MongoClient(host='mongodb://%s:%s@%s/%s' % (username, password, host, auth_db)) dao = Dao(region, mongo_client=mongo_client, new=True) with open(path) as f: for line in f: line = line.strip() if line: print line scraper = ChallongeScraper(line) import_players(scraper, dao) import_tournament(scraper, dao) rankings.generate_ranking(dao)
def get(self, region): dao = Dao(region, mongo_client=mongo_client) args = rankings_get_parser.parse_args() if args['generateNew'] is not None and args['generateNew'] == 'true': rankings.generate_ranking(dao) return_dict = dao.get_latest_ranking().get_json_dict() del return_dict['_id'] return_dict['time'] = str(return_dict['time']) return_dict['tournaments'] = [str(t) for t in return_dict['tournaments']] ranking_list = [] for r in return_dict['ranking']: player = dao.get_player_by_id(r['player']) if player: r['name'] = player.name r['id'] = str(r.pop('player')) ranking_list.append(r) return_dict['ranking'] = ranking_list return return_dict
def test_generate_rankings(self): now = datetime(2013, 10, 17) # assert rankings before they get reset self.assertEquals(self.dao.get_player_by_id(self.player_1_id).ratings, self.player_1.ratings) self.assertEquals(self.dao.get_player_by_id(self.player_2_id).ratings, self.player_2.ratings) self.assertEquals(self.dao.get_player_by_id(self.player_3_id).ratings, self.player_3.ratings) self.assertEquals(self.dao.get_player_by_id(self.player_4_id).ratings, self.player_4.ratings) self.assertEquals(self.dao.get_player_by_id(self.player_5_id).ratings, self.player_5.ratings) rankings.generate_ranking(self.dao, now=now) # assert rankings after ranking calculation self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['norcal'].trueskill_rating.mu, 28.458, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['norcal'].trueskill_rating.sigma, 7.201, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_2_id).ratings['norcal'].trueskill_rating.mu, 18.043, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_2_id).ratings['norcal'].trueskill_rating.sigma, 6.464, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_3_id).ratings['norcal'].trueskill_rating.mu, 31.230, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_3_id).ratings['norcal'].trueskill_rating.sigma, 6.523, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_4_id).ratings['norcal'].trueskill_rating.mu, 18.770, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_4_id).ratings['norcal'].trueskill_rating.sigma, 6.523, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_5_id).ratings['norcal'].trueskill_rating.mu, 29.396, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_5_id).ratings['norcal'].trueskill_rating.sigma, 7.171, delta=delta) # player 1's rating for other regions should not have changed self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['texas'].trueskill_rating.mu, 25, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['texas'].trueskill_rating.sigma, 8.333, delta=delta) ranking = self.dao.get_latest_ranking() self.assertEquals(ranking.region, self.region_id) self.assertEquals(ranking.time, now) self.assertEquals(set(ranking.tournaments), set(self.tournament_ids)) ranking_list = ranking.ranking # the ranking should not have any excluded players self.assertEquals(len(ranking_list), 4) entry = ranking_list[0] self.assertEquals(entry.rank, 1) self.assertEquals(entry.player, self.player_5_id) self.assertAlmostEquals(entry.rating, 7.881, delta=delta) entry = ranking_list[1] self.assertEquals(entry.rank, 2) self.assertEquals(entry.player, self.player_1_id) self.assertAlmostEquals(entry.rating, 6.857, delta=delta) entry = ranking_list[2] self.assertEquals(entry.rank, 3) self.assertEquals(entry.player, self.player_4_id) self.assertAlmostEquals(entry.rating, -.800, delta=delta) entry = ranking_list[3] self.assertEquals(entry.rank, 4) self.assertEquals(entry.player, self.player_2_id) self.assertAlmostEquals(entry.rating, -1.349, delta=delta)
from dao import Dao from pymongo import MongoClient import rankings from config.config import Config config = Config() mongo_client = MongoClient(config.get_mongo_url()) regions = Dao.get_all_regions(mongo_client) for region in regions: d = Dao(region.id, mongo_client) rankings.generate_ranking(d)
def test_generate_rankings(self): now = datetime(2013, 10, 17) # assert rankings before they get reset self.assertEquals(self.dao.get_player_by_id(self.player_1_id).ratings, self.player_1.ratings) self.assertEquals(self.dao.get_player_by_id(self.player_2_id).ratings, self.player_2.ratings) self.assertEquals(self.dao.get_player_by_id(self.player_3_id).ratings, self.player_3.ratings) self.assertEquals(self.dao.get_player_by_id(self.player_4_id).ratings, self.player_4.ratings) self.assertEquals(self.dao.get_player_by_id(self.player_5_id).ratings, self.player_5.ratings) rankings.generate_ranking(self.dao, now=now, day_limit=30, num_tourneys=1) # assert rankings after ranking calculation self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['norcal'].mu, 28.458, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['norcal'].sigma, 7.201, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_2_id).ratings['norcal'].mu, 18.043, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_2_id).ratings['norcal'].sigma, 6.464, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_3_id).ratings['norcal'].mu, 2, delta=delta) #changing this b/c of new in regionon only stuff, lol self.assertAlmostEquals(self.dao.get_player_by_id(self.player_3_id).ratings['norcal'].sigma, 3, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_4_id).ratings['norcal'].mu, 25, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_4_id).ratings['norcal'].sigma, 8.333, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_5_id).ratings['norcal'].mu, 29.396, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_5_id).ratings['norcal'].sigma, 7.171, delta=delta) # player 1's rating for other regions should not have changed self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['texas'].mu, 25, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).ratings['texas'].sigma, 8.333, delta=delta) ranking = self.dao.get_latest_ranking() self.assertEquals(ranking.region, self.region_id) self.assertEquals(ranking.time, now) self.assertEquals(set(ranking.tournaments), set(self.tournament_ids)) ranking_list = ranking.ranking # the ranking should not have any excluded players self.assertEquals(len(ranking_list), 3) entry = ranking_list[0] self.assertEquals(entry.rank, 1) self.assertEquals(entry.player, self.player_5_id) self.assertAlmostEquals(entry.rating, 7.881, delta=delta) entry = ranking_list[1] self.assertEquals(entry.rank, 2) self.assertEquals(entry.player, self.player_1_id) self.assertAlmostEquals(entry.rating, 6.857, delta=delta) entry = ranking_list[2] self.assertEquals(entry.rank, 3) self.assertEquals(entry.player, self.player_2_id) self.assertAlmostEquals(entry.rating, -1.349, delta=delta) '''
def finalize_tournament(region, pending_tournament, dao): if not pending_tournament.are_all_aliases_mapped(): raise Exception("Not all aliases for the pending tournament have been mapped to an id.") tournament = Tournament.from_pending_tournament(pending_tournament) dao.insert_tournament(tournament) rankings.generate_ranking(dao)
def test_generate_rankings(self): now = datetime(2013, 10, 17) # assert rankings before they get reset self.assertEquals( self.dao.get_player_by_id(self.player_1_id).ratings, self.player_1.ratings) self.assertEquals( self.dao.get_player_by_id(self.player_2_id).ratings, self.player_2.ratings) self.assertEquals( self.dao.get_player_by_id(self.player_3_id).ratings, self.player_3.ratings) self.assertEquals( self.dao.get_player_by_id(self.player_4_id).ratings, self.player_4.ratings) self.assertEquals( self.dao.get_player_by_id(self.player_5_id).ratings, self.player_5.ratings) rankings.generate_ranking(self.dao, now=now) # assert rankings after ranking calculation self.assertAlmostEquals(self.dao.get_player_by_id( self.player_1_id).ratings['norcal'].trueskill_rating.mu, 28.458, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_1_id).ratings['norcal'].trueskill_rating.sigma, 7.201, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_2_id).ratings['norcal'].trueskill_rating.mu, 18.043, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_2_id).ratings['norcal'].trueskill_rating.sigma, 6.464, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_3_id).ratings['norcal'].trueskill_rating.mu, 31.230, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_3_id).ratings['norcal'].trueskill_rating.sigma, 6.523, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_4_id).ratings['norcal'].trueskill_rating.mu, 18.770, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_4_id).ratings['norcal'].trueskill_rating.sigma, 6.523, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_5_id).ratings['norcal'].trueskill_rating.mu, 29.396, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_5_id).ratings['norcal'].trueskill_rating.sigma, 7.171, delta=delta) # player 1's rating for other regions should not have changed self.assertAlmostEquals(self.dao.get_player_by_id( self.player_1_id).ratings['texas'].trueskill_rating.mu, 25, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_1_id).ratings['texas'].trueskill_rating.sigma, 8.333, delta=delta) ranking = self.dao.get_latest_ranking() self.assertEquals(ranking.region, self.region_id) self.assertEquals(ranking.time, now) self.assertEquals(set(ranking.tournaments), set(self.tournament_ids)) ranking_list = ranking.ranking # the ranking should not have any excluded players self.assertEquals(len(ranking_list), 4) entry = ranking_list[0] self.assertEquals(entry.rank, 1) self.assertEquals(entry.player, self.player_5_id) self.assertAlmostEquals(entry.rating, 7.881, delta=delta) entry = ranking_list[1] self.assertEquals(entry.rank, 2) self.assertEquals(entry.player, self.player_1_id) self.assertAlmostEquals(entry.rating, 6.857, delta=delta) entry = ranking_list[2] self.assertEquals(entry.rank, 3) self.assertEquals(entry.player, self.player_4_id) self.assertAlmostEquals(entry.rating, -.800, delta=delta) entry = ranking_list[3] self.assertEquals(entry.rank, 4) self.assertEquals(entry.player, self.player_2_id) self.assertAlmostEquals(entry.rating, -1.349, delta=delta)
def test_generate_rankings(self, mock_datetime): now = datetime(2013, 10, 17) mock_datetime.now.return_value = now # assert rankings before they get reset self.assertEquals(self.dao.get_player_by_id(self.player_1_id).rating, self.player_1.rating) self.assertEquals(self.dao.get_player_by_id(self.player_2_id).rating, self.player_2.rating) self.assertEquals(self.dao.get_player_by_id(self.player_3_id).rating, self.player_3.rating) self.assertEquals(self.dao.get_player_by_id(self.player_4_id).rating, self.player_4.rating) self.assertEquals(self.dao.get_player_by_id(self.player_5_id).rating, self.player_5.rating) rankings.generate_ranking(self.dao) # assert rankings after ranking calculation self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).rating.trueskill_rating.mu, 28.458, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_1_id).rating.trueskill_rating.sigma, 7.201, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_2_id).rating.trueskill_rating.mu, 18.043, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_2_id).rating.trueskill_rating.sigma, 6.464, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_3_id).rating.trueskill_rating.mu, 31.230, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_3_id).rating.trueskill_rating.sigma, 6.523, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_4_id).rating.trueskill_rating.mu, 18.770, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_4_id).rating.trueskill_rating.sigma, 6.523, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_5_id).rating.trueskill_rating.mu, 29.396, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id(self.player_5_id).rating.trueskill_rating.sigma, 7.171, delta=delta) ranking = self.dao.get_latest_ranking() self.assertEquals(ranking.time, now) self.assertEquals(set(ranking.tournaments), set(self.tournament_ids)) ranking_list = ranking.ranking # the ranking should not have any excluded players self.assertEquals(len(ranking_list), 4) entry = ranking_list[0] self.assertEquals(entry.rank, 1) self.assertEquals(entry.player, self.player_5_id) self.assertAlmostEquals(entry.rating, 7.881, delta=delta) entry = ranking_list[1] self.assertEquals(entry.rank, 2) self.assertEquals(entry.player, self.player_1_id) self.assertAlmostEquals(entry.rating, 6.857, delta=delta) entry = ranking_list[2] self.assertEquals(entry.rank, 3) self.assertEquals(entry.player, self.player_4_id) self.assertAlmostEquals(entry.rating, -.800, delta=delta) entry = ranking_list[3] self.assertEquals(entry.rank, 4) self.assertEquals(entry.player, self.player_2_id) self.assertAlmostEquals(entry.rating, -1.349, delta=delta)
def test_generate_rankings(self): now = datetime(2013, 10, 17) # assert rankings before they get reset self.assertEquals( self.dao.get_player_by_id(self.player_1_id).ratings, self.player_1.ratings) self.assertEquals( self.dao.get_player_by_id(self.player_2_id).ratings, self.player_2.ratings) self.assertEquals( self.dao.get_player_by_id(self.player_3_id).ratings, self.player_3.ratings) self.assertEquals( self.dao.get_player_by_id(self.player_4_id).ratings, self.player_4.ratings) self.assertEquals( self.dao.get_player_by_id(self.player_5_id).ratings, self.player_5.ratings) rankings.generate_ranking(self.dao, now=now, day_limit=30, num_tourneys=1) # assert rankings after ranking calculation self.assertAlmostEquals(self.dao.get_player_by_id( self.player_1_id).ratings['norcal'].mu, 28.458, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_1_id).ratings['norcal'].sigma, 7.201, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_2_id).ratings['norcal'].mu, 18.043, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_2_id).ratings['norcal'].sigma, 6.464, delta=delta) self.assertAlmostEquals( self.dao.get_player_by_id(self.player_3_id).ratings['norcal'].mu, 2, delta=delta) #changing this b/c of new in regionon only stuff, lol self.assertAlmostEquals(self.dao.get_player_by_id( self.player_3_id).ratings['norcal'].sigma, 3, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_4_id).ratings['norcal'].mu, 25, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_4_id).ratings['norcal'].sigma, 8.333, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_5_id).ratings['norcal'].mu, 29.396, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_5_id).ratings['norcal'].sigma, 7.171, delta=delta) # player 1's rating for other regions should not have changed self.assertAlmostEquals(self.dao.get_player_by_id( self.player_1_id).ratings['texas'].mu, 25, delta=delta) self.assertAlmostEquals(self.dao.get_player_by_id( self.player_1_id).ratings['texas'].sigma, 8.333, delta=delta) ranking = self.dao.get_latest_ranking() self.assertEquals(ranking.region, self.region_id) self.assertEquals(ranking.time, now) self.assertEquals(set(ranking.tournaments), set(self.tournament_ids)) ranking_list = ranking.ranking # the ranking should not have any excluded players self.assertEquals(len(ranking_list), 3) entry = ranking_list[0] self.assertEquals(entry.rank, 1) self.assertEquals(entry.player, self.player_5_id) self.assertAlmostEquals(entry.rating, 7.881, delta=delta) entry = ranking_list[1] self.assertEquals(entry.rank, 2) self.assertEquals(entry.player, self.player_1_id) self.assertAlmostEquals(entry.rating, 6.857, delta=delta) entry = ranking_list[2] self.assertEquals(entry.rank, 3) self.assertEquals(entry.player, self.player_2_id) self.assertAlmostEquals(entry.rating, -1.349, delta=delta) '''