提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.mdk.predict; |
潘 |
2 |
|
69bd5e
|
3 |
import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
4af6b1
|
4 |
import com.iailab.module.model.common.enums.CommonDict; |
69bd5e
|
5 |
import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
7fd198
|
6 |
import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
b3674c
|
7 |
import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
7fd198
|
8 |
import com.iailab.module.model.mdk.factory.ItemEntityFactory; |
潘 |
9 |
import com.iailab.module.model.mdk.vo.DataValueVO; |
|
10 |
import com.iailab.module.model.mdk.vo.PredictResultVO; |
|
11 |
import org.springframework.beans.factory.annotation.Autowired; |
|
12 |
import org.springframework.stereotype.Service; |
|
13 |
import org.springframework.util.CollectionUtils; |
|
14 |
|
4af6b1
|
15 |
import java.math.BigDecimal; |
7fd198
|
16 |
import java.util.*; |
潘 |
17 |
|
|
18 |
@Service |
|
19 |
public class PredictResultHandler { |
|
20 |
@Autowired |
|
21 |
private MmItemResultService mmItemResultService; |
|
22 |
|
|
23 |
@Autowired |
|
24 |
private ItemEntityFactory itemEntityFactory; |
|
25 |
|
b3674c
|
26 |
@Autowired |
潘 |
27 |
private StAdjustResultService stAdjustResultService; |
|
28 |
|
7fd198
|
29 |
/** |
潘 |
30 |
* convertToPredictData |
|
31 |
* |
|
32 |
* @param predictResult |
|
33 |
* @return |
|
34 |
*/ |
9162d9
|
35 |
public Map<String, List<DataValueVO>> convertToPredictData(PredictResultVO predictResult) { |
7fd198
|
36 |
Map<String, List<DataValueVO>> resultMap = new HashMap<>(); |
b3674c
|
37 |
Map<MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); |
潘 |
38 |
HashMap<String, List<DataValueVO>> predictLists = new HashMap<>(); |
|
39 |
for (Map.Entry<MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { |
69bd5e
|
40 |
Integer rows = entry.getValue().length; |
7fd198
|
41 |
List<DataValueVO> predictDataList = new ArrayList<>(); |
69bd5e
|
42 |
Calendar calendar = Calendar.getInstance(); |
D |
43 |
calendar.setTime(predictResult.getPredictTime()); |
|
44 |
for (Integer i = 0; i < rows; i++) { |
7fd198
|
45 |
DataValueVO predictData = new DataValueVO(); |
69bd5e
|
46 |
predictData.setDataTime(calendar.getTime()); |
D |
47 |
predictData.setDataValue(Double.valueOf(entry.getValue()[i])); |
7fd198
|
48 |
predictDataList.add(predictData); |
69bd5e
|
49 |
|
4f1717
|
50 |
calendar.add(Calendar.SECOND, predictResult.getGranularity()); |
7fd198
|
51 |
} |
69bd5e
|
52 |
resultMap.put(entry.getKey().getId(), predictDataList); |
4f1717
|
53 |
predictLists.put(entry.getKey().getResultstr(), predictDataList); |
4af6b1
|
54 |
|
D |
55 |
//处理累计计算 |
|
56 |
if (entry.getKey().getIscumulant() == 1) { |
b3674c
|
57 |
resultMap.put(entry.getKey().getId() + CommonDict.CUMULANT_SUFFIX, new ArrayList<DataValueVO>() {{ |
4af6b1
|
58 |
DataValueVO predictData = new DataValueVO(); |
D |
59 |
// 时间 预测时间+预测长度*粒度 |
|
60 |
Calendar calendar = Calendar.getInstance(); |
|
61 |
calendar.setTime(predictResult.getPredictTime()); |
|
62 |
calendar.add(Calendar.SECOND, predictResult.getGranularity() * (rows - 1)); |
|
63 |
predictData.setDataTime(calendar.getTime()); |
|
64 |
//值 所有值相加/除数 |
|
65 |
BigDecimal sum = BigDecimal.valueOf(Arrays.stream(entry.getValue()).sum()); |
|
66 |
BigDecimal divisor = BigDecimal.valueOf(entry.getKey().getCumuldivisor()); |
|
67 |
predictData.setDataValue(sum.divide(divisor, 2, BigDecimal.ROUND_HALF_UP).doubleValue()); |
|
68 |
add(predictData); |
|
69 |
}}); |
|
70 |
} |
7fd198
|
71 |
} |
69bd5e
|
72 |
predictResult.setPredictLists(predictLists); |
7fd198
|
73 |
return resultMap; |
潘 |
74 |
} |
|
75 |
|
4f1717
|
76 |
public Map<String, List<DataValueVO>> convertToPredictData2(PredictResultVO predictResult) { |
潘 |
77 |
Map<String, List<DataValueVO>> predictLists = new HashMap<>(); |
|
78 |
if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { |
|
79 |
return predictLists; |
|
80 |
} |
5131f1
|
81 |
Map<MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); |
潘 |
82 |
for (Map.Entry<MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { |
4f1717
|
83 |
Integer rows = entry.getValue().length; |
潘 |
84 |
List<DataValueVO> predictDataList = new ArrayList<>(); |
|
85 |
Calendar calendar = Calendar.getInstance(); |
|
86 |
calendar.setTime(predictResult.getPredictTime()); |
|
87 |
for (Integer i = 0; i < rows; i++) { |
|
88 |
DataValueVO predictData = new DataValueVO(); |
|
89 |
predictData.setDataTime(calendar.getTime()); |
|
90 |
predictData.setDataValue(Double.valueOf(entry.getValue()[i])); |
|
91 |
predictDataList.add(predictData); |
|
92 |
|
|
93 |
calendar.add(Calendar.SECOND, predictResult.getGranularity()); |
|
94 |
} |
|
95 |
predictLists.put(entry.getKey().getResultstr(), predictDataList); |
|
96 |
} |
|
97 |
return predictLists; |
|
98 |
} |
|
99 |
|
7fd198
|
100 |
/** |
潘 |
101 |
* savePredictResult |
|
102 |
* |
|
103 |
* @param predictResult |
|
104 |
*/ |
69bd5e
|
105 |
@DSTransactional |
7fd198
|
106 |
public void savePredictResult(PredictResultVO predictResult) { |
潘 |
107 |
Map<String, List<DataValueVO>> resultMap = convertToPredictData(predictResult); |
|
108 |
mmItemResultService.savePredictValue(resultMap, predictResult.getLt(), "n", predictResult.getPredictTime()); |
|
109 |
} |
|
110 |
|
b3674c
|
111 |
/** |
潘 |
112 |
* savePredictAdjustResult |
|
113 |
* |
|
114 |
* @param predictResult |
67f59a
|
115 |
* @param configId |
b3674c
|
116 |
*/ |
潘 |
117 |
@DSTransactional |
67f59a
|
118 |
public void savePredictAdjustResult(PredictResultVO predictResult, String adjustValue, String scheduleModelId, String configId) { |
b3674c
|
119 |
Map<String, List<DataValueVO>> resultMap = convertToPredictData(predictResult); |
67f59a
|
120 |
stAdjustResultService.saveResult(resultMap, predictResult.getPredictTime(), adjustValue, scheduleModelId,configId); |
b3674c
|
121 |
} |
潘 |
122 |
|
7fd198
|
123 |
public List<DataValueVO> getPredictValueByItemNo(String itemNo, Date start, Date end) { |
潘 |
124 |
String itemId = itemEntityFactory.getItemByItemNo(itemNo).getId(); |
a4891a
|
125 |
List<MmItemOutputEntity> outputList = itemEntityFactory.getOutPutByItemId(itemId); |
7fd198
|
126 |
return mmItemResultService.getPredictValue(outputList.get(0).getId(), start, end); |
潘 |
127 |
} |
|
128 |
|
|
129 |
public List<DataValueVO> getPredictValueByItemId(String itemId, Date start, Date end) { |
a4891a
|
130 |
List<MmItemOutputEntity> outputList = itemEntityFactory.getOutPutByItemId(itemId); |
7fd198
|
131 |
return mmItemResultService.getPredictValue(outputList.get(0).getId(), start, end); |
潘 |
132 |
} |
|
133 |
} |