Merge remote-tracking branch 'origin/master'
| | |
| | | |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.common.ApiDataQueryDTO; |
| | | import com.iailab.module.data.common.ApiDataValueDTO; |
| | | import com.iailab.module.data.enums.ApiConstants; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | LinkedHashMap<String, List<ApiPlanDataDTO>> queryPlanItemRecordValue(@RequestBody ApiDataQueryDTO dto); |
| | | |
| | | @GetMapping(PREFIX + "/info/no/{itemNo}") |
| | | @Operation(summary = "根据测点编号查询测点信息") |
| | | @Operation(summary = "根据编号查询计划数据信息") |
| | | ApiPlanItemDTO getInfoByNo(@PathVariable("itemNo") String itemNo); |
| | | |
| | | @GetMapping(PREFIX + "/info/id/{id}") |
| | | @Operation(summary = "根据测点编号查询测点信息") |
| | | @Operation(summary = "根据id查询计划数据信息") |
| | | ApiPlanItemDTO getInfoById(@PathVariable("id") String id); |
| | | |
| | | @PostMapping(PREFIX + "/info/ids") |
| | | @Operation(summary = "根据多个id查询计划数据信息") |
| | | List<ApiPlanItemDTO> getInfoByIds(@RequestParam("planIds") Set<String> planIds); |
| | | } |
| | |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.security.PermitAll; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | |
| | | @PostMapping(PREFIX + "/info/ids") |
| | | @Operation(summary = "根据多个测点ID查询测点信息") |
| | | List<ApiPointDTO> getInfoByIds(@RequestParam("pointNos") List<String> pointIds); |
| | | List<ApiPointDTO> getInfoByIds(@RequestParam("pointNos") Set<String> pointIds); |
| | | |
| | | @PostMapping(PREFIX + "/query-points/real-value") |
| | | @Operation(summary = "查询多个测点当前值") |
| | |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.common.ApiDataQueryDTO; |
| | | import com.iailab.module.data.common.ApiDataValueDTO; |
| | | import com.iailab.module.data.plan.item.collection.PlanItemCollector; |
| | |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | return ConvertUtils.sourceToTarget(entity, ApiPlanItemDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiPlanItemDTO> getInfoByIds(Set<String> planIds) { |
| | | List<PlanItemEntity> plans = planItemService.getInfoByIds(planIds); |
| | | return ConvertUtils.sourceToTarget(plans,ApiPlanItemDTO.class); |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiPointDTO> getInfoByIds(List<String> pointIds) { |
| | | public List<ApiPointDTO> getInfoByIds(Set<String> pointIds) { |
| | | List<ApiPointDTO> result = new ArrayList<>(pointIds.size()); |
| | | for (String pointId : pointIds) { |
| | | result.add(daPointService.getSimpleInfoById(pointId)); |
| | |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.plan.item.entity.PlanItemEntity; |
| | | import com.iailab.module.data.plan.item.vo.PlanItemDataVO; |
| | | import com.iailab.module.data.plan.item.vo.PlanItemPageReqVO; |
| | |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | void delete(String id); |
| | | |
| | | List<PlanItemDataVO> getSourceValue(Map<String, Object> params); |
| | | |
| | | List<PlanItemEntity> getInfoByIds(Set<String> planIds); |
| | | } |
| | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.plan.item.dao.PlanItemDao; |
| | | import com.iailab.module.data.plan.item.entity.PlanItemEntity; |
| | | import com.iailab.module.data.plan.item.service.PlanItemService; |
| | |
| | | public List<PlanItemDataVO> getSourceValue(Map<String, Object> params) { |
| | | return baseDao.getSourceValue(params); |
| | | } |
| | | |
| | | @Override |
| | | public List<PlanItemEntity> getInfoByIds(Set<String> planIds) { |
| | | return baseDao.selectBatchIds(planIds); |
| | | } |
| | | } |
| | |
| | | */ |
| | | public Map<String, List<DataValueVO>> convertToPredictData(PredictResultVO predictResult) { |
| | | Map<String, List<DataValueVO>> resultMap = new HashMap<>(); |
| | | List<MmItemOutputEntity> itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId()); |
| | | |
| | | if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { |
| | | resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); |
| | | return resultMap; |
| | | } |
| | | // List<MmItemOutputEntity> itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId()); |
| | | // |
| | | // if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { |
| | | // resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); |
| | | // return resultMap; |
| | | // } |
| | | Map<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); |
| | | HashMap<String,List<DataValueVO>> predictLists = new HashMap<>(); |
| | | for (Map.Entry<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { |
| | |
| | | package com.iailab.module.model.mdk.predict.impl; |
| | | |
| | | import com.iailab.module.model.common.exception.ModelResultErrorException; |
| | | import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity; |
| | | import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum; |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictModelService; |
| | |
| | | * @throws ItemInvokeException |
| | | */ |
| | | @Override |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException { |
| | | public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException,ModelResultErrorException { |
| | | PredictResultVO predictResult = new PredictResultVO(); |
| | | String itemId = predictItemDto.getId(); |
| | | try { |
| | |
| | | } |
| | | predictResult = predictModelHandler.predictByModel(predictTime, predictModel,predictItemDto.getItemName()); |
| | | predictResult.setPredictId(itemId); |
| | | } catch (ModelResultErrorException ex) { |
| | | throw ex; |
| | | } catch (Exception ex) { |
| | | throw new ItemInvokeException(MessageFormat.format("{0},itemId={1}", |
| | | ItemInvokeException.errorItemFailed, itemId)); |
| | |
| | | } |
| | | String modelId = predictModel.getId(); |
| | | try { |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime, itemName); |
| | | String modelPath = predictModel.getModelpath(); |
| | | if (modelPath == null) { |
| | | log.info("模型路径不存在,modelId=" + modelId); |
| | |
| | | result.setPredictDoubleValues(predictDoubleValues); |
| | | result.setModelResult(modelResult); |
| | | result.setPredictTime(predictTime); |
| | | } catch (Exception ex) { |
| | | log.error("调用发生异常,异常信息为:{}", ex); |
| | | } catch (ModelResultErrorException ex) { |
| | | ex.printStackTrace(); |
| | | throw ex; |
| | | } catch (Exception ex) { |
| | | log.error("调用发生异常,异常信息为:{1}", ex); |
| | | // ex.printStackTrace(); |
| | | throw new ModelInvokeException(ex.getMessage()); |
| | | } |
| | | return result; |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | 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.ApiPointDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
| | | 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.mcs.pre.service.MmItemOutputService; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
| | |
| | | import com.iailab.module.model.mdk.sample.dto.SampleData; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 预测样本数据构造 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class PredictSampleDataConstructor extends SampleDataConstructor { |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | @Autowired |
| | | private MmItemResultService mmItemResultService; |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SampleData> prepareSampleData(SampleInfo sampleInfo) { |
| | | 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匿名函数 |
| | |
| | | //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 |
| | | for (int i = 0; i < entry.getColumnItemList().size(); i++) { |
| | | try { |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i)); |
| | | 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()); |
| | | columnItem.paramId, columnItem.getParamType(),pointMap,planMap); |
| | | |
| | | /** 如果数据取不满,把缺失的数据点放在后面 */ |
| | | if (dataEntityList != null && dataEntityList.size() != 0) { |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | } |
| | | SampleData sampleData = new SampleData(); |
| | |
| | | * getData |
| | | * |
| | | * @param columnItem |
| | | * @param pointMap |
| | | * @param planMap |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private List<DataValueVO> getData(ColumnItem columnItem) throws Exception { |
| | | private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) throws Exception { |
| | | List<DataValueVO> dataList = new ArrayList<>(); |
| | | String paramType = columnItem.getParamType(); |
| | | switch (ModelParamType.getEumByCode(paramType)) { |
| | | case DATAPOINT: |
| | | ApiPointDTO point = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); |
| | | queryDto.setPointNo(point.getPointNo()); |
| | | queryDto.setPointNo(pointMap.get(columnItem.getParamId()).getPointNo()); |
| | | queryDto.setStart(columnItem.getStartTime()); |
| | | queryDto.setEnd(columnItem.getEndTime()); |
| | | List<ApiPointValueDTO> pointValueList = dataPointApi.queryPointHistoryValue(queryDto); |
| | | if (CollectionUtils.isEmpty(pointValueList)) { |
| | | break; |
| | | } |
| | | dataList = pointValueList.stream().map(t -> { |
| | | DataValueVO vo = new DataValueVO(); |
| | | vo.setDataTime(t.getT()); |
| | |
| | | case NORMALITEM: |
| | | case MERGEITEM: |
| | | MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(columnItem.getParamId()); |
| | | dataList = mmItemResultService.getPredictValue(outPut.getId(), |
| | | columnItem.getStartTime(), columnItem.getEndTime()); |
| | | if (dataList == null) { |
| | | throw new Exception("没有预测值"); |
| | | List<DataValueVO> predictValue = mmItemResultService.getPredictValue(outPut.getId(), columnItem.getStartTime(), columnItem.getEndTime()); |
| | | if (CollectionUtils.isEmpty(predictValue)) { |
| | | break; |
| | | } |
| | | dataList = predictValue; |
| | | break; |
| | | case PLAN: |
| | | ApiDataQueryDTO queryPlanItemDto = new ApiDataQueryDTO(); |
| | | queryPlanItemDto.setItemNo(planMap.get(columnItem.getParamId()).getItemNo()); |
| | | queryPlanItemDto.setStart(columnItem.getStartTime()); |
| | | queryPlanItemDto.setEnd(columnItem.getEndTime()); |
| | | List<ApiDataValueDTO> planValueList = planItemApi.queryPlanItemHistoryValue(queryPlanItemDto); |
| | | if (CollectionUtils.isEmpty(planValueList)) { |
| | | break; |
| | | } |
| | | dataList = planValueList.stream().map(t -> { |
| | | DataValueVO vo = new DataValueVO(); |
| | | vo.setDataTime(t.getDataTime()); |
| | | vo.setDataValue(t.getDataValue()); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | default: |
| | | break; |
| | | } |
| | | log.info("数据获取,columnItem:" + columnItem + ",dataList" + dataList); |
| | | return dataList; |
| | | } |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | 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.ApiPointDTO; |
| | | import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity; |
| | |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItem; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | /** |
| | | * 返回样本矩阵的列数 |
| | | * |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | protected List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime) { |
| | | protected SampleInfo getColumnInfo(String modelId, Date predictTime) { |
| | | SampleInfo sampleInfo = new SampleInfo(); |
| | | List<ColumnItemPort> resultList = new ArrayList<>(); |
| | | List<ColumnItem> columnItemList = new ArrayList<>(); |
| | | ColumnItem columnInfo = new ColumnItem(); |
| | |
| | | //设置当前查询数据长度,初始值为最小端口数据长度 |
| | | int curDataLength = modelInputParamEntityList.get(0).getDatalength(); |
| | | // 统一获取测点的信息 |
| | | List<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toList()); |
| | | Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); |
| | | Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity())); |
| | | Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity(), (e1,e2) -> e1)); |
| | | // 统一获取计划数据的信息 |
| | | Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds); |
| | | Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1,e2) -> e1)); |
| | | |
| | | for (MmModelParamEntity entry : modelInputParamEntityList) { |
| | | columnInfo.setParamType(entry.getModelparamtype()); |
| | |
| | | columnInfo.setDataLength(entry.getDatalength()); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo)); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap)); |
| | | |
| | | //对每一个爪进行数据项归并 |
| | | if (curPortOrder != entry.getModelparamportorder()){ |
| | |
| | | curPort.setDataLength(curDataLength); |
| | | curPort.setPortOrder(curPortOrder); |
| | | resultList.add(curPort); |
| | | return resultList; |
| | | sampleInfo.setColumnInfo(resultList); |
| | | sampleInfo.setPointMap(pointMap); |
| | | sampleInfo.setPlanMap(planMap); |
| | | return sampleInfo; |
| | | } |
| | | |
| | | /** |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.model.mdk.common.exceptions.DataAccessException; |
| | | import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleData; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private SampleFactory sampleFactory; |
| | | |
| | | public List<SampleData> constructSample(String typeA, String modelId, Date runTime) { |
| | | public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName) throws ModelInvokeException { |
| | | try { |
| | | SampleInfoConstructor sampleInfoConstructor = sampleFactory.createSampleInfo(typeA, modelId); |
| | | SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime); |
| | | SampleDataConstructor sampleDataConstructor = sampleFactory.createSampelData(typeA); |
| | | return sampleDataConstructor.prepareSampleData(sampleInfo); |
| | | } catch (Exception e) { |
| | | DataAccessException exception = new DataAccessException(MessageFormat.format("{0},类名为{1}", |
| | | DataAccessException.errorDataAccess, Thread.currentThread().getStackTrace()[1].getClassName())); |
| | | System.out.println(exception); |
| | | e.printStackTrace(); |
| | | return null; |
| | | throw new ModelInvokeException(MessageFormat.format("{0},Name:{1}", |
| | | ModelInvokeException.errorGetModelArithParam, itemName)); |
| | | } |
| | | |
| | | |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | 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.ApiPointDTO; |
| | | import com.iailab.module.data.enums.DataPointFreqEnum; |
| | | import com.iailab.module.data.enums.TimeGranularitySecEnum; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleData; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.util.*; |
| | | |
| | | abstract class SampleDataConstructor { |
| | |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | /** |
| | | * prepareSampleData |
| | |
| | | * @param sampleInfo |
| | | * @return |
| | | */ |
| | | public abstract List<SampleData> prepareSampleData(SampleInfo sampleInfo); |
| | | public abstract List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception; |
| | | |
| | | /** |
| | | * 补全数据 |
| | |
| | | * @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) { |
| | | String paramId, String paramType, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | if (CollectionUtils.isEmpty(dataEntityList) || length == dataEntityList.size()) { |
| | | return dataEntityList; |
| | | } else if (length < dataEntityList.size()) { |
| | |
| | | endTime = calendar.getTime(); |
| | | end = endTime.getTime(); |
| | | |
| | | oneMin = 24 * 60 * 60 * 1000; |
| | | oneMin = 60 * 1000L; |
| | | mins = ((end - start) / oneMin); |
| | | break; |
| | | case DATAPOINT: |
| | | // 测点值 |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(paramId); |
| | | ApiPointDTO dataPoint = pointMap.get(paramId); |
| | | oneMin = 1000L * DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); |
| | | // 设置时间偏移量 |
| | | start = start - (start % oneMin) + oneMin; |
| | |
| | | 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: |
| | | break; |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | protected SampleInfo prepareSampleInfo(String modelId, Date predictTime) { |
| | | SampleInfo sampleInfo = new SampleInfo(); |
| | | //调用样本列数的方法 |
| | | // sampleInfo.setSampleColumn(getSampleColumn(modelId)); |
| | | //样本的列信息 |
| | | sampleInfo.setColumnInfo(getColumnInfo(modelId, predictTime)); |
| | | //样本的采样周期 |
| | | // sampleInfo.setSampleCycle(getSampleCycle(modelId)); |
| | | return sampleInfo; |
| | | return getColumnInfo(modelId, predictTime); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param predictTime |
| | | * @return |
| | | */ |
| | | protected abstract List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime); |
| | | protected abstract SampleInfo getColumnInfo(String modelId, Date predictTime); |
| | | |
| | | /** |
| | | * 样本的采样周期 |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap) { |
| | | protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60); |
| | | break; |
| | | case PLAN: |
| | | dateTime = calendar.getTime(); |
| | | 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) { |
| | | protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | case PLAN: |
| | | ApiPlanItemDTO planItem = planItemApi.getInfoByNo(columnItem.getParamId()); |
| | | if (planItem == null) { |
| | | ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); |
| | | if (apiPlanItemDTO == null) { |
| | | return null; |
| | | } |
| | | dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), |
| | | TimeGranularityEnum.getEumByCode(planItem.getTimeGranularity()).getValue()); |
| | | dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Integer getGranularity(ColumnItem columnItem) { |
| | | protected Integer getGranularity(ColumnItem columnItem,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | // 默认60s |
| | | Integer granularity = 60; |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); |
| | | granularity = DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); |
| | | break; |
| | | case NORMALITEM: |
| | | granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); |
| | | break; |
| | | case MERGEITEM: |
| | | granularity = mmPredictItemService.getItemByIdFromCache(columnItem.getParamId()).getGranularity(); |
| | | granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); |
| | | break; |
| | | case IND: |
| | | ApiIndItemDTO indItemDTO = indItemApi.getInfoById(columnItem.getParamId()); |
| | | granularity = TimeGranularitySecEnum.getEumByCode(indItemDTO.getTimeGranularity()).getValue();; |
| | | break; |
| | | case PLAN: |
| | | ApiPlanItemDTO apiPlanItemDTO = planItemApi.getInfoById(columnItem.getParamId()); |
| | | ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); |
| | | granularity = TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue(); |
| | | break; |
| | | default: |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | 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.ApiPointDTO; |
| | | import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelParamEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItem; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | @Override |
| | | protected Integer getSampleColumn(String modelId) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | protected List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime) { |
| | | protected SampleInfo getColumnInfo(String modelId, Date predictTime) { |
| | | SampleInfo sampleInfo = new SampleInfo(); |
| | | List<ColumnItemPort> resultList = new ArrayList<>(); |
| | | List<ColumnItem> columnItemList = new ArrayList<>(); |
| | | ColumnItem columnInfo = new ColumnItem(); |
| | |
| | | //设置当前查询数据长度,初始值为最小端口数据长度 |
| | | int curDataLength = modelInputParamEntityList.get(0).getDatalength(); |
| | | // 统一获取测点的信息 |
| | | List<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toList()); |
| | | Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); |
| | | Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity())); |
| | | // 统一获取计划数据的信息 |
| | | Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds); |
| | | Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1,e2) -> e1)); |
| | | |
| | | for (StScheduleModelParamEntity entry : modelInputParamEntityList) { |
| | | columnInfo.setParamType(entry.getModelparamtype()); |
| | |
| | | columnInfo.setDataLength(entry.getDatalength()); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo)); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap)); |
| | | |
| | | //对每一个爪进行数据项归并 |
| | | if (curPortOrder != entry.getModelparamportorder()){ |
| | |
| | | curPort.setDataLength(curDataLength); |
| | | curPort.setPortOrder(curPortOrder); |
| | | resultList.add(curPort); |
| | | return resultList; |
| | | sampleInfo.setColumnInfo(resultList); |
| | | sampleInfo.setPointMap(pointMap); |
| | | sampleInfo.setPlanMap(planMap); |
| | | return sampleInfo; |
| | | } |
| | | |
| | | @Override |
| | |
| | | package com.iailab.module.model.mdk.sample.dto; |
| | | |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Data |
| | | @AllArgsConstructor |
| | |
| | | private Integer sampleCycle; |
| | | |
| | | private BigDecimal[][] deviation; |
| | | // 所有测点信息,避免重复查询 |
| | | private Map<String, ApiPointDTO> pointMap; |
| | | // 所有计划数据信息,避免重复查询 |
| | | private Map<String, ApiPlanItemDTO> planMap; |
| | | } |
| | |
| | | try { |
| | | //1.根据模型id构造模型输入样本 |
| | | long now = System.currentTimeMillis(); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime,scheduleScheme.getName()); |
| | | log.info("构造模型输入样本消耗时长:" + (System.currentTimeMillis() - now) / 1000 + "秒"); |
| | | if (CollectionUtils.isEmpty(sampleDataList)) { |
| | | log.info("调度模型构造样本失败,schemeCode=" + schemeCode); |