refactor(factors): 拆分 engine.py 为模块化包
将单文件 engine.py (1064行) 拆分为 engine/ 包: - 数据规格、路由器、计划器、计算引擎、因子引擎分离 - 保持向后兼容,API 无变化
This commit is contained in:
47
src/factors/engine/data_spec.py
Normal file
47
src/factors/engine/data_spec.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""数据规格和执行计划定义。
|
||||
|
||||
定义因子计算所需的数据规格和执行计划结构。
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Dict, List, Optional, Set, Union
|
||||
|
||||
import polars as pl
|
||||
|
||||
|
||||
@dataclass
|
||||
class DataSpec:
|
||||
"""数据规格定义。
|
||||
|
||||
描述因子计算所需的数据表和字段。
|
||||
|
||||
Attributes:
|
||||
table: 数据表名称
|
||||
columns: 需要的字段列表
|
||||
lookback_days: 回看天数(用于时序计算)
|
||||
"""
|
||||
|
||||
table: str
|
||||
columns: List[str]
|
||||
lookback_days: int = 1
|
||||
|
||||
|
||||
@dataclass
|
||||
class ExecutionPlan:
|
||||
"""执行计划。
|
||||
|
||||
包含完整的执行所需信息:数据源、转换逻辑、输出格式。
|
||||
|
||||
Attributes:
|
||||
data_specs: 数据规格列表
|
||||
polars_expr: Polars 表达式
|
||||
dependencies: 依赖的原始字段
|
||||
output_name: 输出因子名称
|
||||
factor_dependencies: 依赖的其他因子名称(用于分步执行)
|
||||
"""
|
||||
|
||||
data_specs: List[DataSpec]
|
||||
polars_expr: pl.Expr
|
||||
dependencies: Set[str]
|
||||
output_name: str
|
||||
factor_dependencies: Set[str] = field(default_factory=set)
|
||||
Reference in New Issue
Block a user