CoefficientService.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. package com.gyee.generation.service;
  2. import com.gyee.common.contant.ContantXk;
  3. import com.gyee.common.model.PointData;
  4. import com.gyee.generation.init.CacheContext;
  5. import com.gyee.generation.model.auto.ProBasicEquipment;
  6. import com.gyee.generation.model.auto.ProBasicEquipmentPoint;
  7. import com.gyee.generation.model.auto.ProEconActivePowerData;
  8. import com.gyee.generation.model.auto.ProEconWtPowerCurveFitting;
  9. import com.gyee.generation.model.vo.StatData;
  10. import com.gyee.generation.service.auto.IProEconWtPowerCurveFittingService;
  11. import com.gyee.generation.util.DateUtils;
  12. import com.gyee.generation.util.StringUtils;
  13. import com.gyee.generation.util.realtimesource.IEdosUtil;
  14. import org.springframework.stereotype.Service;
  15. import javax.annotation.Resource;
  16. import java.util.*;
  17. import java.util.stream.Collectors;
  18. @Service
  19. public class CoefficientService {
  20. //
  21. // private static final Logger logger = LoggerFactory.getLogger(CoefficientService.class);
  22. @Resource
  23. private IEdosUtil edosUtil;
  24. @Resource
  25. private IProEconWtPowerCurveFittingService proEconWtPowerCurveFittingService;
  26. public Map<String, Map<String, Double>> coefficient(Date currentDate) throws Exception {
  27. //调度时间是第二天,currentDate 是第一天
  28. currentDate = DateUtils.truncDay(currentDate);
  29. Calendar c = Calendar.getInstance();
  30. c.setTime(currentDate);
  31. c.set(Calendar.DAY_OF_MONTH, 1);
  32. Date monthbeginDate = c.getTime();
  33. c.set(Calendar.MONTH, 0);
  34. Date yearbeginDate = c.getTime();
  35. c.setTime(currentDate);
  36. Date beginDate = c.getTime();
  37. c.add(Calendar.DAY_OF_MONTH, 1);
  38. Date endDate = c.getTime();
  39. Map<String, Map<String, Double>> resultmap = new HashMap<>();
  40. //查询风机
  41. List<ProBasicEquipment> wtls = CacheContext.wtls;
  42. //遍历所有风机ID
  43. for (ProBasicEquipment wt : wtls) {
  44. List<ProEconActivePowerData> yearList;
  45. List<ProEconActivePowerData> queryYear = new ArrayList<>();
  46. Map<String, ProBasicEquipmentPoint> wtpointmap = CacheContext.wtpAimap.get(wt.getId());
  47. ProBasicEquipmentPoint fspoint = wtpointmap.get(ContantXk.CJ_SSFS);
  48. List<PointData> fsls = edosUtil.getHistStat(fspoint.getNemCode(), yearbeginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue());
  49. ProBasicEquipmentPoint glpoint = wtpointmap.get(ContantXk.CJ_SSGL);
  50. List<PointData> glls = edosUtil.getHistStat(glpoint.getNemCode(), yearbeginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue());
  51. if(!fsls.isEmpty() && !glls.isEmpty() && fsls.size()==glls.size())
  52. {
  53. for(int i=0;i<fsls.size();i++)
  54. {
  55. PointData fspd=fsls.get(i);
  56. PointData glpd=fsls.get(i);
  57. ProEconActivePowerData po=new ProEconActivePowerData();
  58. po.setWindturbineId(wt.getId());
  59. po.setModelId(wt.getModelId());
  60. po.setWindpowerstationId(wt.getWindpowerstationId());
  61. po.setFrequency(fsls.size());
  62. po.setSpeed(StringUtils.round(fspd.getPointValueInDouble(),2));
  63. po.setPower(StringUtils.round(glpd.getPointValueInDouble(),2));
  64. queryYear.add(po);
  65. }
  66. }
  67. yearList = calCoefficient(queryYear, wt);
  68. //****************************************月功率一致性统计********************************************************************/
  69. List<ProEconActivePowerData> monthList;
  70. List<ProEconActivePowerData> queryMonth = new ArrayList<>();
  71. fsls = edosUtil.getHistStat(fspoint.getNemCode(), monthbeginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue());
  72. glls = edosUtil.getHistStat(glpoint.getNemCode(), monthbeginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue());
  73. if (!fsls.isEmpty() && !glls.isEmpty() && fsls.size() == glls.size()) {
  74. for (int i = 0; i < fsls.size(); i++) {
  75. PointData fspd = fsls.get(i);
  76. PointData glpd = fsls.get(i);
  77. ProEconActivePowerData po = new ProEconActivePowerData();
  78. po.setWindturbineId(wt.getId());
  79. po.setModelId(wt.getModelId());
  80. po.setWindpowerstationId(wt.getWindpowerstationId());
  81. po.setFrequency(fsls.size());
  82. po.setSpeed(StringUtils.round(fspd.getPointValueInDouble(), 2));
  83. po.setPower(StringUtils.round(glpd.getPointValueInDouble(), 2));
  84. queryMonth.add(po);
  85. }
  86. }
  87. monthList = calCoefficient(queryMonth, wt);
  88. //*****************************************日功率一致性统计********************************************************************/
  89. List<ProEconActivePowerData> dayList;
  90. List<ProEconActivePowerData> queryDay = new ArrayList<>();
  91. fsls = edosUtil.getHistStat(fspoint.getNemCode(), beginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue());
  92. glls = edosUtil.getHistStat(glpoint.getNemCode(), beginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L, StatData.AVG.getValue());
  93. if (!fsls.isEmpty() && !glls.isEmpty() && fsls.size() == glls.size()) {
  94. for (int i = 0; i < fsls.size(); i++) {
  95. PointData fspd = fsls.get(i);
  96. PointData glpd = fsls.get(i);
  97. ProEconActivePowerData po = new ProEconActivePowerData();
  98. po.setWindturbineId(wt.getId());
  99. po.setModelId(wt.getModelId());
  100. po.setWindpowerstationId(wt.getWindpowerstationId());
  101. po.setFrequency(fsls.size());
  102. po.setSpeed(StringUtils.round(fspd.getPointValueInDouble(), 2));
  103. po.setPower(StringUtils.round(glpd.getPointValueInDouble(), 2));
  104. queryDay.add(po);
  105. }
  106. }
  107. dayList = calCoefficient(queryDay, wt);
  108. Double resultYear = coefficient(yearList, currentDate, wt.getId());
  109. Double resultMonth = coefficient(monthList, currentDate, wt.getId());
  110. Double resultDay = coefficient(dayList, currentDate, wt.getId());
  111. Map<String, Double> tempmap = new HashMap<>();
  112. tempmap.put("year", resultYear);
  113. tempmap.put("month", resultMonth);
  114. tempmap.put("day", resultDay);
  115. resultmap.put(wt.getId(), tempmap);
  116. }
  117. return resultmap;
  118. }
  119. private List<ProEconActivePowerData> calCoefficient(List<ProEconActivePowerData> query, ProBasicEquipment wt) {
  120. Map<Double, List<ProEconActivePowerData>> apdataYearMap = query.stream().collect(Collectors.groupingBy(ProEconActivePowerData::getSpeed));
  121. Map<Double, Double> speedAndPowerYearMap = new HashMap<>();
  122. apdataYearMap.forEach((key, value) -> {
  123. DoubleSummaryStatistics summaryStatistics = value.stream().mapToDouble(ProEconActivePowerData::getPower).summaryStatistics();
  124. speedAndPowerYearMap.put(key, summaryStatistics.getAverage());
  125. });
  126. List<ProEconActivePowerData> yearList = new ArrayList<>();
  127. speedAndPowerYearMap.forEach((key, value) -> {
  128. ProEconActivePowerData activepowerdata = new ProEconActivePowerData();
  129. activepowerdata.setWindturbineId(wt.getId());
  130. activepowerdata.setSpeed(key);
  131. activepowerdata.setPower(value);
  132. activepowerdata.setFrequency(1);
  133. activepowerdata.setModelId(wt.getModelId());
  134. yearList.add(activepowerdata);
  135. });
  136. return yearList;
  137. }
  138. //功率一致性系数
  139. private Double coefficient(List<ProEconActivePowerData> dataList, Date currentDate, String windturbineId) {
  140. double result = 0.0;
  141. double count = 0.0;
  142. if (dataList != null && dataList.size() != 0) {
  143. List<ProEconWtPowerCurveFitting> powerList;
  144. Calendar c = Calendar.getInstance();
  145. c.setTime(currentDate);
  146. powerList = proEconWtPowerCurveFittingService.list().stream()
  147. .filter(i -> i.getWindturbineId().equals(windturbineId)).collect(Collectors.toList());
  148. for (ProEconActivePowerData data : dataList) {
  149. Double p1 = data.getPower();
  150. Double speed = data.getSpeed();
  151. if (speed < 3 || speed > 25) {
  152. continue;
  153. }
  154. if (CacheContext.wtmap.containsKey(windturbineId)) {
  155. ProBasicEquipment wt = CacheContext.wtmap.get(windturbineId);
  156. if (wt.getWindpowerstationId().contains("GDC")) {
  157. speed /= 100;
  158. speed = StringUtils.round(speed, 2);
  159. speed *= 100;
  160. speed = StringUtils.round(speed, 2);
  161. } else {
  162. speed = StringUtils.round(speed, 2);
  163. }
  164. }
  165. if (CacheContext.modelpowermap.containsKey(data.getModelId())) {
  166. if (CacheContext.modelpowermap.get(data.getModelId()).size() > 0) {
  167. if (CacheContext.modelpowermap.get(data.getModelId()).containsKey(speed)) {
  168. Double p = CacheContext.modelpowermap.get(data.getModelId()).get(speed).getEnsurePower();
  169. if (p != 0) {
  170. for (int i = 0; i < data.getFrequency(); i++) {
  171. result += Math.abs((p - p1) / p);
  172. count += 1;
  173. }
  174. }
  175. }
  176. } else {
  177. if (powerList.size() > 0) {
  178. Double finalSpeed = speed;
  179. OptionalDouble opd = powerList.stream().filter(i -> Objects.equals(i.getSpeed(), finalSpeed)).mapToDouble(ProEconWtPowerCurveFitting::getOptimalPower).findFirst();
  180. double p;
  181. if (opd.isPresent()) {
  182. p = opd.getAsDouble();
  183. if (p != 0) {
  184. for (int i = 0; i < data.getFrequency(); i++) {
  185. result += Math.abs((p - p1) / p);
  186. count += 1;
  187. }
  188. }
  189. } else {
  190. DoubleSummaryStatistics summaryStatistics = powerList.stream().mapToDouble(ProEconWtPowerCurveFitting::getSpeed).summaryStatistics();
  191. double max = summaryStatistics.getMax();
  192. if (speed > max) {
  193. summaryStatistics = powerList.stream().mapToDouble(ProEconWtPowerCurveFitting::getActualPower).summaryStatistics();
  194. p = summaryStatistics.getMax();
  195. if (p != 0.0) {
  196. for (int i = 0; i < data.getFrequency(); i++) {
  197. result += Math.abs((p - p1) / p);
  198. count += 1;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. if (count != 0)
  208. result = result / count * 100;
  209. else
  210. result = 100.0;
  211. }
  212. return result;
  213. }
  214. }