Kaynağa Gözat

诊断报告,部分参数调整

chenminghua 2 yıl önce
ebeveyn
işleme
fdb135f6ea

+ 1 - 1
gyee-sample-impala/src/main/java/com/gyee/impala/common/util/DateUtil.java

@@ -458,6 +458,6 @@ public class DateUtil extends DateUtils {
     public static void main(String[] args) {
         System.out.println(getCurrentDate());
         System.out.println(getPreviousDate(3 * 360 * 24));
-//        System.out.println(covertDateTimestamp("2021-05-12 00:00:00"));
+        System.out.println(covertDateTimestamp("2021-12-30 00:00:00"));
     }
 }

+ 22 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/AutoFaultController.java

@@ -12,6 +12,7 @@ import com.gyee.impala.model.custom.diagnose.FaultInfo;
 import com.gyee.impala.model.custom.diagnose.PointData;
 import com.gyee.impala.model.master.diagnose.Diagnosepoint;
 import com.gyee.impala.model.master.diagnose.Diagnosereport;
+import com.gyee.impala.service.custom.diagnose.AutoCmdService;
 import com.gyee.impala.service.custom.diagnose.DataPointService;
 import com.gyee.impala.service.custom.diagnose.DataService;
 import com.gyee.impala.service.master.diagnose.DiagnosereportService;
