InverterAnalysis2.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.gyee.power.fitting.dispersionanalysis;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.gyee.power.fitting.common.feign.RemoteServiceBuilder;
  5. import com.gyee.power.fitting.common.result.JsonResult;
  6. import com.gyee.power.fitting.common.result.ResultCode;
  7. import com.gyee.power.fitting.model.ProBasicEquipment;
  8. import com.gyee.power.fitting.model.ProBasicEquipmentPoint;
  9. import com.gyee.power.fitting.model.ProEconEquipmentmodel;
  10. import com.gyee.power.fitting.model.custom.TsDoubleData;
  11. import com.gyee.power.fitting.service.ProBasicEquipmentPointService;
  12. import com.gyee.power.fitting.service.ProBasicEquipmentService;
  13. import com.gyee.power.fitting.service.ProEconEquipmentmodelService;
  14. import org.springframework.web.bind.annotation.*;
  15. import javax.annotation.Resource;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.stream.Collectors;
  21. //等效发电时分析
  22. @CrossOrigin
  23. @RequestMapping("/equivalent")
  24. @RestController
  25. public class InverterAnalysis2 {
  26. @Resource
  27. private ProBasicEquipmentService proBasicEquipmentService;
  28. @Resource
  29. private ProEconEquipmentmodelService proEconEquipmentmodelService;
  30. @Resource
  31. private ProBasicEquipmentPointService proBasicEquipmentPointService;
  32. @Resource
  33. private RemoteServiceBuilder remoteService;
  34. // 计算等效发电时的标准差
  35. private static double calculateStandardDeviationEquivalentOperatingHours(Map<String, Double> data, double average) {
  36. double sum = 0.0;
  37. for (double value : data.values()) {
  38. sum += Math.pow(value - average, 2);
  39. }
  40. return Math.sqrt(sum / data.size());
  41. }
  42. @GetMapping("/powertime")
  43. private JSONObject getFileList(
  44. @RequestParam(value = "station", required = true) String station,
  45. @RequestParam(value = "inverters", required = false) List<String> inverters,
  46. @RequestParam(value = "startdate", required = true) long startdate,
  47. @RequestParam(value = "enddate", required = true) long enddate) {
  48. //获取逆变器
  49. QueryWrapper<ProBasicEquipment> eWrapper = new QueryWrapper<>();
  50. eWrapper.eq("spare1", "IN").eq("windpowerstation_id", station);
  51. List<ProBasicEquipment> eList = proBasicEquipmentService.list(eWrapper);
  52. List<String> inverterIds = eList.stream().map(ProBasicEquipment::getId).collect(Collectors.toList());
  53. //逆变器id,机型
  54. Map<String, String> inverterModelMap = eList.stream().collect(Collectors.toMap(ProBasicEquipment::getId, ProBasicEquipment::getModelId));
  55. //获取机型的装机容量
  56. List<ProEconEquipmentmodel> emList = proEconEquipmentmodelService.list();
  57. //机型、装机容量
  58. Map<String, Double> emMap = emList.stream().collect(Collectors.toMap(ProEconEquipmentmodel::getNemCode, ProEconEquipmentmodel::getPowerProduction));
  59. //获取年发电量
  60. QueryWrapper<ProBasicEquipmentPoint> epWrapper = new QueryWrapper<>();
  61. epWrapper.eq("uniform_code", "NFDL").eq("windpowerstation_id", station).like("windturbine_id", "_IN_");
  62. List<ProBasicEquipmentPoint> epList = proBasicEquipmentPointService.list(epWrapper);
  63. String points = epList.stream().map(ProBasicEquipmentPoint::getNemCode).collect(Collectors.joining(","));
  64. //逆变器id,测点
  65. Map<String, String> epMap = epList.stream().collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
  66. //开始、结束时间的年发电量
  67. Map<String, TsDoubleData> startSection = remoteService.adaptergf().getHistorySection(points, startdate);
  68. Map<String, TsDoubleData> endSection = remoteService.adaptergf().getHistorySection(points, enddate);
  69. // 模拟全站逆变单元的发电数据,这里用一个Map来表示每个逆变单元的发电量
  70. Map<String, Double> dxfdsData = new HashMap<>();
  71. double dxfdsSum = 0;//等效发电时之和
  72. for (String s : inverterIds) {
  73. double dxfds = calculateEquivalentOperatingHours(endSection.get(s).getDoubleValue() - startSection.get(s).getDoubleValue(), emMap.get(inverterModelMap.get(s)));
  74. dxfdsSum += dxfds;
  75. dxfdsData.put(s, dxfds);
  76. }
  77. // 时间段,以小时为单位
  78. //double hours = DateUtil.between(new Date(startdate),new Date(enddate), DateUnit.HOUR);
  79. // 计算等效发电时的平均值
  80. double average = dxfdsSum / inverterIds.size();
  81. // 计算等效发电时的标准差
  82. double stdDeviation = calculateStandardDeviationEquivalentOperatingHours(dxfdsData, average);
  83. // 存储极差逆变单元的列表
  84. List<String> outlierInverters = new ArrayList<>();
  85. // 进行等效发电时分析并找出极差逆变单元
  86. List<InverterData2> inverterData2s = new ArrayList<>();
  87. dxfdsData.forEach((k, v) -> {
  88. // 判断逆变单元的运行水平并根据枚举值进行分类
  89. String currentLevel = determineOperatingLevel(v, average, stdDeviation);
  90. inverterData2s.add(new InverterData2(k, v, average, currentLevel, "等效发电时"));
  91. });
  92. return JsonResult.successData(ResultCode.SUCCESS, inverterData2s);
  93. }
  94. // 计算等效发电时
  95. private double calculateEquivalentOperatingHours(double power, double installedCapacity) {
  96. if (installedCapacity == 0) return 0;
  97. return power / installedCapacity;
  98. }
  99. // 根据等效发电时、平均值和标准差确定运行水平
  100. private String determineOperatingLevel(double equivalentOperatingHours, double average, double stdDeviation) {
  101. double deviation = equivalentOperatingHours - average;
  102. // 使用标准差的倍数来判断运行水平
  103. if (deviation > 2 * stdDeviation) {
  104. return "优秀";
  105. } else if (deviation > stdDeviation) {
  106. return "良好";
  107. } else if (deviation >= -stdDeviation && deviation <= stdDeviation) {
  108. return "平均";
  109. } else if (deviation >= -2 * stdDeviation) {
  110. return "差";
  111. } else {
  112. return "非常差";
  113. }
  114. }
  115. }