|
@@ -1,26 +1,28 @@
|
|
|
package com.gyee.impala.service.custom;
|
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.gyee.impala.common.config.datasource.HiveDataSourceConfig;
|
|
|
+import com.gyee.impala.common.config.jsch.JSchConfig;
|
|
|
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.Base64Util;
|
|
|
import com.gyee.impala.common.util.DateUtil;
|
|
|
+import com.gyee.impala.common.util.FileUtil;
|
|
|
+import com.gyee.impala.common.util.SnowFlakeUtil;
|
|
|
+import com.gyee.impala.model.custom.PowerCurveCondition;
|
|
|
import com.gyee.impala.model.custom.TsDoubleData;
|
|
|
+import com.gyee.impala.model.master.Powercurvebasic;
|
|
|
import com.gyee.impala.model.master.Powercurvefitting;
|
|
|
-import com.gyee.impala.model.master.Windturbinepoint;
|
|
|
import com.gyee.impala.model.slave.Windturbinecurvefittingmonth;
|
|
|
import com.gyee.impala.model.slave.Windturbinetestingpointai2;
|
|
|
+import com.gyee.impala.service.master.PowercurvebasicService;
|
|
|
import com.gyee.impala.service.master.PowercurvefittingService;
|
|
|
-import com.gyee.impala.service.master.WindturbinepointService;
|
|
|
import com.gyee.impala.service.slave.WindturbinecurvefittingmonthService;
|
|
|
import com.gyee.impala.service.slave.Windturbinetestingpointai2Service;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
@@ -33,139 +35,178 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class AnalyseScatterService {
|
|
|
|
|
|
- // 读取golden数据库的时间间隔
|
|
|
- private final int interval = 1200;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private WindturbinepointService windturbinepointService;
|
|
|
@Autowired
|
|
|
- private Windturbinetestingpointai2Service windturbinetestingpointai2Service;
|
|
|
+ private Windturbinetestingpointai2Service pointAi2Service;
|
|
|
@Autowired
|
|
|
private PowercurvefittingService powercurvefittingService;
|
|
|
@Autowired
|
|
|
- private WindturbinecurvefittingmonthService windturbinecurvefittingmonthService;
|
|
|
+ private PowercurvebasicService powercurvebasicService;
|
|
|
+ @Autowired
|
|
|
+ private WindturbinecurvefittingmonthService fittingService;
|
|
|
@Autowired
|
|
|
private RemoteServiceBuilder remoteServiceBuilder;
|
|
|
@Autowired
|
|
|
- private GoldenService goldenService;
|
|
|
+ private SftpFileService fileService;
|
|
|
+ @Autowired
|
|
|
+ private HiveDataSourceConfig hiveConfig;
|
|
|
+ @Autowired
|
|
|
+ private JSchConfig config;
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 偏航对风 通过计算服务取数
|
|
|
+ * 数据预处理
|
|
|
+ *
|
|
|
+ * @param condition
|
|
|
+ */
|
|
|
+ @Async
|
|
|
+ public void dataPreprocess(PowerCurveCondition condition){
|
|
|
+ //对多台风机操作
|
|
|
+ condition.getWindturbineid().stream().forEach(wtId -> {
|
|
|
+ List<Powercurvebasic> list = powercurvebasicService.getList(condition.getStationen(), wtId, condition.getTime());
|
|
|
+ if (list != null && list.size() > 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(DateUtil.parseStrtoDate(condition.getTime(), DateUtil.YYYY_MM));
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
|
|
|
+ long st = cal.getTime().getTime();
|
|
|
+ cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
+ long et = cal.getTime().getTime();
|
|
|
+
|
|
|
+ int interval = condition.getIntervals();
|
|
|
+ String station = condition.getStationen();
|
|
|
+ try {
|
|
|
+ /********************** 数据预处理需要的测点 ******************************/
|
|
|
+ List<Windturbinetestingpointai2> power = pointAi2Service
|
|
|
+ .getListByStationAndCode(station, wtId, Constants.POINT_POWER);
|
|
|
+ List<Windturbinetestingpointai2> speed = pointAi2Service
|
|
|
+ .getListByStationAndCode(station, wtId, Constants.POINT_SPEED);
|
|
|
+
|
|
|
+ // 数据库(oracle)配置问题, 可能有空值
|
|
|
+ List<Windturbinetestingpointai2> rotate = pointAi2Service
|
|
|
+ .getListByStationAndCode(station, wtId, Constants.FDJZS);
|
|
|
+ if (rotate == null)
|
|
|
+ rotate = pointAi2Service
|
|
|
+ .getListByStationAndCode(station, wtId, Constants.FDJZSB);
|
|
|
+ List<Windturbinetestingpointai2> status = pointAi2Service
|
|
|
+ .getListByStationAndCode(station, wtId, Constants.FJZT);
|
|
|
+ List<Windturbinetestingpointai2> fdl = pointAi2Service
|
|
|
+ .getListByStationAndCode(station, wtId, Constants.POINT_QUANTITY);
|
|
|
+ List<Windturbinetestingpointai2> ssqfzt = pointAi2Service
|
|
|
+ .getListByStationAndCode(station, wtId, Constants.RSSQFZT);
|
|
|
+ List<Windturbinetestingpointai2> direct = pointAi2Service
|
|
|
+ .getListByStationAndCode(station, wtId, Constants.POINT_WIND_DIRECT);
|
|
|
+ List<Windturbinetestingpointai2> angle = pointAi2Service
|
|
|
+ .getListByStationAndCode(station, wtId, Constants.POINT_WIND_ANGLE);
|
|
|
+ /********************** 数据预处理需要的测点 ******************************/
|
|
|
+
|
|
|
+
|
|
|
+ /********************** 数据存储到hive ******************************/
|
|
|
+ List<TsDoubleData> dataPower = remoteServiceBuilder.ShardingService()
|
|
|
+ .getHistorySnapAI(power.size() > 0 ? power.get(0).getId() : "", st, et, interval);
|
|
|
+ List<TsDoubleData> dataSpeed = remoteServiceBuilder.ShardingService()
|
|
|
+ .getHistorySnapAI(speed.size() > 0 ? speed.get(0).getId() : "", st, et, interval);
|
|
|
+ List<TsDoubleData> dataRotate = remoteServiceBuilder.ShardingService()
|
|
|
+ .getHistorySnapAI(rotate.size() > 0 ? rotate.get(0).getId() : "", st, et, interval);
|
|
|
+ List<TsDoubleData> dataStatus = remoteServiceBuilder.ShardingService()
|
|
|
+ .getHistorySnapAI(status.size() > 0 ? status.get(0).getId() : "", st, et, interval);
|
|
|
+ List<TsDoubleData> dataFdl = remoteServiceBuilder.ShardingService()
|
|
|
+ .getHistorySnapAI(fdl.size() > 0 ? fdl.get(0).getId() : "", st, et, interval);
|
|
|
+ List<TsDoubleData> dataQfzt = remoteServiceBuilder.ShardingService()
|
|
|
+ .getHistorySnapAI(ssqfzt.size() > 0 ? ssqfzt.get(0).getId() : "", st, et, interval);
|
|
|
+ List<TsDoubleData> dataDirect = remoteServiceBuilder.ShardingService()
|
|
|
+ .getHistorySnapAI(direct.size() > 0 ? direct.get(0).getId() : "", st, et, interval);
|
|
|
+ List<TsDoubleData> dataAngle = remoteServiceBuilder.ShardingService()
|
|
|
+ .getHistorySnapAI(angle.size() > 0 ? angle.get(0).getId() : "", st, et, interval);
|
|
|
+
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for (int i = 0; i < dataPower.size(); i++) {
|
|
|
+ sb.append(SnowFlakeUtil.generateId()).append("^");
|
|
|
+ sb.append(condition.getStationen()).append("^");
|
|
|
+ sb.append(wtId).append("^");
|
|
|
+ sb.append(DateUtil.format(dataPower.get(i).getTs(), DateUtil.YYYY_MM_DD_HH_MM_SS)).append("^");
|
|
|
+ sb.append(dataPower.size() > 0 ? dataPower.get(i).getDoubleValue() : 0).append("^");
|
|
|
+ sb.append(dataSpeed.size() > 0 ? dataSpeed.get(i).getDoubleValue() : 0).append("^");
|
|
|
+ sb.append(dataRotate.size() > 0 ? dataRotate.get(i).getDoubleValue() : 0).append("^");
|
|
|
+ sb.append((int) dataStatus.get(i).getDoubleValue()).append("^");
|
|
|
+ sb.append(dataFdl.size() > 0 ? dataFdl.get(i).getDoubleValue() : 0).append("^");
|
|
|
+ sb.append((int) dataQfzt.get(i).getDoubleValue()).append("^");
|
|
|
+ sb.append(dataDirect.size() > 0 ? dataDirect.get(i).getDoubleValue() : 0).append("^");
|
|
|
+ sb.append(dataAngle.size() > 0 ? dataAngle.get(i).getDoubleValue() : 0).append("^^^^\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ String fileName = station + "_" + wtId + "_" + condition.getTime() + ".txt";
|
|
|
+ /**上传文件**/
|
|
|
+ fileService.uploadFile(fileName, FileUtil.convertStringToInputStream(sb.toString()));
|
|
|
+ /**文件load到hive表**/
|
|
|
+ String sql = "load data local inpath '" + config.getPath() + "/" + fileName + "' into table gyee_sample_kudu.powercurvefitting";
|
|
|
+ hiveConfig.execute(sql);
|
|
|
+ /********************** 数据存储到kudu ******************************/
|
|
|
+ condition.setWtId(wtId);
|
|
|
+ powercurvebasicService.insertItem((Powercurvebasic) new Powercurvebasic().toData(condition));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询散点数据 (散点,实际功率,最有功率)
|
|
|
+ *
|
|
|
* @param station
|
|
|
* @param wtId
|
|
|
* @param time
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String, List<List<Double>>> getScatterList(String station, String wtId, String time) {
|
|
|
- Map<String, List<List<Double>>> result = new HashMap<>();
|
|
|
+ public Map<String, List<List<Object>>> getScatterList(String station, String wtId, String time) {
|
|
|
+ Map<String, List<List<Object>>> result = new HashMap<>();
|
|
|
|
|
|
- List<List<Double>> scatter = new ArrayList<>(); //散点
|
|
|
- List<List<Double>> actual = new ArrayList<>(); //实际功率
|
|
|
- List<List<Double>> optimal = new ArrayList<>(); //最优功率
|
|
|
+ List<List<Object>> scatter = new ArrayList<>(); //散点
|
|
|
+ List<List<Object>> actual = new ArrayList<>(); //实际功率
|
|
|
+ List<List<Object>> optimal = new ArrayList<>(); //最优功率
|
|
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
- Powercurvefitting item = powercurvefittingService.getOne(station, wtId, time);
|
|
|
-
|
|
|
- if (item != null) {
|
|
|
- // 缓存有数据直接使用缓存
|
|
|
- } else {
|
|
|
- // 缓存没数据,先查golden,在缓存
|
|
|
- cal.setTime(DateUtil.dateTime(DateUtil.YYYY_MM, time));
|
|
|
- int year = cal.get(Calendar.YEAR);
|
|
|
- int month = cal.get(Calendar.MONTH);
|
|
|
-
|
|
|
- time = year + "-" + StringUtils.leftPad(String.valueOf(month + 1), 2, "0");
|
|
|
-
|
|
|
- cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
|
|
|
- long startTime = cal.getTime().getTime();
|
|
|
- cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
- long endTime = cal.getTime().getTime();
|
|
|
-
|
|
|
- try{
|
|
|
- // /** -------------- 散点图 风速、功率 -------------**/
|
|
|
- Windturbinetestingpointai2 power = windturbinetestingpointai2Service.getItemByStationAndCode(station, wtId, Constants.POINT_POWER);
|
|
|
- Windturbinetestingpointai2 speed = windturbinetestingpointai2Service.getItemByStationAndCode(station, wtId, Constants.POINT_SPEED);
|
|
|
- Windturbinetestingpointai2 status = windturbinetestingpointai2Service.getItemByStationAndCode(station, wtId, Constants.FJZT);
|
|
|
-
|
|
|
- List<TsDoubleData> listPower = remoteServiceBuilder.ShardingService().getHistorySnapAI(power.getId(), startTime, endTime, interval);
|
|
|
- List<TsDoubleData> listSpeed = remoteServiceBuilder.ShardingService().getHistorySnapAI(speed.getId(), startTime, endTime, interval);
|
|
|
- /** -------------- 散点图 风速、功率 -------------**/
|
|
|
-
|
|
|
- DecimalFormat dcmFmt = new DecimalFormat("0.00");
|
|
|
- if (!listPower.isEmpty() && !listSpeed.isEmpty()) {
|
|
|
- for (int j = 0; j < listPower.size(); j++) {
|
|
|
- List<Double> ds = new ArrayList<>();
|
|
|
-
|
|
|
- double f = listSpeed.get(j).getDoubleValue();
|
|
|
- ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
- f = listPower.get(j).getDoubleValue() < 0 ? 0 : listPower.get(j).getDoubleValue();
|
|
|
- ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
- scatter.add(ds);
|
|
|
- }
|
|
|
+ cal.setTime(DateUtil.parseStrtoDate(time, DateUtil.YYYY_MM));
|
|
|
+ int year = cal.get(Calendar.YEAR);
|
|
|
+ int month = cal.get(Calendar.MONTH);
|
|
|
+ String st = DateUtil.format(cal.getTimeInMillis(), DateUtil.YYYY_MM_DD_HH_MM_SS);
|
|
|
+ cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
+ String et = DateUtil.format(cal.getTimeInMillis(), DateUtil.YYYY_MM_DD_HH_MM_SS);
|
|
|
+
|
|
|
+ try {
|
|
|
+ /**查询散点**/
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
+ List<Powercurvefitting> list = powercurvefittingService.getList(station, wtId, st, et);
|
|
|
+ list.stream().forEach(obj -> {
|
|
|
+ List<Object> ls = new ArrayList<>();
|
|
|
+ ls.add(Double.valueOf(df.format(obj.getSpeed())));
|
|
|
+ ls.add(Double.valueOf(df.format(obj.getPower())));
|
|
|
+ ls.add(obj.getTime());
|
|
|
+ scatter.add(ls);
|
|
|
+ });
|
|
|
+
|
|
|
+ /**查询功率**/
|
|
|
+ List<Windturbinecurvefittingmonth> curve = fittingService.getListByWtIdAndYearAndMonth(wtId, String.valueOf(year), String.valueOf(month));
|
|
|
+ curve.stream().forEach(cv -> {
|
|
|
+ List<Object> ap = new ArrayList<>();
|
|
|
+ List<Object> op = new ArrayList<>();
|
|
|
+ int c = cv.getSpeed().intValue();
|
|
|
+
|
|
|
+ if (c == cv.getSpeed()) {
|
|
|
+ ap.add(cv.getSpeed());
|
|
|
+ ap.add(cv.getActualpower());// 实际拟合功率
|
|
|
+ op.add(cv.getSpeed());// 风速
|
|
|
+ op.add(cv.getOptimalpower());// 最优拟合功率
|
|
|
+ actual.add(ap);
|
|
|
+ optimal.add(op);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- /** -------------- 散点图 风速、功率 -------------**/
|
|
|
- //
|
|
|
- // List<List<Long>> listStatus = goldenService.getConnectData(status.getId(), startTime, endTime);
|
|
|
- //// if (listStatus.size() > 0){
|
|
|
- //// for (int i = 0; i< listStatus.size(); i++){
|
|
|
- //// for (List<Long> ls : listStatus){
|
|
|
- //// List<TsDoubleData> listPower = remoteServiceBuilder.ShardingService().getHistorySnapAI(power.getId(), ls.get(0), ls.get(1), interval);
|
|
|
- //// List<TsDoubleData> listSpeed = remoteServiceBuilder.ShardingService().getHistorySnapAI(speed.getId(), ls.get(0), ls.get(1), interval);
|
|
|
- //// /** -------------- 散点图 风速、功率 -------------**/
|
|
|
- ////
|
|
|
- //// DecimalFormat dcmFmt = new DecimalFormat("0.00");
|
|
|
- //// if (!listPower.isEmpty() && !listSpeed.isEmpty()) {
|
|
|
- //// for (int j = 0; j < listPower.size(); j++) {
|
|
|
- //// List<Double> ds = new ArrayList<>();
|
|
|
- ////
|
|
|
- //// double f = listSpeed.get(j).getDoubleValue();
|
|
|
- //// ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
- //// f = listPower.get(j).getDoubleValue() < 0 ? 0 : listPower.get(j).getDoubleValue();
|
|
|
- //// ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
- //// scatter.add(ds);
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
- //// }
|
|
|
-
|
|
|
- List<Windturbinecurvefittingmonth> curve = windturbinecurvefittingmonthService.getListByWtIdAndYearAndMonth(wtId, String.valueOf(year), String.valueOf(month));
|
|
|
- for (Windturbinecurvefittingmonth wc : curve) {
|
|
|
- List<Double> ap = new ArrayList<>();
|
|
|
- List<Double> op = new ArrayList<>();
|
|
|
- int c = wc.getSpeed().intValue();
|
|
|
-
|
|
|
- if (c == wc.getSpeed()) {
|
|
|
- ap.add(wc.getSpeed());
|
|
|
- ap.add(wc.getActualpower());// 实际拟合功率
|
|
|
- op.add(wc.getSpeed());// 风速
|
|
|
- op.add(wc.getOptimalpower());// 最优拟合功率
|
|
|
- actual.add(ap);
|
|
|
- optimal.add(op);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //新风机的拟合数据插入缓存
|
|
|
-// Powercurvefitting temp = new Powercurvefitting();
|
|
|
-// temp.setStation(station);
|
|
|
-// temp.setWindturbineid(wtId);
|
|
|
-// temp.setTime(time);
|
|
|
-// System.out.println("===" + Base64Util.encode(scatter.toString()).length());
|
|
|
-// temp.setScatter(Base64Util.encode(scatter.toString()));
|
|
|
-// temp.setLineactual(Base64Util.encode(actual.toString()));
|
|
|
-// temp.setLineoptimal(Base64Util.encode(optimal.toString()));
|
|
|
-// temp.setRemark("1");
|
|
|
-// temp.setCategory("1");
|
|
|
-// powercurvefittingService.insertItem(temp);
|
|
|
-
|
|
|
- } catch (CustomException e) {
|
|
|
- log.error(e.getMessage());
|
|
|
- throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
- }
|
|
|
+ });
|
|
|
+ } catch (CustomException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
}
|
|
|
|
|
|
result.put("scatter", scatter);
|
|
@@ -176,27 +217,4 @@ public class AnalyseScatterService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void getTotalRangeCal(String wtId, long startTime, long endTime) {
|
|
|
- try{
|
|
|
- /** -------------- 对风偏差 风速、风向 -------------**/
|
|
|
- Windturbinepoint direct = windturbinepointService.getItemByWtIdAndUniformCode(wtId, Constants.POINT_WIND_DIRECT);
|
|
|
- Windturbinepoint angle = windturbinepointService.getItemByWtIdAndUniformCode(wtId, Constants.POINT_WIND_ANGLE);
|
|
|
- List<TsDoubleData> listDirect = remoteServiceBuilder.ShardingService().getHistorySnapAI(direct.getPoint(), startTime, endTime, interval);
|
|
|
- List<TsDoubleData> listAngle = remoteServiceBuilder.ShardingService().getHistorySnapAI(angle.getPoint(), startTime, endTime, interval);
|
|
|
- /** -------------- 对风偏差 风速、风向 -------------**/
|
|
|
-
|
|
|
- } catch (CustomException e) {
|
|
|
- log.error(e.getMessage());
|
|
|
- throw new CustomException(ResultCode.ERROR_DATA);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static void main(String[] args){
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- for(int i = 0; i < 200000; i++)
|
|
|
- sb.append("A");
|
|
|
-
|
|
|
- System.out.println(sb.toString().length());
|
|
|
- }
|
|
|
}
|