First commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
from app import db
|
||||
from app.utils.time_utils import now_eastern
|
||||
|
||||
|
||||
class FacilityScoreAlert(db.Model):
|
||||
"""Records each score-trend alert sent for a facility.
|
||||
|
||||
Used by send_score_alerts() to deduplicate cron notifications:
|
||||
if an alert row exists for a facility within the last 24 hours,
|
||||
no new alert is sent even if the score is still below threshold.
|
||||
"""
|
||||
__tablename__ = 'facility_score_alerts'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
facility_id = db.Column(db.Integer, db.ForeignKey('facilities.id', ondelete='CASCADE'), nullable=False)
|
||||
sent_at = db.Column(db.DateTime, nullable=False, default=now_eastern)
|
||||
current_avg = db.Column(db.Numeric(5, 2), nullable=False)
|
||||
prior_avg = db.Column(db.Numeric(5, 2), nullable=False)
|
||||
delta = db.Column(db.Numeric(5, 2), nullable=False)
|
||||
|
||||
facility = db.relationship('Facility', foreign_keys=[facility_id])
|
||||
|
||||
def __repr__(self):
|
||||
return f'<FacilityScoreAlert facility={self.facility_id} delta={self.delta} sent={self.sent_at}>'
|
||||
Reference in New Issue
Block a user