"""Player evolution — KPI measurement entries for objectives.""" from app.extensions import db from app.time_utils import utc_now_naive class ObjectiveEntry(db.Model): """A single KPI measurement recorded for an objective. Each entry records a value at a point in time so the evolution graph can plot historical data and compute a trend line. """ __tablename__ = 'objective_entries' id = db.Column(db.Integer, primary_key=True) objective_id = db.Column( db.Integer, db.ForeignKey('objectives.id'), nullable=False, ) value = db.Column(db.Numeric(10, 2), nullable=True) recorded_at = db.Column(db.DateTime, nullable=False, default=utc_now_naive) note = db.Column(db.Text, nullable=True) # Who recorded it recorded_by = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) # Timestamps created_at = db.Column(db.DateTime, default=utc_now_naive) # ----------------------------------------------------------------------- # Relationships # ----------------------------------------------------------------------- objective = db.relationship( 'Objective', backref=db.backref('entries', lazy='dynamic', order_by='ObjectiveEntry.recorded_at'), ) recorder = db.relationship('User', foreign_keys=[recorded_by])