根据标注人和审核人的文件个数 分配标注和审核文件
This commit is contained in:
parent
af1cff7ba0
commit
9c89f087c8
|
|
@ -73,4 +73,12 @@ public class DataSetBasicFileEntity extends BaseEntity {
|
||||||
/**查询目的,表示文件在当前任务下的标注状态*/
|
/**查询目的,表示文件在当前任务下的标注状态*/
|
||||||
String fileAnnotationStatus;
|
String fileAnnotationStatus;
|
||||||
String annotationResult;
|
String annotationResult;
|
||||||
|
public DataSetBasicFileEntity (){}
|
||||||
|
public DataSetBasicFileEntity(Long fileId, Long parentId,String ancestors, String fileName, String fileUrl){
|
||||||
|
this.fileId = fileId;
|
||||||
|
this.parentId = parentId;
|
||||||
|
this.ancestors = ancestors;
|
||||||
|
this.fileName = fileName;
|
||||||
|
this.fileUrl = fileUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import lombok.Data;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.jws.soap.SOAPBinding;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -46,10 +47,10 @@ public class AnnotationTaskEntity extends BaseEntity {
|
||||||
|
|
||||||
|
|
||||||
/**标注人员列表*/
|
/**标注人员列表*/
|
||||||
private List<Long> annotators;
|
private List<UserFileCount> annotators;
|
||||||
|
|
||||||
/**审核人员列表*/
|
/**审核人员列表*/
|
||||||
private List<Long> reviewers;
|
private List<UserFileCount> reviewers;
|
||||||
|
|
||||||
/**分配后子任务,一个标注文件对应一个子任务*/
|
/**分配后子任务,一个标注文件对应一个子任务*/
|
||||||
private List<AnnotationTaskAnnotatorEntity> subAnnotationTasks;
|
private List<AnnotationTaskAnnotatorEntity> subAnnotationTasks;
|
||||||
|
|
@ -79,5 +80,23 @@ public class AnnotationTaskEntity extends BaseEntity {
|
||||||
private String lastVersionName;
|
private String lastVersionName;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class UserFileCount{
|
||||||
|
//人员id
|
||||||
|
private Long id;
|
||||||
|
//文件数量
|
||||||
|
private int num;
|
||||||
|
/*0 审核,1标注*/
|
||||||
|
private String type;
|
||||||
|
public UserFileCount(){
|
||||||
|
this.id = 0L;
|
||||||
|
this.num = 0;
|
||||||
|
this.type = "1";
|
||||||
|
}
|
||||||
|
public UserFileCount(Long userId, int fileCount, String type){
|
||||||
|
this.id = userId;
|
||||||
|
this.num = fileCount;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,73 +3,125 @@ package com.bonus.ai.utils;
|
||||||
import com.bonus.ai.domain.DataSetBasicFileEntity;
|
import com.bonus.ai.domain.DataSetBasicFileEntity;
|
||||||
import com.bonus.ai.domain.dataset.AnnotationTaskAnnotatorEntity;
|
import com.bonus.ai.domain.dataset.AnnotationTaskAnnotatorEntity;
|
||||||
import com.bonus.ai.domain.dataset.AnnotationTaskEntity;
|
import com.bonus.ai.domain.dataset.AnnotationTaskEntity;
|
||||||
import com.bonus.ai.domain.dataset.DatasetFile;
|
|
||||||
import com.bonus.common.security.utils.SecurityUtils;
|
import com.bonus.common.security.utils.SecurityUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AverageUtil {
|
public class AverageUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将文件集合分别平分到 annotators 和 reviewers 中
|
* 将文件集合按照要求的数量分配给相应的annotators 和 reviewers
|
||||||
* @param files 文件集合
|
* @param files 文件集合
|
||||||
* @param taskEntity 标注任务实体
|
* @param taskEntity 标注任务实体
|
||||||
* @return 分配结果,包含标注者和审核者的文件分配
|
* @return 分配结果,包含标注者和审核者的文件分配
|
||||||
*/
|
*/
|
||||||
public static List<AnnotationTaskAnnotatorEntity> distributeFiles(List<DataSetBasicFileEntity> files, AnnotationTaskEntity taskEntity) {
|
public static List<AnnotationTaskAnnotatorEntity> distributeFiles(List<DataSetBasicFileEntity> files, AnnotationTaskEntity taskEntity) {
|
||||||
List<AnnotationTaskAnnotatorEntity> annotatorEntities = new ArrayList<>();
|
List<AnnotationTaskAnnotatorEntity> assignments = new ArrayList<>();
|
||||||
|
|
||||||
List<Long> annotators = taskEntity.getAnnotators(); // 获取标注者列表
|
List<AnnotationTaskEntity.UserFileCount> annotators = taskEntity.getAnnotators(); // 获取标注者列表
|
||||||
List<Long> reviewers = taskEntity.getReviewers(); // 获取审核者列表
|
List<AnnotationTaskEntity.UserFileCount> reviewers = taskEntity.getReviewers(); // 获取审核者列表
|
||||||
|
|
||||||
//标注者与审核者都为空时,默认为当前用户
|
//标注者与审核者都为空时,默认为当前用户
|
||||||
if(("1").equals(taskEntity.getIsStartTeam())){
|
if(("1").equals(taskEntity.getIsStartTeam())){
|
||||||
if (annotators == null || annotators.size() == 0 ) {
|
if (annotators == null || annotators.size() == 0 ) {
|
||||||
annotators = new ArrayList<>();
|
annotators = new ArrayList<>();
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
annotators.add(userId);
|
annotators.add(new AnnotationTaskEntity.UserFileCount(userId,files.size(),"1"));
|
||||||
}
|
}
|
||||||
if (reviewers == null || reviewers.size() == 0) {
|
if (reviewers == null || reviewers.size() == 0) {
|
||||||
reviewers = new ArrayList<>();
|
reviewers = new ArrayList<>();
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
reviewers.add(userId);
|
reviewers.add(new AnnotationTaskEntity.UserFileCount(userId,files.size(),"0"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if (annotators == null || annotators.size() == 0) {
|
if (annotators == null || annotators.size() == 0) {
|
||||||
annotators = new ArrayList<>();
|
annotators = new ArrayList<>();
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
annotators.add(userId);
|
annotators.add(new AnnotationTaskEntity.UserFileCount(userId,files.size(),"1"));
|
||||||
}
|
}
|
||||||
if (reviewers == null || reviewers.size() == 0) {
|
if (reviewers == null || reviewers.size() == 0) {
|
||||||
reviewers = new ArrayList<>();
|
reviewers = new ArrayList<>();
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
reviewers.add(userId);
|
reviewers.add(new AnnotationTaskEntity.UserFileCount(userId,files.size(),"0"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//这里应该是根据标注者列表和审核人列表里的人 与文件相关进行平均分
|
// 创建迭代器以便可以安全地移除已分配的文件
|
||||||
// 平分文件给标注者
|
Iterator<DataSetBasicFileEntity> fileIterator = files.iterator();
|
||||||
for (int i = 0; i < files.size(); i++) {
|
|
||||||
Long annotatorId = annotators.get(i % annotators.size()); // 轮流分配给标注者
|
|
||||||
AnnotationTaskAnnotatorEntity entity = new AnnotationTaskAnnotatorEntity();
|
|
||||||
entity.setAnnotatorId(annotatorId); // 设置标注者 ID
|
|
||||||
entity.setFileId(files.get(i).getFileId()); // 假设 DatasetFile 有 getId() 方法
|
|
||||||
|
|
||||||
//这里需要将基础文件的url也获取并赋值
|
for (DataSetBasicFileEntity file : files) {
|
||||||
entity.setFileUrl(files.get(i).getFileUrl() );
|
|
||||||
annotatorEntities.add(entity);
|
// 为文件寻找一个标注人员
|
||||||
|
AnnotationTaskEntity.UserFileCount annotator = findUserWithQuota(annotators);
|
||||||
|
AnnotationTaskEntity.UserFileCount reviewer = findUserWithQuota(reviewers);
|
||||||
|
|
||||||
|
if (annotator != null && reviewer != null) {
|
||||||
|
// 创建一个任务分配实体
|
||||||
|
AnnotationTaskAnnotatorEntity assignment = new AnnotationTaskAnnotatorEntity();
|
||||||
|
assignment.setAnnotatorId(annotator.getId());
|
||||||
|
assignment.setReviewerId(reviewer.getId());
|
||||||
|
assignment.setTaskId(taskEntity.getTaskId());
|
||||||
|
assignment.setFileId(file.getFileId());
|
||||||
|
assignment.setFileUrl(file.getFileUrl());
|
||||||
|
// 添加到结果列表
|
||||||
|
assignments.add(assignment);
|
||||||
|
|
||||||
|
// 减少标注人员和审核人员的文件配额
|
||||||
|
annotator.setNum(annotator.getNum() - 1);
|
||||||
|
reviewer.setNum(reviewer.getNum() - 1);
|
||||||
|
} else {
|
||||||
|
// 如果没有足够的人员,停止分配
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 平分文件给审核者
|
|
||||||
for (int i = 0; i < annotatorEntities.size(); i++) {
|
|
||||||
Long reviewerId = reviewers.get(i % reviewers.size()); // 轮流分配给审核者
|
|
||||||
annotatorEntities.get(i).setReviewerId(reviewerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return annotatorEntities;
|
return assignments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在用户列表中寻找有剩余配额的用户
|
||||||
|
*/
|
||||||
|
private static AnnotationTaskEntity.UserFileCount findUserWithQuota(List<AnnotationTaskEntity.UserFileCount> users) {
|
||||||
|
for (AnnotationTaskEntity.UserFileCount user : users) {
|
||||||
|
if (user.getNum() > 0) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // 无法找到符合条件的用户
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 示例数据
|
||||||
|
List<DataSetBasicFileEntity> files = Arrays.asList(
|
||||||
|
new DataSetBasicFileEntity(1L, 0L, "0", "file1", "url1"),
|
||||||
|
new DataSetBasicFileEntity(2L, 0L, "0", "file2", "url2"),
|
||||||
|
new DataSetBasicFileEntity(3L, 0L, "0", "file3", "url3")
|
||||||
|
);
|
||||||
|
|
||||||
|
List<AnnotationTaskEntity.UserFileCount> annators = Arrays.asList(
|
||||||
|
new AnnotationTaskEntity.UserFileCount(1L, 2, "1"), // 用户1可以标注2个文件
|
||||||
|
new AnnotationTaskEntity.UserFileCount(2L, 1, "1") // 用户2可以审核1个文件
|
||||||
|
);
|
||||||
|
List<AnnotationTaskEntity.UserFileCount> reviewers = Arrays.asList(// 用户2可以标注1个文件
|
||||||
|
new AnnotationTaskEntity.UserFileCount(2L, 3, "0") // 用户2可以审核1个文件
|
||||||
|
);
|
||||||
|
|
||||||
|
AnnotationTaskEntity task = new AnnotationTaskEntity();
|
||||||
|
|
||||||
|
task.setReviewers(reviewers);
|
||||||
|
task.setAnnotators(annators);
|
||||||
|
// 分配文件
|
||||||
|
List<AnnotationTaskAnnotatorEntity> assignments = distributeFiles(files, task);
|
||||||
|
|
||||||
|
// 打印分配结果
|
||||||
|
assignments.forEach(a -> System.out.println(
|
||||||
|
"AnnotatorId: " + a.getAnnotatorId() +
|
||||||
|
", ReviewerId: " + a.getReviewerId() +
|
||||||
|
", FileId: " + a.getFileId() +
|
||||||
|
", FileUrl: " + a.getFileUrl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue