|
@@ -13,18 +13,24 @@ import com.ruoyi.ucp.service.*;
|
|
|
import com.ruoyi.ucp.util.CalcCache;
|
|
|
import org.apache.commons.math3.fitting.PolynomialCurveFitter;
|
|
|
import org.apache.commons.math3.fitting.WeightedObservedPoints;
|
|
|
+import org.junit.Test;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.net.URI;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
|
|
|
+/* @Resource
|
|
|
+ private PointInfo pointInfo;*/
|
|
|
+
|
|
|
@Resource
|
|
|
private AdapterApi adapter;
|
|
|
@Resource
|
|
@@ -1327,4 +1333,192 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
}
|
|
|
return y;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //切入切出风速
|
|
|
+ @Test
|
|
|
+ public void cutInWindSpeed() {
|
|
|
+ //date当天零点
|
|
|
+ DateTime timeNow = DateUtil.beginOfDay(new Date());
|
|
|
+ //date昨天零点
|
|
|
+ DateTime timeBegin = DateUtil.offsetDay(timeNow, -1);
|
|
|
+ List<PointInfo> turbineZt = calcTurbineAizt(timeBegin, timeNow, 60);
|
|
|
+ List<PointInfo> turbineZtDI = calcTurbineDizt(timeBegin, timeNow, 60);
|
|
|
+ turbineZt.addAll(turbineZtDI);
|
|
|
+
|
|
|
+ //所有风机的风速测点
|
|
|
+ QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("uniform_code", "AI066");
|
|
|
+
|
|
|
+ List<PointInfo>pointInfos = getEntity("AI066", "turbine");
|
|
|
+// List<PointInfo> pointInfos = pointInfo.selectList(queryWrapper);
|
|
|
+
|
|
|
+ //定义切入风速map集合
|
|
|
+ ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapIn = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+ //定义切出风速集合
|
|
|
+ ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapOut = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ //遍历每台风机,取出每台风机的pointDatas
|
|
|
+ for (PointInfo turbine : turbineZt) {
|
|
|
+
|
|
|
+ mapIn.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
|
|
|
+ mapOut.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
|
|
|
+
|
|
|
+ List<PointData> pointDatas = turbine.getPointDatas();
|
|
|
+
|
|
|
+ //风速测点key
|
|
|
+ String windSpeedKey = null;
|
|
|
+
|
|
|
+
|
|
|
+ //遍历pointInfos,找出pointData1的id和pointInfos中相等的,取出pointInfo的pointKey
|
|
|
+ for (PointInfo info : pointInfos) {
|
|
|
+ if (Objects.equals(turbine.getTurbineId(), info.getTurbineId())) {
|
|
|
+ windSpeedKey = info.getPointKey();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //遍历pointDatas,取出当前状态和后一个状态
|
|
|
+ for (int k = 1; k < pointDatas.size(); k++) {
|
|
|
+ PointData pointData1 = pointDatas.get(k - 1);
|
|
|
+ PointData pointData2 = pointDatas.get(k);
|
|
|
+ double value1 = pointData1.getValue();
|
|
|
+ double value2 = pointData2.getValue();
|
|
|
+ //切入时间
|
|
|
+ long ts1;
|
|
|
+ //切出时间
|
|
|
+ long ts2;
|
|
|
+
|
|
|
+ //如果1的值为0,2的值为2,则为切入状态
|
|
|
+ if (value1 == 0 && value2 == 2) {
|
|
|
+ ts1 = pointData2.getTs();
|
|
|
+// String stringDate = DateUtil.date(ts1).toString("yyyy-MM-dd HH:mm:ss");
|
|
|
+// System.out.println(turbine.getTurbineId() + "切入" + stringDate);
|
|
|
+ //切入时间前5分钟
|
|
|
+ long ts11 = ts1 - 300000;
|
|
|
+ //根据风速key,从适配器取切入前5分钟的所有风速
|
|
|
+ List<PointData> pointDatas1 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts11, ts1, 10);
|
|
|
+ //平均所有风速即为平均切入风速
|
|
|
+ double avgCutInWindSpeed = pointDatas1.stream().mapToDouble(PointData::getValue).average().orElse(0);
|
|
|
+// System.out.println(turbine.getTurbineId() + "切入风速" + avgCutInWindSpeed);
|
|
|
+
|
|
|
+ //存入map集合,外层key为turbineId,内层key为ts1,value为平均切入风速
|
|
|
+
|
|
|
+ mapIn.get(turbine.getTurbineId()).put(String.valueOf(ts1), avgCutInWindSpeed);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //切出
|
|
|
+ if (value1 == 2 && value2 != 2) {
|
|
|
+ ts2 = pointData2.getTs();
|
|
|
+ String stringDate = DateUtil.date(ts2).toString("yyyy-MM-dd HH:mm:ss");
|
|
|
+// System.out.println(turbine.getTurbineId() + "切出" + stringDate);
|
|
|
+ //切出时间前5分钟
|
|
|
+ long ts22 = ts2 - 300000;
|
|
|
+ List<PointData> pointDatas2 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts22, ts2, 10);
|
|
|
+ double avgCutOutWindSpeed = pointDatas2.stream().mapToDouble(PointData::getValue).average().orElse(0);
|
|
|
+// System.out.println(turbine.getTurbineId() + "切出风速" + avgCutOutWindSpeed);
|
|
|
+
|
|
|
+ //存入map集合,外层key为turbineId,内层key为ts2,value为平均切出风速
|
|
|
+
|
|
|
+ mapOut.get(turbine.getTurbineId()).put(String.valueOf(ts2), avgCutOutWindSpeed);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //遍历map集合,取出每个风机的所有切入风速,算一个平均值
|
|
|
+ ConcurrentHashMap<String, Double> mapTurbineValues = mapIn.get(turbine.getTurbineId());
|
|
|
+ //平均切入风速
|
|
|
+ double avgCutInWindSpeed = 0;
|
|
|
+ if (mapTurbineValues != null) {
|
|
|
+ AtomicReference<Double> sum = new AtomicReference<>(0.0);
|
|
|
+ //遍历mapTurbineValues,V大于5的舍弃,剩余算平均值
|
|
|
+ for (String key : mapTurbineValues.keySet()) {
|
|
|
+ if (mapTurbineValues.get(key) > 5) {
|
|
|
+ mapTurbineValues.remove(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mapTurbineValues.forEach((k1, v) -> {
|
|
|
+ sum.updateAndGet(v1 -> v1 + v);
|
|
|
+ });
|
|
|
+
|
|
|
+ //如果值为空则置0
|
|
|
+ if (sum.get() == 0) {
|
|
|
+ avgCutInWindSpeed = 0;
|
|
|
+ } else {
|
|
|
+ avgCutInWindSpeed = sum.get() / mapTurbineValues.size();
|
|
|
+ }
|
|
|
+ System.out.println(turbine.getTurbineId() + "切入平均风速" + avgCutInWindSpeed + "时间" + timeBegin);
|
|
|
+ }
|
|
|
+
|
|
|
+ //遍历map集合,取出每个风机的所有切出风速,算一个平均值
|
|
|
+ ConcurrentHashMap<String, Double> mapTurbineValues2 = mapOut.get(turbine.getTurbineId());
|
|
|
+
|
|
|
+ double avgCutOutWindSpeed;
|
|
|
+ if (mapTurbineValues2 != null) {
|
|
|
+ AtomicReference<Double> sum = new AtomicReference<>(0.0);
|
|
|
+
|
|
|
+ for (String key : mapTurbineValues2.keySet()) {
|
|
|
+ if (mapTurbineValues2.get(key) > 5) {
|
|
|
+ mapTurbineValues2.remove(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mapTurbineValues2.forEach((k2, v) -> {
|
|
|
+ sum.updateAndGet(v1 -> v1 + v);
|
|
|
+ });
|
|
|
+
|
|
|
+ if (sum.get() == 0) {
|
|
|
+ avgCutOutWindSpeed = 0;
|
|
|
+ } else {
|
|
|
+ avgCutOutWindSpeed = sum.get() / mapTurbineValues2.size();
|
|
|
+ }
|
|
|
+ System.out.println(turbine.getTurbineId() + "切出平均风速" + avgCutOutWindSpeed + "时间" + timeBegin);
|
|
|
+ }
|
|
|
+
|
|
|
+ //存入数据库
|
|
|
+ String turbineId = turbine.getTurbineId();
|
|
|
+ Date jdkDate = timeBegin.toJdkDate();
|
|
|
+ System.out.println(turbineId + " " + jdkDate);
|
|
|
+ QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
|
|
|
+ turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
|
|
|
+ turbineInfoDayQueryWrapper.eq("record_date", timeBegin.toJdkDate());
|
|
|
+ TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
|
|
|
+ System.out.println(one);
|
|
|
+ if (one == null) {
|
|
|
+ TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
|
|
|
+ turbineInfoDay.setTurbineId(turbine.getTurbineId());
|
|
|
+ turbineInfoDay.setRecordDate(timeBegin.toJdkDate());
|
|
|
+ turbineInfoDay.setXfqrfs(avgCutInWindSpeed);
|
|
|
+ System.out.println(turbineInfoDay);
|
|
|
+ turbineInfoDayService.save(turbineInfoDay);
|
|
|
+ } else {
|
|
|
+ one.setXfqrfs(avgCutInWindSpeed);
|
|
|
+ System.out.println(one);
|
|
|
+ turbineInfoDayService.updateById(one);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //满发下风速
|
|
|
+ @Test
|
|
|
+ public void fullSpeedWindSpeed() {
|
|
|
+ //date当天零点
|
|
|
+ DateTime timeNow = DateUtil.beginOfDay(new Date());
|
|
|
+ //date昨天零点
|
|
|
+ DateTime timeBegin = DateUtil.offsetDay(timeNow, -1);
|
|
|
+
|
|
|
+ //功率曲线拟合,
|
|
|
+ calcGlqxnh_edfs(timeBegin.toJdkDate(), timeNow.toJdkDate());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|