phase3: add normalized domain schema, admin, services, and multistage docker build
This commit is contained in:
23
apps/stats/admin.py
Normal file
23
apps/stats/admin.py
Normal file
@ -0,0 +1,23 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import PlayerSeason, PlayerSeasonStats
|
||||
|
||||
|
||||
@admin.register(PlayerSeason)
|
||||
class PlayerSeasonAdmin(admin.ModelAdmin):
|
||||
list_display = ("player", "season", "team", "competition", "games_played", "minutes_played")
|
||||
list_filter = ("season", "competition")
|
||||
search_fields = ("player__full_name", "team__name", "competition__name", "season__label")
|
||||
|
||||
|
||||
@admin.register(PlayerSeasonStats)
|
||||
class PlayerSeasonStatsAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"player_season",
|
||||
"points",
|
||||
"rebounds",
|
||||
"assists",
|
||||
"usage_rate",
|
||||
"true_shooting_pct",
|
||||
)
|
||||
search_fields = ("player_season__player__full_name",)
|
||||
93
apps/stats/migrations/0001_initial.py
Normal file
93
apps/stats/migrations/0001_initial.py
Normal file
@ -0,0 +1,93 @@
|
||||
# Generated by Django 5.2.12 on 2026-03-10 09:33
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('competitions', '0002_initial'),
|
||||
('players', '0002_initial'),
|
||||
('teams', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='PlayerSeason',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('games_played', models.PositiveSmallIntegerField(default=0)),
|
||||
('games_started', models.PositiveSmallIntegerField(default=0)),
|
||||
('minutes_played', models.PositiveIntegerField(default=0)),
|
||||
('competition', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='player_seasons', to='competitions.competition')),
|
||||
('player', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='player_seasons', to='players.player')),
|
||||
('season', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='player_seasons', to='competitions.season')),
|
||||
('team', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='player_seasons', to='teams.team')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['-season__start_date', 'player__full_name'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='PlayerSeasonStats',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('points', models.DecimalField(decimal_places=2, default=0, max_digits=6)),
|
||||
('rebounds', models.DecimalField(decimal_places=2, default=0, max_digits=6)),
|
||||
('assists', models.DecimalField(decimal_places=2, default=0, max_digits=6)),
|
||||
('steals', models.DecimalField(decimal_places=2, default=0, max_digits=6)),
|
||||
('blocks', models.DecimalField(decimal_places=2, default=0, max_digits=6)),
|
||||
('turnovers', models.DecimalField(decimal_places=2, default=0, max_digits=6)),
|
||||
('fg_pct', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
||||
('three_pct', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
||||
('ft_pct', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
||||
('usage_rate', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
||||
('true_shooting_pct', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
||||
('player_efficiency_rating', models.DecimalField(blank=True, decimal_places=2, max_digits=6, null=True)),
|
||||
('player_season', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='stats', to='stats.playerseason')),
|
||||
],
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='playerseason',
|
||||
index=models.Index(fields=['player', 'season'], name='stats_playe_player__588dfe_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='playerseason',
|
||||
index=models.Index(fields=['season', 'team'], name='stats_playe_season__a42291_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='playerseason',
|
||||
index=models.Index(fields=['season', 'competition'], name='stats_playe_season__acbf94_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='playerseason',
|
||||
index=models.Index(fields=['team', 'competition'], name='stats_playe_team_id_9d2ead_idx'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='playerseason',
|
||||
constraint=models.UniqueConstraint(fields=('player', 'season', 'team', 'competition'), name='uq_player_season_scope'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='playerseasonstats',
|
||||
index=models.Index(fields=['points'], name='stats_playe_points_8222f6_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='playerseasonstats',
|
||||
index=models.Index(fields=['rebounds'], name='stats_playe_rebound_662f1b_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='playerseasonstats',
|
||||
index=models.Index(fields=['assists'], name='stats_playe_assists_960591_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='playerseasonstats',
|
||||
index=models.Index(fields=['usage_rate'], name='stats_playe_usage_r_79913f_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='playerseasonstats',
|
||||
index=models.Index(fields=['true_shooting_pct'], name='stats_playe_true_sh_552b8f_idx'),
|
||||
),
|
||||
]
|
||||
71
apps/stats/models.py
Normal file
71
apps/stats/models.py
Normal file
@ -0,0 +1,71 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class PlayerSeason(models.Model):
|
||||
player = models.ForeignKey("players.Player", on_delete=models.CASCADE, related_name="player_seasons")
|
||||
season = models.ForeignKey("competitions.Season", on_delete=models.CASCADE, related_name="player_seasons")
|
||||
team = models.ForeignKey(
|
||||
"teams.Team",
|
||||
on_delete=models.SET_NULL,
|
||||
blank=True,
|
||||
null=True,
|
||||
related_name="player_seasons",
|
||||
)
|
||||
competition = models.ForeignKey(
|
||||
"competitions.Competition",
|
||||
on_delete=models.SET_NULL,
|
||||
blank=True,
|
||||
null=True,
|
||||
related_name="player_seasons",
|
||||
)
|
||||
games_played = models.PositiveSmallIntegerField(default=0)
|
||||
games_started = models.PositiveSmallIntegerField(default=0)
|
||||
minutes_played = models.PositiveIntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
ordering = ["-season__start_date", "player__full_name"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["player", "season", "team", "competition"],
|
||||
name="uq_player_season_scope",
|
||||
)
|
||||
]
|
||||
indexes = [
|
||||
models.Index(fields=["player", "season"]),
|
||||
models.Index(fields=["season", "team"]),
|
||||
models.Index(fields=["season", "competition"]),
|
||||
models.Index(fields=["team", "competition"]),
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.player} - {self.season}"
|
||||
|
||||
|
||||
class PlayerSeasonStats(models.Model):
|
||||
player_season = models.OneToOneField(
|
||||
"stats.PlayerSeason", on_delete=models.CASCADE, related_name="stats"
|
||||
)
|
||||
points = models.DecimalField(max_digits=6, decimal_places=2, default=0)
|
||||
rebounds = models.DecimalField(max_digits=6, decimal_places=2, default=0)
|
||||
assists = models.DecimalField(max_digits=6, decimal_places=2, default=0)
|
||||
steals = models.DecimalField(max_digits=6, decimal_places=2, default=0)
|
||||
blocks = models.DecimalField(max_digits=6, decimal_places=2, default=0)
|
||||
turnovers = models.DecimalField(max_digits=6, decimal_places=2, default=0)
|
||||
fg_pct = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True)
|
||||
three_pct = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True)
|
||||
ft_pct = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True)
|
||||
usage_rate = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True)
|
||||
true_shooting_pct = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True)
|
||||
player_efficiency_rating = models.DecimalField(max_digits=6, decimal_places=2, blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(fields=["points"]),
|
||||
models.Index(fields=["rebounds"]),
|
||||
models.Index(fields=["assists"]),
|
||||
models.Index(fields=["usage_rate"]),
|
||||
models.Index(fields=["true_shooting_pct"]),
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Stats for {self.player_season}"
|
||||
Reference in New Issue
Block a user