from __future__ import annotations from datetime import datetime from sqlalchemy import DateTime, Float, Integer, SmallInteger, String from sqlalchemy.orm import Mapped, mapped_column from .base import Base class MetricNorm(Base): """What one metric usually does in one time slot (#5739), learned from its own history by steward.core.norms.rebuild_norms. `kind` says what a slot is: "day" (0–23, the UTC hour of day) or "week" (0–167, Monday 00:00 UTC first). A key has slots of one kind at a time. The whole table is rebuilt each pass, so a row is never edited.""" __tablename__ = "metric_norms" source_module: Mapped[str] = mapped_column(String(64), primary_key=True) resource_name: Mapped[str] = mapped_column(String(255), primary_key=True) metric_name: Mapped[str] = mapped_column(String(128), primary_key=True) slot: Mapped[int] = mapped_column(SmallInteger, primary_key=True) kind: Mapped[str] = mapped_column(String(8), nullable=False) # The level the slot's hours usually held, and how high they usually # peaked: the 90th percentile, across past days, of each hour's p95 and max. usual_hold: Mapped[float] = mapped_column(Float, nullable=False) usual_peak: Mapped[float] = mapped_column(Float, nullable=False) days_seen: Mapped[int] = mapped_column(Integer, nullable=False) updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)