Skip to content
Snippets Groups Projects
Commit 8852492a authored by maeries's avatar maeries
Browse files

added world ranking info to team page

parent 7e8ebf15
No related branches found
No related tags found
No related merge requests found
......@@ -155,6 +155,9 @@ class EloSystem:
# For each team, compare with teams ranked below them
date = self.get_competition_date(competition_id) # Use current date as competition date
old_world_ranking = sorted(self.teams.items(), key=lambda x: x[1]['elo'], reverse=True)
old_world_ranking = tuple(name for name, _ in old_world_ranking)
for i in range(len(teams_in_order)):
for j in range(i + 1, len(teams_in_order)):
team_a = teams_in_order[i]
......@@ -165,29 +168,41 @@ class EloSystem:
# Store post-competition Elo ratings and changes
for team in teams_in_order:
rank = teams_in_order.index(team) + 1
placement = teams_in_order.index(team) + 1
previous_elo = self.teams[team]['elo']
elo_change = self.teams[team]['delta_elo']
old_rank = old_world_ranking.index(team) + 1
new_rank = 0
# Store in team history
self.teams[team]['history'].append({
'date': date.strftime("%Y-%m-%d"),
'competition': self.get_competition_name(competition_id),
'competition_id': competition_id,
'rank': rank,
'placement': placement,
'participants': len(teams_in_order),
'previous_elo': previous_elo,
'new_elo': self.teams[team]['elo'] + self.teams[team]['delta_elo'],
'elo_change': elo_change
'elo_change': elo_change,
'old_rank': old_rank,
'new_rank': new_rank,
'rank_change': new_rank - old_rank
})
# Store in competition history
self.competition_history[competition_id]['results'][rank-1][2] = previous_elo
self.competition_history[competition_id]['results'][rank-1][3] = elo_change
self.competition_history[competition_id]['results'][placement-1][2] = previous_elo
self.competition_history[competition_id]['results'][placement-1][3] = elo_change
self.teams[team]['elo'] = self.teams[team]['elo'] + self.teams[team]['delta_elo']
self.teams[team]['delta_elo'] = 0
for team in teams_in_order:
new_world_ranking = sorted(self.teams.items(), key=lambda x: x[1]['elo'], reverse=True)
new_world_ranking = tuple(name for name, _ in new_world_ranking)
new_rank = new_world_ranking.index(team) + 1
self.teams[team]['history'][-1]['new_rank'] = new_rank
self.teams[team]['history'][-1]['rank_change'] = new_rank - self.teams[team]['history'][-1]['old_rank']
def update_elo_pair(self, team_a, team_b, score_a, score_b, competition_id, date):
"""Update Elo ratings for a pair of teams based on their match outcome"""
# Get current Elo ratings
......@@ -448,7 +463,7 @@ class EloSystem:
# Add competition labels
for i, entry in enumerate(team_history):
plt.annotate(entry['competition'] + f" (#{entry['rank']})",
plt.annotate(entry['competition'] + f" (#{entry['placement']})",
(i, entry['new_elo']),
textcoords="offset points",
xytext=(0, 10),
......
......@@ -149,8 +149,8 @@ def get_team_page_html(self, team_name, team_data, team_competitions):
# Calculate average ranking if available
if team_competitions:
avg_rank = sum(comp['rank'] for comp in team_competitions) / len(team_competitions)
best_rank = min(comp['rank'] for comp in team_competitions)
avg_rank = sum(comp['placement'] for comp in team_competitions) / len(team_competitions)
best_rank = min(comp['placement'] for comp in team_competitions)
html_content += f"""
<div class="stat-box">
......@@ -175,8 +175,11 @@ def get_team_page_html(self, team_name, team_data, team_competitions):
<table>
<tr>
<th>Date</th>
<th>Competition</th>
<th>Comp</th>
<th>Placement</th>
<th>Rank Before</th>
<th>Rank After</th>
<th>Rank Change</th>
<th>Elo Before</th>
<th>Elo After</th>
<th>Elo Change</th>
......@@ -186,16 +189,21 @@ def get_team_page_html(self, team_name, team_data, team_competitions):
# Add rows for each competition
for comp in team_competitions:
elo_change = comp['elo_change']
change_class = "positive" if elo_change > 0 else "negative" if elo_change < 0 else ""
elo_change_class = "positive" if elo_change > 0 else "negative" if elo_change < 0 else ""
rank_change = comp['rank_change']
rank_change_class = "positive" if rank_change < 0 else "negative" if rank_change > 0 else ""
html_content += f"""
<tr>
<td>{comp['date']}</td>
<td><a href=../comp/{comp['competition_id']}.html>{comp['competition']}</a></td>
<td>{comp['rank']} / {comp['participants']}</td>
<td>{comp['placement']} / {comp['participants']}</td>
<td>{comp['old_rank']}</td>
<td>{comp['new_rank']}</td>
<td class="{rank_change_class}">{'+' if rank_change > 0 else ''}{comp['rank_change']}</td>
<td>{int(comp['previous_elo'])}</td>
<td>{int(comp['new_elo'])}</td>
<td class="{change_class}">{'+' if elo_change > 0 else ''}{elo_change:.1f}</td>
<td class="{elo_change_class}">{'+' if elo_change > 0 else ''}{elo_change:.1f}</td>
</tr>"""
html_content += """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment