提交 | 用户 | 时间
|
7fd198
|
1 |
package com.iailab.module.model.mdk.predict.impl; |
潘 |
2 |
|
fde993
|
3 |
import com.alibaba.fastjson.JSON; |
a4891a
|
4 |
import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
3059dd
|
5 |
import com.iailab.module.model.mcs.pre.service.MmItemOutputService; |
b3674c
|
6 |
import com.iailab.module.model.mcs.pre.service.MmItemResultJsonService; |
潘 |
7 |
import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
7fd198
|
8 |
import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException; |
潘 |
9 |
import com.iailab.module.model.mdk.factory.ItemEntityFactory; |
|
10 |
import com.iailab.module.model.mdk.predict.PredictItemHandler; |
|
11 |
import com.iailab.module.model.mdk.vo.ItemVO; |
|
12 |
import com.iailab.module.model.mdk.vo.PredictResultVO; |
b3674c
|
13 |
import com.iailab.module.model.mdk.vo.StAdjustDeviationDTO; |
7fd198
|
14 |
import lombok.extern.slf4j.Slf4j; |
潘 |
15 |
import org.springframework.beans.factory.annotation.Autowired; |
|
16 |
import org.springframework.stereotype.Component; |
de1b3b
|
17 |
import org.springframework.util.CollectionUtils; |
7fd198
|
18 |
|
潘 |
19 |
import java.util.*; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author PanZhibao |
|
23 |
* @Description |
|
24 |
* @createTime 2024年09月01日 |
|
25 |
*/ |
|
26 |
@Slf4j |
|
27 |
@Component |
|
28 |
public class PredictItemMergeHandlerImpl implements PredictItemHandler { |
|
29 |
|
|
30 |
@Autowired |
|
31 |
private ItemEntityFactory itemEntityFactory; |
|
32 |
|
|
33 |
@Autowired |
b3674c
|
34 |
private MmItemResultJsonService mmItemResultJsonService; |
3059dd
|
35 |
|
D |
36 |
@Autowired |
|
37 |
private MmItemOutputService mmItemOutputService; |
b3674c
|
38 |
|
潘 |
39 |
@Autowired |
|
40 |
private StAdjustResultService stAdjustResultService; |
3059dd
|
41 |
|
4f1717
|
42 |
/** |
潘 |
43 |
* MergeItem预测 |
|
44 |
* |
|
45 |
* @param predictTime |
|
46 |
* @param predictItemDto |
|
47 |
* @return |
|
48 |
* @throws ItemInvokeException |
|
49 |
*/ |
7fd198
|
50 |
@Override |
1178da
|
51 |
public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) |
7fd198
|
52 |
throws ItemInvokeException { |
潘 |
53 |
PredictResultVO predictResult = new PredictResultVO(); |
|
54 |
String itemId = predictItemDto.getId(); |
|
55 |
try { |
|
56 |
String expression = itemEntityFactory.getMergeItem(itemId).getExpression(); |
|
57 |
int predictLength = itemEntityFactory.getItemById(itemId).getPredictLength(); |
de1b3b
|
58 |
double[] predictResultMat = new double[predictLength]; |
3059dd
|
59 |
String[] mathOutPutId = expression.split("[\\+ \\-]"); |
7fd198
|
60 |
ArrayList<Character> operator = new ArrayList<>(); |
潘 |
61 |
for (int i = 0; i < expression.length(); i++) { |
b3674c
|
62 |
if (expression.charAt(i) == '+' || expression.charAt(i) == '-') { |
7fd198
|
63 |
operator.add(expression.charAt(i)); |
潘 |
64 |
} |
|
65 |
} |
|
66 |
//是否为计算预测项 |
3059dd
|
67 |
if (mathOutPutId.length > 1) { |
7fd198
|
68 |
for (Integer i = 0; i < predictLength; i++) { |
b3674c
|
69 |
double sum = 0.0; |
07890e
|
70 |
sum = predictValueMap.get(mathOutPutId[0])[i]; |
3059dd
|
71 |
for (int j = 1; j < mathOutPutId.length; j++) { |
b3674c
|
72 |
if (operator.get(j - 1) == '+') { |
潘 |
73 |
sum += predictValueMap.get(mathOutPutId[j])[i]; |
|
74 |
} |
|
75 |
if (operator.get(j - 1) == '-') { |
|
76 |
sum -= predictValueMap.get(mathOutPutId[j])[i]; |
|
77 |
} |
7fd198
|
78 |
} |
de1b3b
|
79 |
predictResultMat[i] = sum; |
7fd198
|
80 |
} |
潘 |
81 |
} |
|
82 |
predictResult.setPredictId(itemId); |
de1b3b
|
83 |
List<MmItemOutputEntity> outputServiceByItemid = mmItemOutputService.getByItemid(itemId); |
fde993
|
84 |
if (!CollectionUtils.isEmpty(outputServiceByItemid)) { |
de1b3b
|
85 |
Map<MmItemOutputEntity, double[]> predictMatrixs = new HashMap<>(); |
b3674c
|
86 |
predictMatrixs.put(outputServiceByItemid.get(0), predictResultMat); |
潘 |
87 |
predictResult.setPredictMatrixs(predictMatrixs); |
|
88 |
} |
|
89 |
predictResult.setPredictTime(predictTime); |
|
90 |
} catch (Exception e) { |
|
91 |
log.error("merge项预测失败,itemId:" + itemId); |
|
92 |
e.printStackTrace(); |
|
93 |
throw e; |
|
94 |
} |
|
95 |
log.info("merge项预测完成,itemId:" + itemId + ",结果:" + JSON.toJSONString(predictResult)); |
|
96 |
return predictResult; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public PredictResultVO predictAdjust(Date predictTime, ItemVO predictItemDto, List<StAdjustDeviationDTO> deviationList) |
|
101 |
throws ItemInvokeException { |
|
102 |
PredictResultVO predictResult = new PredictResultVO(); |
|
103 |
String itemId = predictItemDto.getId(); |
|
104 |
try { |
|
105 |
String expression = itemEntityFactory.getMergeItem(itemId).getExpression(); |
|
106 |
int predictLength = itemEntityFactory.getItemById(itemId).getPredictLength(); |
|
107 |
double[] predictResultMat = new double[predictLength]; |
|
108 |
String[] mathOutPutId = expression.split("[\\+ \\-]"); |
|
109 |
ArrayList<Character> operator = new ArrayList<>(); |
|
110 |
for (int i = 0; i < expression.length(); i++) { |
|
111 |
if (expression.charAt(i) == '+' || expression.charAt(i) == '-') { |
|
112 |
operator.add(expression.charAt(i)); |
|
113 |
} |
|
114 |
} |
|
115 |
Map<String, double[]> predictValueMap = new HashMap<>(); |
|
116 |
for (int k = 0; k < mathOutPutId.length; k++) { |
|
117 |
String outPutId = mathOutPutId[k]; |
|
118 |
double[] outPutValue = stAdjustResultService.getSimpleData(outPutId, predictTime, predictLength); |
|
119 |
if (outPutValue == null) { |
|
120 |
outPutValue = mmItemResultJsonService.getSimpleData(outPutId, predictTime, predictLength); |
|
121 |
} |
|
122 |
predictValueMap.put(outPutId, outPutValue); |
|
123 |
} |
|
124 |
|
|
125 |
//是否为计算预测项 |
|
126 |
if (mathOutPutId.length > 1) { |
|
127 |
for (int i = 0; i < predictLength; i++) { |
|
128 |
double sum = predictValueMap.get(mathOutPutId[0])[i]; |
|
129 |
for (int j = 1; j < mathOutPutId.length; j++) { |
|
130 |
if (operator.get(j - 1) == '+') { |
|
131 |
sum += predictValueMap.get(mathOutPutId[j])[i]; |
|
132 |
} |
|
133 |
if (operator.get(j - 1) == '-') { |
|
134 |
sum -= predictValueMap.get(mathOutPutId[j])[i]; |
|
135 |
} |
|
136 |
} |
|
137 |
predictResultMat[i] = sum; |
|
138 |
} |
|
139 |
} |
|
140 |
predictResult.setPredictId(itemId); |
|
141 |
List<MmItemOutputEntity> outputServiceByItemid = mmItemOutputService.getByItemid(itemId); |
|
142 |
if (!CollectionUtils.isEmpty(outputServiceByItemid)) { |
|
143 |
Map<MmItemOutputEntity, double[]> predictMatrixs = new HashMap<>(); |
|
144 |
predictMatrixs.put(outputServiceByItemid.get(0), predictResultMat); |
de1b3b
|
145 |
predictResult.setPredictMatrixs(predictMatrixs); |
D |
146 |
} |
7fd198
|
147 |
predictResult.setPredictTime(predictTime); |
潘 |
148 |
} catch (Exception e) { |
fde993
|
149 |
log.error("merge项预测失败,itemId:" + itemId); |
D |
150 |
e.printStackTrace(); |
7fd198
|
151 |
throw e; |
潘 |
152 |
} |
fde993
|
153 |
log.info("merge项预测完成,itemId:" + itemId + ",结果:" + JSON.toJSONString(predictResult)); |
7fd198
|
154 |
return predictResult; |
潘 |
155 |
} |
|
156 |
} |