iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/utils/ASCIIUtil.java
对比新文件 @@ -0,0 +1,23 @@ package com.iailab.module.model.common.utils; /** * @description: * @author: dzd * @date: 2025/2/19 16:22 **/ public class ASCIIUtil { /** * @description: String 转 ASCII码double[] **/ public static double[] stringToAsciiArray(String str) { int length = str.length(); double[] asciiArray = new double[length]; // 遍历字符串中的每个字符 for (int i = 0; i < length; i++) { // 获取当前字符的 ASCII 码值 asciiArray[i] = str.charAt(i); } return asciiArray; } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/utils/DateUtils.java
@@ -37,6 +37,8 @@ public final static String DATE_PATTERN_YEAR = "yyyy"; public final static String DATE_TIME_STRING = "yyyyMMddHHmmssSSS"; /** * 日期格式化 日期格式为:yyyy-MM-dd * @param date 日期 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/common/enums/ModelParamType.java
@@ -17,7 +17,8 @@ DATAPOINT("DATAPOINT", "测点值"), NORMALITEM("NormalItem", "预测值(NormalItem)"), MERGEITEM("MergeItem", "MergeItem"), IND("IND", "指标值"), IND("IND", "指标值(double)"), IND_ASCII("IND_ASCII", "指标值(ASCII)"), PLAN("PLAN", "计划值"); private String code; iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java
@@ -13,6 +13,7 @@ import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; import com.iailab.module.data.common.ApiDataQueryDTO; import com.iailab.module.data.common.ApiDataValueDTO; import com.iailab.module.model.common.utils.ASCIIUtil; import com.iailab.module.model.mcs.pre.service.MmItemOutputService; import com.iailab.module.model.mcs.pre.service.MmItemResultJsonService; import com.iailab.module.model.mcs.pre.service.MmItemResultService; @@ -76,47 +77,84 @@ Map<String, ApiPointDTO> pointMap = sampleInfo.getPointMap(); Map<String, ApiPlanItemDTO> planMap = sampleInfo.getPlanMap(); Map<String, ApiIndItemDTO> indMap = sampleInfo.getIndMap(); // 校验数据 for (ColumnItemPort itemPort : sampleInfo.getColumnInfo()) { for (ColumnItem columnItem : itemPort.getColumnItemList()) { if (columnItem.getParamType().equals(ModelParamType.IND_ASCII.getCode())) { if (columnItem.getModelParamOrder() != 1 || itemPort.getColumnItemList().size() != 1) { throw new RuntimeException("模型输入数据异常:IND_ASCII类型输入独占一个端口;ParamPortOrder:" + columnItem.getModelParamPortOrder() + ",ParamOrder:" + columnItem.getModelParamOrder()); } } } } //对每个爪分别进行计算 for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 Collections.sort(entry.getColumnItemList(), new Comparator<ColumnItem>() { @Override public int compare(ColumnItem o1, ColumnItem o2) { return o1.getModelParamOrder() - o2.getModelParamOrder(); double[][] matrix = new double[0][0]; // 特殊处理IND_ASCII类型 if (entry.getColumnItemList().get(0).getParamType().equals(ModelParamType.IND_ASCII.getCode())) { // 获取指标数据 ColumnItem columnItem = entry.getColumnItemList().get(0); ApiIndItemQueryDTO queryIndItemDTO = new ApiIndItemQueryDTO(); ApiIndItemDTO intItem = indMap.get(columnItem.getParamId()); queryIndItemDTO.setItemNo(intItem.getItemNo()); queryIndItemDTO.setStart(columnItem.getStartTime()); queryIndItemDTO.setEnd(columnItem.getEndTime()); List<ApiIndItemValueDTO> indItemValueList = indItemApi.queryIndItemHistoryValue(queryIndItemDTO); if (!CollectionUtils.isEmpty(indItemValueList)) { matrix = new double[entry.getDataLength()][0]; if (indItemValueList.size() > entry.getDataLength()) { indItemValueList = indItemValueList.subList(0,entry.getDataLength()); } for (int i = 0; i < indItemValueList.size(); i++) { String stringValue = indItemValueList.get(i).getDataValue().toString(); double[] asciiArray = ASCIIUtil.stringToAsciiArray(stringValue); matrix[i] = asciiArray; } } }); }else { //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 Collections.sort(entry.getColumnItemList(), new Comparator<ColumnItem>() { @Override public int compare(ColumnItem o1, ColumnItem o2) { return o1.getModelParamOrder() - o2.getModelParamOrder(); } }); //默认都是double类型的数据,且按列向量进行拼接,默认初始值为0.0 double[][] matrix = new double[entry.getDataLength()][entry.getColumnItemList().size()]; for (int i = 0; i < entry.getColumnItemList().size(); i++) { for (int j = 0; j < entry.getDataLength(); j++) { matrix[j][i] = -2.0; //默认都是double类型的数据,且按列向量进行拼接,默认初始值为0.0 matrix = new double[entry.getDataLength()][entry.getColumnItemList().size()]; for (int i = 0; i < entry.getColumnItemList().size(); i++) { for (int j = 0; j < entry.getDataLength(); j++) { matrix[j][i] = -2.0; } } } //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 for (int i = 0; i < entry.getColumnItemList().size(); i++) { try { List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap,indMap); //补全数据 ColumnItem columnItem = entry.getColumnItemList().get(i); dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, columnItem.getParamType(),columnItem.getGranularity()); //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 for (int i = 0; i < entry.getColumnItemList().size(); i++) { try { List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap,indMap); //补全数据 ColumnItem columnItem = entry.getColumnItemList().get(i); dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, columnItem.getParamType(),columnItem.getGranularity()); /** 如果数据取不满,把缺失的数据点放在后面 */ if (dataEntityList != null && dataEntityList.size() != 0) { logger.info("设置matrix, i = " + i + ", size = " + dataEntityList.size()); for (int k = 0; k < dataEntityList.size(); k++) { Double dataValue = dataEntityList.get(k).getDataValue(); if (null != dataValue) { matrix[k][i] = dataValue; /** 如果数据取不满,把缺失的数据点放在后面 */ if (dataEntityList != null && dataEntityList.size() != 0) { logger.info("设置matrix, i = " + i + ", size = " + dataEntityList.size()); for (int k = 0; k < dataEntityList.size(); k++) { Double dataValue = dataEntityList.get(k).getDataValue(); if (null != dataValue) { matrix[k][i] = dataValue; } } } } catch (Exception e) { e.printStackTrace(); throw e; } } catch (Exception e) { e.printStackTrace(); throw e; } } SampleData sampleData = new SampleData(); sampleData.setMatrix(matrix); sampleDataList.add(sampleData); @@ -196,6 +234,7 @@ vo.setDataValue(Double.valueOf(t.getDataValue().toString())); return vo; }).collect(Collectors.toList()); break; default: break; } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java
@@ -90,7 +90,7 @@ List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds); Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1, e2) -> e1)); // 统一获取指标数据的信息 Set<String> indIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.IND)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); Set<String> indIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.IND) || ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.IND_ASCII)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); List<ApiIndItemDTO> inds = indItemApi.getInfoByIds(indIds); Map<String, ApiIndItemDTO> indMap = inds.stream().collect(Collectors.toMap(ApiIndItemDTO::getId, Function.identity(), (e1, e2) -> e1)); iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java
@@ -90,6 +90,7 @@ mins = ((end - start) / oneMin); break; case IND: case IND_ASCII: // 测点值 oneMin = 1000L * granularity; // 设置时间偏移量 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
@@ -86,6 +86,7 @@ dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), columnItem.getGranularity()); break; case IND: case IND_ASCII: dateTime = calculateTime(originalTime, true, columnItem.getDataLength()-1, columnItem.getGranularity()); break; case NORMALITEM: @@ -113,6 +114,7 @@ switch (ModelParamType.getEumByCode(columnItem.getParamType())) { case DATAPOINT: case IND: case IND_ASCII: case PLAN: dateTime = calendar.getTime(); break; @@ -146,6 +148,7 @@ granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); break; case IND: case IND_ASCII: ApiIndItemDTO indItemDTO = indMap.get(columnItem.getParamId()); granularity = TimeGranularitySecEnum.getEumByCode(indItemDTO.getTimeGranularity()).getValue();; break; iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java
@@ -65,7 +65,7 @@ List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds); Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1, e2) -> e1)); // 统一获取指标数据的信息 Set<String> indIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.IND)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet()); Set<String> indIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.IND) || ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.IND_ASCII)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet()); List<ApiIndItemDTO> inds = indItemApi.getInfoByIds(indIds); Map<String, ApiIndItemDTO> indMap = inds.stream().collect(Collectors.toMap(ApiIndItemDTO::getId, Function.identity(), (e1, e2) -> e1)); iailab-module-model/iailab-module-model-biz/src/main/resources/mpkResources/IAILMDK/common/Environment.java
对比新文件 @@ -0,0 +1,44 @@ package iail.mdk.model.common; /** * @Description * @Author Forrest * @Mail 1255187617@qq.com * @Date 2021/1/12 */ public class Environment { private native int jniInit(); private native int jniIsInit(); private native void jniRelease(); private native int statusCode(); /** * 初始化环境 */ public int init() { return jniInit(); } /** * 获取初始化状态 */ public int isInit() { return jniIsInit(); } /** * 释放资源 */ public void release() { jniRelease(); } /** *校验机器码 * */ // public int checkMachineCode(String mCode){ // return statusCode(); // } } iailab-module-model/iailab-module-model-biz/src/main/resources/mpkResources/IAILMDK/utils/AlgsUtils.java
对比新文件 @@ -0,0 +1,230 @@ package iail.mdk.model.utils; import java.util.HashMap; import java.util.Map; /** * @description: * @author: dzd * @date: 2024/10/12 9:19 **/ public class AlgsUtils { private HashMap<String, Object> model = new HashMap(); private HashMap<String, Object> eval_pre = new HashMap(); private HashMap<String, Object> train_result_models = new HashMap(); public AlgsUtils() { } public HashMap<String, Object> createPredictHashmap(HashMap<String, Object> models) { if (models.containsKey("model")) { String aaa; if (((String) ((HashMap) models.get("model")).get("param1")).isEmpty()) { aaa = "error"; this.model.put("param1", aaa); } else { aaa = (String) ((HashMap) models.get("model")).get("param1"); this.model.put("param1", aaa); } } else { this.model = models; } return this.model; } public HashMap<String, Object> createPredictHashmapplus(HashMap<String, Object> models) { if (models.containsKey("models")) { String aaa; if (((String) ((HashMap) models.get("models")).get("paramFile")).isEmpty()) { aaa = "error"; this.model.put("param1", aaa); } else { aaa = (String) ((HashMap) models.get("models")).get("paramFile"); this.model.put("paramFile", aaa); if (((HashMap) models.get("models")).containsKey("dim")) { Object dim = ((HashMap) models.get("models")).get("dim"); this.model.put("dim", dim); } } } else { this.model = models; } return this.model; } public HashMap<String, Object> reverseModels(HashMap<String, Object> train_result) { if (train_result.containsKey("models")) { this.train_result_models = (HashMap) train_result.get("models"); if (((HashMap) train_result.get("models")).containsKey("dim")) { double dim = Double.parseDouble((String) ((HashMap) train_result.get("models")).get("dim")); this.train_result_models.put("dim", dim); } train_result.put("models", this.train_result_models); } return train_result; } public int[] getColAndRow(double[][] arr) { int row = arr.length; int col = arr[0].length; int[] result = new int[]{row, col}; return result; } public double[][] getMathergeArr(double[][] data, double[][] refs) { int[] dataRowAndCol = this.getColAndRow(data); int rowData = dataRowAndCol[0]; int colData = dataRowAndCol[1]; int[] refsRowAndCol = this.getColAndRow(refs); int rowrefs = refsRowAndCol[0]; int colrefs = refsRowAndCol[1]; double[][] newData = new double[rowData + rowrefs][colData]; int i; int j; for (i = 0; i < rowData; ++i) { for (j = 0; j < colData; ++j) { newData[i][j] = data[i][j]; } } for (i = 0; i < rowrefs; ++i) { for (j = 0; j < colrefs; ++j) { newData[i + rowData][j] = refs[i][j]; } } return newData; } public HashMap<String, Object> reverseResult(HashMap<String, Object> result) { if (null == result) { return result; } String code = reverseResultCode(result); if (!"100".equals(code)) { return result; } reverseResultValues(result); reverseTest(result); reverseEval(result); reverseOptdParams(result); return result; } private void reverseResultValues(HashMap<String, Object> result) { // 将result中的Double数组转为double数组 if (result.containsKey("result")) { HashMap<String, Object> resultValues = (HashMap) result.get("result"); for (Map.Entry<String, Object> entry : resultValues.entrySet()) { if (entry.getValue() instanceof Double[]) { //一维数组 Double[] value = (Double[]) entry.getValue(); double[] value1 = new double[value.length]; for (int i = 0; i < value.length; i++) { Double d = value[i]; if (Double.isNaN(d)) { value1[i] = new Double(0.0).doubleValue(); } else { value1[i] = d.doubleValue(); } } resultValues.put(entry.getKey(),value1); } if (entry.getValue() instanceof Double[][]) { //二维数组 Double[][] value = (Double[][]) entry.getValue(); double[][] value1 = new double[value.length][]; for (int i = 0; i < value.length; i++) { value1[i] = new double[value[i].length]; for (int j = 0; j < value[i].length; j++) { Double d = value[i][j]; if (Double.isNaN(d)) { value1[i][j] = new Double(0.0).doubleValue(); } else { value1[i][j] = d.doubleValue(); } } } resultValues.put(entry.getKey(),value1); } } } } private String reverseResultCode(HashMap<String, Object> result) { String code = result.containsKey("status_code") ? String.valueOf(result.get("status_code")) : "400"; result.put("status_code", code); return code; } private void reverseTest(HashMap<String, Object> result) { if (result.containsKey("test")) { HashMap<String, Object> test = (HashMap) result.get("test"); Double[][] realValue = (Double[][]) test.get("realValue"); Double[][] predictValue = (Double[][]) test.get("predictValue"); double[][] realValue1 = new double[realValue.length][2]; double[][] predictValue1 = new double[predictValue.length][2]; for (int i = 0; i < realValue.length; i++) { for (int j = 0; j < realValue[i].length; j++) { Double d = (Double) realValue[i][j]; if (Double.isNaN(d)) { realValue1[i][j] = new Double(0.0).doubleValue(); } else { realValue1[i][j] = d.doubleValue(); } } } for (int i = 0; i < predictValue.length; i++) { for (int j = 0; j < predictValue[i].length; j++) { Double d = (Double) predictValue[i][j]; if (Double.isNaN(d)) { predictValue1[i][j] = new Double(0.0).doubleValue(); } else { predictValue1[i][j] = d.doubleValue(); } } } HashMap<String, double[][]> map = new HashMap<>(); map.put("realValue", realValue1); map.put("predictValue", predictValue1); result.put("test", map); } } public void reverseEval(HashMap<String, Object> result) { if (result.containsKey("eval")) { HashMap<String,Object> eval = (HashMap<String,Object>) result.get("eval"); HashMap<String, String> evalMap = new HashMap<>(eval.size()); for (HashMap.Entry<String, Object> entry : eval.entrySet()) { evalMap.put(entry.getKey(),String.valueOf(entry.getValue())); } result.put("eval",evalMap); } } private void reverseOptdParams(HashMap<String, Object> result) { if (result.containsKey("paramsopt")) { HashMap<String,Object> params = (HashMap<String,Object>) result.get("paramsopt"); HashMap<String, String> newParams = new HashMap<>(params.size()); for (HashMap.Entry<String, Object> entry : params.entrySet()) { newParams.put(entry.getKey(),String.valueOf(entry.getValue())); } result.put("optdParams",newParams); } } } iailab-module-model/iailab-module-model-biz/src/main/resources/mpkResources/libs/IAIL.MDK.Mid.Windows.dllBinary files differ
iailab-module-model/iailab-module-model-biz/src/main/resources/mpkResources/libs/IAIL.MDK.Mid.Windows.libBinary files differ
iailab-module-model/iailab-module-model-biz/src/main/resources/mpkResources/libs/IAIL.MDK.Mid.Windowsbak.dllBinary files differ
iailab-module-model/iailab-module-model-biz/src/main/resources/mpkResources/libs/status_code.xml
对比新文件 @@ -0,0 +1,20 @@ <status-codes> <status-code code="100" tips="系统正常运行"/> <status-code code="200" tips="算法模块加载失败"/> <status-code code="201" tips="算法方法加载失败"/> <status-code code="202" tips="类型不匹配"/> <status-code code="203" tips="找不到模型存储路径"/> <status-code code="204" tips="模型参数文件加载失败"/> <status-code code="205" tips="计算过程中的数据或数组维度不匹配"/> <status-code code="206" tips="数值错误"/> <status-code code="207" tips="第三方库问题"/> <status-code code="208" tips="评价指标计算错误"/> <status-code code="209" tips="数据长度问题"/> <status-code code="210" tips="初始化失败"/> <status-code code="211" tips="train/predict函数输入格式错误"/> <status-code code="212" tips="train/predict函数输出格式错误"/> <status-code code="300" tips="MDK未配置"/> <status-code code="301" tips="缺少依赖库"/> <status-code code="400" tips="系统异常,未知错误"/> <status-code code="401" tips="未能进入 Python"/> </status-codes> iailab-module-model/iailab-module-model-biz/src/main/resources/mpkResources/libs/version.xml
对比新文件 @@ -0,0 +1,30 @@ <algorithm-list name="算法版本列表"> <!-- 说明:version="0.11" 即现行算法未显式标注版本的算法--> <algorithms name = "预测"> <algorithm name="非周期短期点预测" type="非周期完整数据" fileName="PredAperioComShortPoint" version="2.0"/> <algorithm name="类周期短期点预测" type="类周期完整数据" fileName="PredPerioComShortPoint" version="2.0"/> <algorithm name="中长期点预测" type="类周期完整数据" fileName="PredPerioComLongPoint" version="0.9.1"/> <algorithm name="N型数据集点预测" type="N型" fileName="PredNTypeComShortPoint" version="0.20.0"/> <algorithm name="调整用户短期点预测" type="阶跃" fileName="PredStepComShortPoint" version="1.0.5"/> <algorithm name="因素预测" type="短期点预测" fileName="PredFactComShortPoint" version="1.1.13"/> </algorithms> <algorithms name="数据预处理"> <algorithm name="滤波" fileName="PrepFilter" version="1.2.6"/> <algorithm name="数据填补" fileName="PrepDaImput" version="0.12.0"/> <algorithm name="异常点检测" fileName="PrepOutDetect" version="1.2.3"/> <algorithm name="特征选择" fileName="prepFeaSelect" version="0.9.5"/> </algorithms> <algorithms name="调度"> <algorithm name="单介质调度" fileName="scheSingleEgy" version="1.0.1"/> <algorithm name="热电调度" fileName="MSCoSchedul" version="1.0.1"/> <algorithm name="调度建议" fileName="schedulSuggest" version="1.0.1"/> </algorithms> </algorithm-list>