x
This commit is contained in:
@@ -111,27 +111,32 @@ class GeometryVerificationService:
|
|||||||
|
|
||||||
logger.info(f"执行验证命令: {' '.join(cmd)}")
|
logger.info(f"执行验证命令: {' '.join(cmd)}")
|
||||||
|
|
||||||
|
# 获取 STP 文件的绝对路径和目录
|
||||||
|
stp_abs_path = Path(stp_path_str).absolute()
|
||||||
|
stp_dir = stp_abs_path.parent
|
||||||
|
|
||||||
# 异步运行子进程
|
# 异步运行子进程
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
*cmd,
|
*cmd,
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE,
|
stderr=asyncio.subprocess.PIPE,
|
||||||
cwd=str(Path(__file__).parent.parent)
|
cwd=str(stp_dir) # 在 STP 文件所在目录运行
|
||||||
)
|
)
|
||||||
|
|
||||||
stdout, stderr = await process.communicate()
|
stdout, stderr = await process.communicate()
|
||||||
|
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
# 尝试读取生成的报告文件
|
# 尝试读取生成的报告文件(在 STP 文件目录下)
|
||||||
report_path = Path(stp_path_str).stem + "_verification_report.json"
|
report_path = stp_dir / (stp_abs_path.stem + "_verification_report.json")
|
||||||
if Path(report_path).exists():
|
if report_path.exists():
|
||||||
with open(report_path, 'r', encoding='utf-8') as f:
|
with open(report_path, 'r', encoding='utf-8') as f:
|
||||||
result = json.load(f)
|
result = json.load(f)
|
||||||
# 删除临时报告文件
|
# 删除临时报告文件
|
||||||
Path(report_path).unlink()
|
report_path.unlink()
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
# 解析 stdout 获取结果
|
# 解析 stdout 获取结果
|
||||||
|
logger.warning(f"验证报告文件不存在: {report_path}")
|
||||||
return self._parse_verification_output(stdout.decode('utf-8'))
|
return self._parse_verification_output(stdout.decode('utf-8'))
|
||||||
else:
|
else:
|
||||||
logger.error(f"验证脚本执行失败 (returncode={process.returncode}): {stderr.decode('utf-8')}")
|
logger.error(f"验证脚本执行失败 (returncode={process.returncode}): {stderr.decode('utf-8')}")
|
||||||
@@ -164,22 +169,39 @@ class GeometryVerificationService:
|
|||||||
"""解析验证脚本输出"""
|
"""解析验证脚本输出"""
|
||||||
result = {
|
result = {
|
||||||
"status": "unknown",
|
"status": "unknown",
|
||||||
"timestamp": datetime.now().isoformat()
|
"timestamp": datetime.now().isoformat(),
|
||||||
|
"comparison": {}
|
||||||
}
|
}
|
||||||
|
|
||||||
lines = output.split('\n')
|
lines = output.split('\n')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if '验证结果:' in line:
|
if '验证结果:' in line:
|
||||||
if '✅ 通过' in line:
|
if '✅ 通过' in line or '通过' in line:
|
||||||
result['status'] = 'passed'
|
result['status'] = 'passed'
|
||||||
elif '❌ 失败' in line:
|
elif '❌ 失败' in line or '失败' in line:
|
||||||
result['status'] = 'failed'
|
result['status'] = 'failed'
|
||||||
elif '体积对比:' in line:
|
elif '体积对比:' in line or '体积差异' in line:
|
||||||
# 解析体积差异
|
try:
|
||||||
pass
|
if '差异:' in line:
|
||||||
elif '表面积对比:' in line:
|
parts = line.split('差异:')
|
||||||
# 解析表面积差异
|
if len(parts) > 1:
|
||||||
pass
|
diff_part = parts[1].strip()
|
||||||
|
if '%' in diff_part:
|
||||||
|
percent = float(diff_part.split('%')[0].strip().split()[-1])
|
||||||
|
result['comparison']['volume'] = {'difference_percent': percent}
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif '表面积对比:' in line or '表面积差异' in line:
|
||||||
|
try:
|
||||||
|
if '差异:' in line:
|
||||||
|
parts = line.split('差异:')
|
||||||
|
if len(parts) > 1:
|
||||||
|
diff_part = parts[1].strip()
|
||||||
|
if '%' in diff_part:
|
||||||
|
percent = float(diff_part.split('%')[0].strip().split()[-1])
|
||||||
|
result['comparison']['surface_area'] = {'difference_percent': percent}
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user