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