|
@@ -0,0 +1,154 @@
|
|
|
+package com.gyee.power.fitting.service.custom.curve;
|
|
|
+
|
|
|
+
|
|
|
+import com.gyee.power.fitting.common.config.GyeeConfig;
|
|
|
+import com.gyee.power.fitting.common.feign.RemoteServiceBuilder;
|
|
|
+import com.gyee.power.fitting.common.spring.InitialRunner;
|
|
|
+import com.gyee.power.fitting.common.util.DateUtil;
|
|
|
+import com.gyee.power.fitting.common.util.FileUtil;
|
|
|
+import com.gyee.power.fitting.model.Powerfittinganalysis;
|
|
|
+import com.gyee.power.fitting.model.ProBasicEquipmentPoint;
|
|
|
+import com.gyee.power.fitting.model.anno.AnnotationTool;
|
|
|
+import com.gyee.power.fitting.model.anno.FixedVo;
|
|
|
+import com.gyee.power.fitting.model.custom.NewDataFittingVo;
|
|
|
+import com.gyee.power.fitting.model.custom.PowerPointData;
|
|
|
+import com.gyee.power.fitting.model.custom.TsDoubleData;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import lombok.val;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class NewDataFittingService {
|
|
|
+ @Autowired
|
|
|
+ private GyeeConfig config;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RemoteServiceBuilder remoteService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Powerfittinganalysis newDataFitting(NewDataFittingVo vo) {
|
|
|
+
|
|
|
+ Map<String,String> prepareMap = new HashMap<>();
|
|
|
+
|
|
|
+ Map<String,String> processMap = new HashMap<>();
|
|
|
+
|
|
|
+ Map<String,String> fittingMap = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ //1.数据获取
|
|
|
+ List<String> wtIds = Arrays.asList(vo.getWtIds().split(","));
|
|
|
+ for (int k = 0; k < wtIds.size(); k++) {
|
|
|
+ String wt = wtIds.get(k);
|
|
|
+ List<List<TsDoubleData>> result = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<String> points = config.getPoints();
|
|
|
+ Map<String, List<ProBasicEquipmentPoint>> collect = InitialRunner.pointNewMap.get(wt).stream().collect(Collectors.groupingBy(w -> w.getUniformCode()));
|
|
|
+ if (collect.size() < 8)
|
|
|
+ continue;
|
|
|
+ for (int i = 0; i < points.size(); i++) {
|
|
|
+ ProBasicEquipmentPoint point = collect.get(points.get(i)).get(0);
|
|
|
+ log.info("测点:" + point.getId() + "----" + point.getName());
|
|
|
+ List<TsDoubleData> data = remoteService.adapter().getHistorySnap(point.getId(), vo.getSt(), vo.getEt(), vo.getInterval());
|
|
|
+ if (data == null || data.size() < 0)
|
|
|
+ break;
|
|
|
+ result.add(data);
|
|
|
+ TimeUnit.MILLISECONDS.sleep(200);
|
|
|
+ }
|
|
|
+ if (result.size() != points.size())
|
|
|
+ continue;
|
|
|
+
|
|
|
+ String content = assemble(result);
|
|
|
+ // 处理的数据保存在本地
|
|
|
+ String wtCode = InitialRunner.wtNewMap.get(wt).getNemCode();
|
|
|
+ String fileName = config.getFilePathPrepare() + vo.getStation() + "_" + wtCode + "_" + System.currentTimeMillis() / 1000 + ".csv";
|
|
|
+ boolean flag = FileUtil.writeFile(fileName, content);
|
|
|
+ prepareMap.put(fileName,content);//保存拿到的数据
|
|
|
+
|
|
|
+ System.out.println("数据准备完成:" + wt);
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.数据筛选
|
|
|
+
|
|
|
+// for (String key : prepareMap.keySet()){
|
|
|
+//
|
|
|
+//
|
|
|
+// /** 读取csv数据 转换成对象数组 **/
|
|
|
+// List<PowerPointData> eis = new ArrayList<>();
|
|
|
+// List<String> list = FileUtil.readFile(obj.getPath(), true);
|
|
|
+// for (int i = 1; i < list.size(); i++) {
|
|
|
+// eis.add(new PowerPointData(list.get(i).split(","), false));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /** 风速 -> 保证功率 来自数据库 **/
|
|
|
+// List<Modelpowerdetails> modelPowerList = InitialRunner.modelPowerDetailMap.get(InitialRunner.wtMap.get(obj.getWindturbine()).getModelid());
|
|
|
+// Map<Double, Double> modelPowerMap = modelPowerList.stream().collect(Collectors.toMap(Modelpowerdetails::getSpeed, Modelpowerdetails::getEnsurepower));
|
|
|
+// /** 数据预处理 **/
|
|
|
+// List<PowerPointData> data = PowerProcessALG.dataProcess(eis, modelPowerMap, maxs, mins, maxp, minp, isfbw, isfhl, isbw, istj, isglpc, isqfh, qfhdj);
|
|
|
+// /** 静风频率 **/
|
|
|
+// List<Double> ls = WindDirectionALG.frequency(data.stream().map(PowerPointData::getSpeed).collect(Collectors.toList()), 3);
|
|
|
+// double frequency = ls.get(0);
|
|
|
+// double speed = ls.get(1);
|
|
|
+//
|
|
|
+// String content = assemble(data);
|
|
|
+// String fileName = config.getFilePathProcess() + obj.getStation() + "_" + obj.getCode() + "_" + SnowFlakeUtil.generateIdL() / 100000 + ".csv";
|
|
|
+// boolean flag = FileUtil.writeFile(fileName, content);
|
|
|
+// if (flag) { // TODO 保存数据库
|
|
|
+// obj.setPath(fileName);
|
|
|
+// obj.setFrequency(frequency);
|
|
|
+// obj.setSpeedavg(speed);
|
|
|
+// obj.setType(Constants.DATA_PROCESS);
|
|
|
+// powerService.insertItem(obj);
|
|
|
+// }
|
|
|
+// System.out.println("功率曲线拟合数据预处理完成:" + obj.getWindturbine());
|
|
|
+// }
|
|
|
+ //3.数据拟合
|
|
|
+
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String assemble(List<List<TsDoubleData>> list){
|
|
|
+ if (list.size() == 0)
|
|
|
+ return null;
|
|
|
+
|
|
|
+ StringBuilder sb = setTitle();
|
|
|
+ List<TsDoubleData> data = list.get(0);
|
|
|
+ for (int i = 0; i < data.size(); i++){
|
|
|
+ sb.append(DateUtil.format(data.get(i).getTs(), DateUtil.DATE_TIME_PATTERN)).append(",");
|
|
|
+ sb.append(data.get(i).getDoubleValue()).append(",");
|
|
|
+ for (int j = 1; j < list.size(); j++){
|
|
|
+ sb.append(list.get(j).get(i).getDoubleValue()).append(",");
|
|
|
+ }
|
|
|
+ sb.deleteCharAt(sb.lastIndexOf(","));
|
|
|
+ sb.append("\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private StringBuilder setTitle(){
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ val list = AnnotationTool.getFixedVoList(PowerPointData.class);
|
|
|
+ String columnName = list.stream().filter(f -> f.getRemark().equals("1")).map(FixedVo::getDes).collect(Collectors.joining(","));
|
|
|
+ sb.append(columnName).append("\n");
|
|
|
+ return sb;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|