Merge branch 'master' of http://dlindusit.com:53929/r/iailab-plat
| | |
| | | if (startTime == null) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictItem.getLastTime()); |
| | | calendar.add(Calendar.MINUTE, -1 * predictItem.getPredictLength()); |
| | | calendar.add(Calendar.SECOND, -1 * predictItem.getPredictLength() * predictItem.getGranularity()); |
| | | startTime = calendar.getTime(); |
| | | } |
| | | Date endTime = reqVO.getEndTime(); |
| | | if (endTime == null) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictItem.getLastTime()); |
| | | calendar.add(Calendar.MINUTE, predictItem.getPredictLength()); |
| | | calendar.add(Calendar.SECOND, predictItem.getPredictLength() * predictItem.getGranularity()); |
| | | endTime = calendar.getTime(); |
| | | } |
| | | if (endTime.getTime() <= startTime.getTime()) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(startTime); |
| | | calendar.add(Calendar.MINUTE, predictItem.getPredictLength()); |
| | | calendar.add(Calendar.SECOND, predictItem.getPredictLength() * predictItem.getGranularity()); |
| | | endTime = calendar.getTime(); |
| | | } |
| | | |
| | |
| | | if (reqDTO.getModuleType() == null) { |
| | | throw new Exception("ModuleType不能为空"); |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(reqDTO.getPredictTime()); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | reqDTO.setPredictTime(calendar.getTime()); |
| | | |
| | | log.info("预测参数:" + JSON.toJSONString(reqDTO)); |
| | | MdkPredictModuleRespDTO result = new MdkPredictModuleRespDTO(); |
| | | result.setPredictTime(reqDTO.getPredictTime()); |
| | | result.setModuleType(reqDTO.getModuleType()); |
| | | List<DmModuleEntity> moduleList = dmModuleService.getModuleByModuleType(reqDTO.getModuleType()); |
| | | log.info("预测计算开始: " + System.currentTimeMillis()); |
| | | for (DmModuleEntity module : moduleList) { |
| | |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum PredGranularityEnum { |
| | | MIN1(60, "1min"); |
| | | MIN1(60, "1min"), |
| | | H1(3600, "1h"), |
| | | D1(86400, "1d"); |
| | | |
| | | private Integer code; |
| | | private String desc; |
| | |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
| | | import com.iailab.module.model.mcs.pre.enums.ItemStatus; |
| | | import com.iailab.module.model.mcs.pre.enums.PredGranularityEnum; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemStatusService; |
| | | import com.iailab.module.model.mdk.factory.PredictItemFactory; |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.time.Duration; |
| | | import java.time.Instant; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | } |
| | | } |
| | | for (ItemVO predictItem : predictItemList) { |
| | | // 根据item粒度处理预测时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictTime); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | if (PredGranularityEnum.H1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE,0); |
| | | }else if (PredGranularityEnum.D1.getCode().equals(predictItem.getGranularity())) { |
| | | calendar.set(Calendar.MINUTE,0); |
| | | calendar.set(Calendar.HOUR_OF_DAY,0); |
| | | } |
| | | PredictResultVO predictResult; |
| | | if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) { |
| | | continue; |
| | |
| | | Long totalDur = 0L; |
| | | ItemRunStatusEnum itemRunStatusEnum = ItemRunStatusEnum.PROCESSING; |
| | | try { |
| | | mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime); |
| | | mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, calendar.getTime()); |
| | | PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId()); |
| | | long start = System.currentTimeMillis(); |
| | | try { |
| | | // 预测项开始预测 |
| | | predictResult = predictItemHandler.predict(predictTime, predictItem, predictValueMap); |
| | | predictResult = predictItemHandler.predict(calendar.getTime(), predictItem, predictValueMap); |
| | | } catch (ModelResultErrorException e) { |
| | | itemRunStatusEnum = ItemRunStatusEnum.MODELRESULTERROR; |
| | | continue; |
| | |
| | | log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}", |
| | | predictItem.getId(), predictItem.getItemName(), e.getMessage(), predictTime)); |
| | | } finally { |
| | | mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime); |
| | | mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, calendar.getTime()); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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); |
| | | 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++) { |
| | | matrix[k][i] = dataEntityList.get(k).getDataValue(); |
| | | Double dataValue = dataEntityList.get(k).getDataValue(); |
| | | if (null != dataValue) { |
| | | matrix[k][i] = dataValue; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | columnInfo.setDataLength(super.getDataLength(dynamicDataLength, entry.getModelparamportorder(), entry.getDatalength())); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime, pointMap, planMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime, pointMap, planMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo, pointMap, planMap)); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime)); |
| | | |
| | | //对每一个爪进行数据项归并 |
| | | if (curPortOrder != entry.getModelparamportorder()) { |
| | |
| | | * @param dataEntityList |
| | | * @param startTime |
| | | * @param endTime |
| | | * @param planMap |
| | | * @return |
| | | */ |
| | | public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime, |
| | | String paramId, String paramType, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime, String paramType, Integer granularity) { |
| | | if (CollectionUtils.isEmpty(dataEntityList) || length == dataEntityList.size()) { |
| | | return dataEntityList; |
| | | } else if (length < dataEntityList.size()) { |
| | |
| | | case NORMALITEM: |
| | | case MERGEITEM: |
| | | // 预测值 |
| | | oneMin = PredGranularityEnum.MIN1.getCode() * 1000L; |
| | | oneMin = granularity * 1000L; |
| | | start = start - (start % oneMin); |
| | | end = end - (end % oneMin); |
| | | mins = ((end - start) / oneMin); |
| | | break; |
| | | case DATAPOINT: |
| | | case PLAN: |
| | | // 测点值 |
| | | ApiPointDTO dataPoint = pointMap.get(paramId); |
| | | oneMin = 1000L * DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); |
| | | oneMin = 1000L * granularity; |
| | | // 设置时间偏移量 |
| | | start = start - (start % oneMin) + oneMin; |
| | | end = end - (end % oneMin) + oneMin; |
| | |
| | | calendar2.set(Calendar.MINUTE, 0); |
| | | calendar2.set(Calendar.SECOND, 0); |
| | | end = calendar2.getTime().getTime(); |
| | | mins = ((end - start) / oneMin); |
| | | break; |
| | | case PLAN: |
| | | // 计划数据 |
| | | ApiPlanItemDTO planItem = planMap.get(paramId); |
| | | oneMin = 1000L * TimeGranularitySecEnum.getEumByCode(planItem.getTimeGranularity()).getValue(); |
| | | // 设置时间偏移量 |
| | | start = start - (start % oneMin) + oneMin; |
| | | end = end - (end % oneMin) + oneMin; |
| | | mins = ((end - start) / oneMin); |
| | | break; |
| | | default: |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | protected Date getStartTime(ColumnItem columnItem, Date originalTime) { |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); |
| | | if (dataPoint == null) { |
| | | return null; |
| | | } |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue()); |
| | | case IND: |
| | | case PLAN: |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), columnItem.getGranularity()); |
| | | break; |
| | | case NORMALITEM: |
| | | case MERGEITEM: |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | case IND: |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60); |
| | | break; |
| | | case PLAN: |
| | | ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); |
| | | if (apiPlanItemDTO == null) { |
| | | return null; |
| | | } |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | protected Date getEndTime(ColumnItem columnItem, Date originalTime) { |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | case IND: |
| | | case PLAN: |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | case NORMALITEM: |
| | | case MERGEITEM: |
| | | dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), 60); |
| | | break; |
| | | case IND: |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | case PLAN: |
| | | dateTime = calendar.getTime(); |
| | | dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), columnItem.getGranularity()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | columnInfo.setDataLength(super.getDataLength(dynamicDataLength, entry.getModelparamportorder(), entry.getDatalength())); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime, pointMap, planMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime, pointMap, planMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo, pointMap, planMap)); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime)); |
| | | |
| | | //对每一个爪进行数据项归并 |
| | | if (curPortOrder != entry.getModelparamportorder()) { |