Commit f477a48f authored by linpeiqin's avatar linpeiqin

怎么模型管理列表筛选,优化任务详情

parent 56e0b47f
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.github.pagehelper.page.PageMethod;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yice.common.core.annotation.MyRequestBody;
......@@ -29,8 +30,11 @@ import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -89,6 +93,7 @@ public class ModelEstimateController {
modelEstimate = modelEstimateService.saveNewWithRelation(modelEstimate, bizData.getSecond());
return ResponseResult.success(modelEstimate.getTaskId());
}
/**
* 获取预览命令。
*
......@@ -139,8 +144,8 @@ public class ModelEstimateController {
@OperationLog(type = SysOperationLogType.UPLOAD, saveResponse = false)
@PostMapping("/postTaskStatus")
public ResponseResult<Void> postTaskStatus(@MyRequestBody Long taskId,
@MyRequestBody Long runTime,
@MyRequestBody Integer taskStatus) {
@MyRequestBody Long runTime,
@MyRequestBody Integer taskStatus) {
String errorMessage;
ModelEstimate modelEstimate = this.modelEstimateService.getById(taskId);
if (modelEstimate == null) {
......@@ -184,20 +189,56 @@ public class ModelEstimateController {
ObjectMapper objectMapper = new ObjectMapper();
return ResponseResult.success(objectMapper.readTree(file).toString());
}
/**
* 获取任务状态明细。
*
* @param taskId 指定对象主键Id。
* @return 应答结果对象,包含对象详情。
*/
@GetMapping("/getStatusDetail")
public ResponseResult<String> getStatusDetail(@RequestParam Long taskId) throws IOException {
@PostMapping(value = "/getStatusDetail")
public ResponseResult<MyPageData<String>> getStatusDetail(@MyRequestBody Long taskId,
@MyRequestBody MyPageParam pageParam) throws IOException {
if (pageParam != null) {
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
}
ModelEstimate modelEstimate = this.modelEstimateService.getById(taskId);
ModelVersion modelVersion = this.modelVersionService.getById(modelEstimate.getModelVersionId());
String url = this.pythonConfig.getModelEstimateFileBaseDir() + modelVersion.getVersionName() + File.separator + "evl_" + taskId + File.separator +"generated_predictions.jsonl";
File file = new File(url); // 指定文件路径
DatasetVersion datasetVersion = this.datasetVersionService.getById(modelEstimate.getDatasetVersionId());
String url = this.pythonConfig.getModelEstimateFileBaseDir() + modelVersion.getVersionName() + File.separator + "evl_" + taskId + File.separator + "generated_predictions.jsonl";
//获取评估输出详情
List<JSONObject> jsonObjects = this.getFileJsonArray(url);
File file = new File(datasetVersion.getFileUrl()); // 指定文件路径
ObjectMapper objectMapper = new ObjectMapper();
return ResponseResult.success(objectMapper.readTree(file).toString());
ArrayNode arrayNode = (ArrayNode) objectMapper.readTree(file); // 读取JSON文件内容并转换为ArrayNode对象
List<String> dataList = new ArrayList<>();
int i = 0;
for (JSONObject jsonNode : jsonObjects) { // 遍历JSON数组并取出每个元素(ObjectNode)中的数据
jsonNode.put("input", arrayNode.get(i).get("instruction").textValue() + arrayNode.get(i).get("input").textValue());
dataList.add(jsonNode.toJSONString());
i++;
}
int total = dataList.size(); // 获取总数据量
int page = pageParam.getPageNum();
int limit = pageParam.getPageSize();
int startIndex = (page - 1) * limit; // 计算起始索引位置
int endIndex = Math.min(page * limit, total); // 计算结束索引位置(不超出总数据量)
List<String> pageDataList = dataList.subList(startIndex, endIndex); // 分页处理并取出指定页的数据列表
return ResponseResult.success(MyPageUtil.makeResponseData(pageDataList, (long) total));
}
private List<JSONObject> getFileJsonArray(String url) {
List<JSONObject> list = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(url))) {
String line;
while ((line = br.readLine()) != null) {
JSONObject jsonObject = JSON.parseObject(line);
list.add(jsonObject);
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
/**
......
......@@ -155,6 +155,39 @@ public class ModelManageController {
return ResponseResult.success(MyPageUtil.makeResponseData(modelManageList, ModelManage.INSTANCE));
}
/**
* 列出符合过滤条件的模型管理列表。
*
* @param modelManageDtoFilter 过滤对象。
* @param modelVersionDtoFilter 一对多从表过滤对象。
* @param modelTaskDtoFilter 一对多从表过滤对象。
* @param modelDeployDtoFilter 一对多从表过滤对象。
* @param orderParam 排序参数。
* @param pageParam 分页参数。
* @return 应答结果对象,包含查询结果集。
*/
@PostMapping("/myList")
public ResponseResult<MyPageData<ModelManageVo>> myList(
@MyRequestBody ModelManageDto modelManageDtoFilter,
@MyRequestBody ModelVersionDto modelVersionDtoFilter,
@MyRequestBody ModelTaskDto modelTaskDtoFilter,
@MyRequestBody ModelDeployDto modelDeployDtoFilter,
@MyRequestBody MyOrderParam orderParam,
@MyRequestBody MyPageParam pageParam) {
if (pageParam != null) {
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
}
ModelManage modelManageFilter = MyModelUtil.copyTo(modelManageDtoFilter, ModelManage.class);
ModelVersion modelVersionFilter = MyModelUtil.copyTo(modelVersionDtoFilter, ModelVersion.class);
ModelTask modelTaskFilter = MyModelUtil.copyTo(modelTaskDtoFilter, ModelTask.class);
ModelDeploy modelDeployFilter = MyModelUtil.copyTo(modelDeployDtoFilter, ModelDeploy.class);
String orderBy = MyOrderParam.buildOrderBy(orderParam, ModelManage.class);
modelManageFilter.setCreateUserId(TokenData.takeFromRequest().getUserId());
List<ModelManage> modelManageList =
modelManageService.getModelManageListWithRelation(modelManageFilter, modelVersionFilter, modelTaskFilter, modelDeployFilter, orderBy);
return ResponseResult.success(MyPageUtil.makeResponseData(modelManageList, ModelManage.INSTANCE));
}
/**
* 查看指定模型管理对象详情。
*
......@@ -171,42 +204,6 @@ public class ModelManageController {
return ResponseResult.success(modelManageVo);
}
private ResponseResult<Tuple2<ModelManage, JSONObject>> doBusinessDataVerifyAndConvert(
ModelManageDto modelManageDto,
boolean forUpdate,
List<ModelVersionDto> modelVersionDtoList) {
ErrorCodeEnum errorCode = ErrorCodeEnum.DATA_VALIDATED_FAILED;
String errorMessage = MyCommonUtil.getModelValidationError(modelManageDto, false);
if (errorMessage != null) {
return ResponseResult.error(errorCode, errorMessage);
}
errorMessage = MyCommonUtil.getModelValidationError(modelVersionDtoList);
if (errorMessage != null) {
return ResponseResult.error(errorCode, "参数 [modelVersionDtoList] " + errorMessage);
}
// 全部关联从表数据的验证和转换
JSONObject relationData = new JSONObject();
CallResult verifyResult;
// 下面是输入参数中,主表关联数据的验证。
ModelManage modelManage = MyModelUtil.copyTo(modelManageDto, ModelManage.class);
ModelManage originalData;
if (forUpdate && modelManage != null) {
originalData = modelManageService.getById(modelManage.getModelId());
if (originalData == null) {
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
}
relationData.put("originalData", originalData);
}
// 处理主表的一对多关联 [ModelVersion]
List<ModelVersion> modelVersionList = MyModelUtil.copyCollectionTo(modelVersionDtoList, ModelVersion.class);
verifyResult = modelVersionService.verifyRelatedData(modelVersionList);
if (!verifyResult.isSuccess()) {
return ResponseResult.errorFrom(verifyResult);
}
relationData.put("modelVersionList", modelVersionList);
return ResponseResult.success(new Tuple2<>(modelManage, relationData));
}
private ResponseResult<Void> doDelete(Long modelId) {
String errorMessage;
// 验证关联Id的数据合法性
......
......@@ -59,6 +59,9 @@
<if test="modelManageFilter.isBaseModel != null">
AND lmp_model_manage.is_base_model = #{modelManageFilter.isBaseModel}
</if>
<if test="modelManageFilter.createUserId != null">
AND lmp_model_manage.create_user_id = #{modelManageFilter.createUserId}
</if>
<if test="modelManageFilter.searchString != null and modelManageFilter.searchString != ''">
<bind name="safeModelManageSearchString" value="'%' + modelManageFilter.searchString + '%'"/>
AND CONCAT(IFNULL(lmp_model_manage.model_name,''), IFNULL(lmp_model_manage.business_label,'')) LIKE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment