|
@@ -17,6 +17,7 @@ import com.css.simulation.resource.scheduler.pojo.po.TaskIndexPO;
|
|
|
import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
|
|
|
import com.css.simulation.resource.scheduler.pojo.to.ScoreTO;
|
|
|
import feign.Response;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -28,6 +29,7 @@ import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class TaskService {
|
|
|
|
|
|
private final String USER_ID = "simulation-resource-scheduler";
|
|
@@ -79,16 +81,16 @@ public class TaskService {
|
|
|
String scenePackageId = projectPO.getScenePackageId(); // 场景测试包 id,指标根 id
|
|
|
int taskNum = projectMapper.selectTaskNumById(projectId);
|
|
|
int completedTaskNum = projectMapper.selectTaskNumByProjectIdAndState(projectId, DictConstants.TASK_COMPLETED);
|
|
|
- if (taskNum != completedTaskNum) {
|
|
|
+ if (taskNum != completedTaskNum) { // 已完成任务数等于所有任务数量,才会准备打分;否则退出。
|
|
|
return;
|
|
|
- } //3 如果已完成任务数等于所有任务数量,调用打分程序,对项目中每个指标进行打分,
|
|
|
+ }
|
|
|
List<TaskPO> taskList = taskMapper.selectTaskListByProjectId(projectId); // 所有任务信息
|
|
|
+ // -------------------------------- 查询叶子指标 --------------------------------
|
|
|
List<IndexTemplatePO> leafIndexTemplateList = indexTemplateMapper.selectLeafIndexWithRuleDetailsByPackageId(scenePackageId);
|
|
|
List<TaskIndexPO> leafTaskIndexList = new ArrayList<>();
|
|
|
-
|
|
|
- // 计算所有叶子节点指标的得分
|
|
|
for (IndexTemplatePO indexTemplatePO : leafIndexTemplateList) {
|
|
|
- String ruleDetails = indexTemplatePO.getRuleDetails();
|
|
|
+// String ruleDetails = indexTemplatePO.getRuleDetails(); // 打分脚本路径
|
|
|
+ // -------------------------------- 查询每个叶子指标包括的场景 --------------------------------
|
|
|
Set<String> sceneIdSet = new HashSet<>();
|
|
|
String naturalIds = indexTemplatePO.getSceneNaturalIds();
|
|
|
String standardIds = indexTemplatePO.getSceneStatueIds();
|
|
@@ -106,22 +108,27 @@ public class TaskService {
|
|
|
sceneIdSet.addAll(Arrays.asList(accidentIdArray));
|
|
|
}
|
|
|
int resultNumberOfCurrentIndex = sceneIdSet.size();
|
|
|
+ // -------------------------------- 计算叶子指标的得分 --------------------------------
|
|
|
double sum = taskList.stream()
|
|
|
.filter(task1 -> sceneIdSet.contains(task1.getSceneId()))
|
|
|
.mapToDouble(task2 -> {
|
|
|
// 计算每个任务的得分
|
|
|
- ScoreTO score = new ScoreTO();
|
|
|
+ ScoreTO score;
|
|
|
+ String runResultMinio = task2.getRunResult();
|
|
|
+ String runResultLinux = manualProjectResultPathLinux + runResultMinio.substring(1);
|
|
|
+ String command = "python3 " + pyPath + " " + runResultLinux + " " + task2.getSceneType(); // 默认使用场景名称找打分脚本
|
|
|
+// String command = "python3 " + pyPath + " " + runResultLinux + " " + task2.getSceneType() + " " + ruleDetails; // 指定打分脚本
|
|
|
try {
|
|
|
- String runResultMinio = task2.getRunResult();
|
|
|
- String runResultLinux = manualProjectResultPathLinux + runResultMinio.substring(1);
|
|
|
Response download = commonService.download(MinioParameter.builder().objectName(runResultMinio).build());
|
|
|
Response.Body body = download.body();
|
|
|
InputStream inputStream = body.asInputStream();
|
|
|
FileUtil.writeInputStreamToLocalFile(inputStream, runResultLinux);
|
|
|
- String executeResult = SshUtil.execute(hostname, username, password, "python3 " + pyPath + " " + runResultLinux + " " + task2.getSceneType());
|
|
|
- score = JsonUtil.jsonToBean(executeResult, ScoreTO.class);
|
|
|
+ log.info("------- 开始执行打分命令:" + command);
|
|
|
+ score = JsonUtil.jsonToBean(SshUtil.execute(hostname, username, password, command), ScoreTO.class);
|
|
|
+ log.info("------- 打分结束,结果为:" + score);
|
|
|
} catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("------- 打分出错,命令为:" + command);
|
|
|
+ throw new RuntimeException();
|
|
|
}
|
|
|
task2.setReturnSceneId(score.getUnit_scene_ID());
|
|
|
task2.setScore(score.getUnit_scene_score());
|
|
@@ -131,10 +138,11 @@ public class TaskService {
|
|
|
task2.setModifyTime(TimeUtil.getNowForMysql());
|
|
|
return score.getUnit_scene_score();
|
|
|
}).sum();
|
|
|
- long notStandardSceneNum = taskList.stream() // 计算不合格的任务数(不到100分就是不合格)
|
|
|
- .filter(task1 -> sceneIdSet.contains(task1.getSceneId()) && task1.getScore() < 100)
|
|
|
- .count();
|
|
|
- double leafIndexScore = sum / resultNumberOfCurrentIndex; // 叶子指标的得分
|
|
|
+ // 计算不合格的任务数(不到100分就是不合格)
|
|
|
+ long notStandardSceneNum = taskList.stream().filter(task1 -> sceneIdSet.contains(task1.getSceneId()) && task1.getScore() < 100).count();
|
|
|
+ // 叶子指标的得分(叶子指标下所有场景得分的平均值)
|
|
|
+ double leafIndexScore = sum / resultNumberOfCurrentIndex;
|
|
|
+ // -------------------------------- 保存叶子指标得分 --------------------------------
|
|
|
indexTemplatePO.setTempScore(leafIndexScore);
|
|
|
TaskIndexPO leafTaskIndex = TaskIndexPO.builder()
|
|
|
.id(StringUtil.getRandomUUID())
|
|
@@ -151,14 +159,14 @@ public class TaskService {
|
|
|
leafTaskIndexList.add(leafTaskIndex);
|
|
|
}
|
|
|
|
|
|
- //4 根据每个指标的得分和权重算出 project 的总得分。
|
|
|
+ // 根据每个指标的得分和权重算出 project 的总得分。
|
|
|
double totalScore = compute(leafIndexTemplateList);
|
|
|
- //5 保存分数
|
|
|
- //5-1 保存任务分数
|
|
|
+ // 保存分数
|
|
|
+ // 保存任务分数
|
|
|
taskManager.batchUpdateByScoreResult(taskList);
|
|
|
- //5-2 保存指标分数
|
|
|
+ // 保存指标分数
|
|
|
taskIndexManager.batchInsertLeafIndex(leafTaskIndexList);
|
|
|
- //5-3 保存总分数
|
|
|
+ // 保存总分数
|
|
|
TaskIndexPO totalTaskIndex = TaskIndexPO.builder()
|
|
|
.id(StringUtil.getRandomUUID())
|
|
|
.pId(projectId)
|