Models (6 + 1 association table): - User: Authentication with bcrypt, admin role check, last_login tracking - Player: Digital signage devices with auth codes, status tracking, online detection - Group: Player/content organization with statistics properties - Content: Media files with type detection, file size helpers, position ordering - ServerLog: Audit trail with class methods for logging levels - PlayerFeedback: Player status updates with error tracking - group_content: Many-to-many association table for groups and content Model improvements: - Added type hints to all methods and properties - Added database indexes on frequently queried columns (username, auth_code, group_id, player_id, position, level, timestamp, status) - Added comprehensive docstrings - Added helper properties (is_online, is_admin, file_size_mb, etc.) - Added relationship back_populates for bidirectional navigation - Added timestamps (created_at, updated_at, last_seen, uploaded_at) Utils (4 modules): - logger.py: Logging utility with level-based functions (info, warning, error) - uploads.py: File upload handling with progress tracking, video optimization - group_player_management.py: Player/group status tracking and bulk operations - pptx_converter.py: PowerPoint to PDF conversion using LibreOffice Utils improvements: - Full type hints on all functions - Comprehensive error handling - Progress tracking for long-running operations - Video optimization (H.264, 30fps, max 1080p, 8Mbps) - Helper functions for time formatting and statistics - Proper logging of all operations Performance optimizations: - Database indexes on all foreign keys and frequently filtered columns - Lazy loading for relationships where appropriate - Efficient queries with proper ordering - Helper properties to avoid repeated calculations Ready for template migration and testing
57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
"""Player model for digital signage players."""
|
|
from datetime import datetime
|
|
from typing import Optional, List
|
|
|
|
from app.extensions import db
|
|
|
|
|
|
class Player(db.Model):
|
|
"""Player model representing a digital signage device.
|
|
|
|
Attributes:
|
|
id: Primary key
|
|
name: Display name for the player
|
|
location: Physical location description
|
|
auth_code: Authentication code for API access
|
|
group_id: Foreign key to assigned group
|
|
status: Current player status (online, offline, error)
|
|
last_seen: Last activity timestamp
|
|
created_at: Player creation timestamp
|
|
"""
|
|
__tablename__ = 'player'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
name = db.Column(db.String(255), nullable=False)
|
|
location = db.Column(db.String(255), nullable=True)
|
|
auth_code = db.Column(db.String(255), unique=True, nullable=False, index=True)
|
|
group_id = db.Column(db.Integer, db.ForeignKey('group.id'), nullable=True, index=True)
|
|
status = db.Column(db.String(50), default='offline', index=True)
|
|
last_seen = db.Column(db.DateTime, nullable=True, index=True)
|
|
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
|
|
|
# Relationships
|
|
group = db.relationship('Group', back_populates='players')
|
|
feedback = db.relationship('PlayerFeedback', back_populates='player',
|
|
cascade='all, delete-orphan', lazy='dynamic')
|
|
|
|
def __repr__(self) -> str:
|
|
"""String representation of Player."""
|
|
return f'<Player {self.name} (ID={self.id}, Status={self.status})>'
|
|
|
|
@property
|
|
def is_online(self) -> bool:
|
|
"""Check if player is online (seen in last 5 minutes)."""
|
|
if not self.last_seen:
|
|
return False
|
|
delta = datetime.utcnow() - self.last_seen
|
|
return delta.total_seconds() < 300 # 5 minutes
|
|
|
|
def update_status(self, status: str) -> None:
|
|
"""Update player status and last seen timestamp.
|
|
|
|
Args:
|
|
status: New status value
|
|
"""
|
|
self.status = status
|
|
self.last_seen = datetime.utcnow()
|