mirror of
https://github.com/nprasad2077/nbaStats.git
synced 2026-11-06 01:50:33 +00:00
create script to reset TOTALS DB
This commit is contained in:
1 parent
9efa5685c8
commit
9a845ade4a
4 files changed
+204
-57
No files matched your search
@@ -0,0 +1,17 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from nba_data.models import PlayerTotalsData
|
||||
from django.db import connection
|
||||
|
||||
class Command(BaseCommand):
|
||||
# Provides a description for use with the custom django management command (python manage.py help).
|
||||
help = 'Delete all player TOTALS data and reset primary key sequence in DB'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# Delete all player data
|
||||
PlayerTotalsData.objects.all().delete()
|
||||
|
||||
# Reset the PK sequence
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute('ALTER SEQUENCE nba_data_playertotalsdata_id_seq RESTART WITH 1;')
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Successfully deleted all players in DB'))
|
||||
@@ -0,0 +1,128 @@
|
||||
# Generated by Django 4.2 on 2023-04-27 20:53
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('nba_data', '0006_playeradvanceddata_playertotalsdata'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='AST',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='BLK',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='DRB',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='ORB',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='PF',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='PTS',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='STL',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='TOV',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='TRB',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='effect_fg_percent',
|
||||
field=models.DecimalField(decimal_places=3, max_digits=6, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='field_attempts',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='field_goals',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='field_percent',
|
||||
field=models.DecimalField(decimal_places=3, max_digits=6, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='ft',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='ft_percent',
|
||||
field=models.DecimalField(decimal_places=3, max_digits=6, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='fta',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='minutes_played',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='three_attempts',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='three_fg',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='three_percent',
|
||||
field=models.DecimalField(decimal_places=3, max_digits=6, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='two_attempts',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='two_fg',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='playertotalsdata',
|
||||
name='two_percent',
|
||||
field=models.DecimalField(decimal_places=3, max_digits=6, null=True),
|
||||
),
|
||||
]
|
||||
+23
-23
@@ -40,29 +40,29 @@ class PlayerTotalsData(models.Model):
|
||||
age = models.IntegerField(null=True)
|
||||
games = models.IntegerField(null=True)
|
||||
games_started = models.IntegerField(null=True)
|
||||
minutes_played = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
field_goals = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
field_attempts = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
field_percent = models.DecimalField(max_digits=5, decimal_places=3, null=True)
|
||||
three_fg = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
three_attempts = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
three_percent = models.DecimalField(max_digits=5, decimal_places=3, null=True)
|
||||
two_fg = models.DecimalField(max_digits=5, decimal_places=3, null=True)
|
||||
two_attempts = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
two_percent = models.DecimalField(max_digits=5, decimal_places=3, null=True)
|
||||
effect_fg_percent = models.DecimalField(max_digits=5, decimal_places=3, null=True)
|
||||
ft = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
fta = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
ft_percent = models.DecimalField(max_digits=5, decimal_places=3, null=True)
|
||||
ORB= models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
DRB = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
TRB = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
AST = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
STL = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
BLK = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
TOV = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
PF = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
PTS = models.DecimalField(max_digits=5, decimal_places=2, null=True)
|
||||
minutes_played = models.IntegerField(null=True)
|
||||
field_goals = models.IntegerField(null=True)
|
||||
field_attempts = models.IntegerField(null=True)
|
||||
field_percent = models.DecimalField(max_digits=6, decimal_places=3, null=True)
|
||||
three_fg = models.IntegerField(null=True)
|
||||
three_attempts = models.IntegerField(null=True)
|
||||
three_percent = models.DecimalField(max_digits=6, decimal_places=3, null=True)
|
||||
two_fg = models.IntegerField(null=True)
|
||||
two_attempts = models.IntegerField(null=True)
|
||||
two_percent = models.DecimalField(max_digits=6, decimal_places=3, null=True)
|
||||
effect_fg_percent = models.DecimalField(max_digits=6, decimal_places=3, null=True)
|
||||
ft = models.IntegerField(null=True)
|
||||
fta = models.IntegerField(null=True)
|
||||
ft_percent = models.DecimalField(max_digits=6, decimal_places=3, null=True)
|
||||
ORB= models.IntegerField(null=True)
|
||||
DRB = models.IntegerField(null=True)
|
||||
TRB = models.IntegerField(null=True)
|
||||
AST = models.IntegerField(null=True)
|
||||
STL = models.IntegerField(null=True)
|
||||
BLK = models.IntegerField(null=True)
|
||||
TOV = models.IntegerField(null=True)
|
||||
PF = models.IntegerField(null=True)
|
||||
PTS = models.IntegerField(null=True)
|
||||
team = models.CharField(max_length=30, default='')
|
||||
season = models.IntegerField(null=True)
|
||||
|
||||
|
||||
@@ -70,40 +70,42 @@ for team in teams:
|
||||
with open(json_output_path, 'w') as jsonfile:
|
||||
json.dump(data, jsonfile)
|
||||
|
||||
# # save data to database
|
||||
# for row in data:
|
||||
# player_data = PlayerData(
|
||||
# name=row['Player'],
|
||||
# age=row['Age'],
|
||||
# games=row['G'],
|
||||
# games_started=row['GS'],
|
||||
# minutes_pg=row['MP'],
|
||||
# field_goals=row['FG'],
|
||||
# field_attempts=row['FGA'],
|
||||
# field_percent=row['FG%'],
|
||||
# three_fg=row['3P'],
|
||||
# three_attempts=row['3PA'],
|
||||
# three_percent=row['3P%'],
|
||||
# two_fg=row['2P'],
|
||||
# two_attempts=row['2PA'],
|
||||
# two_percent=row['2P%'],
|
||||
# effect_fg_percent=row['eFG%'],
|
||||
# ft=row['FT'],
|
||||
# fta=row['FTA'],
|
||||
# ft_percent=row['FT%'],
|
||||
# ORB=row['ORB'],
|
||||
# DRB=row['DRB'],
|
||||
# TRB=row['TRB'],
|
||||
# AST=row['AST'],
|
||||
# STL=row['STL'],
|
||||
# BLK=row['BLK'],
|
||||
# TOV=row['TOV'],
|
||||
# PF=row['PF'],
|
||||
# PTS=row['PTS'],
|
||||
# team=row['team'],
|
||||
# season=row['season'],
|
||||
# )
|
||||
# player_data.save()
|
||||
# save data to database
|
||||
for row in data:
|
||||
player_data = PlayerTotalsData(
|
||||
player_name = row['Player'],
|
||||
age = row['Age'],
|
||||
games = row['G'],
|
||||
games_started = row['GS'],
|
||||
minutes_played = row['MP'],
|
||||
field_goals = row['FG'],
|
||||
field_attempts = row['FGA'],
|
||||
field_percent = row['FG%'],
|
||||
three_fg = row['3P'],
|
||||
three_attempts = row['3PA'],
|
||||
three_percent = row['3P%'],
|
||||
two_fg = row['2P'],
|
||||
two_attempts = row['2PA'],
|
||||
two_percent = row['2P%'],
|
||||
effect_fg_percent = row['eFG%'],
|
||||
ft = row['FT'],
|
||||
fta = row['FTA'],
|
||||
ft_percent = row['FT%'],
|
||||
ORB= row['ORB'],
|
||||
DRB = row['DRB'],
|
||||
TRB = row['TRB'],
|
||||
AST = row['AST'],
|
||||
STL = row['STL'],
|
||||
BLK = row['BLK'],
|
||||
TOV = row['TOV'],
|
||||
PF = row['PF'],
|
||||
PTS = row['PTS'],
|
||||
team = row['team'],
|
||||
season = row['season'],
|
||||
)
|
||||
player_data.save()
|
||||
|
||||
print('success')
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user