Skip to content

Commit

Permalink
Revert "Try global leaderboard stuff"
Browse files Browse the repository at this point in the history
This reverts commit b739537.
  • Loading branch information
BrennanB committed Sep 23, 2024
1 parent e409f72 commit 28c5fe5
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 95 deletions.
26 changes: 0 additions & 26 deletions ranked/templates/ranked/global_leaderboard.html

This file was deleted.

5 changes: 2 additions & 3 deletions ranked/templates/ranked/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ <h1 style="color: white" class="display-4 fw-normal">
<a href="/ranked/{{ leaderboard_code }}/{{ player_data.player.player.id }}">{{ player_data.player.player }}</a>
</td>
<td>{{ player_data.player.elo|floatformat:1 }}</td>
<td>{{ player_data.mmr|floatformat:1 }}</td>
<!-- Updated line to use CSS class instead of inline style -->
<td class="{{ player_data.color }}">{{ player_data.rank }}</td>
<td>{{ player_data.player.mmr|floatformat:1 }}</td>
<td style="color: {{ player_data.color }}">{{ player_data.rank }}</td>
<td>{{ player_data.player.matches_played }}</td>
<td>{{ player_data.player.win_rate|floatformat:2 }}%</td>
<td>{{ player_data.player.matches_won }}</td>
Expand Down
1 change: 0 additions & 1 deletion ranked/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
path('', views.ranked_home, name='home'),
path('<str:name>/', views.leaderboard, name='leaderboard'),
path('<str:name>/<str:player_id>', views.player_info, name='player_info'),
path('global_leaderboard/', views.global_leaderboard, name='global_leaderboard'),
]
66 changes: 1 addition & 65 deletions ranked/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.shortcuts import render, HttpResponseRedirect
from django.db.models import Max, Min, F, Q, Count, ExpressionWrapper, FloatField, Case, When, Value, Sum
from django.db.models import Max, Min, F, Q, Count, ExpressionWrapper, FloatField, Case, When, Value
from django.utils import timezone
from datetime import datetime, timedelta
import math
Expand Down Expand Up @@ -115,67 +115,3 @@ def player_info(request, name, player_id):

def mmr_calc(elo, matches_played, delta_hours):
return elo * 2 / ((1 + pow(math.e, 1/168 * pow(delta_hours, 0.63))) * (1 + pow(math.e, -0.33 * matches_played)))

def global_leaderboard(request):
# Fetch all players
players = PlayerElo.objects.all()

global_scores = []

for player in players:
# Fetch all game modes for the player
game_modes = GameMode.objects.filter(playerelo=player)

if not game_modes.exists():
continue

# Determine the most played game mode per game type
game_type_dict = {}
for mode in game_modes:
game_type = mode.game
match_count = mode.match_count # Assuming 'match_count' exists
if game_type not in game_type_dict or match_count > game_type_dict[game_type]['match_count']:
game_type_dict[game_type] = {'mode': mode, 'match_count': match_count}

# Calculate weighted Elo
total_weight = 0
weighted_elo = 0
for game_type, data in game_type_dict.items():
weight = data['match_count'] # Full weight for the most played game
weighted_elo += data['mode'].elo * weight
total_weight += weight

# Adjust weights for less played games (1/3 weight)
for game_type, data in game_type_dict.items():
if data['match_count'] < max(d['match_count'] for d in game_type_dict.values()):
weighted_elo += data['mode'].elo * (data['match_count'] / 3)
total_weight += data['match_count'] / 3

if total_weight > 0:
global_elo = weighted_elo / total_weight
global_scores.append({'player': player, 'global_elo': global_elo})

# Sort players by global Elo in descending order
global_scores = sorted(global_scores, key=lambda x: x['global_elo'], reverse=True)

# Assign ranks and colors
highest_elo = global_scores[0]['global_elo'] if global_scores else 0
lowest_elo = global_scores[-1]['global_elo'] if global_scores else 0

players_with_rank = []
for entry in global_scores:
rank, color = mmr_to_rank(entry['global_elo'], highest_elo, lowest_elo)
players_with_rank.append({
'player': entry['player'],
'rank': rank,
'color': color,
'global_elo': round(entry['global_elo'], 1),
})

context = {
'leaderboard_code': 'global',
'leaderboard_name': 'Global Elo Leaderboard',
'players_with_rank': players_with_rank,
}

return render(request, "ranked/global_leaderboard.html", context)

0 comments on commit 28c5fe5

Please sign in to comment.