Browse Source

切入风速完成

malijun 8 months ago
parent
commit
12001697cd
1 changed files with 67 additions and 64 deletions
  1. 67 64
      ruoyi-admin/src/test/java/com/ruoyi/ZhiBiaoCalculation.java

+ 67 - 64
ruoyi-admin/src/test/java/com/ruoyi/ZhiBiaoCalculation.java

@@ -99,7 +99,7 @@ public class ZhiBiaoCalculation {
                 //如果1的值为0,2的值为2,则为切入状态
                 if (value1 == 0 && value2 == 2) {
                     ts1 = pointData2.getTs();
-                    String stringDate = DateUtil.date(ts1).toString("yyyy-MM-dd HH:mm:ss");
+//                    String stringDate = DateUtil.date(ts1).toString("yyyy-MM-dd HH:mm:ss");
 //                    System.out.println(turbine.getTurbineId() + "切入" + stringDate);
                     //切入时间前5分钟
                     long ts11 = ts1 - 300000;
@@ -130,83 +130,86 @@ public class ZhiBiaoCalculation {
 
                     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();
+
+            }
+            //遍历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);
                     }
-                    System.out.println(turbine.getTurbineId() + "切入平均风速" + avgCutInWindSpeed + "时间" + timeBegin);
                 }
+                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());
+            //遍历map集合,取出每个风机的所有切出风速,算一个平均值
+            ConcurrentHashMap<String, Double> mapTurbineValues2 = mapOut.get(turbine.getTurbineId());
 
-                double avgCutOutWindSpeed;
-                if (mapTurbineValues2 != null) {
-                    AtomicReference<Double> sum = new AtomicReference<>(0.0);
+            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();
+                for (String key : mapTurbineValues2.keySet()) {
+                    if (mapTurbineValues2.get(key) > 5) {
+                        mapTurbineValues2.remove(key);
                     }
-                    System.out.println(turbine.getTurbineId() + "切出平均风速" + avgCutOutWindSpeed + "时间" + timeBegin);
                 }
+                mapTurbineValues2.forEach((k2, v) -> {
+                    sum.updateAndGet(v1 -> v1 + v);
+                });
 
-                //存入数据库
-                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);
+                if (sum.get() == 0) {
+                    avgCutOutWindSpeed = 0;
                 } else {
-                    one.setXfqrfs(avgCutInWindSpeed);
-                    System.out.println(one);
-//                turbineInfoDayService.updateById(one);
+                    avgCutOutWindSpeed = sum.get() / mapTurbineValues2.size();
                 }
+                System.out.println(turbine.getTurbineId() + "切出平均风速" + avgCutOutWindSpeed + "时间" + timeBegin);
+            }
 
-//            turbineInfoDayService.saveOrUpdate(one);
-
+            //存入数据库
+            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);
             }
+
         }
+    }
 
 
+    //满发下风速
+    public void fullSpeedWindSpeed() {
     }
+
+
 }