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