提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.mdk.predict; |
潘 |
2 |
|
69bd5e
|
3 |
import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
D |
4 |
import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
7fd198
|
5 |
import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
潘 |
6 |
import com.iailab.module.model.mdk.factory.ItemEntityFactory; |
|
7 |
import com.iailab.module.model.mdk.vo.DataValueVO; |
|
8 |
import com.iailab.module.model.mdk.vo.PredictResultVO; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
import org.springframework.scheduling.annotation.Async; |
|
11 |
import org.springframework.stereotype.Service; |
|
12 |
import org.springframework.util.CollectionUtils; |
|
13 |
|
|
14 |
import java.util.*; |
|
15 |
|
|
16 |
@Service |
|
17 |
public class PredictResultHandler { |
|
18 |
@Autowired |
|
19 |
private MmItemResultService mmItemResultService; |
|
20 |
|
|
21 |
@Autowired |
|
22 |
private ItemEntityFactory itemEntityFactory; |
|
23 |
|
|
24 |
/** |
|
25 |
* convertToPredictData |
|
26 |
* |
|
27 |
* @param predictResult |
|
28 |
* @return |
|
29 |
*/ |
9162d9
|
30 |
public Map<String, List<DataValueVO>> convertToPredictData(PredictResultVO predictResult) { |
7fd198
|
31 |
Map<String, List<DataValueVO>> resultMap = new HashMap<>(); |
a4891a
|
32 |
List<MmItemOutputEntity> itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId()); |
7fd198
|
33 |
|
潘 |
34 |
if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { |
|
35 |
resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); |
|
36 |
return resultMap; |
|
37 |
} |
a4891a
|
38 |
Map<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); |
69bd5e
|
39 |
HashMap<String,List<DataValueVO>> predictLists = new HashMap<>(); |
a4891a
|
40 |
for (Map.Entry<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { |
69bd5e
|
41 |
Integer rows = entry.getValue().length; |
7fd198
|
42 |
List<DataValueVO> predictDataList = new ArrayList<>(); |
69bd5e
|
43 |
Calendar calendar = Calendar.getInstance(); |
D |
44 |
calendar.setTime(predictResult.getPredictTime()); |
|
45 |
for (Integer i = 0; i < rows; i++) { |
7fd198
|
46 |
DataValueVO predictData = new DataValueVO(); |
69bd5e
|
47 |
predictData.setDataTime(calendar.getTime()); |
D |
48 |
predictData.setDataValue(Double.valueOf(entry.getValue()[i])); |
7fd198
|
49 |
predictDataList.add(predictData); |
69bd5e
|
50 |
|
4f1717
|
51 |
calendar.add(Calendar.SECOND, predictResult.getGranularity()); |
7fd198
|
52 |
} |
69bd5e
|
53 |
resultMap.put(entry.getKey().getId(), predictDataList); |
4f1717
|
54 |
predictLists.put(entry.getKey().getResultstr(), predictDataList); |
7fd198
|
55 |
} |
69bd5e
|
56 |
predictResult.setPredictLists(predictLists); |
7fd198
|
57 |
return resultMap; |
潘 |
58 |
} |
|
59 |
|
4f1717
|
60 |
public Map<String, List<DataValueVO>> convertToPredictData2(PredictResultVO predictResult) { |
潘 |
61 |
Map<String, List<DataValueVO>> predictLists = new HashMap<>(); |
|
62 |
if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { |
|
63 |
return predictLists; |
|
64 |
} |
a4891a
|
65 |
Map<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs(); |
潘 |
66 |
for (Map.Entry<com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) { |
4f1717
|
67 |
Integer rows = entry.getValue().length; |
潘 |
68 |
List<DataValueVO> predictDataList = new ArrayList<>(); |
|
69 |
Calendar calendar = Calendar.getInstance(); |
|
70 |
calendar.setTime(predictResult.getPredictTime()); |
|
71 |
for (Integer i = 0; i < rows; i++) { |
|
72 |
DataValueVO predictData = new DataValueVO(); |
|
73 |
predictData.setDataTime(calendar.getTime()); |
|
74 |
predictData.setDataValue(Double.valueOf(entry.getValue()[i])); |
|
75 |
predictDataList.add(predictData); |
|
76 |
|
|
77 |
calendar.add(Calendar.SECOND, predictResult.getGranularity()); |
|
78 |
} |
|
79 |
predictLists.put(entry.getKey().getResultstr(), predictDataList); |
|
80 |
} |
|
81 |
return predictLists; |
|
82 |
} |
|
83 |
|
7fd198
|
84 |
/** |
潘 |
85 |
* savePredictResult |
|
86 |
* |
|
87 |
* @param predictResult |
|
88 |
*/ |
|
89 |
@Async |
69bd5e
|
90 |
@DSTransactional |
7fd198
|
91 |
public void savePredictResult(PredictResultVO predictResult) { |
潘 |
92 |
Map<String, List<DataValueVO>> resultMap = convertToPredictData(predictResult); |
|
93 |
mmItemResultService.savePredictValue(resultMap, predictResult.getLt(), "n", predictResult.getPredictTime()); |
a6e46f
|
94 |
// 存double类型输出 |
D |
95 |
if (!CollectionUtils.isEmpty(predictResult.getPredictDoubleValues())) { |
|
96 |
mmItemResultService.savePredictValue(predictResult.getPredictDoubleValues(), predictResult.getPredictTime()); |
|
97 |
} |
7fd198
|
98 |
} |
潘 |
99 |
|
|
100 |
public List<DataValueVO> getPredictValueByItemNo(String itemNo, Date start, Date end) { |
|
101 |
String itemId = itemEntityFactory.getItemByItemNo(itemNo).getId(); |
a4891a
|
102 |
List<MmItemOutputEntity> outputList = itemEntityFactory.getOutPutByItemId(itemId); |
7fd198
|
103 |
return mmItemResultService.getPredictValue(outputList.get(0).getId(), start, end); |
潘 |
104 |
} |
|
105 |
|
|
106 |
public List<DataValueVO> getPredictValueByItemId(String itemId, Date start, Date end) { |
a4891a
|
107 |
List<MmItemOutputEntity> outputList = itemEntityFactory.getOutPutByItemId(itemId); |
7fd198
|
108 |
return mmItemResultService.getPredictValue(outputList.get(0).getId(), start, end); |
潘 |
109 |
} |
|
110 |
} |