소스 검색

功率曲线拟合接口修改调试

王波 1 개월 전
부모
커밋
816d1f392a

+ 3 - 3
runeconomy-xk/src/main/java/com/gyee/runeconomy/config/GyeeConfig.java

@@ -98,7 +98,7 @@ public class GyeeConfig {
     }
 
     public String getFilePathPrepare() {
-        return jarF.getParentFile().getAbsolutePath() + "\\" + filePathPrepare;
+        return jarF.getParentFile().getAbsolutePath() + File.separator +  filePathPrepare;
     }
 
     public void setFilePathPrepare(String filePathPrepare) {
@@ -106,7 +106,7 @@ public class GyeeConfig {
     }
 
     public String getFilePathProcess() {
-        return jarF.getParentFile().getAbsolutePath() + "\\" + filePathProcess;
+        return jarF.getParentFile().getAbsolutePath() + File.separator + filePathProcess;
     }
 
     public void setFilePathProcess(String filePathProcess) {
@@ -114,7 +114,7 @@ public class GyeeConfig {
     }
 
     public String getFilePathFitting() {
-        return jarF.getParentFile().getAbsolutePath() + "\\" + filePathFitting;
+        return jarF.getParentFile().getAbsolutePath() + File.separator + filePathFitting;
     }
 
     public void setFilePathFitting(String filePathFitting) {

+ 21 - 5
runeconomy-xk/src/main/java/com/gyee/runeconomy/controller/NewDataFittingController.java

@@ -26,13 +26,29 @@ public class NewDataFittingController {
 
     /**
      * 功率曲线拟合
-     * @param newDataFittingVo
+     * @param
      * @return
      */
-    @PostMapping("/data")
-    public JSONObject dataFitting(@RequestBody NewDataFittingVo newDataFittingVo ) {
-
-        ProEconPowerFittingAnalySis obj = newDataFittingService.newDataFitting(newDataFittingVo);
+    @GetMapping("/data")
+    public JSONObject dataFitting(@RequestParam(value = "station",  required = false) String station,
+                                  @RequestParam(value = "wtIds",  required = false) String wtIds,
+                                  @RequestParam(value = "st",  required = false) Long st,
+                                  @RequestParam(value = "et",  required = false) Long et,
+                                  @RequestParam(value = "interval",  required = false) Integer interval,
+                                  @RequestParam(value = "isbw",  required = false) Boolean isbw,
+                                  @RequestParam(value = "isfbw",  required = false) Boolean isfbw,
+                                  @RequestParam(value = "isfhl",  required = false) Boolean isfhl,
+                                  @RequestParam(value = "istj",  required = false) Boolean istj,
+                                  @RequestParam(value = "isglpc",  required = false) Boolean isglpc,
+                                  @RequestParam(value = "maxp",  required = false) double maxp,
+                                  @RequestParam(value = "maxs",  required = false) double maxs,
+                                  @RequestParam(value = "mins",  required = false) double mins,
+                                  @RequestParam(value = "minp",  required = false) double minp,
+                                  @RequestParam(value = "mode",  required = false) Integer mode,
+                                  @RequestParam(value = "dimension",  required = false) Integer dimension
+    ) {
+
+        ProEconPowerFittingAnalySis obj = newDataFittingService.newDataFitting(station,wtIds,st,et,interval,isbw,isfbw,isfhl,istj,isglpc,maxp,maxs,mins,minp,mode,dimension);
         return JsonResult.successData(ResultCode.SUCCESS, obj);
 
     }

+ 1 - 1
runeconomy-xk/src/main/java/com/gyee/runeconomy/model/auto/ProEconPowerFittingAnalySis.java

@@ -24,7 +24,7 @@ public class ProEconPowerFittingAnalySis extends Model<ProEconPowerFittingAnalyS
 
     private static final long serialVersionUID=1L;
 
-    @TableId(value = "id", type = IdType.ASSIGN_UUID)
+    @TableId(value = "ID", type = IdType.ASSIGN_ID)
     private String id;
 
     private String station;

+ 1 - 4
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/agc/AgcDeviateService.java

@@ -91,10 +91,7 @@ public class AgcDeviateService {
         int baseSize4 = ladt.get(3).getValues().size();
         int baseSize5 = ladt.get(4).getValues().size();
 
-
-        // 假设 'ladt' 是你的 AgcDeviateTag 对象的 ArrayList
-
-        // 首先,从 "理论功率" 中找到参考尺寸
+        // 首先,从 "理论功率" 中找到参考数量
         int referenceSize = -1;
         for (AgcDeviateTag tag : ladt) {
             if ("理论功率".equals(tag.getName())) {

+ 120 - 39
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/auto/impl/NewDataFittingService.java

@@ -1,5 +1,6 @@
 package com.gyee.runeconomy.service.auto.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.gyee.runeconomy.config.GyeeConfig;
 import com.gyee.runeconomy.dto.FiveLoss.AnnotationTool;
@@ -15,13 +16,11 @@ import com.gyee.runeconomy.model.PowerProcessALG;
 import com.gyee.runeconomy.model.auto.ProBasicEquipmentPoint;
 import com.gyee.runeconomy.model.auto.ProBasicModelPower;
 import com.gyee.runeconomy.model.auto.ProEconPowerFittingAnalySis;
-import com.gyee.runeconomy.model.vo.NewDataFittingVo;
 import com.gyee.runeconomy.model.vo.PointVo;
 import com.gyee.runeconomy.service.DBSCANPointALG;
 import com.gyee.runeconomy.service.DataScanService;
 import com.gyee.runeconomy.service.WindDirection.Point;
 import com.gyee.runeconomy.util.FileUtil;
-import com.gyee.runeconomy.util.SnowFlakeUtil;
 import com.gyee.runeconomy.util.realtimesource.feign.RemoteServiceBuilder;
 import com.gyee.runeconomy.util.realtimesource.feign.TsDoubleData;
 import lombok.extern.slf4j.Slf4j;
@@ -30,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.io.File;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -71,16 +71,16 @@ public class NewDataFittingService {
     /**
      * 数据准备拟合
      *
-     * @param vo
+     * @param
      * @return
      */
-    public ProEconPowerFittingAnalySis newDataFitting(NewDataFittingVo vo) {
+    public ProEconPowerFittingAnalySis newDataFitting(String station,String wtId,Long st,Long et,Integer interval,Boolean isbw,Boolean isfbw,Boolean isfhl,Boolean istj,Boolean isglpc,double maxp,double maxs,double mins,double minp,Integer mode,Integer dimension) {
         prepareMap = new HashMap<>();
         processMap = new HashMap<>();
         fittingMap = new HashMap<>();
 
         //1.数据获取
-        List<String> wtIds = Arrays.asList(vo.getWtIds().split(","));
+        List<String> wtIds = Arrays.asList(wtId.split(","));
         //        deleteDir(config.getFilePathPrepare());
         for (int k = 0; k < wtIds.size(); k++) {
             String wt = wtIds.get(k);
@@ -96,7 +96,7 @@ public class NewDataFittingService {
                     ProBasicEquipmentPoint point = collect.get(points.get(i)).get(0);
                     if (point == null) continue;
                     log.info("测点:" + point.getId() + "----" + point.getName());
-                    List<TsDoubleData> data = remoteService.adapterfd().getHistorySnap(point.getNemCode(), vo.getSt(), vo.getEt(), vo.getInterval());
+                    List<TsDoubleData> data = remoteService.adapterfd().getHistorySnap(point.getNemCode(), st, et, interval);
                     //                    List<TsDoubleData> data = edosUtil.getHistorySnap(point.getNemCode(), vo.getSt(), vo.getEt(), vo.getInterval());
                     //                    List<PointData> data = edosUtil.getHistoryDatasSnap(point.getNemCode(), vo.getSt(), vo.getEt(), vo.getInterval());
                     if (data == null || data.size() == 0)
@@ -107,26 +107,46 @@ public class NewDataFittingService {
                 if (result.size() != points.size())
                     continue;
 
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
                 String content = prepareAssemble(result);
                 //                 处理的数据保存在本地
                 String wtCode = CacheContext.wtmap.get(wt).getId();
                 String wtCode2 = CacheContext.wtmap.get(wt).getNemCode();
-                String fileName = config.getFilePathPrepare() + vo.getStation() + "_" + wtCode + "_" + System.currentTimeMillis() / 1000 + ".csv";
+//                String fileName = config.getFilePathPrepare() + station + "_" + wtCode + "_" + System.currentTimeMillis() / 1000 + ".csv";
+                String fileName = config.getFilePathPrepare() + station + "_" + wtCode + "_" + sdf.format(new Date(st)) + "-" + sdf.format(new Date(et)) + ".csv";
+
+                // 创建 File 对象
+                File file = new File(fileName);
+                // 检查文件是否存在
+                if (file.exists()) {
+                    // 尝试删除文件
+                    boolean isDeleted = file.delete();
+                    if (isDeleted) {
+                        System.out.println("文件删除成功: " + fileName);
+                    } else {
+                        System.out.println("文件删除失败: " + fileName);
+                    }
+                } else {
+                    System.out.println("文件不存在: " + fileName);
+                }
+
                 boolean flag = FileUtil.writeFile(fileName, content);
 
                 if (flag) {  // TODO  保存数据库
                     ProEconPowerFittingAnalySis obj = new ProEconPowerFittingAnalySis();
-                    obj.setStation(vo.getStation());
-                    obj.setStationcn(CacheContext.wtstandardmap.get(vo.getStation()));
+                    obj.setStation(station);
+                    obj.setStationcn(CacheContext.wtstandardmap.get(station));
                     obj.setWindturbineId(wt);
                     obj.setCode(wtCode2);
                     //                    obj.setTime(DateUtil.format(vo.getSt(), "yyyy年MM月dd日") + "-" + DateUtil.format(vo.getEt(), "yyyy年MM月dd日"));
-                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
-                    obj.setTime(sdf.format(new Date(vo.getSt())) + "-" + sdf.format(new Date(vo.getEt())));
-                    obj.setInterval(vo.getInterval().toString());
+
+                    obj.setTime(sdf.format(new Date(st)) + "-" + sdf.format(new Date(et)));
+                    obj.setInterval(String.valueOf(interval));
                     obj.setPath(fileName);
                     obj.setType("prepare");
-                    obj.setInterp(vo.getInterval());
+                    obj.setInterp(interval);
+
+                    proEconPowerFittingAnalySisService.delete(obj.getTime(), fileName);
                     proEconPowerFittingAnalySisService.saveOrUpdate(obj);
                     prepareMap.put(obj.getId(), fileName);//保存拿到的数据
                 }
@@ -155,24 +175,52 @@ public class NewDataFittingService {
                 List<ProBasicModelPower> modelPowerList = CacheContext.modelPowerDetailNewMap.get(CacheContext.wtmap.get(obj.getWindturbineId()).getModelId());
                 Map<Double, Double> modelPowerMap = modelPowerList.stream().collect(Collectors.toMap(ProBasicModelPower::getSpeed, ProBasicModelPower::getEnsurePower));
                 /** 数据预处理 **/
-                List<PowerPointData> data = PowerProcessALG.dataProcess(eis, modelPowerMap, vo.getMaxs(), vo.getMins(), vo.getMaxp(), vo.getMinp(), vo.getIsfbw(), vo.getIsfhl(), vo.getIsbw(), vo.getIstj(), vo.getIsglpc(), vo.getIsqfh(), vo.getQfhdj());
+                Boolean qfh = true;
+                Integer qfhdj = 2;
+                List<PowerPointData> data = PowerProcessALG.dataProcess(eis, modelPowerMap, maxs, mins, maxp, minp, isfbw, isfhl, isbw, istj, isglpc, qfh, 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 = processAssemble(data);
-                String fileName = config.getFilePathProcess() + vo.getStation() + "_" + obj.getWindturbineId() + "_" + SnowFlakeUtil.generateIdL() / 100000 + ".csv";
-                boolean flag = FileUtil.writeFile(fileName, content);
+//                String fileName = config.getFilePathProcess() + station + "_" + obj.getWindturbineId() + "_" + SnowFlakeUtil.generateIdL() / 100000 + ".csv";
+                String fileName = config.getFilePathProcess() + station + "_" + obj.getWindturbineId() + "_" + obj.getTime() + ".csv";
+
+                // 创建 File 对象
+                File file = new File(fileName);
+                // 检查文件是否存在
+                if (file.exists()) {
+                    // 尝试删除文件
+                    boolean isDeleted = file.delete();
+                    if (isDeleted) {
+                        System.out.println("文件删除成功: " + fileName);
+                    } else {
+                        System.out.println("文件删除失败: " + fileName);
+                    }
+                } else {
+                    System.out.println("文件不存在: " + fileName);
+                }
+
 
+                boolean flag = FileUtil.writeFile(fileName, content);
+                ProEconPowerFittingAnalySis obj1 = new ProEconPowerFittingAnalySis();
                 if (flag) {  // TODO  保存数据库
                     //                    obj.setId(null);
-                    obj.setPath(fileName);
-                    obj.setFrequency(frequency);
-                    obj.setSpeedavg(speed);
-                    obj.setType(DATA_PROCESS);
-                    proEconPowerFittingAnalySisService.saveOrUpdate(obj);
-                    processMap.put(obj.getId(), fileName);//保存预处理的的数据
+                    obj1.setStation(station);
+                    obj1.setStationcn(CacheContext.wtstandardmap.get(station));
+                    obj1.setWindturbineId(obj.getWindturbineId());
+                    obj1.setCode(obj.getCode());
+                    obj1.setTime(obj.getTime());
+                    obj1.setPath(fileName);
+                    obj1.setFrequency(frequency);
+                    obj1.setSpeedavg(speed);
+                    obj1.setInterval(obj.getInterval());
+                    obj1.setType(DATA_PROCESS);
+
+                    proEconPowerFittingAnalySisService.delete(obj1.getTime(), fileName);
+                    proEconPowerFittingAnalySisService.saveOrUpdate(obj1);
+                    processMap.put(obj1.getId(), fileName);//保存预处理的的数据
                 }
 
                 System.out.println("功率曲线拟合数据预处理完成:" + obj.getWindturbineId());
@@ -184,7 +232,7 @@ public class NewDataFittingService {
 
         AtomicReference<ProEconPowerFittingAnalySis> object = new AtomicReference<>();
         //        deleteDir(config.getFilePathFitting());
-        if (vo.getMode() == 0) {  //单台拟合
+        if (mode == 0) {  //单台拟合
             for (String processkey : processMap.keySet()) {
                 List<ProEconPowerFittingAnalySis> list = proEconPowerFittingAnalySisService.selectListByIds(processkey);
                 List<Double> arraySpeed = new ArrayList<>();
@@ -193,14 +241,14 @@ public class NewDataFittingService {
                 //                String content = processAssemble(dataFilter);
                 //                String[] lines = content.split("\n");
                 //                List<String> line = new ArrayList<>(Arrays.asList(lines));
-                csvParse(line, arraySpeed, arrayPower, vo.getMins(), vo.getMaxs(), vo.getMinp(), vo.getMaxp());
+                csvParse(line, arraySpeed, arrayPower, mins, maxs, minp, maxp);
                 List<ProBasicModelPower> mp = CacheContext.modelPowerDetailNewMap.get(CacheContext.wtmap.get(list.get(0).getWindturbineId()).getModelId());
                 Double maxP = mp.stream().map(ProBasicModelPower::getEnsurePower).max(Comparator.comparing(Double::doubleValue)).get();
-                object.set(fittingMode(list, maxP, arraySpeed, arrayPower, vo.getDimension(), vo.getMode()));
+                object.set(fittingMode(list, maxP, arraySpeed, arrayPower, dimension, mode));
 
             }
         }
-        if (vo.getMode() == 1) {  //合并拟合
+        if (mode == 1) {  //合并拟合
 
             AtomicReference<Double> maxP = new AtomicReference<>(0.0);
             List<Double> arraySpeed = new ArrayList<>();
@@ -213,16 +261,16 @@ public class NewDataFittingService {
                 //                String content = processAssemble(dataFilter);
                 //                String[] lines = content.split("\n");
                 //                List<String> line = new ArrayList<>(Arrays.asList(lines));
-                csvParse(line, arraySpeed, arrayPower, vo.getMins(), vo.getMaxs(), vo.getMinp(), vo.getMaxp());
+                csvParse(line, arraySpeed, arrayPower, mins, maxs, minp, maxp);
                 List<ProBasicModelPower> mp = CacheContext.modelPowerDetailNewMap.get(CacheContext.wtmap.get(fittingAnalySis.getWindturbineId()).getModelId());
                 Double maxPower = mp.stream().map(ProBasicModelPower::getEnsurePower).max(Comparator.comparing(Double::doubleValue)).get();
                 if (maxPower > maxP.get()) maxP.set(maxPower);
             }
             List<ProEconPowerFittingAnalySis> list = proEconPowerFittingAnalySisService.selectListByIds(ids.toString());
 
-            object.set(fittingMode(list, maxP.get(), arraySpeed, arrayPower, vo.getDimension(), vo.getMode()));
+            object.set(fittingMode(list, maxP.get(), arraySpeed, arrayPower, dimension, mode));
         }
-        if (vo.getMode() == 2) {
+        if (mode == 2) {
             //同名拟合(暂时不支持)
         }
         fittingMap.put(object.get().getId(), object.get().getPath());
@@ -411,6 +459,14 @@ public class NewDataFittingService {
         return sb;
     }
 
+    private StringBuilder setTitleFitting() {
+        StringBuilder sb = new StringBuilder();
+        val list = AnnotationTool.getFixedVoList(PowerFittingData.class);
+        String columnName = list.stream().filter(f -> f.getRemark().equals("1")).map(FixedVo::getDes).collect(Collectors.joining(","));
+        sb.append(columnName).append("\n");
+        return sb;
+    }
+
 
     /**
      * 读取csv数据 转换成对象数组
@@ -461,28 +517,53 @@ public class NewDataFittingService {
         String fileName = null;
         if (mode == 0) {
             processId = obj.getId();
-            fileName = config.getFilePathFitting() + obj.getStation() + "_" + obj.getCode() + "_" + SnowFlakeUtil.generateIdL() / 100000 + ".csv";
+//            fileName = config.getFilePathFitting() + obj.getStation() + "_" + obj.getCode() + "_" + SnowFlakeUtil.generateIdL() / 100000 + ".csv";
+            fileName = config.getFilePathFitting() + obj.getStation() + "_" + obj.getCode() + "_" + obj.getTime() + ".csv";
         }
         if (mode == 1) {
             processId = list.stream().map(d -> d.getId()).collect(Collectors.joining(","));
-            fileName = config.getFilePathFitting() + obj.getStation() + "_merge" + "_" + SnowFlakeUtil.generateIdL() / 100000 + ".csv";
+            fileName = config.getFilePathFitting() + obj.getStation() + "_merge" + "_" + obj.getTime() + ".csv";
         }
         if (mode == 2) {
             processId = list.stream().map(d -> d.getId()).collect(Collectors.joining(","));
-            fileName = config.getFilePathFitting() + obj.getStation() + "_same" + "_" + SnowFlakeUtil.generateIdL() / 100000 + ".csv";
+            fileName = config.getFilePathFitting() + obj.getStation() + "_same" + "_" + obj.getTime() + ".csv";
+        }
+
+        // 创建 File 对象
+        File file = new File(fileName);
+        // 检查文件是否存在
+        if (file.exists()) {
+            // 尝试删除文件
+            boolean isDeleted = file.delete();
+            if (isDeleted) {
+                System.out.println("文件删除成功: " + fileName);
+            } else {
+                System.out.println("文件删除失败: " + fileName);
+            }
+        } else {
+            System.out.println("文件不存在: " + fileName);
         }
+        ProEconPowerFittingAnalySis obj2 = new ProEconPowerFittingAnalySis();
         boolean flag = FileUtil.writeFile(fileName, content);
         if (flag) {  // TODO  保存数据库
             //        obj.setId(null);
-            obj.setPath(fileName);
-            obj.setProcessid(processId);
-            obj.setCpavg(lf.getCpAvg());
-            obj.setType(DATA_FITTING);
-            proEconPowerFittingAnalySisService.saveOrUpdate(obj);
+
+            obj2.setCode(obj.getCode());
+            obj2.setStation(obj.getStation());
+            obj2.setTime(obj.getTime());
+            obj2.setWindturbineId(obj.getWindturbineId());
+            obj2.setPath(fileName);
+            obj2.setInterval(obj.getInterval());
+            obj2.setProcessid(processId);
+            obj2.setCpavg(lf.getCpAvg());
+            obj2.setType(DATA_FITTING);
+
+            proEconPowerFittingAnalySisService.delete(obj2.getTime(), fileName);
+            proEconPowerFittingAnalySisService.saveOrUpdate(obj2);
         }
         System.out.println("功率曲线拟合完成:" + obj.getWindturbineId());
 
-        return obj;
+        return obj2;
     }
 
 
@@ -562,7 +643,7 @@ public class NewDataFittingService {
     }
 
     private String fittingAssemble(LineCurveFitting lf) {
-        StringBuilder sb = setTitle();
+        StringBuilder sb = setTitleFitting();
         for (int i = 0; i < lf.getYLines().size(); i++) {
             Point cp = lf.getCpValue().get(i);
             Point gl = lf.getYLines().get(i);

+ 1 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/auto/impl/ProEconPowerFittingAnalySisService.java

@@ -16,6 +16,7 @@ import java.util.List;
 public interface ProEconPowerFittingAnalySisService extends IService<ProEconPowerFittingAnalySis> {
 
     ProEconPowerFittingAnalySis selectItemById(String id);
+    ProEconPowerFittingAnalySis delete(String time,String fileName);
 
     /**
      * 根据类型查询

+ 9 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/auto/impl/ProEconPowerFittingAnalySisServiceImpl.java

@@ -38,6 +38,15 @@ public class ProEconPowerFittingAnalySisServiceImpl extends ServiceImpl<ProEconP
     }
 
     @Override
+    public ProEconPowerFittingAnalySis delete(String time, String fileName) {
+        QueryWrapper<ProEconPowerFittingAnalySis> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("time",time);
+        queryWrapper.eq("path", fileName);
+        int delete = baseMapper.delete(queryWrapper);
+        return null;
+    }
+
+    @Override
     public List<ProEconPowerFittingAnalySis> selectList(List<String> stations,String type) {
         List<ProEconPowerFittingAnalySis> list = new ArrayList();
 

+ 3 - 3
runeconomy-xk/src/main/resources/application-nxf.yml

@@ -97,9 +97,9 @@ appendSation:
 
 
 powerCurveFitting:
-  prepare: prepare
-  process: process
-  fitting: fitting
+  prepare: data\prepare\
+  process: data\process\
+  fitting: data\fitting\
   # 功率曲线离线数据保存路径
   file-path-power: data\power\