diff --git a/nba_data/management/commands/remove_duplicates_playoff_advanced.py b/nba_data/management/commands/remove_duplicates_playoff_advanced.py new file mode 100644 index 0000000..d2414b5 --- /dev/null +++ b/nba_data/management/commands/remove_duplicates_playoff_advanced.py @@ -0,0 +1,27 @@ +from django.core.management.base import BaseCommand +from nba_data.models import PlayerPlayoffAdvancedData + + +class Command(BaseCommand): + help = 'Remove duplicate records for DAL and BOS in season 2010' + + def handle(self, *args, **options): + season = 2010 + teams = ['DAL', 'BOS'] + + for team in teams: + duplicates = PlayerPlayoffAdvancedData.objects.filter(season=season, team=team).order_by('player_name') + + # Group records by name + players_grouped = {} + for duplicate in duplicates: + if duplicate.player_name not in players_grouped: + players_grouped[duplicate.player_name] = [] + players_grouped[duplicate.player_name].append(duplicate) + + # Delete duplicates while keeping one record per player + for player_name, player_records in players_grouped.items(): + if len(player_records) > 1: + for player_record in player_records[1:]: + player_record.delete() + self.stdout.write(self.style.SUCCESS(f"Deleted duplicate {player_name} for {team} in season {season}")) \ No newline at end of file diff --git a/nba_data/nba_scraper_playoffs_advanced.py b/nba_data/nba_scraper_playoffs_advanced.py index 77fee73..9bb8fc4 100644 --- a/nba_data/nba_scraper_playoffs_advanced.py +++ b/nba_data/nba_scraper_playoffs_advanced.py @@ -27,7 +27,9 @@ from nba_data.models import PlayerPlayoffAdvancedData # Change LAC to SDC for 1984 and prior. -teams = ['HOU' ,'PHI', 'BOS', 'NYK', 'BRK', 'TOR', 'MEM', 'NOP', 'DAL', 'SAS', 'DEN', 'MIN', 'OKC', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA'] +teams = ['HOU' ,'PHI', 'BOS', 'NYK', 'NJN', 'TOR', 'MEM', 'NOH', 'DAL', 'SAS', 'DEN', 'MIN', 'OKC', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA'] + +teams2 = ['HOU' ,'PHI', 'NYK', 'NJN', 'TOR', 'MEM', 'NOH', 'SAS', 'DEN', 'MIN', 'OKC', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA'] team_abbreviations = ['ATL', 'BOS', 'BRK', 'CHI', 'CHO', 'CLE', 'DAL', 'DEN', 'DET', 'GSW', 'HOU', 'IND', 'LAC', 'LAL', 'MEM', 'MIA', 'MIL', 'MIN', 'NOP', 'NYK', 'OKC', 'ORL', 'PHI', 'PHO', 'POR', 'SAC', 'SAS', 'TOR', 'UTA', 'WAS']