提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.mdk.sample; |
潘 |
2 |
|
91343d
|
3 |
import com.iailab.module.data.api.ind.IndItemApi; |
潘 |
4 |
import com.iailab.module.data.api.ind.dto.ApiIndItemDTO; |
e78121
|
5 |
import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
7fd198
|
6 |
import com.iailab.module.data.api.point.dto.ApiPointDTO; |
e78121
|
7 |
import com.iailab.module.data.enums.DataPointFreqEnum; |
91343d
|
8 |
import com.iailab.module.data.enums.TimeGranularitySecEnum; |
潘 |
9 |
import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
e78121
|
10 |
import com.iailab.module.model.mdk.common.enums.ModelParamType; |
7fd198
|
11 |
import com.iailab.module.model.mdk.sample.dto.ColumnItem; |
潘 |
12 |
import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
|
13 |
import org.springframework.beans.factory.annotation.Autowired; |
bab433
|
14 |
import org.springframework.util.CollectionUtils; |
7fd198
|
15 |
|
潘 |
16 |
import java.util.Calendar; |
|
17 |
import java.util.Date; |
07890e
|
18 |
import java.util.Map; |
7fd198
|
19 |
|
潘 |
20 |
/** |
|
21 |
* @author PanZhibao |
|
22 |
* @Description |
|
23 |
* @createTime 2024年09月03日 |
|
24 |
*/ |
|
25 |
abstract class SampleInfoConstructor { |
e78121
|
26 |
|
潘 |
27 |
@Autowired |
91343d
|
28 |
private IndItemApi indItemApi; |
潘 |
29 |
|
|
30 |
@Autowired |
|
31 |
private MmPredictItemService mmPredictItemService; |
7fd198
|
32 |
|
潘 |
33 |
/** |
|
34 |
* prepareSampleInfo |
|
35 |
* |
|
36 |
* @param modelId |
|
37 |
* @param predictTime |
|
38 |
* @return |
|
39 |
*/ |
bab433
|
40 |
protected SampleInfo prepareSampleInfo(String modelId, Date predictTime, Map<Integer, Integer> dynamicDataLength) { |
7fd198
|
41 |
//样本的列信息 |
bab433
|
42 |
return getColumnInfo(modelId, predictTime, dynamicDataLength); |
7fd198
|
43 |
} |
潘 |
44 |
|
|
45 |
/** |
|
46 |
* 返回样本矩阵的列数 |
|
47 |
* |
|
48 |
* @param modelId |
|
49 |
* @return |
|
50 |
*/ |
|
51 |
protected abstract Integer getSampleColumn(String modelId); |
45520a
|
52 |
|
D |
53 |
|
|
54 |
/** |
|
55 |
* 样本的列信息 |
|
56 |
* |
|
57 |
* @param modelId |
|
58 |
* @param predictTime |
|
59 |
* @return |
|
60 |
*/ |
bab433
|
61 |
protected abstract SampleInfo getColumnInfo(String modelId, Date predictTime, Map<Integer, Integer> dynamicDataLength); |
45520a
|
62 |
|
D |
63 |
/** |
|
64 |
* 样本的采样周期 |
|
65 |
* |
|
66 |
* @param modelId |
|
67 |
* @return |
|
68 |
*/ |
|
69 |
protected abstract Integer getSampleCycle(String modelId); |
7fd198
|
70 |
|
潘 |
71 |
/** |
|
72 |
* 获取开始时间 |
|
73 |
* |
|
74 |
* @param columnItem |
|
75 |
* @param originalTime |
|
76 |
* @return |
|
77 |
* @throws Exception |
|
78 |
*/ |
e691b9
|
79 |
protected Date getStartTime(ColumnItem columnItem, Date originalTime) { |
7fd198
|
80 |
Date dateTime = new Date(); |
潘 |
81 |
Calendar calendar = Calendar.getInstance(); |
|
82 |
calendar.setTime(originalTime); |
e78121
|
83 |
switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
潘 |
84 |
case DATAPOINT: |
e691b9
|
85 |
case IND: |
D |
86 |
case PLAN: |
|
87 |
dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), columnItem.getGranularity()); |
7fd198
|
88 |
break; |
19a4fb
|
89 |
case NORMALITEM: |
D |
90 |
case MERGEITEM: |
3ddbb6
|
91 |
dateTime = calendar.getTime(); |
7fd198
|
92 |
break; |
潘 |
93 |
default: |
|
94 |
break; |
|
95 |
} |
|
96 |
return dateTime; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* 获取结束时间 |
|
101 |
* |
|
102 |
* @param columnItem |
|
103 |
* @param originalTime |
|
104 |
* @return |
|
105 |
* @throws Exception |
|
106 |
*/ |
e691b9
|
107 |
protected Date getEndTime(ColumnItem columnItem, Date originalTime) { |
7fd198
|
108 |
Date dateTime = new Date(); |
潘 |
109 |
Calendar calendar = Calendar.getInstance(); |
|
110 |
calendar.setTime(originalTime); |
e78121
|
111 |
switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
潘 |
112 |
case DATAPOINT: |
e691b9
|
113 |
case IND: |
D |
114 |
case PLAN: |
b2aca2
|
115 |
dateTime = calendar.getTime(); |
7fd198
|
116 |
break; |
19a4fb
|
117 |
case NORMALITEM: |
D |
118 |
case MERGEITEM: |
e691b9
|
119 |
dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), columnItem.getGranularity()); |
7fd198
|
120 |
break; |
潘 |
121 |
default: |
|
122 |
break; |
|
123 |
} |
|
124 |
return dateTime; |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* 获取粒度,s |
|
129 |
* |
|
130 |
* @param columnItem |
|
131 |
* @return |
|
132 |
* @throws Exception |
|
133 |
*/ |
8bf553
|
134 |
protected Integer getGranularity(ColumnItem columnItem,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
91343d
|
135 |
// 默认60s |
7fd198
|
136 |
Integer granularity = 60; |
91343d
|
137 |
switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
潘 |
138 |
case DATAPOINT: |
8bf553
|
139 |
ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); |
e78121
|
140 |
granularity = DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); |
7fd198
|
141 |
break; |
19a4fb
|
142 |
case NORMALITEM: |
D |
143 |
case MERGEITEM: |
50084d
|
144 |
granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); |
7fd198
|
145 |
break; |
91343d
|
146 |
case IND: |
潘 |
147 |
ApiIndItemDTO indItemDTO = indItemApi.getInfoById(columnItem.getParamId()); |
|
148 |
granularity = TimeGranularitySecEnum.getEumByCode(indItemDTO.getTimeGranularity()).getValue();; |
7fd198
|
149 |
break; |
91343d
|
150 |
case PLAN: |
8bf553
|
151 |
ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); |
91343d
|
152 |
granularity = TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue(); |
7fd198
|
153 |
break; |
潘 |
154 |
default: |
|
155 |
break; |
|
156 |
} |
|
157 |
return granularity; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* 计算取值的时间 |
|
162 |
* |
|
163 |
* @param originalTime |
|
164 |
* @param backward |
|
165 |
* @param dataLength |
|
166 |
* @param granularity |
|
167 |
* @return |
|
168 |
*/ |
|
169 |
public Date calculateTime(Date originalTime, Boolean backward, int dataLength, int granularity) { |
|
170 |
int timeLength; |
|
171 |
if (backward) { |
|
172 |
timeLength = (-1) * dataLength; |
|
173 |
} else { |
033e69
|
174 |
timeLength = dataLength; |
7fd198
|
175 |
} |
潘 |
176 |
Date desTime = originalTime; |
|
177 |
Calendar calendar = Calendar.getInstance(); |
|
178 |
calendar.setTime(desTime); |
|
179 |
calendar.set(Calendar.MILLISECOND, 0); |
|
180 |
// 数据长度 * 粒度 |
|
181 |
calendar.add(Calendar.SECOND, timeLength * granularity); |
e78121
|
182 |
return calendar.getTime(); |
潘 |
183 |
} |
bab433
|
184 |
|
潘 |
185 |
protected int getDataLength(Map<Integer, Integer> dynamicDataLength, Integer port, Integer dataLength) { |
|
186 |
if (CollectionUtils.isEmpty(dynamicDataLength)) { |
|
187 |
return dataLength; |
|
188 |
} |
|
189 |
if (dynamicDataLength.containsKey(port)) { |
|
190 |
return dynamicDataLength.get(port); |
|
191 |
} |
|
192 |
return dataLength; |
|
193 |
} |
7fd198
|
194 |
} |