123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- package com.gyee.impala.service.custom;
- import com.gyee.impala.common.constant.Constants;
- import com.gyee.impala.common.exception.CustomException;
- import com.gyee.impala.common.feign.RemoteServiceBuilder;
- import com.gyee.impala.common.result.ResultCode;
- import com.gyee.impala.common.util.DateUtil;
- import com.gyee.impala.model.custom.TsBooleanData;
- import com.gyee.impala.model.custom.TsDoubleData;
- import com.gyee.impala.model.master.Caseperformance;
- import com.gyee.impala.model.master.Windturbinepoint;
- import com.gyee.impala.service.master.CaseperformanceService;
- import com.gyee.impala.service.master.WindturbinepointService;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.*;
- @Slf4j
- @Service
- public class GoldenService {
- @Autowired
- private RemoteServiceBuilder remoteService;
- @Autowired
- private WindturbinepointService windturbinepointService;
- @Autowired
- private CaseperformanceService caseperformanceService;
- /**
- * 查询原始数据
- *
- * @param points
- * @param startTs 精确到毫秒
- * @param endTs
- * @param interval
- * @return
- */
- public List<Map> getCurveScatter(String[] points, long startTs, long endTs, int interval) {
- List<Map> list = new ArrayList<>();
- try {
- for (String point : points) {
- Windturbinepoint w = windturbinepointService.getByPoint(point);
- List<TsDoubleData> data = new ArrayList<>();
- Map m = new HashMap();
- if (interval <= 0) {
- data = remoteService.ShardingService().getHistoryRawAI(point, startTs, endTs);
- } else {
- data = remoteService.ShardingService().getHistorySnapAI(point, startTs, endTs, interval);
- }
- m.put("name", w.getPointdes());
- m.put("code", w.getWidgetcode());
- m.put("point", w.getPoint());
- m.put("list", data);
- list.add(m);
- }
- } catch (Exception e) {
- log.error(e.getMessage());
- throw new CustomException(ResultCode.ERROR_DATA);
- }
- return list;
- }
- /**
- * 获取风速和功率的曲线数据
- * @param ids 样本ID
- * @param interval 数据时间间隔
- * @param type 类型 0-单台 1-多台合并 2-同名合并
- * @return
- */
- public Map<String, List> getCurveScatter(String[] ids, int interval, Integer type) {
- Map<String, List> maps = new HashMap<>();
- try {
- for (String id : ids) {
- String[] codes = new String[]{Constants.POINT_SPEED, Constants.POINT_POWER};
- Caseperformance cp = caseperformanceService.getPerformanceByid(id);
- //查询测点名
- List<Windturbinepoint> winds = windturbinepointService.getListByStationAndWtIdAndUniformCode(cp.getStationen(), cp.getWindturbineid(), codes);
- //golden适配器取数据
- List<TsDoubleData> speedList = remoteService.ShardingService().getHistorySnapAI(winds.get(0).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
- DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
- List<TsDoubleData> powerList = remoteService.ShardingService().getHistorySnapAI(winds.get(1).getPoint(), DateUtil.covertDateTimestamp(cp.getStarttime()),
- DateUtil.covertDateTimestamp(cp.getEndtime()), interval);
- if (speedList == null || powerList == null)
- return maps;
- //计算数组最小的
- int len = speedList.size() <= powerList.size() ? speedList.size() : powerList.size();
- //折线图
- // List listZ = new ArrayList<>();
- //散点图
- List listS = new ArrayList<>();
- // int val = len / 5 > 0 ? len / 5 : 1;
- for (int i = 0; i < len; i++) {
- //计算折线图
- // List lp = new ArrayList();
- // if (i % val == 0){
- // lp.add(speedList.get(i).getDoubleValue());
- // lp.add(powerList.get(i).getDoubleValue());
- // listZ.add(lp);
- // listZ.add(powerList.get(i).getDoubleValue());
- // }
- //补齐最后一条
- // if (i == len - 1){
- // lp.add(speedList.get(i).getDoubleValue());
- // lp.add(powerList.get(i).getDoubleValue());
- // listZ.add(lp);
- // listZ.add(powerList.get(i).getDoubleValue());
- // }
- //计算散点图
- List ls = new ArrayList();
- ls.add(speedList.get(i).getDoubleValue());
- ls.add(powerList.get(i).getDoubleValue());
- listS.add(ls);
- }
- maps.put(cp.getWindturbineid(), listS);
- }
- return maps;
- } catch (Exception e) {
- log.error(e.getMessage());
- throw new CustomException(ResultCode.ERROR_DATA);
- }
- }
- /**
- * 过滤并网的数据时间
- * @param point
- * @param startTime
- * @param endTime
- * @return
- */
- public List<List<Long>> getConnectData(String point, long startTime, long endTime) {
- List<List<Long>> list = new ArrayList<>();
- try{
- List<TsDoubleData> data = remoteService.ShardingService().getHistoryRawAI(point, startTime, endTime);
- int index = 0;
- boolean flag = false;
- if (data != null && data.size() > 0){
- for (int i = 0; i < data.size() - 1; i++){
- TsDoubleData obj = data.get(i);
- // 1表示并网
- if (flag == false && obj.getDoubleValue() == 1){
- index = i;
- flag = true;
- continue;
- }
- if (flag == true && obj.getDoubleValue() == 0){
- List<Long> ls = new ArrayList<>();
- ls.add(data.get(index).getTs());
- ls.add(obj.getTs());
- list.add(ls);
- flag = false;
- }
- }
- }
- }catch (Exception e) {
- log.error(e.getMessage());
- throw new CustomException(ResultCode.ERROR_DATA);
- }
- return list;
- }
- }
|