169 lines
5.0 KiB
Python
169 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
快速验证DataFrame长度修复的脚本
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import subprocess
|
|
|
|
def check_strategy_syntax():
|
|
"""检查策略文件语法"""
|
|
print("🔍 检查策略文件语法...")
|
|
|
|
strategy_file = "/Users/zhangkun/myTestFreqAI/freqtrade/templates/freqaiprimer.py"
|
|
|
|
if not os.path.exists(strategy_file):
|
|
print(f"❌ 策略文件不存在: {strategy_file}")
|
|
return False
|
|
|
|
# 检查Python语法
|
|
try:
|
|
result = subprocess.run([
|
|
'python3', '-c',
|
|
f"import ast; ast.parse(open('{strategy_file}').read())"
|
|
], capture_output=True, text=True)
|
|
|
|
if result.returncode == 0:
|
|
print("✅ 策略文件语法正确")
|
|
return True
|
|
else:
|
|
print(f"❌ 策略文件语法错误: {result.stderr}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ 检查语法时出错: {e}")
|
|
return False
|
|
|
|
def check_imports():
|
|
"""检查必要的导入"""
|
|
print("📦 检查必要的导入...")
|
|
|
|
imports_to_check = [
|
|
"import pandas as pd",
|
|
"import numpy as np",
|
|
"from freqtrade.strategy.interface import IStrategy"
|
|
]
|
|
|
|
for imp in imports_to_check:
|
|
try:
|
|
result = subprocess.run([
|
|
'python3', '-c', imp
|
|
], capture_output=True, text=True)
|
|
|
|
if result.returncode != 0:
|
|
print(f"⚠️ 导入警告: {imp}")
|
|
print(f" 错误: {result.stderr.strip()}")
|
|
else:
|
|
print(f"✅ 导入正常: {imp}")
|
|
|
|
except Exception as e:
|
|
print(f"⚠️ 检查导入时出错: {e}")
|
|
|
|
return True
|
|
|
|
def check_dataframe_fixes():
|
|
"""检查DataFrame修复代码是否存在"""
|
|
print("🔧 检查DataFrame修复代码...")
|
|
|
|
strategy_file = "/Users/zhangkun/myTestFreqAI/freqtrade/templates/freqaiprimer.py"
|
|
|
|
try:
|
|
with open(strategy_file, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# 检查关键修复代码
|
|
fixes_found = []
|
|
|
|
if "DataFrame长度不匹配" in content:
|
|
fixes_found.append("✅ DataFrame长度验证代码")
|
|
|
|
if "original_length" in content and "original_index" in content:
|
|
fixes_found.append("✅ 原始长度记录")
|
|
|
|
if "数据填充完成" in content:
|
|
fixes_found.append("✅ 数据填充修复")
|
|
|
|
if "数据截断完成" in content:
|
|
fixes_found.append("✅ 数据截断修复")
|
|
|
|
if "数据长度验证通过" in content:
|
|
fixes_found.append("✅ 长度验证完成")
|
|
|
|
if fixes_found:
|
|
print("找到的修复代码:")
|
|
for fix in fixes_found:
|
|
print(f" {fix}")
|
|
return len(fixes_found) >= 3
|
|
else:
|
|
print("❌ 未找到DataFrame修复代码")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ 检查修复代码时出错: {e}")
|
|
return False
|
|
|
|
def check_files():
|
|
"""检查必要文件是否存在"""
|
|
print("📁 检查必要文件...")
|
|
|
|
files_to_check = [
|
|
"/Users/zhangkun/myTestFreqAI/freqtrade/templates/freqaiprimer.py",
|
|
"/Users/zhangkun/myTestFreqAI/apply_dataframe_fix.sh",
|
|
"/Users/zhangkun/myTestFreqAI/system_restart.sh"
|
|
]
|
|
|
|
all_exist = True
|
|
for file_path in files_to_check:
|
|
if os.path.exists(file_path):
|
|
print(f"✅ 存在: {os.path.basename(file_path)}")
|
|
else:
|
|
print(f"❌ 不存在: {os.path.basename(file_path)}")
|
|
all_exist = False
|
|
|
|
return all_exist
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print("🚀 DataFrame长度修复验证")
|
|
print("=" * 40)
|
|
|
|
# 切换到正确目录
|
|
os.chdir('/Users/zhangkun/myTestFreqAI')
|
|
|
|
# 运行各项检查
|
|
checks = [
|
|
("文件检查", check_files),
|
|
("语法检查", check_strategy_syntax),
|
|
("导入检查", check_imports),
|
|
("修复代码检查", check_dataframe_fixes)
|
|
]
|
|
|
|
passed = 0
|
|
total = len(checks)
|
|
|
|
for name, check_func in checks:
|
|
print(f"\n{name}:")
|
|
if check_func():
|
|
passed += 1
|
|
else:
|
|
print(f" ❌ {name}失败")
|
|
|
|
print("\n" + "=" * 40)
|
|
print(f"🎯 检查结果: {passed}/{total} 项通过")
|
|
|
|
if passed == total:
|
|
print("\n🎉 所有检查通过!修复已就绪")
|
|
print("\n📋 下一步操作:")
|
|
print(" 1. 运行修复脚本: ./apply_dataframe_fix.sh")
|
|
print(" 2. 或者手动操作:")
|
|
print(" • 停止服务: pkill -f freqtrade")
|
|
print(" • 清理缓存: rm -rf user_data/data/*")
|
|
print(" • 启动服务: python3 -m freqtrade trade -c config.json")
|
|
return 0
|
|
else:
|
|
print("\n❌ 部分检查失败,请查看详细信息")
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |