模型运行方法
ItemStatus STATUS1(1, "启用");
添加字段 mpkProjectId
模型运行api 其他bug调整
| | |
| | | resp.setPredictTime(reqDTO.getPredictTime()); |
| | | log.info("预测计算结束: " + System.currentTimeMillis()); |
| | | } catch (Exception ex) { |
| | | log.info("预测计算异常: " + System.currentTimeMillis()); |
| | | log.info("预测计算异常: " + System.currentTimeMillis(),ex); |
| | | return resp; |
| | | } |
| | | |
| | |
| | | package com.iailab.module.model.mcs.pre.controller.admin; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | |
| | | @PostMapping("/upload-model") |
| | | public CommonResult<Map<String, Object>> uploadModel(@RequestParam("file") MultipartFile file) throws Exception { |
| | | String uploadDir = modelPath + file.getOriginalFilename(); |
| | | FileUtil.mkParentDirs(uploadDir); |
| | | file.transferTo(new File(uploadDir)); |
| | | Map<String, Object> result = iAILModelUtil.parseModel(uploadDir); |
| | | result.put("originalFilename", file.getOriginalFilename().replace(CommonConstant.MDK_SUFFIX, "")); |
| | |
| | | * 预测阶段需要输入的数据长度 |
| | | */ |
| | | private Integer pdim; |
| | | |
| | | /** |
| | | * 项目id |
| | | */ |
| | | private String mpkprojectid; |
| | | } |
| | |
| | | @AllArgsConstructor |
| | | public enum ItemStatus { |
| | | STATUS0(0, "禁用"), |
| | | STATUS1(0, "启用"); |
| | | STATUS1(1, "启用"); |
| | | |
| | | private Integer code; |
| | | private String desc; |
| | |
| | | |
| | | @Override |
| | | public List<MmModelArithSettingsEntity> getByModelId(String modelId) { |
| | | QueryWrapper<MmModelArithSettingsEntity> queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("modelid", modelId); |
| | | return mmModelArithSettingsDao.selectList(queryWrapper); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("modelid", modelId); |
| | | return mmModelArithSettingsDao.getMmModelArithSettings(params); |
| | | } |
| | | } |
| | |
| | | @Override |
| | | public List<ItemVO> getByModuleId(String moduleId) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | |
| | | params.put("MODULEID",moduleId); |
| | | return mmPredictItemDao.getByModuleId(params); |
| | | } |
| | | |
| | |
| | | |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | for (ItemVO predictItem : predictItemList) { |
| | | if (!predictItem.getStatus().equals(ItemStatus.STATUS1)) { |
| | | if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) { |
| | | continue; |
| | | } |
| | | try { |
| | |
| | | import com.iailab.module.model.mdk.sample.SampleConstructor; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleData; |
| | | import com.iailab.module.model.mdk.vo.PredictResultVO; |
| | | import com.iailab.module.model.mpk.common.utils.DllUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | log.info(String.valueOf(jsonObjParam2Values)); |
| | | |
| | | //IAILMDK.run |
| | | HashMap<String, Object> modelResult = IAILMDK.run(newModelBean, param2Values); |
| | | // HashMap<String, Object> modelResult = IAILMDK.run(newModelBean, param2Values); |
| | | HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, predictModel.getMpkprojectid()); |
| | | //打印结果 |
| | | JSONObject jsonObjResult = new JSONObject(); |
| | | jsonObjResult.put("result", result); |
| | | jsonObjResult.put("result", modelResult); |
| | | log.info(String.valueOf(jsonObjResult)); |
| | | |
| | | MmModelResultstrEntity modelResultstr = mmModelResultstrService.getInfo(predictModel.getResultstrid()); |
| | | log.info("模型计算完成:modelId=" + modelId + result); |
| | | double[][] temp = (double[][]) modelResult.get(modelResultstr.getResultstr()); |
| | | result.setPredictMatrix(temp); |
| | | if (modelResult.containsKey(modelResultstr.getResultstr())) { |
| | | Double[][] temp = (Double[][]) modelResult.get(modelResultstr.getResultstr()); |
| | | double[][] temp1 = new double[temp.length][temp[0].length]; |
| | | for (int i = 0; i < temp.length; i++) { |
| | | for (int j = 0; j < temp[i].length; j++) { |
| | | temp1[i][j] = temp[i][j].doubleValue(); |
| | | } |
| | | } |
| | | result.setPredictMatrix(temp1); |
| | | } |
| | | result.setModelResult(modelResult); |
| | | result.setPredictTime(predictTime); |
| | | } catch (Exception ex) { |
| | | log.error("IAILModel对象构造失败,modelId=" + modelId); |
| | |
| | | int curDataLength = modelInputParamEntityList.get(0).getDatalength(); |
| | | for (MmModelParamEntity entry : modelInputParamEntityList) { |
| | | columnInfo.setParamType(entry.getModelparamtype()); |
| | | columnInfo.setId(entry.getModelparamid()); |
| | | columnInfo.setParamId(entry.getModelparamid()); |
| | | columnInfo.setDataLength(entry.getDatalength()); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | |
| | | * 保留的预测点位 (T+2 则n=2, T+30则n=30, T+n则表示从最后点位开始,n=预测长度;n由系统配置得出) |
| | | */ |
| | | private String saveIndex; |
| | | |
| | | /** |
| | | * 项目id |
| | | */ |
| | | private String mpkProjectId; |
| | | } |
| | |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | @Data |
| | |
| | | * 预测集合 |
| | | */ |
| | | private List<DataValueVO> predictList; |
| | | |
| | | /** |
| | | * 模型结果 |
| | | */ |
| | | private HashMap<String, Object> modelResult; |
| | | } |
| | |
| | | package com.iailab.module.model.mpk.common.utils; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.iail.model.IAILModel; |
| | | import com.iail.utils.RSAUtils; |
| | | import com.iailab.module.model.mpk.common.MdkConstant; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | public static HashMap<String, Object> run(IAILModel model, Object[] paramsValueArray, String projectId) throws Exception { |
| | | if (RSAUtils.checkLisenceBean().getCode() != 1) { |
| | | throw new SecurityException("Lisence 不可用!"); |
| | | } else if (model == null) { |
| | | throw new RuntimeException("模型文件不能为空!"); |
| | | } else { |
| | | URLClassLoader classLoader = DllUtils.getClassLoader(projectId); |
| | | Class<?> clazz = classLoader.loadClass(model.getClassName()); |
| | | Method method = clazz.getMethod(model.getMethodName(), model.getParamsArray()); |
| | | return (HashMap)method.invoke(clazz.newInstance(), paramsValueArray); |
| | | } |
| | | } |
| | | } |
| | |
| | | modelMethodService.insertList(dto.getModelMethods(), entity.getId()); |
| | | |
| | | // 替换环境变量MDK_PKGS下的py文件 |
| | | String mdkPkgs = System.getenv("MDK_PKGS"); |
| | | String pyFilePath = mdkPkgs + File.separator + entity.getPyModule().replace(".", File.separator) + File.separator + entity.getPyName() + ".pyd"; |
| | | FileUtil.mkParentDirs(pyFilePath); |
| | | FileUtil.copy(entity.getFilePath(), pyFilePath, true); |
| | | // String mdkPkgs = System.getenv("MDK_PKGS"); |
| | | // String pyFilePath = mdkPkgs + File.separator + entity.getPyModule().replace(".", File.separator) + File.separator + entity.getPyName() + ".pyd"; |
| | | // FileUtil.mkParentDirs(pyFilePath); |
| | | // FileUtil.copy(entity.getFilePath(), pyFilePath, true); |
| | | } |
| | | |
| | | @Override |
| | |
| | | modelMethodService.insertList(dto.getModelMethods(), entity.getId()); |
| | | |
| | | // 替换环境变量MDK_PKGS下的py文件 |
| | | String mdkPkgs = System.getenv("MDK_PKGS"); |
| | | String pyFilePath = mdkPkgs + File.separator + entity.getPyModule().replace(".", File.separator) + File.separator + entity.getPyName() + ".pyd"; |
| | | FileUtil.mkParentDirs(pyFilePath); |
| | | FileUtil.copy(entity.getFilePath(), pyFilePath, true); |
| | | // String mdkPkgs = System.getenv("MDK_PKGS"); |
| | | // String pyFilePath = mdkPkgs + File.separator + entity.getPyModule().replace(".", File.separator) + File.separator + entity.getPyName() + ".pyd"; |
| | | // FileUtil.mkParentDirs(pyFilePath); |
| | | // FileUtil.copy(entity.getFilePath(), pyFilePath, true); |
| | | } |
| | | |
| | | @Override |
| | |
| | | t1.outputorder |
| | | FROM t_mm_item_output t1, |
| | | t_mm_result_table t2 |
| | | WHERE t1.itemid = #{value} |
| | | WHERE t1.itemid = #{itemid} |
| | | AND t1.resulttableid = t2.id |
| | | ORDER BY t1.outputorder |
| | | </select> |
| | |
| | | t1.predictphase, |
| | | t1.workchecked |
| | | FROM |
| | | ${TABLESCHEMA}.t_mm_predict_item t1, |
| | | ${TABLESCHEMA}.t_mm_item_type t2 |
| | | t_mm_predict_item t1, |
| | | t_mm_item_type t2 |
| | | WHERE t1.itemtypeid=t2.id |
| | | <if test="ITEMID != null and ITEMID != ''"> |
| | | AND t1.id=#{ITEMID} |