|
@@ -1,13 +1,15 @@
|
|
|
+/**
|
|
|
+ * 20241029 ©WANGKANG 1686617586@qq.com
|
|
|
+ */
|
|
|
+
|
|
|
package com.taais.biz.service.impl;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
@@ -17,7 +19,7 @@ import com.taais.biz.constant.BizConstant;
|
|
|
import com.taais.biz.domain.*;
|
|
|
import com.taais.biz.domain.vo.AlgorithmConfigTrackVo;
|
|
|
import com.taais.biz.domain.vo.AlgorithmModelTrackVo;
|
|
|
-import com.taais.biz.domain.vo.StartToInfraredTask;
|
|
|
+import com.taais.biz.domain.vo.StartTaskConfig;
|
|
|
import com.taais.biz.utils.ZipUtils;
|
|
|
import com.taais.common.core.config.TaaisConfig;
|
|
|
import com.taais.common.core.constant.Constants;
|
|
@@ -30,6 +32,7 @@ import com.taais.common.orm.core.service.impl.BaseServiceImpl;
|
|
|
import com.taais.system.domain.vo.SysOssVo;
|
|
|
import com.taais.system.service.ISysOssService;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
@@ -45,6 +48,9 @@ import com.taais.biz.service.ITrackSequenceService;
|
|
|
|
|
|
import static com.taais.biz.constant.BizConstant.VideoStatus.NOT_START;
|
|
|
import static com.taais.biz.domain.table.TrackSequenceTableDef.TRACK_SEQUENCE;
|
|
|
+import static com.taais.biz.service.impl.TargetDetectionServiceImpl.getFileSize;
|
|
|
+import static com.taais.biz.service.impl.TargetDetectionServiceImpl.port;
|
|
|
+import static com.taais.biz.service.impl.ToInfraredServiceImpl.readLogContent;
|
|
|
import static com.taais.biz.service.impl.VideoStableServiceImpl.*;
|
|
|
import static com.taais.biz.service.impl.VideoStableServiceImpl.makeDir;
|
|
|
|
|
@@ -56,7 +62,11 @@ import static com.taais.biz.service.impl.VideoStableServiceImpl.makeDir;
|
|
|
*/
|
|
|
@Service
|
|
|
public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMapper, TrackSequence> implements ITrackSequenceService {
|
|
|
- @Value("${server.task_stop_url}")
|
|
|
+
|
|
|
+ private static final String MASC = "MASC";
|
|
|
+ private static final String CAT = "CAT";
|
|
|
+
|
|
|
+ @Value("${server.task_stop_url_cat}")
|
|
|
private String task_stop_url;
|
|
|
|
|
|
@Autowired
|
|
@@ -77,30 +87,18 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
|
|
|
|
|
|
private QueryWrapper buildQueryWrapper(TrackSequenceBo trackSequenceBo) {
|
|
|
QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.NAME.like
|
|
|
- (trackSequenceBo.getName()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.STATUS.eq
|
|
|
- (trackSequenceBo.getStatus()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.START_TIME.eq
|
|
|
- (trackSequenceBo.getStartTime()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.END_TIME.eq
|
|
|
- (trackSequenceBo.getEndTime()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.COST_SECOND.eq
|
|
|
- (trackSequenceBo.getCostSecond()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.LOG.eq
|
|
|
- (trackSequenceBo.getLog()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.REMARKS.eq
|
|
|
- (trackSequenceBo.getRemarks()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.URL.eq
|
|
|
- (trackSequenceBo.getUrl()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.INPUT_OSS_ID.eq
|
|
|
- (trackSequenceBo.getInputOssId()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.INPUT_PATH.eq
|
|
|
- (trackSequenceBo.getInputPath()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.OUTPUT_PATH.eq
|
|
|
- (trackSequenceBo.getOutputPath()));
|
|
|
- queryWrapper.and(TRACK_SEQUENCE.ZIP_FILE_PATH.eq
|
|
|
- (trackSequenceBo.getZipFilePath()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.NAME.like(trackSequenceBo.getName()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.STATUS.eq(trackSequenceBo.getStatus()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.START_TIME.eq(trackSequenceBo.getStartTime()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.END_TIME.eq(trackSequenceBo.getEndTime()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.COST_SECOND.eq(trackSequenceBo.getCostSecond()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.LOG.eq(trackSequenceBo.getLog()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.REMARKS.eq(trackSequenceBo.getRemarks()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.URL.eq(trackSequenceBo.getUrl()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.INPUT_OSS_ID.eq(trackSequenceBo.getInputOssId()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.INPUT_PATH.eq(trackSequenceBo.getInputPath()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.OUTPUT_PATH.eq(trackSequenceBo.getOutputPath()));
|
|
|
+ queryWrapper.and(TRACK_SEQUENCE.ZIP_FILE_PATH.eq(trackSequenceBo.getZipFilePath()));
|
|
|
|
|
|
return queryWrapper;
|
|
|
}
|
|
@@ -141,13 +139,30 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
|
|
|
Page<TrackSequenceVo> page = this.pageAs(PageQuery.build(), queryWrapper, TrackSequenceVo.class);
|
|
|
page.getRecords().forEach(entity -> {
|
|
|
Long modelId = entity.getAlgorithmModelId();
|
|
|
- AlgorithmModelTrackVo model = algorithmModelTrackService.selectById(modelId);
|
|
|
- if (ObjectUtil.isNotNull(model)) {
|
|
|
- AlgorithmConfigTrackVo config = algorithmConfigTrackService.selectById(model.getAlgorithmId());
|
|
|
- entity.setType(config.getType());
|
|
|
- entity.setSubsystem(config.getSubsystem());
|
|
|
- entity.setAlgorithmName(config.getAlgorithmName());
|
|
|
- entity.setModelName(model.getModelName());
|
|
|
+ Long algorithmId = entity.getAlgorithmId();
|
|
|
+ if (modelId != null) {
|
|
|
+ AlgorithmModelTrackVo model = algorithmModelTrackService.selectById(modelId);
|
|
|
+ if (ObjectUtil.isNotNull(model)) {
|
|
|
+ entity.setModelName(model.getModelName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (algorithmId != null) {
|
|
|
+ AlgorithmConfigTrackVo config = algorithmConfigTrackService.selectById(algorithmId);
|
|
|
+ if (ObjectUtil.isNotNull(config)) {
|
|
|
+ entity.setType(config.getType());
|
|
|
+ entity.setSubsystem(config.getSubsystem());
|
|
|
+ entity.setAlgorithmName(config.getAlgorithmName());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ AlgorithmModelTrackVo model = algorithmModelTrackService.selectById(modelId);
|
|
|
+ if (ObjectUtil.isNotNull(model)) {
|
|
|
+ AlgorithmConfigTrackVo config = algorithmConfigTrackService.selectById(model.getAlgorithmId());
|
|
|
+ if (ObjectUtil.isNotNull(config)) {
|
|
|
+ entity.setType(config.getType());
|
|
|
+ entity.setSubsystem(config.getSubsystem());
|
|
|
+ entity.setAlgorithmName(config.getAlgorithmName());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
return PageResult.build(page);
|
|
@@ -160,20 +175,37 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
|
|
|
* @return 结果:true 操作成功,false 操作失败
|
|
|
*/
|
|
|
@Override
|
|
|
- public boolean insert(TrackSequenceBo trackSequenceBo) {
|
|
|
+ public CommonResult insert(TrackSequenceBo trackSequenceBo) {
|
|
|
+ // 检查任务名称
|
|
|
+ if (ObjectUtil.isEmpty(trackSequenceBo.getName()) || (!trackSequenceBo.getName().startsWith(MASC) && !trackSequenceBo.getName().startsWith(CAT))) {
|
|
|
+ return CommonResult.fail("任务命名错误,需以MASC或CAT开头!");
|
|
|
+ }
|
|
|
+
|
|
|
// 检查input_oss_id是否存在
|
|
|
if (ObjectUtil.isNull(trackSequenceBo.getInputOssId())) {
|
|
|
- return false;
|
|
|
+ return CommonResult.fail("请上传模型");
|
|
|
}
|
|
|
|
|
|
SysOssVo ossEntity = ossService.getById(trackSequenceBo.getInputOssId());
|
|
|
if (ObjectUtil.isNull(ossEntity)) {
|
|
|
- return false;
|
|
|
+ return CommonResult.fail("找不到指定模型!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (trackSequenceBo.getName().startsWith(MASC)) {
|
|
|
+ if (ObjectUtil.isEmpty(trackSequenceBo.getAlgorithmId())) {
|
|
|
+ return CommonResult.fail("请指定算法!");
|
|
|
+ }
|
|
|
+
|
|
|
+ AlgorithmConfigTrackVo config = algorithmConfigTrackService.selectById(trackSequenceBo.getAlgorithmId());
|
|
|
+ if (ObjectUtil.isNull(config)) {
|
|
|
+ return CommonResult.fail("找不到指定的算法!");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
TrackSequence trackSequence = new TrackSequence();
|
|
|
|
|
|
- trackSequence.setInputOssId(trackSequenceBo.getInputOssId());
|
|
|
+ BeanUtils.copyProperties(trackSequenceBo, trackSequence);
|
|
|
+
|
|
|
trackSequence.setUrl(ossEntity.getUrl());
|
|
|
|
|
|
String filePath = ossEntity.getFileName();
|
|
@@ -189,14 +221,15 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
|
|
|
trackSequence.setOutputPath(outPath.toString());
|
|
|
|
|
|
trackSequence.setZipFilePath(path.resolveSibling(fileName_without_suffix + ".zip").toString());
|
|
|
-
|
|
|
- trackSequence.setName(trackSequenceBo.getName());
|
|
|
trackSequence.setStatus(NOT_START);
|
|
|
- trackSequence.setRemarks(trackSequenceBo.getRemarks());
|
|
|
|
|
|
- trackSequence.setAlgorithmModelId(trackSequenceBo.getAlgorithmModelId());
|
|
|
|
|
|
- return this.save(trackSequence);// 使用全局配置的雪花算法主键生成器生成ID值
|
|
|
+ boolean __ = this.save(trackSequence);// 使用全局配置的雪花算法主键生成器生成ID值
|
|
|
+ if (__) {
|
|
|
+ return CommonResult.success();
|
|
|
+ } else {
|
|
|
+ return CommonResult.fail();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -229,62 +262,138 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
|
|
|
|
|
|
@Override
|
|
|
public CommonResult start(Long id) {
|
|
|
+ /*
|
|
|
+ * WANGKANG 望维护此代码的后来者安息。
|
|
|
+ *
|
|
|
+ * 不是我想写这么恶心,只是没办法,算法端的逻辑写的跟屎一样。。。。
|
|
|
+ */
|
|
|
TrackSequence entity = getById(id);
|
|
|
+ AlgorithmModelTrack algorithmModelTrack = algorithmModelTrackService.getById(entity.getAlgorithmModelId());
|
|
|
+ AlgorithmConfigTrack algorithmConfigTrack = null;
|
|
|
+ try {
|
|
|
+ algorithmConfigTrack = algorithmConfigTrackService.getById(entity.getAlgorithmId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ algorithmConfigTrack = algorithmConfigTrackService.getById(algorithmModelTrack.getAlgorithmId());
|
|
|
+ }
|
|
|
|
|
|
- SysOssVo inputOssEntity = ossService.getById(entity.getInputOssId());
|
|
|
+ StartTaskConfig startTaskConfig = new StartTaskConfig();
|
|
|
|
|
|
- String filePath = inputOssEntity.getFileName();
|
|
|
- String localPath = TaaisConfig.getProfile();
|
|
|
- String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
|
|
|
+ if (algorithmConfigTrack.getType().equals(BizConstant.AlgorithmType.TEST) && (entity.getName().startsWith(MASC) || entity.getName().startsWith(CAT))) {
|
|
|
+ startTaskConfig.setBizType(BizConstant.BizType.TRACK_SEQUENCE);
|
|
|
+ startTaskConfig.setBizId(entity.getId());
|
|
|
|
|
|
- String fileName = StringUtils.substringAfterLast(filePath, "/");
|
|
|
- String fileName_without_suffix = removeFileExtension(fileName);
|
|
|
+ startTaskConfig.setOtherParams(algorithmConfigTrack.getParameterConfig());
|
|
|
|
|
|
- Path path = Paths.get(resourcePath);
|
|
|
- Path inputPath = path.resolveSibling(fileName_without_suffix + BizConstant.UNZIP_SUFFIX);
|
|
|
- Path outputPath = path.resolveSibling(fileName_without_suffix + BizConstant.TRACK_SEQUENCE_SUFFIX);
|
|
|
+ startTaskConfig.setSource_dir(entity.getInputPath());
|
|
|
+ startTaskConfig.setResult_dir(entity.getOutputPath());
|
|
|
+ startTaskConfig.setLog_path(entity.getOutputPath() + File.separator + getLogFileName(entity));
|
|
|
+ } else {
|
|
|
+ SysOssVo inputOssEntity = ossService.getById(entity.getInputOssId());
|
|
|
|
|
|
- makeDir(inputPath.toString());
|
|
|
- makeDir(outputPath.toString());
|
|
|
+ String filePath = inputOssEntity.getFileName();
|
|
|
+ String localPath = TaaisConfig.getProfile();
|
|
|
+ String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
|
|
|
|
|
|
- File file = new File(resourcePath);
|
|
|
- if (!file.exists()) {
|
|
|
- ZipUtils.unzip(resourcePath, inputPath.toString());
|
|
|
- }
|
|
|
+ String fileName = StringUtils.substringAfterLast(filePath, "/");
|
|
|
+ String fileName_without_suffix = removeFileExtension(fileName);
|
|
|
|
|
|
- entity.setInputPath(inputPath.toString());
|
|
|
- entity.setOutputPath(outputPath.toString());
|
|
|
+ Path path = Paths.get(resourcePath);
|
|
|
+ Path inputPath = path.resolveSibling(fileName_without_suffix + BizConstant.UNZIP_SUFFIX);
|
|
|
+ Path outputPath = path.resolveSibling(entity.getId().toString() + BizConstant.TRACK_SEQUENCE_SUFFIX);
|
|
|
|
|
|
- entity.setStartTime(new Date());
|
|
|
+// makeDir(inputPath.toString());
|
|
|
+ makeDir(outputPath.toString());
|
|
|
|
|
|
- AlgorithmModelTrack algorithmModelTrack = algorithmModelTrackService.getById(entity.getAlgorithmModelId());
|
|
|
- AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(algorithmModelTrack.getAlgorithmId());
|
|
|
+ File file = new File(inputPath.toString());
|
|
|
+ if (!file.exists()) {
|
|
|
+ ZipUtils.unzip(resourcePath, inputPath.toString());
|
|
|
+ }
|
|
|
|
|
|
- StartToInfraredTask startToInfraredTask = new StartToInfraredTask();
|
|
|
- startToInfraredTask.setBizType(BizConstant.BizType.TRACK_SEQUENCE);
|
|
|
- startToInfraredTask.setBizId(entity.getId());
|
|
|
+ entity.setInputPath(inputPath.toString());
|
|
|
+ entity.setOutputPath(outputPath.toString());
|
|
|
|
|
|
- startToInfraredTask.setOtherParams(algorithmConfigTrack.getParameterConfig());
|
|
|
+ entity.setStartTime(new Date());
|
|
|
|
|
|
- startToInfraredTask.setSource_dir(entity.getInputPath());
|
|
|
- startToInfraredTask.setResult_dir(entity.getOutputPath());
|
|
|
+ startTaskConfig.setBizType(BizConstant.BizType.TRACK_SEQUENCE);
|
|
|
+ startTaskConfig.setBizId(entity.getId());
|
|
|
|
|
|
- if (BizConstant.AlgorithmType.REASONING.equals(algorithmConfigTrack.getType())) {
|
|
|
- if(algorithmModelTrack.getModelName().startsWith("masc") || algorithmModelTrack.getModelName().startsWith("MASC")) {
|
|
|
- String modelPath = algorithmModelTrack.getModelAddress() + File.separator + algorithmModelTrack.getModelName().substring(5);
|
|
|
- startToInfraredTask.setModel_path(modelPath);
|
|
|
- }
|
|
|
- else if(algorithmModelTrack.getModelName().startsWith("cat") || algorithmModelTrack.getModelName().startsWith("CAT")) {
|
|
|
+ startTaskConfig.setOtherParams(algorithmConfigTrack.getParameterConfig());
|
|
|
+
|
|
|
+ startTaskConfig.setSource_dir(entity.getInputPath());
|
|
|
+ startTaskConfig.setResult_dir(entity.getOutputPath());
|
|
|
+ startTaskConfig.setLog_path(entity.getOutputPath() + File.separator + getLogFileName(entity));
|
|
|
+
|
|
|
+ if (BizConstant.AlgorithmType.REASONING.equals(algorithmConfigTrack.getType())) {
|
|
|
String modelPath = algorithmModelTrack.getModelAddress();
|
|
|
- startToInfraredTask.setModel_path(modelPath);
|
|
|
- }
|
|
|
- else {
|
|
|
- return CommonResult.fail("模型命名失败,请以MASC或CAT开头命名模型");
|
|
|
+ startTaskConfig.setModel_path(modelPath);
|
|
|
+ if (entity.getName().startsWith(CAT)) {
|
|
|
+ startTaskConfig.setSource_dir(startTaskConfig.getSource_dir());
|
|
|
+// File file________ = new File(startTaskConfig.getSource_dir());
|
|
|
+// if (!file________.exists()) {
|
|
|
+// return CommonResult.fail("数据集为空!");
|
|
|
+// }
|
|
|
+// if (file________.listFiles() != null && file________.listFiles().length > 0) {
|
|
|
+// for (File file___________________tmp : file________.listFiles()) {
|
|
|
+// if (file___________________tmp.isDirectory()) {
|
|
|
+// startTaskConfig.setSource_dir(file___________________tmp.getPath());
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ File file___________________________ = new File(startTaskConfig.getModel_path());
|
|
|
+ if (!file___________________________.exists()) {
|
|
|
+ return CommonResult.fail("模型不存在!");
|
|
|
+ }
|
|
|
+ if (file___________________________.listFiles() != null && file___________________________.listFiles().length > 0) {
|
|
|
+ for (File file___________________tmp : file___________________________.listFiles()) {
|
|
|
+ if (file___________________tmp.isDirectory()) {
|
|
|
+ startTaskConfig.setModel_path(file___________________tmp.getPath());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// if (algorithmModelTrack.getModelName().startsWith("masc") || algorithmModelTrack.getModelName().startsWith("MASC")) {
|
|
|
+// String modelPath = algorithmModelTrack.getModelAddress() + File.separator + algorithmModelTrack.getModelName().substring(5);
|
|
|
+// startTaskConfig.setModel_path(modelPath);
|
|
|
+// } else if (algorithmModelTrack.getModelName().startsWith("cat") || algorithmModelTrack.getModelName().startsWith("CAT")) {
|
|
|
+// String modelPath = algorithmModelTrack.getModelAddress();
|
|
|
+// startTaskConfig.setModel_path(modelPath);
|
|
|
+// } else {
|
|
|
+// return CommonResult.fail("模型命名失败,请以MASC或CAT开头命名模型");
|
|
|
+// }
|
|
|
+ } else if (BizConstant.AlgorithmType.TRAIN.equals(algorithmConfigTrack.getType()) && entity.getName().startsWith(CAT)) {
|
|
|
+ File file________ = new File(startTaskConfig.getSource_dir());
|
|
|
+ if (!file________.exists()) {
|
|
|
+ return CommonResult.fail("数据集为空!");
|
|
|
+ }
|
|
|
+ boolean flag = false;
|
|
|
+ if (file________.listFiles() != null && file________.listFiles().length > 0) {
|
|
|
+ for (File file___________________tmp : file________.listFiles()) {
|
|
|
+ if (file___________________tmp.isDirectory()) {
|
|
|
+ startTaskConfig.setSource_dir(file___________________tmp.getPath());
|
|
|
+ flag = true;
|
|
|
+// if (file___________________tmp.listFiles() != null && file___________________tmp.listFiles().length > 0) {
|
|
|
+// for (File file________________________________________________________________________________________ : file___________________tmp.listFiles()) {
|
|
|
+// if (file________________________________________________________________________________________.isDirectory() &&
|
|
|
+// file________________________________________________________________________________________.getName().equals("images")) {
|
|
|
+// startTaskConfig.setSource_dir(file________________________________________________________________________________________.getPath());
|
|
|
+// flag = true;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!(flag && !false && (1!=2) && (1 == 1))) {
|
|
|
+ return CommonResult.fail("数据集错误!!!!!!");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- HttpResponseEntity responseEntity = sendPostMsg(algorithmConfigTrack.getAlgorithmAddress(), startToInfraredTask);
|
|
|
+ HttpResponseEntity responseEntity = sendPostMsg(algorithmConfigTrack.getAlgorithmAddress(), startTaskConfig);
|
|
|
if (ObjectUtil.isNotNull(responseEntity) && responseEntity.getStatus() == 200) {
|
|
|
entity.setStatus(BizConstant.VideoStatus.RUNNING);
|
|
|
updateById(entity);
|
|
@@ -300,11 +409,11 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
|
|
|
public CommonResult stop(Long id) {
|
|
|
TrackSequence entity = getById(id);
|
|
|
|
|
|
- StartToInfraredTask startToInfraredTask = new StartToInfraredTask();
|
|
|
- startToInfraredTask.setBizType(BizConstant.BizType.TRACK_SEQUENCE);
|
|
|
- startToInfraredTask.setBizId(entity.getId());
|
|
|
+ StartTaskConfig startTaskConfig = new StartTaskConfig();
|
|
|
+ startTaskConfig.setBizType(BizConstant.BizType.TRACK_SEQUENCE);
|
|
|
+ startTaskConfig.setBizId(entity.getId());
|
|
|
|
|
|
- HttpResponseEntity responseEntity = sendPostMsg(task_stop_url, startToInfraredTask);
|
|
|
+ HttpResponseEntity responseEntity = sendPostMsg(task_stop_url, startTaskConfig);
|
|
|
if (ObjectUtil.isNotNull(responseEntity) && responseEntity.getStatus() == 200) {
|
|
|
entity.setStatus(BizConstant.VideoStatus.INTERRUPTED);
|
|
|
updateById(entity);
|
|
@@ -329,9 +438,17 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
|
|
|
|
|
|
if (BizConstant.AlgorithmType.REASONING.equals(algorithmConfigTrack.getType())) {
|
|
|
outputPath = entity.getOutputPath() + File.separator + "predict";
|
|
|
+ File file__ = new File(outputPath);
|
|
|
+ if (!file__.exists()) {
|
|
|
+ outputPath = entity.getOutputPath();
|
|
|
+ }
|
|
|
zipFilePath = outputPath + ".zip";
|
|
|
} else if (BizConstant.AlgorithmType.TEST.equals(algorithmConfigTrack.getType())) {
|
|
|
outputPath = entity.getOutputPath() + File.separator + "evaluate";
|
|
|
+ File file__ = new File(outputPath);
|
|
|
+ if (!file__.exists()) {
|
|
|
+ outputPath = entity.getOutputPath();
|
|
|
+ }
|
|
|
zipFilePath = outputPath + ".zip";
|
|
|
} else if (BizConstant.AlgorithmType.TRAIN.equals(algorithmConfigTrack.getType())) {
|
|
|
outputPath = entity.getOutputPath();
|
|
@@ -355,10 +472,7 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
|
|
|
}
|
|
|
|
|
|
org.springframework.core.io.Resource resource = new FileSystemResource(file);
|
|
|
- return ResponseEntity.ok()
|
|
|
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"")
|
|
|
- .header(HttpHeaders.CONTENT_TYPE, "application/octet-stream")
|
|
|
- .body(resource);
|
|
|
+ return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"").header(HttpHeaders.CONTENT_TYPE, "application/octet-stream").body(resource);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -392,4 +506,156 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
|
|
|
}
|
|
|
return CommonResult.success();
|
|
|
}
|
|
|
+
|
|
|
+ private String getLogFileName(TrackSequence entity) {
|
|
|
+ return entity.getId() + BizConstant.TRACK_SEQUENCE_SUFFIX + ".log";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult getLog(Long id) {
|
|
|
+ TrackSequence entity = getById(id);
|
|
|
+ String outPutPath = entity.getOutputPath();
|
|
|
+ String logPath = outPutPath + File.separator + getLogFileName(entity);
|
|
|
+ System.out.println(logPath);
|
|
|
+ File file = new File(logPath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ return CommonResult.fail("日志文件不存在!");
|
|
|
+ }
|
|
|
+ return CommonResult.success(readLogContent(logPath), "success");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult getDetail(Long id) {
|
|
|
+ TrackSequenceVo entity = selectById(id);
|
|
|
+ if (entity.getName().startsWith(MASC)) {
|
|
|
+ AlgorithmModelTrack modelTrack = algorithmModelTrackService.getById(entity.getAlgorithmModelId());
|
|
|
+ AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(entity.getAlgorithmId());
|
|
|
+
|
|
|
+ AlgorithmModelTrackVo res = new AlgorithmModelTrackVo();
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(modelTrack, res);
|
|
|
+ BeanUtils.copyProperties(algorithmConfigTrack, res);
|
|
|
+
|
|
|
+ res.setAlgorithmId(algorithmConfigTrack.getId());
|
|
|
+ res.setId(modelTrack.getId());
|
|
|
+
|
|
|
+ return CommonResult.success(res, "success");
|
|
|
+ } else if (entity.getName().startsWith(CAT)) {
|
|
|
+ AlgorithmModelTrack modelTrack = algorithmModelTrackService.getById(entity.getAlgorithmModelId());
|
|
|
+ AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(modelTrack.getAlgorithmId());
|
|
|
+
|
|
|
+ AlgorithmModelTrackVo res = new AlgorithmModelTrackVo();
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(modelTrack, res);
|
|
|
+ BeanUtils.copyProperties(algorithmConfigTrack, res);
|
|
|
+
|
|
|
+ res.setAlgorithmId(algorithmConfigTrack.getId());
|
|
|
+ res.setId(modelTrack.getId());
|
|
|
+
|
|
|
+ return CommonResult.success(res, "success");
|
|
|
+ } else {
|
|
|
+ return CommonResult.fail("命名错误!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult addEvaluate(AddEvaluate addEvaluate) {
|
|
|
+ // 检查任务名称
|
|
|
+ if (ObjectUtil.isEmpty(addEvaluate.getName()) || (!addEvaluate.getName().startsWith(MASC) && !addEvaluate.getName().startsWith(CAT))) {
|
|
|
+ return CommonResult.fail("任务命名错误,需以MASC或CAT开头!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(addEvaluate.getAlgorithmId())) {
|
|
|
+ return CommonResult.fail("请指定算法!");
|
|
|
+ }
|
|
|
+
|
|
|
+ AlgorithmConfigTrackVo config = algorithmConfigTrackService.selectById(addEvaluate.getAlgorithmId());
|
|
|
+ if (ObjectUtil.isNull(config)) {
|
|
|
+ return CommonResult.fail("找不到指定的算法!");
|
|
|
+ }
|
|
|
+
|
|
|
+ TrackSequence entity = this.getById(addEvaluate.getId());
|
|
|
+ TrackSequence evaluate_entity = new TrackSequence();
|
|
|
+ evaluate_entity.setStatus(NOT_START);
|
|
|
+ evaluate_entity.setUrl(entity.getUrl());
|
|
|
+ if (addEvaluate.getName().startsWith(MASC)) {
|
|
|
+ evaluate_entity.setInputPath(entity.getInputPath() + ";" + entity.getOutputPath() + File.separator + "gaze" + File.separator + "txt");
|
|
|
+ } else if (addEvaluate.getName().startsWith(CAT)) {
|
|
|
+ File file________ = new File(entity.getInputPath());
|
|
|
+ if (!file________.exists()) {
|
|
|
+ return CommonResult.fail("数据集为空!");
|
|
|
+ }
|
|
|
+ evaluate_entity.setInputPath(entity.getInputPath() + ";" + entity.getOutputPath() + File.separator + "txt");
|
|
|
+// if (file________.listFiles() != null && file________.listFiles().length > 0) {
|
|
|
+// for (File file___________________tmp : file________.listFiles()) {
|
|
|
+// if (file___________________tmp.isDirectory()) {
|
|
|
+// evaluate_entity.setInputPath(file___________________tmp.getPath() + ";" + entity.getOutputPath() + File.separator + "txt");
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ } else {
|
|
|
+ return CommonResult.fail("命名错误!");
|
|
|
+ }
|
|
|
+ evaluate_entity.setZipFilePath(entity.getZipFilePath());
|
|
|
+ evaluate_entity.setAlgorithmModelId(entity.getAlgorithmModelId());
|
|
|
+ evaluate_entity.setInputOssId(entity.getInputOssId());
|
|
|
+
|
|
|
+ evaluate_entity.setName(addEvaluate.getName());
|
|
|
+ evaluate_entity.setAlgorithmId(addEvaluate.getAlgorithmId());
|
|
|
+ evaluate_entity.setRemarks(addEvaluate.getRemarks());
|
|
|
+
|
|
|
+ boolean flag__ = save(evaluate_entity);
|
|
|
+
|
|
|
+ if (flag__) {
|
|
|
+ Path path = Paths.get(entity.getOutputPath());
|
|
|
+ evaluate_entity.setOutputPath(path.resolveSibling(evaluate_entity.getId().toString() + BizConstant.TRACK_SEQUENCE_SUFFIX).toString());
|
|
|
+ boolean flag___ = updateById(evaluate_entity);
|
|
|
+ if (flag___) {
|
|
|
+ return CommonResult.success("新增评估任务成功!");
|
|
|
+ } else {
|
|
|
+ return CommonResult.success("新增评估任务成功! 更新输出路径失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return CommonResult.success("新增评估任务失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult getModelList(Long id) {
|
|
|
+ TrackSequence entity = getById(id);
|
|
|
+ String outPutPath = entity.getOutputPath();
|
|
|
+ String modelPath = outPutPath;
|
|
|
+ File modelDir = new File(modelPath);
|
|
|
+ if (!modelDir.exists()) {
|
|
|
+ return CommonResult.fail("模型输出目录不存在!");
|
|
|
+ }
|
|
|
+ File[] files = modelDir.listFiles();
|
|
|
+ Integer idx = 0;
|
|
|
+ ArrayList<Map<String, String>> res = new ArrayList<>();
|
|
|
+ for (File file : files) {
|
|
|
+ if (!file.isDirectory()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ idx += 1;
|
|
|
+ Map<String, String> tmp = new HashMap<>();
|
|
|
+ tmp.put("id", idx.toString());
|
|
|
+ tmp.put("name", file.getName());
|
|
|
+ String filePath = file.getPath();
|
|
|
+ tmp.put("path", filePath);
|
|
|
+ // todo 获取真正的url
|
|
|
+ // http://localhost:9090/profile/upload/2024/10/27/1_1729404909511_20241027153840A001.zip
|
|
|
+ String url = "http://localhost:" + port + Constants.RESOURCE_PREFIX + filePath.substring(TaaisConfig.getProfile().length());
|
|
|
+ url = url.replaceAll("\\\\", "/"); // windows
|
|
|
+ tmp.put("url", url);
|
|
|
+
|
|
|
+ double fileSize = (getFileSize(file) / (1024.0 * 1024.0));
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
|
+ String formatFileSize = decimalFormat.format(fileSize);
|
|
|
+ tmp.put("size", formatFileSize + "MB");
|
|
|
+ res.add(tmp);
|
|
|
+ }
|
|
|
+ return CommonResult.success(res, "success");
|
|
|
+ }
|
|
|
+
|
|
|
}
|