dengzedong
3 天以前 07890ec0dcb75572740f25a29c80f6d7bddb39e0
提交 | 用户 | 时间
7fd198 1 package com.iailab.module.model.mdk.sample;
2
07890e 3 import com.iailab.module.data.api.point.DataPointApi;
D 4 import com.iailab.module.data.api.point.dto.ApiPointDTO;
7fd198 5 import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity;
91343d 6 import com.iailab.module.model.mcs.pre.service.MmModelParamService;
7 import com.iailab.module.model.mcs.pre.service.MmPredictItemService;
7fd198 8 import com.iailab.module.model.mcs.pre.service.MmPredictModelService;
07890e 9 import com.iailab.module.model.mdk.common.enums.ModelParamType;
7fd198 10 import com.iailab.module.model.mdk.sample.dto.ColumnItem;
11 import com.iailab.module.model.mdk.sample.dto.ColumnItemPort;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.stereotype.Component;
14 import org.springframework.util.CollectionUtils;
15
16 import java.util.ArrayList;
17 import java.util.Date;
18 import java.util.List;
07890e 19 import java.util.Map;
D 20 import java.util.function.Function;
21 import java.util.stream.Collectors;
7fd198 22
23 /**
24  * @author PanZhibao
25  * @Description
26  * @createTime 2024年09月03日
27  */
28 @Component
29 public class PredictSampleInfoConstructor extends SampleInfoConstructor {
30
31     @Autowired
32     private MmPredictModelService mmPredictModelService;
33
34     @Autowired
91343d 35     private MmModelParamService mmModelParamService;
7fd198 36
37     @Autowired
91343d 38     private MmPredictItemService mmPredictItemService;
07890e 39
D 40     @Autowired
41     private DataPointApi dataPointApi;
7fd198 42
43     /**
44      * 返回样本矩阵的列数
45      *
46      * @param modelId
47      * @return
48      */
49     @Override
50     protected Integer getSampleColumn(String modelId) {
51         return mmPredictModelService.getSampleLength(modelId).intValue();
52     }
53
54     /**
55      * 样本的列信息
56      *
57      * @param modelId
58      * @param predictTime
59      * @return
60      */
61     @Override
62     protected List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime) {
63         List<ColumnItemPort> resultList = new ArrayList<>();
64         List<ColumnItem> columnItemList = new ArrayList<>();
65         ColumnItem columnInfo = new ColumnItem();
66         ColumnItemPort curPort = new ColumnItemPort();  //当前端口
45520a 67         List<MmModelParamEntity> modelInputParamEntityList = mmModelParamService.getByModelidFromCache(modelId);
7fd198 68         if (CollectionUtils.isEmpty(modelInputParamEntityList)) {
69             return null;
70         }
71         //设置当前端口号,初始值为最小端口(查询结果按端口号从小到达排列)
72         int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder();
73         //设置当前查询数据长度,初始值为最小端口数据长度
74         int curDataLength = modelInputParamEntityList.get(0).getDatalength();
07890e 75         // 统一获取测点的信息
D 76         List<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toList());
77         List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds);
78         Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity()));
79
7fd198 80         for (MmModelParamEntity entry : modelInputParamEntityList) {
81             columnInfo.setParamType(entry.getModelparamtype());
1a2b62 82             columnInfo.setParamId(entry.getModelparamid());
7fd198 83             columnInfo.setDataLength(entry.getDatalength());
84             columnInfo.setModelParamOrder(entry.getModelparamorder());
85             columnInfo.setModelParamPortOrder(entry.getModelparamportorder());
07890e 86             columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap));
D 87             columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap));
7fd198 88             columnInfo.setGranularity(super.getGranularity(columnInfo));
89
90             //对每一个爪进行数据项归并
91             if (curPortOrder != entry.getModelparamportorder()){
92                 //当数据项端口号不为当前端口号时,封装上一个端口类,操作下一个端口类
93                 curPort.setColumnItemList(columnItemList);
94                 curPort.setDataLength(curDataLength);
95                 curPort.setPortOrder(curPortOrder);
96                 resultList.add(curPort);
97                 curPort = new ColumnItemPort(); //对象重新初始化,防止引用拷贝导致数据覆盖
98                 //封装上一个端口类后更新当前的各个参数
99                 columnItemList = new ArrayList<>();
100                 curDataLength = entry.getDatalength();
101                 curPortOrder = entry.getModelparamportorder();
102             }
103             columnItemList.add(columnInfo);
104             columnInfo = new ColumnItem();    //对象重新初始化,防止引用拷贝导致数据覆盖
105         }
106         //当迭代到最后一个项的时候,封装最后一个端口的信息
107         curPort.setColumnItemList(columnItemList);
108         curPort.setDataLength(curDataLength);
109         curPort.setPortOrder(curPortOrder);
110         resultList.add(curPort);
111         return resultList;
112     }
113
114     /**
115      * 样本的采样周期
116      *
117      * @param modelId
118      * @return
119      */
120     @Override
121     protected Integer getSampleCycle(String modelId) {
b82ba2 122         return mmPredictItemService.getItemByIdFromCache(mmPredictModelService.getInfoFromCatch(modelId).getItemid()).getGranularity();
7fd198 123     }
124
125
126 }