|
@@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -70,33 +69,35 @@ public class TaskService {
|
|
redisTemplate.opsForValue().set(manualProjectTopic + ":" + projectId + ":" + taskId, TimeUtil.getNowString());
|
|
redisTemplate.opsForValue().set(manualProjectTopic + ":" + projectId + ":" + taskId, TimeUtil.getNowString());
|
|
}
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
public void taskState(String taskId, String state) {
|
|
public void taskState(String taskId, String state) {
|
|
- log.info("------- /state 接收到任务 " + taskId + "的状态:" + state);
|
|
|
|
- //1 根据 taskId 修改任务状态 taskState。
|
|
|
|
|
|
+ log.info("------- /state 修改任务 " + taskId + "的状态:" + state);
|
|
taskMapper.updateState(taskId, state);
|
|
taskMapper.updateState(taskId, state);
|
|
- //2 如果 taskState 为完成状态,校验一下项目的已完成数量。
|
|
|
|
ProjectPO projectPO = projectMapper.selectById(taskId);
|
|
ProjectPO projectPO = projectMapper.selectById(taskId);
|
|
String projectId = projectPO.getId();
|
|
String projectId = projectPO.getId();
|
|
String scenePackageId = projectPO.getScenePackageId(); // 场景测试包 id,指标根 id
|
|
String scenePackageId = projectPO.getScenePackageId(); // 场景测试包 id,指标根 id
|
|
|
|
+ log.info("------- /state 任务 " + taskId + " 的父项目为:" + projectId);
|
|
int taskNum = projectMapper.selectTaskNumById(projectId);
|
|
int taskNum = projectMapper.selectTaskNumById(projectId);
|
|
- int completedTaskNum = projectMapper.selectTaskNumByProjectIdAndState(projectId, DictConstants.TASK_COMPLETED);
|
|
|
|
- if (taskNum != completedTaskNum) { // 已完成任务数等于所有任务数量,才会准备打分;否则退出。
|
|
|
|
|
|
+ int endTaskNum = projectMapper.selectEndTaskNum(projectId); // 查询已结束的任务 'Aborted', 'PendingAnalysis', 'Terminated'
|
|
|
|
+ log.info("------- /state 项目 " + projectId + " 完成进度为:" + endTaskNum + "/" + taskNum);
|
|
|
|
+ if (taskNum != endTaskNum) { // 已结束任务数等于所有任务数量,才会准备打分;否则退出。
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ projectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED); // 修改该 project 的状态为已完成
|
|
List<TaskPO> taskList = taskMapper.selectTaskListByProjectId(projectId); // 所有任务信息
|
|
List<TaskPO> taskList = taskMapper.selectTaskListByProjectId(projectId); // 所有任务信息
|
|
// -------------------------------- 查询叶子指标 --------------------------------
|
|
// -------------------------------- 查询叶子指标 --------------------------------
|
|
List<IndexTemplatePO> leafIndexTemplateList = indexTemplateMapper.selectLeafIndexWithRuleDetailsByPackageId(scenePackageId);
|
|
List<IndexTemplatePO> leafIndexTemplateList = indexTemplateMapper.selectLeafIndexWithRuleDetailsByPackageId(scenePackageId);
|
|
List<TaskIndexPO> leafTaskIndexList = new ArrayList<>();
|
|
List<TaskIndexPO> leafTaskIndexList = new ArrayList<>();
|
|
|
|
+ log.info("------- /state 共有 " + leafIndexTemplateList.size() + "个叶子节点!");
|
|
for (int i = 0; i < leafIndexTemplateList.size(); i++) {
|
|
for (int i = 0; i < leafIndexTemplateList.size(); i++) {
|
|
IndexTemplatePO indexTemplatePO = leafIndexTemplateList.get(i);
|
|
IndexTemplatePO indexTemplatePO = leafIndexTemplateList.get(i);
|
|
- // -------------------------------- 将叶子节点对应的打分规则保存到临时目录 --------------------------------
|
|
|
|
|
|
+ String indexId = indexTemplatePO.getIndexId();
|
|
|
|
+ log.info("------- /state 开始执行对第 " + i + " 个叶子节点 " + indexId + " 进行打分!");
|
|
String ruleName = indexTemplatePO.getRuleName(); // 打分脚本名称,例如 AEB_1-1
|
|
String ruleName = indexTemplatePO.getRuleName(); // 打分脚本名称,例如 AEB_1-1
|
|
String ruleDetails = indexTemplatePO.getRuleDetails(); // 打分脚本内容
|
|
String ruleDetails = indexTemplatePO.getRuleDetails(); // 打分脚本内容
|
|
- String ruleDetailsPath = pyPath + "script/" + projectId + "_" + i;
|
|
|
|
- FileUtil.writeInputStreamToLocalFile(IoUtil.stringToInputStream(ruleDetails), ruleDetailsPath);
|
|
|
|
- // -------------------------------- 查询每个叶子指标包括的场景 --------------------------------
|
|
|
|
|
|
+ String ruleFilePath = pyPath + "script/" + ruleName.split("_")[0] + "/" + ruleName + ".py";
|
|
|
|
+ log.info("------- /state 将叶子节点 " + indexId + " 对应的打分规则保存到临时目录:" + ruleFilePath);
|
|
|
|
+ FileUtil.writeInputStreamToLocalFile(IoUtil.stringToInputStream(ruleDetails), ruleFilePath);
|
|
Set<String> sceneIdSet = new HashSet<>();
|
|
Set<String> sceneIdSet = new HashSet<>();
|
|
String naturalIds = indexTemplatePO.getSceneNaturalIds();
|
|
String naturalIds = indexTemplatePO.getSceneNaturalIds();
|
|
String standardIds = indexTemplatePO.getSceneStatueIds();
|
|
String standardIds = indexTemplatePO.getSceneStatueIds();
|
|
@@ -114,24 +115,29 @@ public class TaskService {
|
|
sceneIdSet.addAll(Arrays.asList(accidentIdArray));
|
|
sceneIdSet.addAll(Arrays.asList(accidentIdArray));
|
|
}
|
|
}
|
|
int resultNumberOfCurrentIndex = sceneIdSet.size();
|
|
int resultNumberOfCurrentIndex = sceneIdSet.size();
|
|
- // -------------------------------- 计算叶子指标的得分 --------------------------------
|
|
|
|
|
|
+ log.info("------- /state 叶子节点 " + indexId + " 包括 " + resultNumberOfCurrentIndex + " 个场景!");
|
|
|
|
+ log.info("------- /state 计算叶子节点 " + indexId + " 的得分!");
|
|
double sum = taskList.stream()
|
|
double sum = taskList.stream()
|
|
.filter(task1 -> sceneIdSet.contains(task1.getSceneId()))
|
|
.filter(task1 -> sceneIdSet.contains(task1.getSceneId()))
|
|
.mapToDouble(task2 -> {
|
|
.mapToDouble(task2 -> {
|
|
|
|
+ String task2Id = task2.getId();
|
|
|
|
+ taskMapper.updateState(task2Id, DictConstants.TASK_ANALYSING);
|
|
// 计算每个任务的得分
|
|
// 计算每个任务的得分
|
|
ScoreTO score;
|
|
ScoreTO score;
|
|
String runResultMinio = task2.getRunResult();
|
|
String runResultMinio = task2.getRunResult();
|
|
String runResultLinux = linuxTempPath + runResultMinio;
|
|
String runResultLinux = linuxTempPath + runResultMinio;
|
|
|
|
+// python3 /home/ubuntu/test/Evaluate/main.py /home/ubuntu/test/test_data.csv 4 AEB_1-2
|
|
// String command = "python3 " + pyPath + " " + runResultLinux + " " + task2.getSceneType(); // 默认使用场景名称找打分脚本
|
|
// String command = "python3 " + pyPath + " " + runResultLinux + " " + task2.getSceneType(); // 默认使用场景名称找打分脚本
|
|
- String command = "python3 " + pyPath + "main.py " + runResultLinux + " " + task2.getSceneType() + " " + ruleDetailsPath; // 指定打分脚本
|
|
|
|
-
|
|
|
|
|
|
+ String command = "python3 " + pyPath + "main.py " + runResultLinux + " " + task2.getSceneType() + " " + ruleName; // 指定打分脚本
|
|
try {
|
|
try {
|
|
|
|
+ log.info("------- /state 下载 minio 上的结果文件 " + runResultMinio + " 到本地:" + runResultLinux);
|
|
MinioUtil.downloadToFile(minioClient, bucketName, runResultMinio, runResultLinux);
|
|
MinioUtil.downloadToFile(minioClient, bucketName, runResultMinio, runResultLinux);
|
|
- log.info("------- 开始执行打分命令:" + command);
|
|
|
|
|
|
+ log.info("------- /state 开始执行打分命令:" + command);
|
|
score = JsonUtil.jsonToBean(SshUtil.execute(hostname, username, password, command), ScoreTO.class);
|
|
score = JsonUtil.jsonToBean(SshUtil.execute(hostname, username, password, command), ScoreTO.class);
|
|
- log.info("------- 打分结束,结果为:" + score);
|
|
|
|
|
|
+ log.info("------- /state 打分结束,结果为:" + score);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("------- 打分出错,命令为:" + command);
|
|
|
|
|
|
+ log.error("------- /state 任务 " + task2Id + " 打分出错,命令为:" + command + " 修改状态为:" + DictConstants.TASK_ABORTED);
|
|
|
|
+ taskMapper.updateState(task2Id, DictConstants.TASK_ABORTED);
|
|
throw new RuntimeException(e.getMessage());
|
|
throw new RuntimeException(e.getMessage());
|
|
}
|
|
}
|
|
task2.setReturnSceneId(score.getUnit_scene_ID());
|
|
task2.setReturnSceneId(score.getUnit_scene_ID());
|
|
@@ -183,6 +189,8 @@ public class TaskService {
|
|
totalTaskIndex.setModifyTime(TimeUtil.getNowForMysql());
|
|
totalTaskIndex.setModifyTime(TimeUtil.getNowForMysql());
|
|
totalTaskIndex.setIsDeleted("0");
|
|
totalTaskIndex.setIsDeleted("0");
|
|
taskIndexMapper.insertTotalIndex(totalTaskIndex);
|
|
taskIndexMapper.insertTotalIndex(totalTaskIndex);
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|