mirror of
https://github.com/nprasad2077/nbaStats.git
synced 2026-11-13 13:23:46 +00:00
find duplicates and delete script
This commit is contained in:
1 parent
e51e25fe08
commit
f92e4cc54e
2 files changed
+30
-1
No files matched your search
@@ -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}"))
|
||||||
@@ -27,7 +27,9 @@ from nba_data.models import PlayerPlayoffAdvancedData
|
|||||||
# Change LAC to SDC for 1984 and prior.
|
# 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']
|
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']
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user