PCM_Report/example_data_script.py

71 lines
1.7 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.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
实验流程数据脚本示例
此脚本将在生成报告时被执行,用于生成特定表格的数据。
脚本应该输出JSON格式的数据到标准输出stdout
返回数据格式示例:
{
"headers": ["列1", "列2", "列3"],
"rows": [
["值1", "值2", "值3"],
["值4", "值5", "值6"]
]
}
"""
import json
import sys
def generate_data():
"""
生成表格数据
Returns:
dict: 包含headers和rows的字典
"""
# TODO: 这里可以从数据库、文件、API等地方获取数据
# TODO: 可以进行数据处理、计算、转换等操作
# 示例:生成一些测试数据
data = {
"headers": ["序号", "参数名称", "测试值", "标准值", "结果"],
"rows": [
["1", "温度", "25.3°C", "25±2°C", "合格"],
["2", "压力", "10.2MPa", "10±1MPa", "合格"],
["3", "流量", "150L/min", "145±10L/min", "合格"],
["4", "转速", "1450rpm", "1440±20rpm", "合格"],
["5", "效率", "92.5%", "≥90%", "合格"],
]
}
return data
def main():
"""主函数"""
try:
# 生成数据
data = generate_data()
# 输出JSON到stdout
# 注意使用ensure_ascii=False支持中文
print(json.dumps(data, ensure_ascii=False))
# 返回成功状态码
sys.exit(0)
except Exception as e:
# 错误信息输出到stderr
print(f"Error: {e}", file=sys.stderr)
# 返回失败状态码
sys.exit(1)
if __name__ == "__main__":
main()