You've already forked DataMate
fix(data-annotation): 修复数据标注任务进度计算问题
- 添加 toSafeCount 工具函数确保数值安全处理 - 支持 totalCount 和 total_count 字段兼容性 -
This commit is contained in:
@@ -57,6 +57,9 @@ export default function DataAnnotation() {
|
|||||||
const [selectedRowKeys, setSelectedRowKeys] = useState<AnnotationTaskRowKey[]>([]);
|
const [selectedRowKeys, setSelectedRowKeys] = useState<AnnotationTaskRowKey[]>([]);
|
||||||
const [selectedRows, setSelectedRows] = useState<AnnotationTaskListItem[]>([]);
|
const [selectedRows, setSelectedRows] = useState<AnnotationTaskListItem[]>([]);
|
||||||
|
|
||||||
|
const toSafeCount = (value: unknown) =>
|
||||||
|
typeof value === "number" && Number.isFinite(value) ? value : 0;
|
||||||
|
|
||||||
const handleAnnotate = (task: AnnotationTaskListItem) => {
|
const handleAnnotate = (task: AnnotationTaskListItem) => {
|
||||||
const projectId = task.id;
|
const projectId = task.id;
|
||||||
if (!projectId) {
|
if (!projectId) {
|
||||||
@@ -207,8 +210,20 @@ export default function DataAnnotation() {
|
|||||||
width: 100,
|
width: 100,
|
||||||
align: "center" as const,
|
align: "center" as const,
|
||||||
render: (value: number, record: AnnotationTaskListItem) => {
|
render: (value: number, record: AnnotationTaskListItem) => {
|
||||||
const total = record.totalCount || 0;
|
const total = toSafeCount(record.totalCount ?? record.total_count);
|
||||||
const annotated = value || 0;
|
const annotatedRaw = toSafeCount(
|
||||||
|
value ?? record.annotatedCount ?? record.annotated_count
|
||||||
|
);
|
||||||
|
const segmentationEnabled =
|
||||||
|
record.segmentationEnabled ?? record.segmentation_enabled;
|
||||||
|
const inProgressRaw = segmentationEnabled
|
||||||
|
? toSafeCount(record.inProgressCount ?? record.in_progress_count)
|
||||||
|
: 0;
|
||||||
|
const shouldExcludeInProgress =
|
||||||
|
total > 0 && annotatedRaw + inProgressRaw > total;
|
||||||
|
const annotated = shouldExcludeInProgress
|
||||||
|
? Math.max(annotatedRaw - inProgressRaw, 0)
|
||||||
|
: annotatedRaw;
|
||||||
const percent = total > 0 ? Math.round((annotated / total) * 100) : 0;
|
const percent = total > 0 ? Math.round((annotated / total) * 100) : 0;
|
||||||
return (
|
return (
|
||||||
<span title={`${annotated}/${total} (${percent}%)`}>
|
<span title={`${annotated}/${total} (${percent}%)`}>
|
||||||
|
|||||||
Reference in New Issue
Block a user