Adds the full Django application layer on top of sportstime_parser: - core: Sport, Team, Stadium, Game models with aliases and league structure - scraper: orchestration engine, adapter, job management, Celery tasks - cloudkit: CloudKit sync client, sync state tracking, sync jobs - dashboard: staff dashboard for monitoring scrapers, sync, review queue - notifications: email reports for scrape/sync results - Docker setup for deployment (Dockerfile, docker-compose, entrypoint) Game exports now use game_datetime_utc (ISO 8601 UTC) instead of venue-local date+time strings, matching the canonical format used by the iOS app. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
79 lines
2.2 KiB
Python
79 lines
2.2 KiB
Python
from django.db import models
|
|
from simple_history.models import HistoricalRecords
|
|
|
|
|
|
class Sport(models.Model):
|
|
"""
|
|
Sport configuration model.
|
|
"""
|
|
SEASON_TYPE_CHOICES = [
|
|
('split', 'Split Year (e.g., 2024-25)'),
|
|
('single', 'Single Year (e.g., 2024)'),
|
|
]
|
|
|
|
code = models.CharField(
|
|
max_length=10,
|
|
primary_key=True,
|
|
help_text='Sport code (e.g., nba, mlb, nfl)'
|
|
)
|
|
name = models.CharField(
|
|
max_length=100,
|
|
help_text='Full name (e.g., National Basketball Association)'
|
|
)
|
|
short_name = models.CharField(
|
|
max_length=20,
|
|
help_text='Short name (e.g., NBA)'
|
|
)
|
|
season_type = models.CharField(
|
|
max_length=10,
|
|
choices=SEASON_TYPE_CHOICES,
|
|
help_text='Whether season spans two years or one'
|
|
)
|
|
expected_game_count = models.PositiveIntegerField(
|
|
default=0,
|
|
help_text='Expected number of regular season games'
|
|
)
|
|
season_start_month = models.PositiveSmallIntegerField(
|
|
default=1,
|
|
help_text='Month when season typically starts (1-12)'
|
|
)
|
|
season_end_month = models.PositiveSmallIntegerField(
|
|
default=12,
|
|
help_text='Month when season typically ends (1-12)'
|
|
)
|
|
icon_name = models.CharField(
|
|
max_length=50,
|
|
blank=True,
|
|
help_text='SF Symbol name (e.g., baseball.fill, basketball.fill)'
|
|
)
|
|
color_hex = models.CharField(
|
|
max_length=10,
|
|
blank=True,
|
|
help_text='Brand color hex (e.g., #CE1141)'
|
|
)
|
|
is_active = models.BooleanField(
|
|
default=True,
|
|
help_text='Whether this sport is actively being scraped'
|
|
)
|
|
|
|
# Metadata
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
# Audit trail
|
|
history = HistoricalRecords()
|
|
|
|
class Meta:
|
|
ordering = ['name']
|
|
verbose_name = 'Sport'
|
|
verbose_name_plural = 'Sports'
|
|
|
|
def __str__(self):
|
|
return self.short_name
|
|
|
|
def get_season_display(self, year: int) -> str:
|
|
"""Return display string for a season (e.g., '2024-25' or '2024')."""
|
|
if self.season_type == 'split':
|
|
return f"{year}-{str(year + 1)[-2:]}"
|
|
return str(year)
|