feat(sector-radar): add weighted scores and rank-change views

This commit is contained in:
yuxuanhui
2026-09-21 23:57:55 +08:00
parent 669e89d3c3
commit b9981aa48d
45 changed files with 2468 additions and 320 deletions
@@ -0,0 +1,27 @@
"""Keep weighted ranking scores separate from raw flow values."""
import sqlalchemy as sa
from alembic import op
revision = "0010_radar_weighted_score"
down_revision = "0009_radar_sector_detail"
branch_labels = None
depends_on = None
def upgrade() -> None:
"""Preserve existing publication rows with an unknown (NULL) score."""
op.add_column(
"sector_radar_ranking", sa.Column("weighted_score", sa.Numeric(28, 12), nullable=True)
)
op.create_check_constraint(
"ck_radar_weighted_score_finite",
"sector_radar_ranking",
"weighted_score IS NULL OR weighted_score NOT IN "
"('NaN'::numeric, 'Infinity'::numeric, '-Infinity'::numeric)",
)
def downgrade() -> None:
"""Remove the additional score projection without changing raw values."""
op.drop_column("sector_radar_ranking", "weighted_score")