Browse Source

更新密码

523096025 1 year ago
parent
commit
f076d81fce

+ 179 - 0
huimv-admin/src/main/java/com/huimv/guowei/admin/timer/Pipe.java

@@ -0,0 +1,179 @@
+package com.huimv.guowei.admin.timer;
+
+
+import java.util.List;
+
+public class Pipe {
+    private final int pipeWidth, pipLength, threshold;
+    private int index;
+    private final boolean log = false;
+    private final List<Integer> data;
+
+    public Pipe(List<Integer> data) {
+        this.index = 0;
+        this.data = data;
+        this.pipeWidth = 40;  // stable range
+        this.pipLength = 6;  // stable window length
+        this.threshold = 100;  // sudden change threshold
+        this.run();
+    }
+
+    public Pipe(List<Integer> data, int width, int length, int thresh) {
+        this.index = 0;
+        this.data = data;
+        this.pipeWidth = width;
+        this.pipLength = length;
+        this.threshold = thresh;
+        this.run();
+    }
+
+    public static void show(List<Integer> data, String tag) {
+        System.out.println(tag + data);
+    }
+
+    public void show(String tag) {
+        System.out.println(tag + this.data);
+    }
+
+    private void run() {
+        while (this.index < this.data.size()) {
+            this.index = nextSudden();
+            if (this.index == -1) break;
+            int last = lastStable(), next = nextStable();
+            if (last == -1) {
+                if (next == -1) {
+                    smoothAfter(this.index);
+                    break;
+                } else {
+                    int value = stableValue(false, next);
+                    for (; this.index < next; this.index++) {
+                        if (this.log) System.out.printf("update1: data[%d]=%d -> %d\n", this.index, this.data.get(this.index), value);
+                        this.data.set(this.index, value);
+                    }
+                }
+            } else {
+                int value1 = stableValue(true, last);
+                if (next == -1) {
+                    for (; this.index < this.data.size(); this.index++) {
+                        if (this.log) System.out.printf("update2: data[%d]=%d -> %d\n", this.index, this.data.get(this.index), value1);
+                        this.data.set(this.index, value1);
+                    }
+                    break;
+                } else {
+                    int value2 = stableValue(false, next);
+                    if (Math.abs(value1 - this.data.get(this.index)) < Math.abs(value2 - this.data.get(this.index))) {
+                        for (int i = last + this.pipLength; i <= this.index; ++i) {
+                            if (this.log) System.out.printf("update3: data[%d]=%d -> %d\n", i, this.data.get(i), value1);
+                            this.data.set(i, value1);
+                        }
+                    } else {
+                        for (; this.index < next; this.index++) {
+                            if (this.log) System.out.printf("update4: data[%d]=%d -> %d\n", this.index, this.data.get(this.index), value2);
+                            this.data.set(this.index, value2);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private int nextSudden() {
+        if (this.log) System.out.printf("find sudden from %d\n", this.index);
+        for (int start = this.index, end = this.data.size() - 1; start < end; start++) {
+            if (Math.abs(this.data.get(start) - this.data.get(start + 1)) > this.threshold) {
+                if (this.log) System.out.printf("data[%d]=%d, data[%d]=%d, sudden found\n", start, this.data.get(start), start + 1, this.data.get(start + 1));
+                return start + 1;
+            }
+        }
+        return -1;
+    }
+
+    private int nextStable() {
+        int start = this.index + 1, end = this.index + this.pipLength;
+        while (end < this.data.size()) {
+            boolean stable = true;
+            for (int i = start; i < end; i++) {
+                if (Math.abs(this.data.get(i) - this.data.get(i + 1)) > this.pipeWidth) {
+                    stable = false;
+                    break;
+                }
+            }
+            if (stable) return start;
+            else {
+                start++;
+                end++;
+            }
+        }
+        return -1;
+    }
+
+    private int lastStable() {
+        int start = this.index - this.pipLength, end = this.index - 1;
+        while (start >= 0) {
+            boolean stable = true;
+            for (int i = start; i < end; i++) {
+                if (Math.abs(this.data.get(i) - this.data.get(i + 1)) > this.pipeWidth) {
+                    stable = false;
+                    break;
+                }
+            }
+            if (stable) return start;
+            else {
+                start--;
+                end--;
+            }
+        }
+        return -1;
+    }
+
+    private Integer stableValue(boolean last, int start) {
+        if (last) return this.data.get(start + this.pipLength - 1);
+        else return this.data.get(start);
+    }
+
+    private void smoothAfter(int start) {
+        for (; start < this.data.size(); ++start) {
+            if (this.log) System.out.printf("data[%d]=%d -> %d\n", start, this.data.get(start), windowAvg(start));
+            this.data.set(start, windowAvg(start));
+        }
+    }
+
+    private int windowAvg(int start) {
+        int end = start + this.pipLength;
+        if (end > this.data.size()) {
+            end = this.data.size();
+            start = end - this.pipLength;
+        }
+        int sum = 0;
+        while (start != end) sum += this.data.get(start++);
+        return sum / this.pipLength;
+    }
+
+    public int calcWeightLoss(final int hold) {
+        int sum = 0, pos1 = 0, pos2;
+        while (true) {
+            pos2 = nextAdd(pos1, hold);
+            if (pos2 == -1) {
+                int tmp = this.data.get(pos1) - this.data.get(this.data.size() - 1);
+                sum += Math.max(tmp, 0);
+                if (this.log) System.out.printf("data[%d]=%d - data[tail]=%d = %d, sum = %d\n", pos1, this.data.get(pos1), this.data.get(this.data.size() - 1), tmp, sum);
+                break;
+            } else {
+                int tmp = this.data.get(pos1) - this.data.get(pos2);
+                sum += Math.max(tmp, 0);
+                if (this.log) System.out.printf("data[%d]=%d - data[%d]=%d = %d, sum = %d\n", pos1, this.data.get(pos1), pos2, this.data.get(pos2), tmp, sum);
+                pos1 = pos2 + 1;
+            }
+        }
+        return sum;
+    }
+
+    private int nextAdd(int start, int hold) {
+        for (; start < this.data.size() - 1; start++) {
+            if (this.data.get(start + 1) - this.data.get(start) > hold) {
+                return start;
+            }
+        }
+        return -1;
+    }
+}

+ 20 - 10
huimv-admin/src/main/java/com/huimv/guowei/admin/timer/ProcudeFeed.java

@@ -37,19 +37,24 @@ public class ProcudeFeed {
     private RawDataMapper rawDataMapper;
 
 
-    //    @Scheduled(cron = "*/5 * * * * ?")
     //生成采食记录
     @Scheduled(cron = "12 0 * * * ?")
+//    @Scheduled(cron = "12 * * * * ?")
     private void saveFeed() {
 
         QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("farm_id", 21).eq("device_type", 3);
         List<EnvDevice> devices = deviceMapper.selectList(queryWrapper);
-        DateTime dateTime = DateUtil.beginOfDay(new Date());
+//        DateTime startdateTime = DateUtil.beginOfDay(new Date());
+//        DateTime endDate = DateUtil.endOfDay(new Date());
+        Date date = new Date();
+//        DateTime startdateTime =  DateUtil.offsetMinute(DateUtil.beginOfDay(DateUtil.offsetDay(new Date(),-4)),1);
+//        DateTime endDate = DateUtil.endOfDay(DateUtil.offsetDay(new Date(),-4));
         for (EnvDevice device : devices) {
             String deviceCode = device.getDeviceCode();
             //拿到采食记录,
-            List<EnvRegularCallFeeding> envRegularCallFeedings = feedingMapper.selectList(new QueryWrapper<EnvRegularCallFeeding>().eq("call_code", deviceCode).ge("call_date", dateTime));
+//            List<EnvRegularCallFeeding> envRegularCallFeedings = feedingMapper.selectList(new QueryWrapper<EnvRegularCallFeeding>().eq("call_code", deviceCode).ge("call_date", dateTime));
+            List<EnvRegularCallFeeding> envRegularCallFeedings = feedingMapper.selectList(new QueryWrapper<EnvRegularCallFeeding>().eq("call_code", deviceCode).ge("call_date", date));
             //拿到鸭只信息
             Integer unitId = device.getUnitId();
             BaseDuckInfo baseDuckInfo = baseDuckInfoMapper.selectOne(new QueryWrapper<BaseDuckInfo>().eq("unit_id", unitId).eq("is_cage", 0));
@@ -58,11 +63,15 @@ public class ProcudeFeed {
                 continue;
             }
             //拿到原始数据
-            List<RawData> rawData = rawDataMapper.selectList(new QueryWrapper<RawData>().eq("device_code", deviceCode).ge("create_time", dateTime));
+            List<RawData> rawData = rawDataMapper.selectList(new QueryWrapper<RawData>().eq("device_code", deviceCode).ge("create_time",  date));
             Double weight = 0.0;
             if (ObjectUtil.isNotEmpty(rawData)){
                 //拿到重量
                  weight = getWeight(rawData);
+
+            }
+            if (weight<0.0){
+                weight =0.0;
             }
 
             if (weight <0.0){
@@ -73,7 +82,7 @@ public class ProcudeFeed {
             if (ObjectUtil.isEmpty(envRegularCallFeedings)){
                 EnvRegularCallFeeding envRegularCallFeeding = new EnvRegularCallFeeding();
 //                envRegularCallFeeding.setBattery(batStr);
-                envRegularCallFeeding.setCallDate(new Date());
+                envRegularCallFeeding.setCallDate(date);
                 envRegularCallFeeding.setCallCode(deviceCode);
                 envRegularCallFeeding.setCallName(device.getDeviceName());
                 envRegularCallFeeding.setDuckId(baseDuckInfo.getId());
@@ -89,6 +98,7 @@ public class ProcudeFeed {
             }else {
                 EnvRegularCallFeeding envRegularCallFeeding = envRegularCallFeedings.get(0);
                 envRegularCallFeeding.setDuckWeight(weight);
+                envRegularCallFeeding.setCallDate(new Date());
                 feedingMapper.updateById(envRegularCallFeeding);
             }
 
@@ -107,11 +117,11 @@ public class ProcudeFeed {
             }
         }
         //获取重量算法
-        Filter filter = new Filter(list.stream()
-                .mapToInt(Integer::intValue)
-                .toArray());
-        int weightInt = filter.calcWeightLoss();
-        return  weightInt /10.0;
+
+        Pipe pipe = new Pipe(list);
+        int sum = pipe.calcWeightLoss(5000);
+
+        return  sum /10.0;
 
     }
 

+ 9 - 0
input/src/main/java/com/huimv/input/server/EnvInputServerHandler.java

@@ -294,6 +294,10 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter   {
             System.out.println("该位置不存在鸭子,数据抛弃");
             return;
         }
+        if (baseDuckInfo.getDuckSex() ==0){
+            System.out.println("该位置为雄鸭,数据抛弃");
+            return;
+        }
         List<EggProduction> farm_id = eggProductionMapper.selectList(new QueryWrapper<EggProduction>().eq("farm_id", envDevice.getFarmId()));
 
 
@@ -329,6 +333,11 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter   {
         BigDecimal minWeight = new BigDecimal(99999);
         //检蛋
         if(currentTime.isAfter(jianStartTime) && currentTime.isBefore(jianEndTime)){
+            List<EnvRegularCallEgg> call_date = envRegularCallEggMapper.selectList(new QueryWrapper<EnvRegularCallEgg>().ge("call_date", DateUtil.beginOfDay(new Date())));
+            if (ObjectUtil.isEmpty(call_date)){
+                return;
+            }
+
             for (int i = 0; i < 60; i++) {
                 String str1 = s[i * 2 + 11] + s[i * 2 + 10];
                 BigDecimal weight = new BigDecimal(Integer.parseInt(str1, 16));