|
@@ -16,6 +16,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.math.RoundingMode;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -35,46 +36,37 @@ public class CauseJobHandler implements ApplicationRunner {
|
|
|
|
|
|
private final Map<String, ArrayDeque<PointData>> pdaqMap = new ConcurrentHashMap<>();
|
|
private final Map<String, ArrayDeque<PointData>> pdaqMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
- private boolean isload = false;
|
|
|
|
-
|
|
|
|
- //@Resource
|
|
|
|
- //private DataFillJobHandler dataFillJobHandler;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void run(ApplicationArguments args) throws Exception {
|
|
public void run(ApplicationArguments args) throws Exception {
|
|
-
|
|
|
|
- //dataFillJobHandler.calcEquipPowerGenDay();
|
|
|
|
init();
|
|
init();
|
|
taskExecutor.submit(this::refreshQueue);
|
|
taskExecutor.submit(this::refreshQueue);
|
|
- isload = true;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void init() throws InterruptedException {
|
|
private void init() throws InterruptedException {
|
|
-
|
|
|
|
//缓存1分钟的值填满pdaqMap
|
|
//缓存1分钟的值填满pdaqMap
|
|
for (int i = 0; i < 60; i++) {
|
|
for (int i = 0; i < 60; i++) {
|
|
Map<String, PointData> latest = adapterApi.getLatest(CacheContext.pointCodes);
|
|
Map<String, PointData> latest = adapterApi.getLatest(CacheContext.pointCodes);
|
|
if (i == 0) {
|
|
if (i == 0) {
|
|
latest.forEach((k, v) -> {
|
|
latest.forEach((k, v) -> {
|
|
ArrayDeque<PointData> pdaq = new ArrayDeque<>(60);
|
|
ArrayDeque<PointData> pdaq = new ArrayDeque<>(60);
|
|
- pdaq.offer(v);
|
|
|
|
|
|
+ pdaq.offerFirst(v);
|
|
pdaqMap.put(k, pdaq);
|
|
pdaqMap.put(k, pdaq);
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
- latest.forEach((k, v) -> pdaqMap.get(k).offer(v));
|
|
|
|
|
|
+ latest.forEach((k, v) -> pdaqMap.get(k).offerFirst(v));
|
|
}
|
|
}
|
|
Thread.sleep(1000);
|
|
Thread.sleep(1000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void refreshQueue() {
|
|
private void refreshQueue() {
|
|
-
|
|
|
|
while (true) {
|
|
while (true) {
|
|
try {
|
|
try {
|
|
Map<String, PointData> latest = adapterApi.getLatest(CacheContext.pointCodes);
|
|
Map<String, PointData> latest = adapterApi.getLatest(CacheContext.pointCodes);
|
|
latest.forEach((k, v) -> {
|
|
latest.forEach((k, v) -> {
|
|
- pdaqMap.get(k).poll();
|
|
|
|
- pdaqMap.get(k).offer(v);
|
|
|
|
|
|
+ pdaqMap.get(k).pollLast();
|
|
|
|
+ pdaqMap.get(k).offerFirst(v);
|
|
});
|
|
});
|
|
Thread.sleep(1000);
|
|
Thread.sleep(1000);
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
@@ -84,89 +76,66 @@ public class CauseJobHandler implements ApplicationRunner {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 计算常用测点的1分钟平均数据
|
|
|
|
|
|
+ * 计算常用测点的1分钟平均数据,第一次执行延时60s
|
|
*/
|
|
*/
|
|
- @Scheduled(fixedRate = 60000)
|
|
|
|
|
|
+ @Scheduled(initialDelay = 60000, fixedRate = 60000)
|
|
private void calcRealtimeAverageTarget() {
|
|
private void calcRealtimeAverageTarget() {
|
|
-
|
|
|
|
- if (!isload) return;
|
|
|
|
try {
|
|
try {
|
|
- String pointCode;
|
|
|
|
- RealtimeAverageTarget target;
|
|
|
|
- double v;
|
|
|
|
//uniformcode,点名
|
|
//uniformcode,点名
|
|
- Map<String, String> entryValue;
|
|
|
|
Map<String, String> uniformcodeOne = appConfig.getUniformcodeOne();
|
|
Map<String, String> uniformcodeOne = appConfig.getUniformcodeOne();
|
|
- double speed;
|
|
|
|
- Double power;
|
|
|
|
|
|
|
|
List<RealtimeAverageTarget> targets = new ArrayList<>();
|
|
List<RealtimeAverageTarget> targets = new ArrayList<>();
|
|
for (Map.Entry<String, Map<String, String>> entry : CacheContext.equipUcMap.entrySet()) {
|
|
for (Map.Entry<String, Map<String, String>> entry : CacheContext.equipUcMap.entrySet()) {
|
|
-
|
|
|
|
- entryValue = entry.getValue();
|
|
|
|
-
|
|
|
|
- target = new RealtimeAverageTarget();
|
|
|
|
|
|
+ Map<String, String> entryValue = entry.getValue();
|
|
|
|
+ RealtimeAverageTarget target = new RealtimeAverageTarget();
|
|
target.setTime(DateUtil.beginOfMinute(DateUtil.date()).toTimestamp());
|
|
target.setTime(DateUtil.beginOfMinute(DateUtil.date()).toTimestamp());
|
|
- //target.setEquipmentId(entry.getKey());
|
|
|
|
target.setTbname(CacheContext.pjzb1fzMap.get(entry.getKey()));
|
|
target.setTbname(CacheContext.pjzb1fzMap.get(entry.getKey()));
|
|
|
|
|
|
- pointCode = entryValue.get(uniformcodeOne.get("wind-speed"));
|
|
|
|
|
|
+ String pointCode = entryValue.get(uniformcodeOne.get("wind-speed"));
|
|
if (pointCode != null) {
|
|
if (pointCode != null) {
|
|
//风速
|
|
//风速
|
|
- ArrayDeque<PointData> pointData = pdaqMap.get(pointCode);
|
|
|
|
- v = pointData.stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
- if (System.currentTimeMillis()-pointData.getFirst().getTs()>30*60*1000) {
|
|
|
|
- //如果离线或者别的原因获取不到风速,从全场实时平均风速获取
|
|
|
|
- Map<String, PointData> latest = adapterApi.getLatest(CacheContext.stationRealMeanSpeedMap.get(CacheContext.equipMap.get(entry.getKey()).getWindpowerstationId()));
|
|
|
|
- Iterator<PointData> iterator = latest.values().iterator();
|
|
|
|
- double doubleValue = 0;
|
|
|
|
- if (iterator.hasNext()) doubleValue = iterator.next().getDoubleValue();
|
|
|
|
- if (doubleValue > 3) v = doubleValue;
|
|
|
|
- }
|
|
|
|
- speed = NumberUtil.round(v, 2).doubleValue();
|
|
|
|
|
|
+ double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
+ double speed = NumberUtil.round(v, 2, RoundingMode.DOWN).doubleValue();
|
|
target.setWindSpeed((float) speed);
|
|
target.setWindSpeed((float) speed);
|
|
-
|
|
|
|
- if (speed < 3) {
|
|
|
|
|
|
+ Double power = CacheContext.mpdsMapMap.get(CacheContext.equipModelMap.get(entry.getKey())).get(speed);
|
|
|
|
+ if (power == null || speed <= 3){
|
|
power = 0.0;
|
|
power = 0.0;
|
|
- } else {
|
|
|
|
- power = CacheContext.mpdsMapMap.get(CacheContext.equipModelMap.get(entry.getKey())).get(speed);
|
|
|
|
}
|
|
}
|
|
- if (power == null) power = 0.0;
|
|
|
|
- target.setTheoryGeneration(NumberUtil.round(power, 2).floatValue());
|
|
|
|
|
|
+ target.setTheoryGeneration(NumberUtil.round(power, 2, RoundingMode.DOWN).floatValue());
|
|
}
|
|
}
|
|
pointCode = entryValue.get(uniformcodeOne.get("active-power"));
|
|
pointCode = entryValue.get(uniformcodeOne.get("active-power"));
|
|
if (pointCode != null) {
|
|
if (pointCode != null) {
|
|
- v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
- target.setPower(NumberUtil.round(v, 2).floatValue());
|
|
|
|
|
|
+ double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
+ target.setPower(NumberUtil.round(v, 2, RoundingMode.DOWN).floatValue());
|
|
}
|
|
}
|
|
pointCode = entryValue.get(uniformcodeOne.get("generator_speed"));
|
|
pointCode = entryValue.get(uniformcodeOne.get("generator_speed"));
|
|
if (pointCode != null) {
|
|
if (pointCode != null) {
|
|
- v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
- target.setGeneratorSpeed(NumberUtil.round(v, 2).floatValue());
|
|
|
|
|
|
+ double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
+ target.setGeneratorSpeed(NumberUtil.round(v, 2, RoundingMode.DOWN).floatValue());
|
|
}
|
|
}
|
|
pointCode = entryValue.get(uniformcodeOne.get("impeller_speed"));
|
|
pointCode = entryValue.get(uniformcodeOne.get("impeller_speed"));
|
|
if (pointCode != null) {
|
|
if (pointCode != null) {
|
|
- v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
- target.setImpellerSpeed(NumberUtil.round(v, 2).floatValue());
|
|
|
|
|
|
+ double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
+ target.setImpellerSpeed(NumberUtil.round(v, 2, RoundingMode.DOWN).floatValue());
|
|
}
|
|
}
|
|
pointCode = entryValue.get(uniformcodeOne.get("wind_direction"));
|
|
pointCode = entryValue.get(uniformcodeOne.get("wind_direction"));
|
|
if (pointCode != null) {
|
|
if (pointCode != null) {
|
|
- v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
|
|
+ double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
target.setWindDirection(NumberUtil.round(v, 2).floatValue());
|
|
target.setWindDirection(NumberUtil.round(v, 2).floatValue());
|
|
}
|
|
}
|
|
pointCode = entryValue.get(uniformcodeOne.get("blade_angle"));
|
|
pointCode = entryValue.get(uniformcodeOne.get("blade_angle"));
|
|
if (pointCode != null) {
|
|
if (pointCode != null) {
|
|
- v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
|
|
+ double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
target.setBladeAngle(NumberUtil.round(v, 2).floatValue());
|
|
target.setBladeAngle(NumberUtil.round(v, 2).floatValue());
|
|
}
|
|
}
|
|
pointCode = entryValue.get(uniformcodeOne.get("engine_direction"));
|
|
pointCode = entryValue.get(uniformcodeOne.get("engine_direction"));
|
|
if (pointCode != null) {
|
|
if (pointCode != null) {
|
|
- v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
|
|
+ double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
target.setEngineDirection(NumberUtil.round(v, 2).floatValue());
|
|
target.setEngineDirection(NumberUtil.round(v, 2).floatValue());
|
|
}
|
|
}
|
|
pointCode = entryValue.get(uniformcodeOne.get("wind_deviation"));
|
|
pointCode = entryValue.get(uniformcodeOne.get("wind_deviation"));
|
|
if (pointCode != null) {
|
|
if (pointCode != null) {
|
|
- v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
|
|
|
|
+ double v = pdaqMap.get(pointCode).stream().mapToDouble(PointData::getDoubleValue).average().orElse(0);
|
|
target.setWindDeviation(NumberUtil.round(v, 2).floatValue());
|
|
target.setWindDeviation(NumberUtil.round(v, 2).floatValue());
|
|
}
|
|
}
|
|
targets.add(target);
|
|
targets.add(target);
|
|
@@ -180,7 +149,6 @@ public class CauseJobHandler implements ApplicationRunner {
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|