|
@@ -26,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.*;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.Files;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -38,9 +39,9 @@ import java.util.stream.Collectors;
|
|
|
public class SceneEvaluationRuleService {
|
|
|
|
|
|
|
|
|
-// @Value("${server.linux-path.temp}")
|
|
|
+ // @Value("${server.linux-path.temp}")
|
|
|
private String linuxTempPath = "";
|
|
|
-//
|
|
|
+ //
|
|
|
// @Value("${server.scene-evaluation.script}")
|
|
|
private String sceneEvaluationScript = "";
|
|
|
|
|
@@ -215,7 +216,7 @@ public class SceneEvaluationRuleService {
|
|
|
*
|
|
|
* @param param
|
|
|
*/
|
|
|
- public void computeSceneReference(SceneImportParam param, String sceneId, String taskId, String computeType, String evaluationPath) {
|
|
|
+ public void computeSceneReference(SceneImportParam param, SceneEvaluationComputeParam sceneEvaluationComputeParam) {
|
|
|
if (StringUtils.isEmpty(param.getSceneEvaluationRuleId())) {
|
|
|
return;
|
|
|
}
|
|
@@ -227,12 +228,10 @@ public class SceneEvaluationRuleService {
|
|
|
return;
|
|
|
}
|
|
|
// 1 判断有没有用户目录,没有则复制
|
|
|
- String evaluationDirectoryOfUser = linuxTempPath + "scene/evaluation/" + taskId + "/";
|
|
|
+ String evaluationDirectoryOfUser = linuxTempPath + "scene/evaluation/" + sceneEvaluationComputeParam.getTaskId() + "/";
|
|
|
String scriptsPath = evaluationDirectoryOfUser + "scripts/";
|
|
|
if (!new File(evaluationDirectoryOfUser).exists()) {
|
|
|
- // 创建临时目录
|
|
|
- FileUtil.createDirectory(evaluationDirectoryOfUser);
|
|
|
- // 2 将场景评价规则脚本保存到 script 目录
|
|
|
+ // 1 将场景评价规则脚本保存到 script 目录
|
|
|
FileUtil.createDirectory(scriptsPath);
|
|
|
final ArrayList<String> scriptFilePath = CollectionUtil.createArrayList(
|
|
|
"/data_preprocessing.py",
|
|
@@ -253,17 +252,25 @@ public class SceneEvaluationRuleService {
|
|
|
return;
|
|
|
}
|
|
|
String pyMainPath = scriptsPath + "/" + sceneEvaluationRulePO.getRuleId() + ".py";
|
|
|
- if (!new File(sceneEvaluationRulePO.getRuleId()).exists()) {
|
|
|
+ if (!new File(pyMainPath).exists()) {
|
|
|
Response download = fileDownService.download(MinioParameter.builder().objectName(sceneEvaluationRulePO.getScriptPath()).build());
|
|
|
String pyStr = download.body().toString();
|
|
|
download.close();
|
|
|
FileUtil.writeStringToLocalFile(pyStr, pyMainPath);
|
|
|
}
|
|
|
+ // 创建场景路径
|
|
|
+ if (!new File(evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId()).exists()) {
|
|
|
+ FileUtil.createDirectory(evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId());
|
|
|
+ } else {
|
|
|
+ // 一个场景只计算一次
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (StringUtils.equals(computeType, "1")) {
|
|
|
+
|
|
|
+ if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), "1")) {
|
|
|
// 计算复杂度,根据场景 id 获取场景信息,下载 osc odr
|
|
|
|
|
|
- } else if (StringUtils.equals(computeType, "2")) {
|
|
|
+ } else if (StringUtils.equals(sceneEvaluationComputeParam.getComputeType(), "2")) {
|
|
|
// 计算危险度 从 minio path 下载 csv (ego 和 sensors)
|
|
|
|
|
|
} else {
|
|
@@ -271,14 +278,14 @@ public class SceneEvaluationRuleService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- String sceneEvaluationCommand = "python3 " + pyMainPath + " " + (evaluationDirectoryOfUser + sceneId);
|
|
|
+ String sceneEvaluationCommand = "python3 " + pyMainPath + " " + (evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId());
|
|
|
String sceneEvaluationResult;
|
|
|
- SceneEvaluationResultEntity evaluationScore = null;
|
|
|
+ String evaluationScore = null;
|
|
|
log.info("开始执行场景评价命令:" + sceneEvaluationCommand);
|
|
|
Runtime r = Runtime.getRuntime();
|
|
|
Process p = null;
|
|
|
try {
|
|
|
- p = r.exec(sceneEvaluationCommand, null, new File(evaluationDirectoryOfUser + sceneId));
|
|
|
+ p = r.exec(sceneEvaluationCommand, null, new File(evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId()));
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
@@ -294,17 +301,38 @@ public class SceneEvaluationRuleService {
|
|
|
sb.append(inline).append("\n");
|
|
|
}
|
|
|
sceneEvaluationResult = sb.toString();
|
|
|
- log.info("场景" + sceneId + " 的场景评价结束,结果为:" + sceneEvaluationResult);
|
|
|
+ log.info("场景" + sceneEvaluationComputeParam.getSceneId() + " 的场景评价结束,结果为:" + sceneEvaluationResult);
|
|
|
String replace = StringUtil.replace(sceneEvaluationResult, "'", "\"");
|
|
|
try {
|
|
|
- evaluationScore = JsonUtil.jsonToBean(replace, SceneEvaluationResultEntity.class);
|
|
|
+ evaluationScore = JsonUtil.stringToJson(replace);
|
|
|
} catch (Exception e) {
|
|
|
- log.debug("场景" + sceneId + " 的场景评价失败:", e);
|
|
|
+ log.error("场景" + sceneEvaluationComputeParam.getSceneId() + " 的场景评价失败:", e);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
+ private void downloadDependFile(String minioPath, String localPath) throws IOException {
|
|
|
+// Response egoDownload = fileDownService.download(MinioParameter.builder().objectName(sceneEvaluationComputeParam.getEvaluationPath() + "/Ego.csv").build());
|
|
|
+ Response download = fileDownService.download(MinioParameter.builder().objectName(minioPath).build());
|
|
|
+ Response.Body body = download.body();
|
|
|
+ InputStream inputStream = null;
|
|
|
+ inputStream = body.asInputStream();
|
|
|
+// File file = new File(evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId() + "/Ego.csv");
|
|
|
+ File file = new File(localPath);
|
|
|
+ OutputStream outputStream = Files.newOutputStream(file.toPath());
|
|
|
+
|
|
|
+// log.error("文件 " + evaluationDirectoryOfUser + sceneEvaluationComputeParam.getSceneId() + "/Ego.csv 下载失败", e);
|
|
|
+
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int bytesRead;
|
|
|
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+ download.close();
|
|
|
}
|
|
|
|
|
|
}
|