""" Database models for employee workstation activity tracking. This module defines the SQLAlchemy models used for storing activity events. """ from app import db class WorkEvent(db.Model): """ Represents a user activity event with state transitions (working/stopped). Attributes: id (int): Primary key for the event user (str): Username of the person whose activity is being tracked state (str): Current activity state ('working' or 'stopped') ts (datetime): Timestamp when the event occurred """ __tablename__ = 'work_events' id = db.Column(db.Integer, primary_key=True) user = db.Column(db.String(100), nullable=False, index=True) state = db.Column(db.String(10), nullable=False) # 'working' or 'stopped' ts = db.Column(db.DateTime, nullable=False, server_default=db.func.current_timestamp(), index=True) def __repr__(self): """Return a string representation of the model.""" return f"" def to_dict(self): """Convert model to dictionary for API responses.""" return { 'id': self.id, 'user': self.user, 'state': self.state, 'ts': self.ts.isoformat() if self.ts else None }