refactor(factor): 完全重构因子计算框架 - 引入DSL表达式系统
- 删除旧因子框架:移除 base.py、composite.py、data_loader.py、data_spec.py 及所有子模块(momentum、financial、quality、sentiment等) - 新增DSL表达式系统:实现 factor DSL 编译器和翻译器 - dsl.py: 领域特定语言定义 - compiler.py: AST编译与优化 - translator.py: Polars表达式翻译 - api.py: 统一API接口 - 新增数据路由层:data_router.py 实现字段到表的动态路由 - 新增API封装:api_pro_bar.py 提供pro_bar数据接口 - 更新执行引擎:engine.py 适配新的DSL架构 - 重构测试体系:删除旧测试,新增 test_dsl_promotion.py、 test_factor_integration.py、test_pro_bar.py - 清理文档:删除8个过时文档(factor_design、db_sync_guide等)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
从环境变量加载应用配置,使用pydantic-settings进行类型验证
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from pydantic_settings import BaseSettings
|
||||
@@ -15,20 +16,33 @@ CONFIG_DIR = PROJECT_ROOT / "config"
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""应用配置类,从环境变量加载"""
|
||||
"""应用配置类,从环境变量加载
|
||||
|
||||
# 数据库配置
|
||||
所有配置项都会自动从环境变量读取(小写转大写)
|
||||
例如:tushare_token 会读取 TUSHARE_TOKEN 环境变量
|
||||
"""
|
||||
|
||||
# Tushare API 配置
|
||||
tushare_token: str = ""
|
||||
|
||||
# 数据存储配置
|
||||
root_path: str = "" # 项目根路径,默认自动检测
|
||||
data_path: str = "data" # 数据存储路径,相对于 root_path
|
||||
|
||||
# API 速率限制(每分钟请求数)
|
||||
rate_limit: int = 300
|
||||
|
||||
# 同步工作线程数
|
||||
threads: int = 10
|
||||
|
||||
# 数据库配置(可选,用于未来扩展)
|
||||
database_host: str = "localhost"
|
||||
database_port: int = 5432
|
||||
database_name: str = "prostock"
|
||||
database_user: str
|
||||
database_password: str
|
||||
database_user: Optional[str] = None
|
||||
database_password: Optional[str] = None
|
||||
|
||||
# API密钥配置
|
||||
api_key: str
|
||||
secret_key: str
|
||||
|
||||
# Redis配置
|
||||
# Redis配置(可选,用于未来扩展)
|
||||
redis_host: str = "localhost"
|
||||
redis_port: int = 6379
|
||||
redis_password: Optional[str] = None
|
||||
@@ -38,11 +52,27 @@ class Settings(BaseSettings):
|
||||
app_debug: bool = False
|
||||
app_port: int = 8000
|
||||
|
||||
@property
|
||||
def project_root(self) -> Path:
|
||||
"""获取项目根路径。"""
|
||||
if self.root_path:
|
||||
return Path(self.root_path)
|
||||
return PROJECT_ROOT
|
||||
|
||||
@property
|
||||
def data_path_resolved(self) -> Path:
|
||||
"""获取解析后的数据路径(绝对路径)。"""
|
||||
path = Path(self.data_path)
|
||||
if path.is_absolute():
|
||||
return path
|
||||
return self.project_root / path
|
||||
|
||||
class Config:
|
||||
# 从 config/ 目录读取 .env.local 文件
|
||||
env_file = str(CONFIG_DIR / ".env.local")
|
||||
env_file_encoding = "utf-8"
|
||||
case_sensitive = False
|
||||
extra = "ignore" # 忽略 .env.local 中的额外变量
|
||||
|
||||
|
||||
@lru_cache()
|
||||
|
||||
Reference in New Issue
Block a user