PCM_Report/test_table_script_debug.py

66 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""
测试table.py脚本的调试工具
"""
import os
import sys
from pathlib import Path
# 设置环境变量
os.environ["TABLE_LOG_LEVEL"] = "DEBUG"
os.environ["TABLE_LOG_FILE"] = "table_debug.log"
# 设置实验时间(示例)
os.environ["EXPERIMENT_START"] = "2026-03-13T15:24:08"
os.environ["EXPERIMENT_END"] = "2026-03-13T18:54:08"
# 设置InfluxDB配置需要根据实际情况修改
os.environ["INFLUX_URL"] = os.environ.get("INFLUX_URL", "")
os.environ["INFLUX_ORG"] = os.environ.get("INFLUX_ORG", "")
os.environ["INFLUX_TOKEN"] = os.environ.get("INFLUX_TOKEN", "")
os.environ["INFLUX_BUCKET"] = os.environ.get("INFLUX_BUCKET", "PCM")
os.environ["INFLUX_MEASUREMENT"] = os.environ.get("INFLUX_MEASUREMENT", "PCM_Measurement")
print("=== 测试table.py脚本 ===")
print(f"EXPERIMENT_START: {os.environ.get('EXPERIMENT_START')}")
print(f"EXPERIMENT_END: {os.environ.get('EXPERIMENT_END')}")
print(f"INFLUX_URL: {os.environ.get('INFLUX_URL', '<未设置>')}")
print()
# 导入并执行脚本
sys.path.insert(0, str(Path("configs/600泵")))
from table import generate_table_data
try:
result = generate_table_data(None)
print("\n=== 生成结果 ===")
print(f"表格数量: {len(result.get('tables', []))}")
if result.get('tables'):
table = result['tables'][0]
cells = table.get('cells', [])
print(f"单元格数量: {len(cells)}")
# 显示前10个单元格
print("\n前10个单元格:")
for cell in cells[:10]:
print(f" row={cell['row']}, col={cell['col']}, value={cell.get('value', '')}")
# 检查是否有温度数据
temp_cells = [c for c in cells if c['row'] >= 4 and c.get('value')]
print(f"\n温度数据单元格数量: {len(temp_cells)}")
# 检查时间戳
time_cells = [c for c in cells if c['row'] == 1 and c['col'] in [1, 3]]
print(f"\n时间戳单元格: {time_cells}")
# 检查环境温度
env_temp = [c for c in cells if c['row'] == 0 and c['col'] == 1]
print(f"\n环境温度: {env_temp}")
except Exception as e:
print(f"\n错误: {e}")
import traceback
traceback.print_exc()
print("\n详细日志已保存到: table_debug.log")