| | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants.NOT_GENERAT; |
| | | import static com.iailab.framework.common.pojo.CommonResult.error; |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | |
| | | try { |
| | | File jarFile = new File(mpkTenantBakFilePath + File.separator + MdkConstant.JAR + File.separator + dto.getPyName() + ".jar"); |
| | | if (!jarFile.exists()) { |
| | | throw new RuntimeException("jar包不存在,请先生成代码。jarPath:" + jarFile.getAbsolutePath()); |
| | | log.error("jar包不存在,请先生成代码。jarPath:" + jarFile.getAbsolutePath()); |
| | | return CommonResult.error(NOT_GENERAT.getCode(),NOT_GENERAT.getMsg()); |
| | | } |
| | | File dllFile = new File(mpkTenantBakFilePath + File.separator + MdkConstant.DLL + File.separator + dto.getPyName() + ".dll"); |
| | | if (!dllFile.exists()) { |
| | | throw new RuntimeException("dll文件不存在,请先生成代码。dllPath:" + dllFile.getAbsolutePath()); |
| | | log.error("dll文件不存在,请先生成代码。dllPath:" + dllFile.getAbsolutePath()); |
| | | return CommonResult.error(NOT_GENERAT.getCode(),NOT_GENERAT.getMsg()); |
| | | } |
| | | // 加载jar包 |
| | | classLoader = DllUtils.loadJar(jarFile.getAbsolutePath()); |
| | |
| | | return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),"请重新导入模型参数"); |
| | | } |
| | | JSONArray jsonArray = JSON.parseArray(cache.get(uuid)); |
| | | double[][] data = new double[jsonArray.size()][jsonArray.getJSONArray(0).size()]; |
| | | |
| | | double[][] data = new double[jsonArray.size()][]; |
| | | for (int j = 0; j < jsonArray.size(); j++) { |
| | | data[j] = new double[jsonArray.getJSONArray(j).size()]; |
| | | for (int k = 0; k < jsonArray.getJSONArray(j).size(); k++) { |
| | | data[j][k] = jsonArray.getJSONArray(j).getDoubleValue(k); |
| | | } |
| | |
| | | return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),"模型设置错误,请检查!"); |
| | | } |
| | | |
| | | log.info("#######################测试运行模型 " + dto.getPyName() + " ##########################"); |
| | | log.info("参数: " + JSON.toJSONString(paramsValueArray)); |
| | | HashMap result = (HashMap) clazz.getDeclaredMethod(dto.getMethodName(), paramsArray).invoke(clazz.newInstance(), paramsValueArray); |
| | | log.info("model test run result:" + result); |
| | | return success(JSON.toJSONString(result)); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | |
| | | DllUtils.unloadDll(classLoader); |
| | | DllUtils.unloadJar(classLoader); |
| | | } |
| | | System.gc(); |
| | | } |
| | | } |
| | | |