From 0c97648a9e2dd349e00266e106b2b71aa59281aa Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sun, 18 Jan 2026 17:35:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(annotation):=20=E4=BF=AE=E5=A4=8D=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=8A=B6=E6=80=81=E8=BF=87=E6=BB=A4=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在获取总文件数时添加 ACTIVE 状态过滤条件 - 修改已标注文件数统计逻辑,使用 distinct(file_id) 进行计数 - 在导出功能中为所有文件查询添加 ACTIVE 状态过滤 - 增加日志记录以跟踪导出统计过程 - 修正 --- .../app/module/annotation/service/export.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/runtime/datamate-python/app/module/annotation/service/export.py b/runtime/datamate-python/app/module/annotation/service/export.py index 8fa268b..ac27716 100644 --- a/runtime/datamate-python/app/module/annotation/service/export.py +++ b/runtime/datamate-python/app/module/annotation/service/export.py @@ -47,22 +47,26 @@ class AnnotationExportService: async def get_export_stats(self, project_id: str) -> ExportAnnotationsResponse: """获取导出统计信息""" project = await self._get_project_or_404(project_id) + logger.info(f"Export stats for project: id={project_id}, dataset_id={project.dataset_id}, name={project.name}") - # 获取总文件数 + # 获取总文件数(只统计 ACTIVE 状态的文件) total_result = await self.db.execute( select(func.count()).select_from(DatasetFiles).where( - DatasetFiles.dataset_id == project.dataset_id + DatasetFiles.dataset_id == project.dataset_id, + DatasetFiles.status == "ACTIVE", ) ) total_files = int(total_result.scalar() or 0) + logger.info(f"Total files (ACTIVE): {total_files} for dataset_id={project.dataset_id}") - # 获取已标注文件数 + # 获取已标注文件数(统计不同的 file_id 数量) annotated_result = await self.db.execute( - select(func.count(AnnotationResult.id.distinct())).where( + select(func.count(func.distinct(AnnotationResult.file_id))).where( AnnotationResult.project_id == project_id ) ) annotated_files = int(annotated_result.scalar() or 0) + logger.info(f"Annotated files: {annotated_files} for project_id={project_id}") return ExportAnnotationsResponse( project_id=project_id, @@ -154,9 +158,12 @@ class AnnotationExportService: ) ) else: - # 获取所有文件,包括未标注的 + # 获取所有文件,包括未标注的(只获取 ACTIVE 状态的文件) files_result = await self.db.execute( - select(DatasetFiles).where(DatasetFiles.dataset_id == dataset_id) + select(DatasetFiles).where( + DatasetFiles.dataset_id == dataset_id, + DatasetFiles.status == "ACTIVE", + ) ) files = files_result.scalars().all()