@@ -32,6 +33,8 @@ public class AutoFaultController {
     private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
     @Resource
+    private AutoCmdService autoCmdService;
+    @Resource
     private DataService dataService;
     @Resource
     private DataPointService dataPointService;
@@ -144,6 +147,25 @@ public class AutoFaultController {
         return JsonResult.successData(ResultCode.SUCCESS, list);
     }
 
+
+    /**
+     * 在线测试  调用训练的脚本
+     * @param faultid
+     * @return
+     */
+    @GetMapping("/test/{faultid}")
+    public JSONObject test(@PathVariable long faultid) {
+        List<FaultInfo> fis = shardingBuilder.sharding().getFaultHistoryById(faultid + "");
+        if (fis == null || fis.size() <= 0) {
+            return JsonResult.error(ResultCode.ERROR_DATA);
+        }
+
+        FaultInfo fi = fis.get(0);
+        autoCmdService.exec(fi);
+        return JsonResult.success(ResultCode.SUCCESS);
+    }
+
+
     public static void main(String[] args){
         Calendar calendar = Calendar.getInstance();
         System.out.println(DateUtil.format(calendar.getTime(), DateUtil.YYYY_MM_DD_HH_MM_SS));

+ 37 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/DiagnoseReportController.java

@@ -0,0 +1,37 @@
+package com.gyee.impala.controller.diagnose;
+
+import com.alibaba.fastjson.JSONObject;
+import com.gyee.impala.common.result.JsonResult;
+import com.gyee.impala.common.result.ResultCode;
+import com.gyee.impala.common.spring.InitialRunner;
+import com.gyee.impala.model.master.Casefaultalg;
+import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
+import com.gyee.impala.service.master.CasefaultalgService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@CrossOrigin
+@RestController
+@RequestMapping("/api/diagnosereport")
+public class DiagnoseReportController {
+
+    @Autowired
+    private CasefaultalgService casefaultalgService;
+
+    @GetMapping("/item")
+    public JSONObject getOne(String id){
+        Casefaultalg fault = casefaultalgService.getById(id);
+        List<Diagnosetrainhistory> info = InitialRunner.historyModelMap.get(fault.getStationen() + "_" + fault.getModel());
+        Map<String, Object> map = new HashMap<>();
+        map.put("fault", fault);
+        map.put("info", info);
+        return JsonResult.successData(ResultCode.SUCCESS, map);
+    }
+}

+ 2 - 2
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/TrainFileModeController.java

@@ -185,9 +185,9 @@ public class TrainFileModeController {
             data.setFaultTime(faults.get(i).getStarttime());
 
             cal.setTime(DateUtil.parseStrtoDate(faults.get(i).getStarttime(), DateUtil.YYYY_MM_DD_HH_MM_SS));
-            cal.add(Calendar.MINUTE, -30);
+            cal.add(Calendar.MINUTE, -10);
             data.setStartTs(cal.getTimeInMillis() + "");
-            cal.add(Calendar.MINUTE, 30);
+            cal.add(Calendar.MINUTE, 10);
             data.setEndTs(cal.getTimeInMillis() + "");
             dataInfos[i] = data;
         }

+ 2 - 2
gyee-sample-impala/src/main/java/com/gyee/impala/model/custom/diagnose/PointData.java

@@ -1,9 +1,9 @@
 package com.gyee.impala.model.custom.diagnose;
 
 public class PointData {
-    private long ts;
+    private long ts = 0;
     private double doubleValue = 0;
-    private boolean booleanValue ;
+    private boolean booleanValue = false;
 
     public double getValue(){
         return booleanValue ? 1 : doubleValue;

+ 2 - 1
gyee-sample-impala/src/main/java/com/gyee/impala/service/custom/diagnose/AutoCmdService.java

@@ -36,7 +36,8 @@ public class AutoCmdService {
         List<Diagnosetrainhistory> ls = InitialRunner.historyModelMap.get(fi.getStationId() + "_" + fi.getModelId());
         try {
             Diagnosetrainhistory history = ls.get(0);
-            String[] cmd = {"/bin/sh", "-c", "python " + cmdPath + "predict_route.py " + history.getCode() + " " + fi.getId()};
+            System.out.println("脚本调用成功: " + history.toString());
+            String[] cmd = {"/bin/sh", "-c", "python " + cmdPath + "Predict_Online.py " + history.getCode() + " " + fi.getId()};
             //String[] cmd = {"/bin/sh", "-c", "python " + cmdPath + "ANNs_predict" + fi.getStationId() + "_" + fi.getModelId() + ".py " + fi.getId()};
             p = Runtime.getRuntime().exec(cmd);
             BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));

+ 8 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/service/custom/diagnose/DataPointService.java

@@ -150,6 +150,14 @@ public class DataPointService {
             }
             try {
                 List<PointData> pds = dataAdapterBuilder.adapter().getHistoryByUniformCode(ci.getUniformcode(), di.getStartTs(), di.getEndTs(), di.getThingId());
+                long st = Long.valueOf(di.getStartTs());
+                long et = Long.valueOf(di.getEndTs());
+                if (pds.size() == 0){
+                    for (long i = st; i <= et; i++){
+                        PointData obj = new PointData();
+                        pds.add(obj);
+                    }
+                }
                 pairs.put(ci.getName(), pds);
             } catch (Exception e) {
                 e.printStackTrace();

+ 3 - 18
gyee-sample-impala/src/main/java/com/gyee/impala/service/custom/diagnose/FaultRefreshService.java

@@ -53,13 +53,10 @@ public class FaultRefreshService implements ApplicationRunner {
         while (true) {
             try {
                 toRefresh();
+                Thread.sleep(30 * 1000);
             } catch (Exception ex) {
                 ex.printStackTrace();
             }
-            try {
-                Thread.sleep(10 * 1000);
-            } catch (Exception e) {
-            }
         }
     }
 
@@ -68,21 +65,9 @@ public class FaultRefreshService implements ApplicationRunner {
      */
     private void toRefresh() {
         calendar = Calendar.getInstance();
-        calendar.add(Calendar.MINUTE, -10);
+        calendar.add(Calendar.MINUTE, -5);
         String s = dateFormat.format(calendar.getTime());
 
-        /** 每次启动先缓存一次 **/
-        if (infoCache.faultMap.size() == 0){
-            List<FaultInfo> faultRecent = shardingBuilder.sharding().getFaultRecent(s);
-            List<FaultInfo> collect = faultRecent.stream().filter(f -> f.getCategory1().equals("FJ") && f.getCategory2().equals("GZ")).collect(Collectors.toList());
-            Map<Long, FaultInfo> map = collect.stream().collect(Collectors.toMap(FaultInfo::getId, Function.identity(), (key1, key2) -> key2));
-            for (FaultInfo fi : map.values()) {
-                if (!infoCache.faultMap.containsKey(fi.getId()+fi.getFaultTime()+fi.getSnapID())) {
-                    infoCache.faultMap.put(fi.getId()+fi.getFaultTime()+fi.getSnapID(), fi);
-                }
-            }
-        }
-
         List<FaultInfo> faultRecent = shardingBuilder.sharding().getFaultRecent(s);
         List<FaultInfo> collect = faultRecent.stream().filter(f -> f.getCategory1().equals("FJ") && f.getCategory2().equals("GZ")).collect(Collectors.toList());
         Map<Long, FaultInfo> map = collect.stream().collect(Collectors.toMap(FaultInfo::getId, Function.identity(), (key1, key2) -> key2));
@@ -94,7 +79,7 @@ public class FaultRefreshService implements ApplicationRunner {
             }
         }
 
-        /** 缓存数据量太大于2000条时  清除部分缓存 **/
+        /** 缓存数据量太大于1000条时  清除部分缓存 **/
         if (infoCache.faultMap.size() > 1000){
             int count = 0;
             for (Iterator<Map.Entry<String, FaultInfo>> it = infoCache.faultMap.entrySet().iterator(); it.hasNext();){

+ 2 - 1
gyee-sample-impala/src/main/java/com/gyee/impala/service/impl/slave/FaulthistoryServiceImpl.java

@@ -28,7 +28,8 @@ public class FaulthistoryServiceImpl extends ServiceImpl<FaulthistoryMapper, Fau
         ExcludeQueryWrapper<Faulthistory> wrapper = new ExcludeQueryWrapper<>();
 
         wrapper.eq("snapid", snapId)
-                .between("faulttime", startTime, endTime);
+                .between("faulttime", startTime, endTime)
+                .orderByDesc("faulttime");
         try {
             return baseMapper.selectList(wrapper);
         } catch (Exception e) {