GoldenService.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package com.gyee.impala.service.custom;
  2. import com.gyee.impala.common.constant.Constants;
  3. import com.gyee.impala.common.exception.CustomException;
  4. import com.gyee.impala.common.feign.RemoteServiceBuilder;
  5. import com.gyee.impala.common.result.ResultCode;
  6. import com.gyee.impala.common.util.DateUtil;
  7. import com.gyee.impala.model.custom.TsBooleanData;
  8. import com.gyee.impala.model.custom.TsDoubleData;
  9. import com.gyee.impala.model.master.Caseperformance;
  10. import com.gyee.impala.model.master.Windturbinepoint;
  11. import com.gyee.impala.service.master.CaseperformanceService;
  12. import com.gyee.impala.service.master.WindturbinepointService;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import java.util.*;
  17. @Slf4j
  18. @Service
  19. public class GoldenService {
  20. @Autowired
  21. private RemoteServiceBuilder remoteService;
  22. @Autowired
  23. private WindturbinepointService windturbinepointService;
  24. @Autowired
  25. private CaseperformanceService caseperformanceService;
  26. /**
  27. * 查询原始数据
  28. *
  29. * @param points
  30. * @param startTs 精确到毫秒
  31. * @param endTs
  32. * @param interval
  33. * @return
  34. */
  35. public List<Map> getCurveScatter(String[] points, long startTs, long endTs, int interval) {
  36. List<Map> list = new ArrayList<>();
  37. try {
  38. for (String point : points) {
  39. Windturbinepoint w = windturbinepointService.getByPoint(point);
  40. List<TsDoubleData> data = new ArrayList<>();
  41. Map m = new HashMap();
  42. if (interval <= 0) {
  43. data = remoteService.ShardingService().getHistoryRawAI(point, startTs, endTs);
  44. } else {
  45. data = remoteService.ShardingService().getHistorySnapAI(point, startTs, endTs, interval);
  46. }
  47. m.put("name", w.getPointdes());
  48. m.put("code", w.getWidgetcode());
  49. m.put("point", w.getPoint());
  50. m.put("list", data);
  51. list.add(m);
  52. }
  53. } catch (Exception e) {
  54. log.error(e.getMessage());
  55. throw new CustomException(ResultCode.ERROR_DATA);
  56. }
  57. return list;
  58. }
  59. /**
  60. * 获取风速和功率的曲线数据
  61. * @param ids 样本ID
  62. * @param interval 数据时间间隔
  63. * @param type 类型 0-单台 1-多台合并 2-同名合并
  64. * @return
  65. */
  66. public Map<String, List> getCurveScatter(String[] ids, int interval, Integer type) {
  67. Map<String, List> maps = new HashMap<>();
  68. try {
  69. for (String id : ids) {
  70. String[] codes = new String[]{Constants.POINT_SPEED, Constants.POINT_POWER};
  71. Caseperformance cp = caseperformanceService.getPerformanceByid(id);
  72. //查询测点名
  73. List<Windturbinepoint> winds = windturbinepointService.getListByStationAndWtIdAndUniformCode(cp.getStationen(), cp.getWindturbineid(), codes);
  74. //golden适配器取数据
  75. List<TsDoubleData> speedList = remoteService.ShardingService().getHistorySnapAI(winds.get(0).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
  76. DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
  77. List<TsDoubleData> powerList = remoteService.ShardingService().getHistorySnapAI(winds.get(1).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
  78. DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
  79. if (speedList == null || powerList == null)
  80. return maps;
  81. //计算数组最小的
  82. int len = speedList.size() <= powerList.size() ? speedList.size() : powerList.size();
  83. //折线图
  84. // List listZ = new ArrayList<>();
  85. //散点图
  86. List listS = new ArrayList<>();
  87. // int val = len / 5 > 0 ? len / 5 : 1;
  88. for (int i = 0; i < len; i++) {
  89. //计算折线图
  90. // List lp = new ArrayList();
  91. // if (i % val == 0){
  92. // lp.add(speedList.get(i).getDoubleValue());
  93. // lp.add(powerList.get(i).getDoubleValue());
  94. // listZ.add(lp);
  95. // listZ.add(powerList.get(i).getDoubleValue());
  96. // }
  97. //补齐最后一条
  98. // if (i == len - 1){
  99. // lp.add(speedList.get(i).getDoubleValue());
  100. // lp.add(powerList.get(i).getDoubleValue());
  101. // listZ.add(lp);
  102. // listZ.add(powerList.get(i).getDoubleValue());
  103. // }
  104. //计算散点图
  105. List ls = new ArrayList();
  106. ls.add(speedList.get(i).getDoubleValue());
  107. ls.add(powerList.get(i).getDoubleValue());
  108. listS.add(ls);
  109. }
  110. maps.put(cp.getWindturbineid(), listS);
  111. }
  112. return maps;
  113. } catch (Exception e) {
  114. log.error(e.getMessage());
  115. throw new CustomException(ResultCode.ERROR_DATA);
  116. }
  117. }
  118. /**
  119. * 过滤并网的数据时间
  120. * @param point
  121. * @param startTime
  122. * @param endTime
  123. * @return
  124. */
  125. public List<List<Long>> getConnectData(String point, long startTime, long endTime) {
  126. List<List<Long>> list = new ArrayList<>();
  127. try{
  128. List<TsDoubleData> data = remoteService.ShardingService().getHistoryRawAI(point, startTime, endTime);
  129. int index = 0;
  130. boolean flag = false;
  131. if (data != null && data.size() > 0){
  132. for (int i = 0; i < data.size() - 1; i++){
  133. TsDoubleData obj = data.get(i);
  134. // 1表示并网
  135. if (flag == false && obj.getDoubleValue() == 1){
  136. index = i;
  137. flag = true;
  138. continue;
  139. }
  140. if (flag == true && obj.getDoubleValue() == 0){
  141. List<Long> ls = new ArrayList<>();
  142. ls.add(data.get(index).getTs());
  143. ls.add(obj.getTs());
  144. list.add(ls);
  145. flag = false;
  146. }
  147. }
  148. }
  149. }catch (Exception e) {
  150. log.error(e.getMessage());
  151. throw new CustomException(ResultCode.ERROR_DATA);
  152. }
  153. return list;
  154. }
  155. }