提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.mdk.sample; |
潘 |
2 |
|
|
3 |
import com.iailab.module.data.api.point.DataPointApi; |
|
4 |
import com.iailab.module.data.api.point.dto.ApiPointDTO; |
|
5 |
import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
|
6 |
import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
a4891a
|
7 |
import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
潘 |
8 |
import com.iailab.module.model.mcs.pre.service.MmItemOutputService; |
7fd198
|
9 |
import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
a4891a
|
10 |
import com.iailab.module.model.mcs.pre.service.MmItemTypeService; |
潘 |
11 |
import com.iailab.module.model.mdk.common.enums.ModelParamType; |
7fd198
|
12 |
import com.iailab.module.model.mdk.sample.dto.ColumnItem; |
潘 |
13 |
import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
|
14 |
import com.iailab.module.model.mdk.sample.dto.SampleData; |
|
15 |
import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
|
16 |
import com.iailab.module.model.mdk.vo.DataValueVO; |
|
17 |
import org.slf4j.Logger; |
|
18 |
import org.slf4j.LoggerFactory; |
|
19 |
import org.springframework.beans.factory.annotation.Autowired; |
|
20 |
import org.springframework.stereotype.Component; |
|
21 |
|
|
22 |
import java.math.BigDecimal; |
|
23 |
import java.util.*; |
214275
|
24 |
import java.util.stream.Collectors; |
7fd198
|
25 |
|
潘 |
26 |
/** |
|
27 |
* 预测样本数据构造 |
|
28 |
*/ |
|
29 |
@Component |
|
30 |
public class PredictSampleDataConstructor extends SampleDataConstructor { |
|
31 |
|
|
32 |
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
33 |
|
|
34 |
@Autowired |
|
35 |
private DataPointApi dataPointApi; |
|
36 |
|
|
37 |
@Autowired |
|
38 |
private MmItemResultService mmItemResultService; |
|
39 |
|
|
40 |
@Autowired |
a4891a
|
41 |
private MmItemTypeService mmItemTypeService; |
潘 |
42 |
|
|
43 |
@Autowired |
|
44 |
private MmItemOutputService mmItemOutputService; |
7fd198
|
45 |
|
潘 |
46 |
/** |
|
47 |
* alter by zfc 2020.11.24 修改数据样本构造方案:sampleInfo中数据已按爪子进行分类,但爪内数据为无序的, |
|
48 |
* 对爪内数据样本拼接:先基于modelParamOrder对项进行排序(重写comparator匿名函数),再逐项拼接 |
|
49 |
* |
|
50 |
* @param sampleInfo |
|
51 |
* @return |
|
52 |
*/ |
|
53 |
@Override |
|
54 |
public List<SampleData> prepareSampleData(SampleInfo sampleInfo) { |
|
55 |
List<SampleData> sampleDataList = new ArrayList<>(); |
|
56 |
//对每个爪分别进行计算 |
|
57 |
for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { |
|
58 |
//先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 |
|
59 |
Collections.sort(entry.getColumnItemList(), new Comparator<ColumnItem>() { |
|
60 |
@Override |
|
61 |
public int compare(ColumnItem o1, ColumnItem o2) { |
|
62 |
return o1.getModelParamOrder() - o2.getModelParamOrder(); |
|
63 |
} |
|
64 |
}); |
|
65 |
|
|
66 |
//默认都是double类型的数据,且按列向量进行拼接,默认初始值为0.0 |
|
67 |
double[][] matrix = new double[entry.getDataLength()][entry.getColumnItemList().size()]; |
|
68 |
for (int i = 0; i < entry.getColumnItemList().size(); i++) { |
|
69 |
for (int j = 0; j < entry.getDataLength(); j++) { |
|
70 |
matrix[j][i] = -2.0; |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
//对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 |
|
75 |
for (int i = 0; i < entry.getColumnItemList().size(); i++) { |
|
76 |
try { |
|
77 |
List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i)); |
|
78 |
//补全数据 |
|
79 |
ColumnItem columnItem = entry.getColumnItemList().get(i); |
a4891a
|
80 |
dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, |
潘 |
81 |
columnItem.paramId, columnItem.getParamType()); |
7fd198
|
82 |
|
潘 |
83 |
/** 如果数据取不满,把缺失的数据点放在后面 */ |
|
84 |
if (dataEntityList != null && dataEntityList.size() != 0) { |
|
85 |
logger.info("设置matrix, i = " + i + ", size = " + dataEntityList.size()); |
|
86 |
for (int k = 0; k < dataEntityList.size(); k++) { |
|
87 |
matrix[k][i] = dataEntityList.get(k).getDataValue(); |
|
88 |
} |
|
89 |
} |
|
90 |
} catch (Exception e) { |
|
91 |
e.printStackTrace(); |
|
92 |
} |
|
93 |
} |
|
94 |
SampleData sampleData = new SampleData(); |
|
95 |
sampleData.setMatrix(matrix); |
|
96 |
sampleDataList.add(sampleData); |
|
97 |
} |
|
98 |
return sampleDataList; |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* getData |
|
103 |
* |
|
104 |
* @param columnItem |
|
105 |
* @return |
|
106 |
* @throws Exception |
|
107 |
*/ |
|
108 |
private List<DataValueVO> getData(ColumnItem columnItem) throws Exception { |
|
109 |
List<DataValueVO> dataList = new ArrayList<>(); |
|
110 |
String paramType = columnItem.getParamType(); |
a4891a
|
111 |
switch (ModelParamType.getEumByCode(paramType)) { |
潘 |
112 |
case DATAPOINT: |
b2aca2
|
113 |
ApiPointDTO point = dataPointApi.getInfoById(columnItem.getParamId()); |
7fd198
|
114 |
ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); |
潘 |
115 |
queryDto.setPointNo(point.getPointNo()); |
|
116 |
queryDto.setStart(columnItem.getStartTime()); |
|
117 |
queryDto.setEnd(columnItem.getEndTime()); |
536b8e
|
118 |
List<ApiPointValueDTO> pointValueList = dataPointApi.queryPointHistoryValue(queryDto); |
a4891a
|
119 |
dataList = pointValueList.stream().map(t -> { |
214275
|
120 |
DataValueVO vo = new DataValueVO(); |
潘 |
121 |
vo.setDataTime(t.getT()); |
|
122 |
vo.setDataValue(t.getV()); |
|
123 |
return vo; |
|
124 |
}).collect(Collectors.toList()); |
7fd198
|
125 |
break; |
19a4fb
|
126 |
case NORMALITEM: |
D |
127 |
case MERGEITEM: |
|
128 |
MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(columnItem.getParamId()); |
7fd198
|
129 |
dataList = mmItemResultService.getPredictValue(outPut.getId(), |
潘 |
130 |
columnItem.getStartTime(), columnItem.getEndTime()); |
|
131 |
if (dataList == null) { |
|
132 |
throw new Exception("没有预测值"); |
|
133 |
} |
|
134 |
break; |
|
135 |
default: |
|
136 |
break; |
|
137 |
} |
|
138 |
return dataList; |
|
139 |
} |
|
140 |
} |