主要改动: 1. Config类改为单例模式,支持根据global.yaml的current_mode自动加载环境配置 2. Logger类改为单例模式,通过类方法直接访问 3. 拆分配置文件:global.yaml仅指定模式,backtest.yaml/simulation.yaml/production.yaml存储各环境配置 4. 移除所有config参数传递,使用Config.get()直接访问 5. 移除所有logger实例传递,使用Logger.info()等类方法直接访问 6. 修复初始化顺序:Config.initialize() -> Logger.initialize() -> 其他组件 7. 修复Logger参数默认值,确保所有方法可正常调用 8. 新增三个环境配置文件结构统一,只有参数值不同 9. 客户端URL端口修正为8030(回测)/8020(模拟)/8010(实盘) 配置文件变更: - configs/global.yaml:简化为仅包含current_mode - configs/backtest.yaml:回测环境完整配置 - configs/simulation.yaml:模拟环境完整配置 - configs/production.yaml:实盘环境完整配置 代码重构: - src/core/config.py:单例模式,自动加载环境配置 - src/core/logger.py:单例模式,类方法访问 - 所有模块:移除config/logger参数,使用单例访问
53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
"""快速删除旧格式的指标表"""
|
|
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
project_root = Path(__file__).parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
from src.database_manager import DatabaseManager
|
|
from src.core.config import Config
|
|
from sqlalchemy import create_engine, text
|
|
|
|
Config.initialize()
|
|
db = DatabaseManager()
|
|
db_name = Config.get("database.database")
|
|
|
|
# 获取所有旧格式的表
|
|
tables = db.list_tables(db_name)
|
|
old_tables = [
|
|
t
|
|
for t in tables
|
|
if any(
|
|
t.startswith(f"{ind}_") for ind in ["macd", "kdj", "boll", "rsi", "ma", "ema"]
|
|
)
|
|
and not t.startswith("indicators_")
|
|
]
|
|
|
|
print(f"\n发现 {len(old_tables)} 个旧格式的表")
|
|
print("开始删除...\n")
|
|
|
|
# 创建数据库连接
|
|
db_url = (
|
|
f"mysql+pymysql://{Config.get('database.user')}:"
|
|
f"{Config.get('database.password')}@"
|
|
f"{Config.get('database.host')}:{Config.get('database.port')}"
|
|
f"/{db_name}"
|
|
)
|
|
engine = create_engine(db_url)
|
|
|
|
with engine.connect() as conn:
|
|
conn.execute(text("SET FOREIGN_KEY_CHECKS = 0"))
|
|
|
|
for table in old_tables:
|
|
conn.execute(text(f"DROP TABLE `{table}`"))
|
|
print(f"✓ 已删除: {table}")
|
|
|
|
conn.execute(text("SET FOREIGN_KEY_CHECKS = 1"))
|
|
conn.commit()
|
|
|
|
engine.dispose()
|
|
print(f"\n✓ 成功删除 {len(old_tables)} 个旧表\n")
|