myTestFreqAI/check_original_data.py
zhangkun9038@dingtalk.com 2a30c49118 tradestocsv.py
2025-10-14 22:07:06 +08:00

80 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
import os
from pathlib import Path
# 定义结果目录(使用正确的相对路径)
data_dir = Path('./result')
# 指定要检查的文件
specific_file = data_dir / 'backtest-result-2025-10-14_13-45-04.json'
if not specific_file.exists():
print(f"文件 {specific_file} 不存在")
exit(1)
print(f"检查文件: {specific_file}")
print(f"文件大小: {specific_file.stat().st_size / (1024 * 1024):.2f} MB")
# 由于文件可能很大,我们先尝试快速检查文件的前几行
try:
with open(specific_file, 'r', encoding='utf-8') as f:
# 读取前500个字符来了解文件结构
first_chars = f.read(500)
print(f"\n文件前500个字符:\n{first_chars}")
except Exception as e:
print(f"读取文件头部失败: {e}")
# 尝试加载文件,但限制交易数量以避免内存问题
try:
with open(specific_file, 'r', encoding='utf-8') as f:
# 使用生成器来逐行解析JSON避免一次加载整个文件
print("\n尝试解析JSON文件...")
# 创建一个简单的解析函数来快速检查结构
def find_key_value_pairs(text, max_chars=50000):
"""简单函数来查找文本中的键值对"""
pairs = {}
chars_read = 0
lines = []
for line in text:
lines.append(line)
chars_read += len(line)
if chars_read > max_chars:
break
full_text = ''.join(lines)
# 查找常见的键
common_keys = ['strategy', 'trades', 'orders', 'ft_is_entry', 'FreqaiPrimer']
for key in common_keys:
if key in full_text:
# 找到key出现的位置
pos = full_text.find(key)
# 获取key附近的文本
context_start = max(0, pos - 20)
context_end = min(len(full_text), pos + 100)
pairs[key] = full_text[context_start:context_end]
return pairs
# 重新打开文件并使用我们的简单解析函数
f.seek(0)
key_pairs = find_key_value_pairs(f)
print("\n找到的关键结构:")
for key, context in key_pairs.items():
print(f"{key}: {context}")
print("\n文件结构分析完成")
except json.JSONDecodeError as e:
print(f"JSON解析错误: {e}")
print("文件可能是有效的JSON但格式复杂或者不是标准JSON格式")
except Exception as e:
print(f"处理文件时出错: {e}")
print("\n下一步建议:")
print("1. 如果文件是标准JSON格式我们可以修改tradestocsv.py来正确处理它")
print("2. 我们可以添加强制模拟加仓的选项,确保即使原始数据中没有加仓信息也能生成模拟数据")