feat(sector_radar): enhance sector radar functionality with active moneyflow and detailed metrics

- Introduced ActiveMoneyflowSource to fetch optional active-order flow, enhancing the sector radar's data capabilities.
- Updated StockFactRecord and DailyAggregateRecord to include pct_change and active_buy_net_amount_yuan for improved financial insights.
- Modified the build process to incorporate active moneyflow data without invalidating main rankings on failure.
- Enhanced the HTTP API to return detailed sector history and metrics, including pct_change and active buy metrics for members.
- Updated tests to validate the new functionality and ensure data integrity across various scenarios.
This commit is contained in:
yuxuanhui
2026-09-06 16:06:17 +08:00
parent 68282f5d46
commit 7f93d6b0f5
48 changed files with 4883 additions and 95 deletions
@@ -0,0 +1,33 @@
"""Store source sector detail alongside immutable publication daily inputs."""
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "0009_radar_sector_detail"
down_revision: str | None = "0008_radar_detail"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
"""Keep all previous rows readable with nullable provider detail."""
op.add_column(
"sector_radar_daily_aggregate", sa.Column("pct_change", sa.Numeric(), nullable=True)
)
op.add_column(
"sector_radar_daily_aggregate", sa.Column("leading_code", sa.Text(), nullable=True)
)
op.create_check_constraint(
"ck_radar_sector_pct_change_finite",
"sector_radar_daily_aggregate",
"pct_change IS NULL OR pct_change NOT IN "
"('NaN'::numeric, 'Infinity'::numeric, '-Infinity'::numeric)",
)
def downgrade() -> None:
"""Remove only the nullable projection; original provider snapshots remain intact."""
op.drop_column("sector_radar_daily_aggregate", "leading_code")
op.drop_column("sector_radar_daily_aggregate", "pct_change")