feat(selection): 补充策略执行结果查询链路
This commit is contained in:
@@ -5,6 +5,8 @@ from sqlalchemy import (
|
||||
Column,
|
||||
Date,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
Index,
|
||||
Integer,
|
||||
MetaData,
|
||||
Numeric,
|
||||
@@ -12,8 +14,10 @@ from sqlalchemy import (
|
||||
String,
|
||||
Table,
|
||||
Text,
|
||||
UniqueConstraint,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
|
||||
metadata = MetaData()
|
||||
|
||||
@@ -114,3 +118,78 @@ market_sync_item = Table(
|
||||
Column("created_at", DateTime(timezone=True), nullable=False, server_default=func.now()),
|
||||
PrimaryKeyConstraint("batch_id", "item_kind", "item_key"),
|
||||
)
|
||||
|
||||
selection_run = Table(
|
||||
"selection_run",
|
||||
metadata,
|
||||
Column("id", String(36), primary_key=True),
|
||||
Column("strategy", String(64), nullable=False),
|
||||
Column("target_trade_date", Date, nullable=False),
|
||||
Column("market_sync_batch_id", String(36), nullable=False),
|
||||
Column("status", String(24), nullable=False),
|
||||
Column("target_count", Integer, nullable=False),
|
||||
Column("eligible_count", Integer, nullable=False, server_default="0"),
|
||||
Column("evaluated_count", Integer, nullable=False, server_default="0"),
|
||||
Column("selected_stock_count", Integer, nullable=False, server_default="0"),
|
||||
Column("signal_count", Integer, nullable=False, server_default="0"),
|
||||
Column("failed_count", Integer, nullable=False, server_default="0"),
|
||||
Column("coverage", Numeric(8, 6), nullable=False, server_default="0"),
|
||||
Column("error_type", String(64)),
|
||||
Column("error_message", Text),
|
||||
Column("created_at", DateTime(timezone=True), nullable=False, server_default=func.now()),
|
||||
Column("finished_at", DateTime(timezone=True)),
|
||||
UniqueConstraint("strategy", "target_trade_date", name="uq_selection_run_strategy_date"),
|
||||
)
|
||||
|
||||
selection_run_item = Table(
|
||||
"selection_run_item",
|
||||
metadata,
|
||||
Column(
|
||||
"run_id", String(36), ForeignKey("selection_run.id", ondelete="CASCADE"), nullable=False
|
||||
),
|
||||
Column("ts_code", String(12), nullable=False),
|
||||
Column("name", String(128), nullable=False),
|
||||
Column("status", String(32), nullable=False),
|
||||
Column("signal_count", Integer, nullable=False, server_default="0"),
|
||||
Column("reason", Text),
|
||||
Column("created_at", DateTime(timezone=True), nullable=False, server_default=func.now()),
|
||||
PrimaryKeyConstraint("run_id", "ts_code"),
|
||||
)
|
||||
|
||||
selection_signal = Table(
|
||||
"selection_signal",
|
||||
metadata,
|
||||
Column(
|
||||
"run_id", String(36), ForeignKey("selection_run.id", ondelete="CASCADE"), nullable=False
|
||||
),
|
||||
Column("ts_code", String(12), nullable=False),
|
||||
Column("name", String(128), nullable=False),
|
||||
Column("target_trade_date", Date, nullable=False),
|
||||
Column("strategy", String(64), nullable=False),
|
||||
Column("category", String(64), nullable=False),
|
||||
Column("close", Numeric(20, 6), nullable=False),
|
||||
Column("details", JSONB, nullable=False),
|
||||
Column("created_at", DateTime(timezone=True), nullable=False, server_default=func.now()),
|
||||
PrimaryKeyConstraint("run_id", "ts_code", "category"),
|
||||
)
|
||||
|
||||
# Keep the declarative metadata aligned with the indexes created by the
|
||||
# Alembic revisions. Alembic uses this object for both offline inspection
|
||||
# and future autogeneration, so omitting these indexes would make the schema
|
||||
# appear drifted even though the migration creates them.
|
||||
Index("ix_market_daily_bar_trade_date", market_daily_bar.c.trade_date)
|
||||
Index("ix_market_daily_basic_trade_date", market_daily_basic.c.trade_date)
|
||||
Index("ix_market_sync_item_status", market_sync_item.c.batch_id, market_sync_item.c.status)
|
||||
Index(
|
||||
"ix_selection_run_status_date",
|
||||
selection_run.c.strategy,
|
||||
selection_run.c.status,
|
||||
selection_run.c.target_trade_date,
|
||||
)
|
||||
Index("ix_selection_run_item_status", selection_run_item.c.run_id, selection_run_item.c.status)
|
||||
Index(
|
||||
"ix_selection_signal_strategy_date",
|
||||
selection_signal.c.strategy,
|
||||
selection_signal.c.target_trade_date,
|
||||
selection_signal.c.ts_code,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user