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:
@@ -0,0 +1,38 @@
|
||||
"""Preserve independent stock detail facts without invalidating old publications."""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0008_radar_detail"
|
||||
down_revision: str | None = "0007_selection_pattern_scoring"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Add nullable facts and allow the optional raw moneyflow checkpoint."""
|
||||
for name in ("pct_change", "active_buy_net_amount_yuan"):
|
||||
op.add_column("sector_radar_stock_fact", sa.Column(name, sa.Numeric(), nullable=True))
|
||||
op.create_check_constraint(
|
||||
f"ck_radar_stock_{name}_finite",
|
||||
"sector_radar_stock_fact",
|
||||
f"{name} IS NULL OR {name} NOT IN "
|
||||
"('NaN'::numeric, 'Infinity'::numeric, '-Infinity'::numeric)",
|
||||
)
|
||||
op.drop_constraint(
|
||||
"ck_sector_radar_publication_source_group", "sector_radar_publication_source"
|
||||
)
|
||||
op.create_check_constraint(
|
||||
"ck_sector_radar_publication_source_group",
|
||||
"sector_radar_publication_source",
|
||||
"source_group IN ('calendar', 'concept_indices', 'industry_indices', 'members', "
|
||||
"'stock_basics', 'suspensions', 'daily', 'moneyflow_dc', 'moneyflow')",
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Drop added fact columns; retain optional checkpoint audit rows for older readers."""
|
||||
for name in ("pct_change", "active_buy_net_amount_yuan"):
|
||||
op.drop_column("sector_radar_stock_fact", name)
|
||||
@@ -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")
|
||||
Reference in New Issue
Block a user