#!/usr/bin/env python3
"""Debug script to understand why 508 players are unassigned"""

import json

def load_data():
    """Load player data"""
    all_players = []
    for season in range(1, 13):
        with open(f"/tmp/players_season_{season}.json", 'r') as f:
            season_data = json.load(f)
        all_players.extend(season_data)
    
    return all_players

def main():
    players = load_data()
    print(f"Total players loaded: {len(players)}")
    
    # Check for players already assigned to SbaPlayer
    already_assigned = [p for p in players if p.get('sbaplayer_id')]
    print(f"Already assigned players: {len(already_assigned)}")
    
    # Check season distribution
    season_counts = {}
    for p in players:
        season = p['season']
        season_counts[season] = season_counts.get(season, 0) + 1
    
    print("\nSeason distribution:")
    for season in sorted(season_counts.keys()):
        print(f"  Season {season}: {season_counts[season]} players")
    
    # Show some sample unassigned players
    unassigned_names = set()
    for p in players:
        if not p.get('sbaplayer_id'):
            unassigned_names.add(p['name'])
    
    print(f"\nTotal unique unassigned player names: {len(unassigned_names)}")
    print("Sample unassigned players:")
    for name in sorted(list(unassigned_names))[:20]:
        print(f"  {name}")

if __name__ == "__main__":
    main()