-
Notifications
You must be signed in to change notification settings - Fork 39
fix: Fix the sync issue between DataMate & LabelStudio; Fix the tag update issue in DataMate #399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -612,14 +612,13 @@ async def sync_manual_annotations_to_database( | |
| ): | ||
| """从 Label Studio 项目同步当前手动标注结果到 DM 数据库。 | ||
|
|
||
| 行为: | ||
| - 基于 mapping_id 定位 Label Studio 项目; | ||
| - 遍历项目下所有 task,按 task.data.file_id 找到对应 t_dm_dataset_files 记录; | ||
| - 读取每个 task 的 annotations + predictions,写入: | ||
| * tags: 从 result 中提取的标签概要,供 DM 列表/预览展示; | ||
| * annotation: 完整原始 JSON 结果; | ||
| * tags_updated_at: 当前时间戳。 | ||
| 返回值为成功更新的文件数量。 | ||
| 行为: | ||
| - 基于 mapping_id 定位 Label Studio 项目; | ||
| - 先执行 DM -> Label Studio 的文件差异同步(增量创建新文件任务、删除孤儿任务); | ||
| - 再执行双向标签同步(LS <-> DM),按时间戳保留较新标注: | ||
| * LS 更新时间更新 -> 覆盖 DM; | ||
| * DM tags_updated_at 更新 -> 覆盖 LS。 | ||
| 返回值为同步变更数量(LS->DM + DM->LS)。 | ||
| """ | ||
|
|
||
| mapping_service = DatasetMappingService(db) | ||
|
|
@@ -631,13 +630,28 @@ async def sync_manual_annotations_to_database( | |
| base_url=settings.label_studio_base_url, | ||
| token=settings.label_studio_user_token, | ||
| ) | ||
| sync_service = LSAnnotationSyncService(db, ls_client) | ||
|
|
||
| updated = await sync_service.sync_project_annotations_to_dm( | ||
| project_id=str(mapping.labeling_project_id), | ||
| dm_client = DatasetManagementService(db) | ||
| sync_orchestrator = SyncService(dm_client, ls_client, mapping_service) | ||
| file_sync_result = await sync_orchestrator.sync_files(mapping, batch_size=50) | ||
|
Comment on lines
+634
to
+636
|
||
| logger.info( | ||
| "Manual sync-db pre file-sync done: mapping=%s, created=%s, deleted=%s, total=%s", | ||
| mapping_id, | ||
| file_sync_result.get("created", 0), | ||
| file_sync_result.get("deleted", 0), | ||
| file_sync_result.get("total", 0), | ||
| ) | ||
|
|
||
| annotation_sync_result = await sync_orchestrator.sync_annotations_bidirectional( | ||
| mapping, | ||
| batch_size=50, | ||
| overwrite=True, | ||
| overwrite_ls=True, | ||
| sync_files_first=False, | ||
| ) | ||
|
|
||
| return StandardResponse(code="0", message="success", data=updated) | ||
| total_synced = annotation_sync_result.synced_to_dm + annotation_sync_result.synced_to_ls | ||
| return StandardResponse(code="0", message="success", data=total_synced) | ||
|
|
||
| @router.get("", response_model=StandardResponse[PaginatedData[DatasetMappingResponse]]) | ||
| async def list_mappings( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,20 +194,34 @@ def iter_results() -> List[Dict[str, Any]]: | |
|
|
||
| for r in results: | ||
| r_type = r.get("type") | ||
| if isinstance(r_type, str): | ||
| r_type = r_type.strip().lower() | ||
|
|
||
| from_name = r.get("from_name") or r.get("fromName") | ||
| to_name = r.get("to_name") or r.get("toName") | ||
| value_obj = r.get("value") or {} | ||
| if not isinstance(value_obj, dict): | ||
| continue | ||
|
|
||
| # 将 Label Studio 的 value 映射为 values,方便前端统一解析 | ||
| values: Dict[str, Any] = {} | ||
| for key, v in value_obj.items(): | ||
| values[key] = v | ||
| normalized_key = str(key).strip().lower() if key is not None else "" | ||
| if normalized_key: | ||
| values[normalized_key] = v | ||
|
|
||
| if isinstance(r_type, str) and r_type: | ||
| if r_type in values: | ||
| values = {r_type: values[r_type]} | ||
| elif len(values) == 1: | ||
| only_value = next(iter(values.values())) | ||
| values = {r_type: only_value} | ||
|
|
||
| tag = { | ||
| "id": r.get("id"), | ||
| "type": r_type, | ||
| "from_name": from_name, | ||
| "to_name": to_name, | ||
| "values": values, | ||
| } | ||
|
Comment on lines
220
to
226
|
||
| normalized.append(tag) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LSAnnotationSyncServiceis imported in this module but is no longer referenced after switching the /sync-db flow toSyncServiceorchestration. Please remove the unused import to avoid lint/type-check failures.