Browse Source

修改能耗计算,修改重量计算

wukai 6 tháng trước cách đây
mục cha
commit
c5b8cc8941

+ 25 - 39
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/AsyncServiceImpl.java

@@ -56,11 +56,11 @@ public class AsyncServiceImpl {
         Map<String, Object> map = calc(table, startTime, endTime);
 
 
-        //0.已织造米数 1.总重量 2.总能耗
+        //0.已织造米数  1.总能耗 2.总重量
         float[] total = (float[]) map.get("total");
         hour.setLength(BigDecimal.valueOf(total[0]));
-        hour.setWeight(BigDecimal.valueOf(total[1]));
-        hour.setKwh(BigDecimal.valueOf(total[2]));
+        hour.setWeight(BigDecimal.valueOf(total[2]));
+        hour.setKwh(BigDecimal.valueOf(total[1]));
         hour.setOpenTime((long) total[3]);
         hour.setCloseTime((long) total[4]);
         calcHours.add(hour);
@@ -99,7 +99,8 @@ public class AsyncServiceImpl {
             "Alarm_unit_14", "Alarm_unit_15", "Alarm_unit_16", "Alarm_unit_17", "Alarm_unit_18",
             "Alarm_unit_19", "Alarm_unit_20", "Alarm_unit_21", "Alarm_unit_22", "Alarm_unit_23",
             "Alarm_unit_24", "Alarm_unit_25", "Alarm_unit_26", "Alarm_unit_27", "Capacity_data_33",
-            "Capacity_data_15", "Capacity_data_16", "Capacity_data_17", "Capacity_data_18", "Capacity_data_19"
+            "Capacity_data_15", "Capacity_data_16", "Capacity_data_17", "Capacity_data_18", "Capacity_data_19",
+            "Capacity_data_34"
     };
 
 
@@ -133,11 +134,11 @@ public class AsyncServiceImpl {
         JSONArray timestamps = data.getJSONArray("timestamps");
         //初始时间点数据
         //0-data2,1-data37,2-data38,3-data39,4-data42,5-data-43,6data-44
-        //2024-06-26 1-6不要了 0织造米长
-        float[] first = new float[1];
+        //2024-06-26 1-6不要了 0织造米长 1.电量
+        float[] first = new float[2];
         //上一个时间点数据
-        float[] last = new float[1];
-        //统计数据,后面2个分别代表0.织造米长 1.重量,2.电量,3.开机时间,4.停机时间
+        float[] last = new float[2];
+        //统计数据,后面2个分别代表0.织造米长,1.电量 2.重量,3.开机时间,4.停机时间
         float[] total = new float[5];
         //上一个时间点盘头数据
         int[] lastPanHead = new int[5];
@@ -165,7 +166,7 @@ public class AsyncServiceImpl {
             JSONArray da = values.getJSONArray(i);
             //0-data2,1-data37,2-data38,3-data39,4-data42,5-data-43,6data-44
             //当前时间数据
-            float[] curr = {da.getFloat(0)};
+            float[] curr = {da.getFloat(0), da.getFloat(fieldList.indexOf("Capacity_data_34"))};
             int[] currPan = {da.getInt(fieldList.indexOf("Capacity_data_15")), da.getInt(fieldList.indexOf("Capacity_data_16")), da.getInt(fieldList.indexOf("Capacity_data_17")),
                     da.getInt(fieldList.indexOf("Capacity_data_18")), da.getInt(fieldList.indexOf("Capacity_data_19"))};
             int curr48 = da.getInt(7);
@@ -180,20 +181,19 @@ public class AsyncServiceImpl {
                 last48 = curr48;
                 continue;
             }
-            //计算电量
-            calcKwh(da, total);
             //计算盘头
             calcPan(currPan, lastPanHead, panHeadInfo, timestamps.getLong(i));
 
-            for (int j = 0; j < first.length; j++) {
+//            for (int j = 0; j < first.length; j++) {
                 //如果当前值为小于上一个,且上一个值不为0,则计算
                 //因为会出现数据波动,停机再启动之后的第一个点不为0,为0.00几几几的
                 //计算累加类的数据
-                if (curr[j] < last[j] && last[j] != 0f) {
-                    calcTotal(j, last, first, total, lastMkz, lastFk);
-                    first[j] = curr[j];
+                //这里只计算米长
+                if (curr[0] < last[0] && last[0] != 0f) {
+                    calcTotal(0, last, first, total, lastMkz, lastFk);
+                    first[0] = curr[0];
                 }
-            }
+//            }
             calcAlarms(values, old, timestamps.getLong(i), alarmRecord, i);
             calcStops(curr48, last48, timestamps.getLong(i), total, stopRecord, old, i);
 
@@ -206,13 +206,17 @@ public class AsyncServiceImpl {
         }
         //最后再补一次计算
         for (int j = 0; j < first.length; j++) {
+            //这里米长和电量都要计算
             calcTotal(j, last, first, total, lastMkz, lastFk);
         }
 
         //存入最后一条记录的停机状态
 //        CacheUtils.put(Constants.IOT_TOKEN, table, values.getJSONArray(values.size() - 1));
-
-        total[3] = (endTime - startTime) / 1000 + 1 - total[4];
+        long openTime = (endTime - startTime) / 1000 + 1;
+        if (openTime < total[4]) {
+            total[4] = openTime;
+        }
+        total[3] = openTime - total[4];
 
         Map<String, Object> result = new HashMap<>(16);
         result.put("total", total);
@@ -244,27 +248,9 @@ public class AsyncServiceImpl {
         }
     }
 
-    /**
-     * 能耗计算
-     * total[2].总电量
-     *
-     * @param da    当前数据
-     * @param total 统计数组
-     */
-
-    private void calcKwh(JSONArray da, float[] total) {
-        BigDecimal v = da.getBigDecimal(fieldList.indexOf("Capacity_data_33"));
-        //单位为W 换算成当前这一秒的用电量 需要除以1000变成千瓦,再除以3600 变成千瓦时
-        v = v.divide(BigDecimal.valueOf(3600), 5, RoundingMode.HALF_UP);
-        v = v.divide(BigDecimal.valueOf(1000), 5, RoundingMode.HALF_UP);
-        float kwh = v.floatValue();
-        total[2] = total[2] + kwh;
-    }
 
     /**
      * 停机次数计算
-     */
-    /**
      * 停机处理
      *
      * @param curr       当前值
@@ -444,9 +430,9 @@ public class AsyncServiceImpl {
         float v = last[j] - first[j];
         total[j] += v;
         if (j == 0) {
-            //如果是米长,则计算重量
-            float weight = BigDecimal.valueOf(v * lastMkz * lastFk / 1000 / 1000).setScale(2, RoundingMode.HALF_UP).floatValue();
-            total[1] = total[1] + weight;
+            //如果是米长,则计算重量,米长*米克重*2 2024-11-15
+            float weight = BigDecimal.valueOf(v * lastMkz * 2 / 1000 / 1000).setScale(2, RoundingMode.HALF_UP).floatValue();
+            total[2] = total[2] + weight;
         }
     }
 

+ 69 - 0
ruoyi-admin/src/test/java/com/jjt/JlTest.java

@@ -0,0 +1,69 @@
+package com.jjt;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.ruoyi.RuoYiApplication;
+import com.ruoyi.biz.domain.TwinDevice;
+import com.ruoyi.biz.service.IIotService;
+import com.ruoyi.biz.service.ITwinDeviceService;
+import com.ruoyi.biz.service.impl.AsyncServiceImpl;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.annotation.Resource;
+
+/**
+ * DataProcess$
+ *
+ * @author wukai
+ * @date 2024/5/7 11:49
+ */
+@SpringBootTest(classes = RuoYiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class JlTest {
+    @Resource
+    private JdbcTemplate jdbcTemplate;
+    @Resource
+    private ITwinDeviceService deviceService;
+    @Resource
+    private IIotService iotService;
+    @Resource
+    private AsyncServiceImpl asyncService;
+
+    @Test
+    void tt() {
+        TwinDevice device = new TwinDevice();
+        device.setOnline("1");
+        deviceService.selectTwinDeviceList(device).forEach(twinDevice -> {
+            String table = twinDevice.getDevicePath();
+            Long id = twinDevice.getDeviceId();
+//            process(id, table);
+        });
+//        String table = "root.tl.suxi.knittings33_plc1";
+//        process(33l,table);
+    }
+
+    @Test
+    void process() {
+        String sql = "select last Capacity_data_48 from root.tl.suxi.**";
+        JSONObject jsonObject = iotService.query(sql);
+        JSONObject data = jsonObject.getJSONObject("data");
+        JSONArray values = data.getJSONArray("values");
+        int xxx=0;
+        int yyy=0;
+        for (int i = 0; i < values.size(); i++) {
+            JSONArray arr = values.getJSONArray(i);
+            String name = arr.getStr(0);
+            if (name.startsWith("root.tl.suxi.knittings")) {
+                xxx++;
+                Float value = arr.getFloat(1);
+                if (value == 7f) {
+                    yyy++;
+                System.err.println(name + "\t" + value);
+                }
+            }
+        }
+
+        System.err.println(xxx+"\t"+yyy);
+    }
+}

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 9 - 9
ruoyi-admin/src/test/java/com/jjt/LastProcess.java


+ 69 - 0
ruoyi-admin/src/test/java/com/jjt/OnlineTest.java

@@ -0,0 +1,69 @@
+package com.jjt;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.ruoyi.RuoYiApplication;
+import com.ruoyi.biz.domain.TwinDevice;
+import com.ruoyi.biz.service.IIotService;
+import com.ruoyi.biz.service.ITwinDeviceService;
+import com.ruoyi.biz.service.impl.AsyncServiceImpl;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.annotation.Resource;
+
+/**
+ * DataProcess$
+ *
+ * @author wukai
+ * @date 2024/5/7 11:49
+ */
+@SpringBootTest(classes = RuoYiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class OnlineTest {
+    @Resource
+    private JdbcTemplate jdbcTemplate;
+    @Resource
+    private ITwinDeviceService deviceService;
+    @Resource
+    private IIotService iotService;
+    @Resource
+    private AsyncServiceImpl asyncService;
+
+    @Test
+    void tt() {
+        TwinDevice device = new TwinDevice();
+        device.setOnline("1");
+        deviceService.selectTwinDeviceList(device).forEach(twinDevice -> {
+            String table = twinDevice.getDevicePath();
+            Long id = twinDevice.getDeviceId();
+//            process(id, table);
+        });
+//        String table = "root.tl.suxi.knittings33_plc1";
+//        process(33l,table);
+    }
+
+    @Test
+    void process() {
+        String sql = "select last Capacity_data_1 from root.tl.suxi.**";
+        JSONObject jsonObject = iotService.query(sql);
+        JSONObject data = jsonObject.getJSONObject("data");
+        JSONArray values = data.getJSONArray("values");
+        int xxx=0;
+        int yyy=0;
+        for (int i = 0; i < values.size(); i++) {
+            JSONArray arr = values.getJSONArray(i);
+            String name = arr.getStr(0);
+            if (name.startsWith("root.tl.suxi.knittings")) {
+                xxx++;
+                Float value = arr.getFloat(1);
+                if (value > 0f) {
+                    yyy++;
+                }
+                System.err.println(name + "\t" + value);
+            }
+        }
+
+        System.err.println(xxx+"\t"+yyy);
+    }
+}

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác