player analysis update
This commit is contained in:
+29
-10
@@ -165,17 +165,26 @@ class Scoring:
|
||||
for participant_id, participant in league_data['participants'].items():
|
||||
tournament_scores = []
|
||||
|
||||
# Get all tournament scores where player participated
|
||||
# Get all tournament scores where player participated with tournament number
|
||||
for result in participant['tournament_results']:
|
||||
if result['participated']:
|
||||
tournament_scores.append(result['score'])
|
||||
tournament_scores.append({
|
||||
'tournament_number': result.get('tournament', result.get('league_tournament_number', 0)),
|
||||
'score': result['score']
|
||||
})
|
||||
|
||||
# Sort scores descending and take best 4
|
||||
tournament_scores.sort(reverse=True)
|
||||
tournament_scores.sort(key=lambda x: x['score'], reverse=True)
|
||||
best_scores = tournament_scores[:4] if len(tournament_scores) > 4 else tournament_scores
|
||||
|
||||
participant['final_score'] = sum(best_scores)
|
||||
# Track which tournament was excluded (if any)
|
||||
excluded_tournament = None
|
||||
if len(tournament_scores) > 4:
|
||||
excluded_tournament = tournament_scores[4]['tournament_number']
|
||||
|
||||
participant['final_score'] = sum(item['score'] for item in best_scores)
|
||||
participant['tournaments_participated'] = len(tournament_scores)
|
||||
participant['excluded_tournament'] = excluded_tournament
|
||||
|
||||
@staticmethod
|
||||
def get_league_final_rankings(league_data):
|
||||
@@ -196,7 +205,8 @@ class Scoring:
|
||||
'tournaments_participated': data['tournaments_participated'],
|
||||
'joker_used': data['joker_used'],
|
||||
'tournament_results': data['tournament_results'],
|
||||
'total_tens': total_tens
|
||||
'total_tens': total_tens,
|
||||
'excluded_tournament': data.get('excluded_tournament', None)
|
||||
})
|
||||
|
||||
# Sort by final score (best 4 tournaments) descending, then by total 10s
|
||||
@@ -219,16 +229,24 @@ class Scoring:
|
||||
|
||||
for result in data['tournament_results']:
|
||||
if result['participated']:
|
||||
tournament_scores.append(result['score'])
|
||||
tournament_scores.append({
|
||||
'tournament_number': result.get('tournament', result.get('league_tournament_number', 0)),
|
||||
'score': result['score']
|
||||
})
|
||||
completed_tournaments += 1
|
||||
total_tens += result.get('tens_count', 0)
|
||||
|
||||
# Current score is sum of all completed tournaments
|
||||
current_total = sum(tournament_scores)
|
||||
current_total = sum(item['score'] for item in tournament_scores)
|
||||
|
||||
# For display, show what the final score would be if we took best 4 now
|
||||
tournament_scores.sort(reverse=True)
|
||||
projected_final = sum(tournament_scores[:4]) if len(tournament_scores) >= 4 else sum(tournament_scores)
|
||||
tournament_scores_sorted = sorted(tournament_scores, key=lambda x: x['score'], reverse=True)
|
||||
projected_final = sum(item['score'] for item in tournament_scores_sorted[:4]) if len(tournament_scores_sorted) >= 4 else sum(item['score'] for item in tournament_scores_sorted)
|
||||
|
||||
# Track which tournament would be excluded (if we have more than 4)
|
||||
excluded_tournament = None
|
||||
if len(tournament_scores_sorted) > 4:
|
||||
excluded_tournament = tournament_scores_sorted[4]['tournament_number']
|
||||
|
||||
participants.append({
|
||||
'id': player_id,
|
||||
@@ -238,7 +256,8 @@ class Scoring:
|
||||
'tournaments_completed': completed_tournaments,
|
||||
'joker_used': data['joker_used'],
|
||||
'tournament_results': data['tournament_results'],
|
||||
'total_tens': total_tens
|
||||
'total_tens': total_tens,
|
||||
'excluded_tournament': excluded_tournament
|
||||
})
|
||||
|
||||
# Sort by current total score (descending), then by total 10s
|
||||
|
||||
Reference in New Issue
Block a user