Exemplo n.º 1
0
def team_elo():
	team_elo = {}
	for game in Game.select(sqlbuilder.IN(Game.q.id, sqlbuilder.Select(
			GameTeam.q.gameID, where=GameTeam.q.score>0)), orderBy='date'):

		pre_game = []
		for gameTeam in game.gameTeams:
			pre_game.append((gameTeam.team, team_elo.get(gameTeam.team.id, elo.start_r), gameTeam.score))
		assert len(pre_game) == 2, 'Should have exactly two teams in game'

		(teama, ra, scorea), (teamb, rb, scoreb) = pre_game
		if scorea > scoreb:
			sa = 1
			sb = 0
		elif scorea == scoreb:
			sa = .5
			sb = .5
		else:
			sa = 0
			sb = 1

		team_elo[teama.id] = elo.r(ra, [(rb, sa)], elo.k)
		team_elo[teamb.id] = elo.r(rb, [(ra, sb)], elo.k)

	return team_elo
Exemplo n.º 2
0
def race_elo():
	race_elo = {}
	for game in Game.select(sqlbuilder.IN(Game.q.id, sqlbuilder.Select(
			GameTeam.q.gameID, where=GameTeam.q.score>0)), orderBy='date'):

		pre_game = []
		for gameTeam in game.gameTeams:
			pre_game.append((gameTeam.team.race, race_elo.get(gameTeam.team.race.id, elo.start_r), gameTeam.score))
		assert len(pre_game) == 2, 'Should have exactly two races in game'

		(racea, ra, scorea), (raceb, rb, scoreb) = pre_game
		if racea.id == raceb.id:
			continue # skip games that are between the same race
		if scorea > scoreb:
			sa = 1
			sb = 0
		elif scorea == scoreb:
			sa = .5
			sb = .5
		else:
			sa = 0
			sb = 1

		race_elo[racea.id] = elo.r(ra, [(rb, sa)], elo.k)
		race_elo[raceb.id] = elo.r(rb, [(ra, sb)], elo.k)

	return race_elo