deving
This commit is contained in:
+102
-72
@@ -315,91 +315,121 @@ async def get_analysis_snapshot(snapshot_id: int, db_session: AsyncSession = Dep
|
|||||||
async def result_page(request: Request, task_id: str, db_session: AsyncSession = Depends(get_db_session)):
|
async def result_page(request: Request, task_id: str, db_session: AsyncSession = Depends(get_db_session)):
|
||||||
"""结果详情页面"""
|
"""结果详情页面"""
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from models.database import ProcessingTask, STPFile, GeometryData, MoldCavityData, HTMLFile
|
from models.database import ProcessingTask, STPFile, GeometryData, MoldCavityData, HTMLFile, AnalysisResultSnapshot
|
||||||
|
|
||||||
# 从数据库查询任务详情及相关数据
|
# 先尝试从分析结果快照获取数据(包含完整的 key_info)
|
||||||
result = await db_session.execute(
|
result = await db_session.execute(
|
||||||
select(ProcessingTask, STPFile, GeometryData, MoldCavityData, HTMLFile)
|
select(AnalysisResultSnapshot, ProcessingTask, STPFile)
|
||||||
|
.join(ProcessingTask, AnalysisResultSnapshot.stp_file_id == ProcessingTask.stp_file_id)
|
||||||
.join(STPFile, ProcessingTask.stp_file_id == STPFile.id)
|
.join(STPFile, ProcessingTask.stp_file_id == STPFile.id)
|
||||||
.outerjoin(GeometryData, STPFile.id == GeometryData.stp_file_id)
|
|
||||||
.outerjoin(MoldCavityData, STPFile.id == MoldCavityData.stp_file_id)
|
|
||||||
.outerjoin(HTMLFile, STPFile.id == HTMLFile.stp_file_id)
|
|
||||||
.where(ProcessingTask.task_id == task_id)
|
.where(ProcessingTask.task_id == task_id)
|
||||||
|
.order_by(AnalysisResultSnapshot.created_time.desc())
|
||||||
|
.limit(1)
|
||||||
)
|
)
|
||||||
|
|
||||||
task_record = result.first()
|
snapshot_record = result.first()
|
||||||
|
|
||||||
if not task_record:
|
|
||||||
raise HTTPException(404, "任务不存在")
|
|
||||||
|
|
||||||
task, stp_file, geometry_data, mold_cavity_data, html_file = task_record
|
|
||||||
|
|
||||||
# 构建任务详情数据
|
# 构建任务详情数据
|
||||||
task_data = {
|
task_data = {}
|
||||||
"task_id": task.task_id,
|
|
||||||
"filename": stp_file.original_filename if stp_file else "",
|
|
||||||
"file_size": stp_file.file_size if stp_file else 0,
|
|
||||||
"status": task.status,
|
|
||||||
"progress": task.progress,
|
|
||||||
"current_step": task.current_step,
|
|
||||||
"created_at": task.created_time.isoformat() if task.created_time else "",
|
|
||||||
"completed_at": task.completed_time.isoformat() if task.completed_time else "",
|
|
||||||
"error": task.error_message if task.error_message else ""
|
|
||||||
}
|
|
||||||
|
|
||||||
# 如果有几何数据,添加到返回结果
|
if snapshot_record:
|
||||||
if geometry_data:
|
# 从快照获取完整数据
|
||||||
task_data["geometry_data"] = {
|
snapshot, task, stp_file = snapshot_record
|
||||||
"volume": geometry_data.volume,
|
task_data = {
|
||||||
"surface_area": geometry_data.surface_area,
|
"task_id": task.task_id,
|
||||||
"bounding_box": {
|
"filename": stp_file.original_filename if stp_file else "",
|
||||||
"min": geometry_data.bounding_box_min,
|
"file_size": stp_file.file_size if stp_file else 0,
|
||||||
"max": geometry_data.bounding_box_max,
|
"status": task.status,
|
||||||
"dimensions": [
|
"progress": task.progress,
|
||||||
geometry_data.bounding_box_max[0] - geometry_data.bounding_box_min[0] if geometry_data.bounding_box_max and geometry_data.bounding_box_min else 0,
|
"current_step": task.current_step,
|
||||||
geometry_data.bounding_box_max[1] - geometry_data.bounding_box_min[1] if geometry_data.bounding_box_max and geometry_data.bounding_box_min else 0,
|
"upload_time": task.created_time.isoformat() if task.created_time else "",
|
||||||
geometry_data.bounding_box_max[2] - geometry_data.bounding_box_min[2] if geometry_data.bounding_box_max and geometry_data.bounding_box_min else 0
|
"completed_at": task.completed_time.isoformat() if task.completed_time else "",
|
||||||
]
|
"error": task.error_message if task.error_message else ""
|
||||||
},
|
|
||||||
"topology": {
|
|
||||||
"faces": geometry_data.topology_faces,
|
|
||||||
"edges": geometry_data.topology_edges,
|
|
||||||
"vertices": geometry_data.topology_vertices
|
|
||||||
},
|
|
||||||
"center_of_mass": geometry_data.center_of_mass
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# 如果有模具型腔数据,添加到返回结果
|
# 从快照获取完整的数据
|
||||||
if mold_cavity_data:
|
task_data["geometry_data"] = snapshot.geometry_data if snapshot.geometry_data else None
|
||||||
task_data["key_info"] = {
|
task_data["key_info"] = snapshot.key_info if snapshot.key_info else None
|
||||||
"metadata": {
|
task_data["mold_cavity_data"] = snapshot.mold_cavity_data if snapshot.mold_cavity_data else None
|
||||||
"shrinkage_rate": mold_cavity_data.shrinkage_rate,
|
|
||||||
"draft_angle": mold_cavity_data.draft_angle
|
logger.info(f"从快照加载任务数据: {task_id}")
|
||||||
},
|
else:
|
||||||
"manufacturing_info": {
|
# 如果没有快照,从各个表分别获取
|
||||||
"mold_material": mold_cavity_data.mold_material,
|
result = await db_session.execute(
|
||||||
"estimated_clamping_force": mold_cavity_data.estimated_clamping_force,
|
select(ProcessingTask, STPFile, GeometryData, MoldCavityData, HTMLFile)
|
||||||
"parting_line_length": mold_cavity_data.parting_line_length
|
.join(STPFile, ProcessingTask.stp_file_id == STPFile.id)
|
||||||
},
|
.outerjoin(GeometryData, STPFile.id == GeometryData.stp_file_id)
|
||||||
"mold_cavities": {
|
.outerjoin(MoldCavityData, STPFile.id == MoldCavityData.stp_file_id)
|
||||||
"cavity_key_info": {
|
.outerjoin(HTMLFile, STPFile.id == HTMLFile.stp_file_id)
|
||||||
"geometric_characteristics": {
|
.where(ProcessingTask.task_id == task_id)
|
||||||
"product_weight": mold_cavity_data.product_weight,
|
)
|
||||||
"product_volume": mold_cavity_data.product_volume,
|
|
||||||
"wall_thickness_range": mold_cavity_data.wall_thickness_range,
|
task_record = result.first()
|
||||||
"complexity_score": mold_cavity_data.complexity_score
|
|
||||||
|
if not task_record:
|
||||||
|
raise HTTPException(404, "任务不存在")
|
||||||
|
|
||||||
|
task, stp_file, geometry_data, mold_cavity_data, html_file = task_record
|
||||||
|
|
||||||
|
task_data = {
|
||||||
|
"task_id": task.task_id,
|
||||||
|
"filename": stp_file.original_filename if stp_file else "",
|
||||||
|
"file_size": stp_file.file_size if stp_file else 0,
|
||||||
|
"status": task.status,
|
||||||
|
"progress": task.progress,
|
||||||
|
"current_step": task.current_step,
|
||||||
|
"upload_time": task.created_time.isoformat() if task.created_time else "",
|
||||||
|
"completed_at": task.completed_time.isoformat() if task.completed_time else "",
|
||||||
|
"error": task.error_message if task.error_message else ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# 如果有几何数据,添加到返回结果
|
||||||
|
if geometry_data:
|
||||||
|
task_data["geometry_data"] = {
|
||||||
|
"volume": geometry_data.volume,
|
||||||
|
"surface_area": geometry_data.surface_area,
|
||||||
|
"bounding_box": {
|
||||||
|
"min": geometry_data.bounding_box_min,
|
||||||
|
"max": geometry_data.bounding_box_max,
|
||||||
|
"dimensions": [
|
||||||
|
geometry_data.bounding_box_max[0] - geometry_data.bounding_box_min[0] if geometry_data.bounding_box_max and geometry_data.bounding_box_min else 0,
|
||||||
|
geometry_data.bounding_box_max[1] - geometry_data.bounding_box_min[1] if geometry_data.bounding_box_max and geometry_data.bounding_box_min else 0,
|
||||||
|
geometry_data.bounding_box_max[2] - geometry_data.bounding_box_min[2] if geometry_data.bounding_box_max and geometry_data.bounding_box_min else 0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"topology": {
|
||||||
|
"faces": geometry_data.topology_faces,
|
||||||
|
"edges": geometry_data.topology_edges,
|
||||||
|
"vertices": geometry_data.topology_vertices
|
||||||
|
},
|
||||||
|
"center_of_mass": geometry_data.center_of_mass
|
||||||
|
}
|
||||||
|
|
||||||
|
# 如果有模具型腔数据,添加到返回结果
|
||||||
|
if mold_cavity_data:
|
||||||
|
task_data["key_info"] = {
|
||||||
|
"metadata": {
|
||||||
|
"shrinkage_rate": mold_cavity_data.shrinkage_rate,
|
||||||
|
"draft_angle": mold_cavity_data.draft_angle
|
||||||
|
},
|
||||||
|
"manufacturing_info": {
|
||||||
|
"mold_material": mold_cavity_data.mold_material,
|
||||||
|
"estimated_clamping_force": mold_cavity_data.estimated_clamping_force,
|
||||||
|
"parting_line_length": mold_cavity_data.parting_line_length
|
||||||
|
},
|
||||||
|
"mold_cavities": {
|
||||||
|
"cavity_key_info": {
|
||||||
|
"geometric_characteristics": {
|
||||||
|
"product_weight": mold_cavity_data.product_weight,
|
||||||
|
"product_volume": mold_cavity_data.product_volume,
|
||||||
|
"wall_thickness_range": mold_cavity_data.wall_thickness_range,
|
||||||
|
"complexity_score": mold_cavity_data.complexity_score
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
logger.info(f"从各个表加载任务数据: {task_id}")
|
||||||
# 如果有HTML文件信息,添加到返回结果
|
|
||||||
if html_file:
|
|
||||||
task_data["html_info"] = {
|
|
||||||
"filename": html_file.filename,
|
|
||||||
"file_path": html_file.file_path,
|
|
||||||
"generated_time": html_file.generated_time.isoformat() if html_file.generated_time else ""
|
|
||||||
}
|
|
||||||
|
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
import os
|
import os
|
||||||
|
|||||||
+2
-2
@@ -505,8 +505,8 @@ body {
|
|||||||
.features-data,
|
.features-data,
|
||||||
.recommendations-data,
|
.recommendations-data,
|
||||||
.metrics-data,
|
.metrics-data,
|
||||||
.analysis-info,
|
.analysis-info {
|
||||||
.key-info-categories {
|
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user