新增期货数据动态播放器功能,包括基础版和增强版实现,添加测试脚本和详细文档说明。主要变更包括: 1. 实现买卖盘深度可视化播放功能 2. 添加播放控制、速度调节和跳转功能 3. 提供统一价格轴显示优化版本 4. 添加测试脚本验证功能 5. 编写详细使用文档和README说明
127 lines
3.5 KiB
Python
127 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
简单的期货数据播放器测试脚本
|
||
用于验证程序是否能正常加载和运行
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
|
||
def test_imports():
|
||
"""测试必需的库是否可以导入"""
|
||
print("Testing required libraries...")
|
||
|
||
try:
|
||
import pandas as pd
|
||
print("+ pandas imported successfully")
|
||
except ImportError as e:
|
||
print(f"- pandas import failed: {e}")
|
||
return False
|
||
|
||
try:
|
||
import numpy as np
|
||
print("✓ numpy imported successfully")
|
||
except ImportError as e:
|
||
print(f"✗ numpy import failed: {e}")
|
||
return False
|
||
|
||
try:
|
||
import matplotlib.pyplot as plt
|
||
print("✓ matplotlib imported successfully")
|
||
except ImportError as e:
|
||
print(f"✗ matplotlib import failed: {e}")
|
||
return False
|
||
|
||
try:
|
||
import tkinter as tk
|
||
print("✓ tkinter imported successfully")
|
||
except ImportError as e:
|
||
print(f"✗ tkinter import failed: {e}")
|
||
return False
|
||
|
||
return True
|
||
|
||
def test_data_file():
|
||
"""测试数据文件是否存在"""
|
||
print("\\nTesting data file...")
|
||
|
||
data_path = 'data/au2512_20251013.parquet'
|
||
if os.path.exists(data_path):
|
||
print(f"✓ Data file found: {data_path}")
|
||
|
||
# 尝试读取数据
|
||
try:
|
||
import pandas as pd
|
||
df = pd.read_parquet(data_path)
|
||
print(f"✓ Data loaded successfully: {len(df)} rows")
|
||
print(f" Time range: {df.iloc[0]['时间'] if '时间' in df.columns else 'N/A'}")
|
||
return True
|
||
except Exception as e:
|
||
print(f"✗ Failed to load data: {e}")
|
||
return False
|
||
else:
|
||
print(f"✗ Data file not found: {data_path}")
|
||
return False
|
||
|
||
def test_basic_functionality():
|
||
"""测试基本功能"""
|
||
print("\\nTesting basic functionality...")
|
||
|
||
try:
|
||
# 导入播放器类
|
||
from futures_player_enhanced import EnhancedFuturesPlayer
|
||
print("✓ Player class imported successfully")
|
||
|
||
# 尝试创建实例(但不运行GUI)
|
||
print("✓ Creating player instance...")
|
||
player = EnhancedFuturesPlayer()
|
||
|
||
# 测试数据加载
|
||
if player.df is not None and len(player.df) > 0:
|
||
print(f"✓ Player data loaded: {len(player.df)} rows")
|
||
|
||
# 测试更新显示功能
|
||
player.update_display()
|
||
print("✓ Display update test passed")
|
||
|
||
# 清理
|
||
player.on_closing()
|
||
return True
|
||
else:
|
||
print("✗ Player data not loaded properly")
|
||
return False
|
||
|
||
except Exception as e:
|
||
print(f"✗ Basic functionality test failed: {e}")
|
||
return False
|
||
|
||
def main():
|
||
"""主测试函数"""
|
||
print("=== Futures Data Player Test Suite ===\\n")
|
||
|
||
# 测试导入
|
||
if not test_imports():
|
||
print("\\n❌ Import test failed. Please install required libraries:")
|
||
print("pip install pandas numpy matplotlib")
|
||
return False
|
||
|
||
# 测试数据文件
|
||
if not test_data_file():
|
||
print("\\n❌ Data file test failed. Please check data path.")
|
||
return False
|
||
|
||
# 测试基本功能
|
||
if not test_basic_functionality():
|
||
print("\\n❌ Basic functionality test failed.")
|
||
return False
|
||
|
||
print("\\n✅ All tests passed! The player should work correctly.")
|
||
print("\\nTo run the full application:")
|
||
print("python futures_player_enhanced.py")
|
||
|
||
return True
|
||
|
||
if __name__ == "__main__":
|
||
success = main()
|
||
sys.exit(0 if success else 1) |