| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.iailab.module.data.api.ind.IndItemApi; |
| | | import com.iailab.module.data.api.ind.dto.ApiIndItemDTO; |
| | | import com.iailab.module.data.api.ind.dto.ApiIndItemQueryDTO; |
| | | import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO; |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | |
| | | 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.mcs.pre.entity.MmItemOutputEntity; |
| | | 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; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemTypeService; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private PlanItemApi planItemApi; |
| | | |
| | | @Autowired |
| | | private IndItemApi indItemApi; |
| | | |
| | | @Autowired |
| | | private MmItemResultService mmItemResultService; |
| | | |
| | | @Autowired |
| | | private MmItemResultJsonService mmItemResultJsonService; |
| | | |
| | | @Autowired |
| | | private MmItemTypeService mmItemTypeService; |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception { |
| | | public List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception { |
| | | List<SampleData> sampleDataList = new ArrayList<>(); |
| | | Map<String, ApiPointDTO> pointMap = sampleInfo.getPointMap(); |
| | | Map<String, ApiPlanItemDTO> planMap = sampleInfo.getPlanMap(); |
| | | //对每个爪分别进行计算 |
| | | 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类型的数据,且按列向量进行拼接,默认初始值为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; |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 |
| | | for (int i = 0; i < entry.getColumnItemList().size(); i++) { |
| | | try { |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i),pointMap,planMap); |
| | | //补全数据 |
| | | ColumnItem columnItem = entry.getColumnItemList().get(i); |
| | | dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, |
| | | columnItem.paramId, columnItem.getParamType(),pointMap,planMap); |
| | | int deviationIndex = 0; |
| | | |
| | | /** 如果数据取不满,把缺失的数据点放在后面 */ |
| | | if (dataEntityList != null && dataEntityList.size() != 0) { |
| | | logger.info("设置matrix, i = " + i + ", size = " + dataEntityList.size()); |
| | | for (int k = 0; k < dataEntityList.size(); k++) { |
| | | matrix[k][i] = dataEntityList.get(k).getDataValue(); |
| | | } |
| | | //对每个爪分别进行计算 |
| | | for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { |
| | | 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()); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw e; |
| | | 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 |
| | | 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[] deviationItem = null; |
| | | if (sampleInfo.getDeviation() != null && sampleInfo.getDeviation().length > 0) { |
| | | deviationItem = sampleInfo.getDeviation()[deviationIndex]; |
| | | } |
| | | deviationIndex ++; |
| | | |
| | | //对每一项依次进行数据查询,然后将查询出的值赋给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; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | } |
| | | } |
| | | SampleData sampleData = new SampleData(); |
| | |
| | | * @param columnItem |
| | | * @param pointMap |
| | | * @param planMap |
| | | * @param indMap |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) throws Exception { |
| | | private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap, Map<String, ApiIndItemDTO> indMap) throws Exception { |
| | | List<DataValueVO> dataList = new ArrayList<>(); |
| | | String paramType = columnItem.getParamType(); |
| | | switch (ModelParamType.getEumByCode(paramType)) { |
| | |
| | | break; |
| | | case NORMALITEM: |
| | | case MERGEITEM: |
| | | // MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(columnItem.getParamId()); |
| | | List<DataValueVO> predictValue = mmItemResultService.getPredictValue(columnItem.getParamId(), columnItem.getStartTime(), columnItem.getEndTime()); |
| | | |
| | | if (CollectionUtils.isEmpty(predictValue)) { |
| | | break; |
| | | } |
| | |
| | | vo.setDataValue(t.getDataValue()); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | break; |
| | | case IND: |
| | | 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)) { |
| | | break; |
| | | } |
| | | |
| | | dataList = indItemValueList.stream().map(t -> { |
| | | DataValueVO vo = new DataValueVO(); |
| | | vo.setDataTime(DateUtil.parse(t.getDataTime())); |
| | | vo.setDataValue(Double.valueOf(t.getDataValue().toString())); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |