ソースを参照

文件名修改

chenminghua 2 年 前
コミット
02a0aa5441

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

@@ -16,7 +16,7 @@ import com.gyee.impala.model.master.diagnose.Diagnosepoint;
 import com.gyee.impala.model.master.diagnose.Diagnosereport;
 import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
 import com.gyee.impala.service.custom.diagnose.AutoCmdService;
-import com.gyee.impala.service.custom.diagnose.DataPointService;
+import com.gyee.impala.service.custom.diagnose.DataDiagnoseService;
 import com.gyee.impala.service.custom.diagnose.DataService;
 import com.gyee.impala.service.master.diagnose.DiagnosereportService;
 import org.springframework.web.bind.annotation.*;
@@ -38,7 +38,7 @@ public class AutoFaultController {
     @Resource
     private DataService dataService;
     @Resource
-    private DataPointService dataPointService;
+    private DataDiagnoseService dataPointService;
     @Resource
     private DiagnosereportService reportService;
     @Resource

+ 187 - 48
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/TrainFaultDiagnoseController.java

@@ -10,77 +10,168 @@ import com.gyee.impala.model.custom.diagnose.ExecuteInfo;
 import com.gyee.impala.model.master.Casefault;
 import com.gyee.impala.model.master.diagnose.Diagnosepoint;
 import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
+import com.gyee.impala.model.master.diagnose.TrainInfo;
 import com.gyee.impala.service.custom.diagnose.DataDiagnoseService;
-import com.gyee.impala.service.custom.diagnose.TrainFaultDiagnoseService;;
+import com.gyee.impala.service.master.CasefaultService;
+import com.gyee.impala.service.custom.diagnose.TrainDataModeService;
+import com.gyee.impala.service.custom.diagnose.TrainFileModeService;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.kudu.client.ListTablesResponse;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
 import java.util.stream.Collectors;
 
+
 /**
- * 故障预测
+ * 故障诊断模型训练
  */
 @Slf4j
 @CrossOrigin
 @RestController
-    @RequestMapping("/api/diagnose")
+@RequestMapping("/api/diagnose")
 public class TrainFaultDiagnoseController {
 
-
     @Autowired
-    private TrainFaultDiagnoseService trainFaultDiagnoseService;
+    private DataDiagnoseService dataService;
+    @Autowired
+    private CasefaultService casefaultService;
+    @Autowired
+    TrainDataModeService trainDataModeService;
+
     /**
-     * 参数
+     * 线程池
      */
+    @Resource
+    private ThreadPoolTaskExecutor taskExecutor;
+
+    @Autowired
+    private TrainFileModeService trainFileModeService;
+
+    private static final Object locker = new Object();
+
+
+    private String name1;
+    private String forecastLabel1;
+    private String[] inputLabel1;
+    private String host1;
+    private MultipartFile file1;
     private ExecuteInfo executeInfo;
+    private String fileName;
+
 
     /**
-     * 数据服务
+     * 文件模式训练接口
+     * @param request
+     * @param name
+     * @param forecastLabel
+     * @param inputLabel
+     * @param host
+     * @param file
+     * @return
      */
-    @Autowired
-    private DataDiagnoseService dataDiagnoseService;
+    @PostMapping("/trainfile")
+    @ResponseBody
+    public JSONObject getTrainfile(HttpServletRequest request, String name, String forecastLabel, String[] inputLabel, String host, MultipartFile file) {
+
+        if (!trainFileModeService.isComplete()) {
+            return JsonResult.error(4000, "命令正在执行...");
+        }
+
+        if (file.isEmpty()) {
+            return JsonResult.error(ResultCode.ERROR_FILE_NO);
+        }
+
+        try {
+            synchronized (locker) {
+                name1 = name;
+                forecastLabel1 = forecastLabel;
+                inputLabel1 = inputLabel;
+                host1 = host;
+                file1 = file;
+                taskExecutor.submit(this::execute);
+            }
+
+            return JsonResult.success(ResultCode.SUCCESS);
+        } catch (Exception e) {
+            return JsonResult.error(ResultCode.ERROR_DATA_FILE);
+        }
+    }
+
 
     /**
-     * 线程池
+     * 调用执行脚本
      */
-    @Resource
-    private ThreadPoolTaskExecutor taskExecutor;
+    private void execute() {
+        trainFileModeService.exec(name1, forecastLabel1, inputLabel1, host1, file1);
+    }
 
+    /**   在线训练  **/
     /**
-     * 预测生成文件名
+     * 查询数据库的表
+     * @return
      */
-    private String fileName;
-
+    @GetMapping("/tables")
+    public JSONObject getListTables(){
+        List<Map<String, String>> list = new ArrayList<>();
+        try {
+            List<ListTablesResponse.TableInfo> tables = trainDataModeService.getListTables();
+            tables.stream().filter(a -> a.getTableName().equals("impala::gyee_sample_kudu.casefault")).forEach(obj -> {
+                Map<String, String> map = new HashMap<>();
+                String name = obj.getTableName().substring(obj.getTableName().lastIndexOf(".") + 1);
+                map.put("tableId", obj.getTableId());
+                map.put("tableName", name);
+                list.add(map);
+            });
+        } catch (Exception e) { e.getMessage(); }
+
+        return JsonResult.successData(ResultCode.SUCCESS,list);
+    }
 
-    private static final Object locker = new Object();
+    /**
+     * 查询数据库表的列
+     * @param table
+     * @return
+     */
+    @GetMapping("/columns")
+    public JSONObject getColumns(String table){
+        Object columns = null;
+        try {
+            columns = trainDataModeService.getColumns(table);
+        } catch (Exception e) { e.getMessage(); }
 
+        return JsonResult.successData(ResultCode.SUCCESS, columns);
+    }
 
 
+    /** 查询样本数据 **/
+    @GetMapping("/data")
+    public JSONObject getData(String sql){
+        List<Casefault> list = casefaultService.executeSql(sql);
+        return JsonResult.successData(ResultCode.SUCCESS, list);
+    }
 
 
-    /** 开始预测 查询 golden 所有原始数据
-     *  flag  ture: 所有数据 ;false: 前10条数据
+    /** 开始训练 查询 golden 所有原始数据
+     *  flag  ture: 所有数据
+     *  flag  false: 前10条数据
      * **/
-    @PostMapping("/pointfaultdata")
+    @PostMapping("/pointdata")
     public JSONObject getPointData(@RequestBody JSONObject json){
         if (json == null)
             return JsonResult.error(ResultCode.PARAM_IS_BLANK);
 
-
-        log.info("进入预测程序");
         boolean flag = json.getBooleanValue("flag");
         List<Diagnosepoint> points = JSONObject.parseArray(json.getJSONArray("points").toString(), Diagnosepoint.class);
         List<Casefault> faults = JSONObject.parseArray(json.getJSONArray("faults").toString(), Casefault.class);
 
         /** 组装数据  删除添加的故障类型**/
-        dataDiagnoseService.formatUniformcode(points.stream().filter(a -> !a.getUniformcode().equals("faulttype")).collect(Collectors.toList()));
+        dataService.formatUniformcode(points.stream().filter(a -> !a.getUniformcode().equals("faulttype")).collect(Collectors.toList()));
         executeInfo = new ExecuteInfo();
         Calendar cal = Calendar.getInstance();
         DataInfo[] dataInfos = new DataInfo[faults.size()];
@@ -94,58 +185,89 @@ public class TrainFaultDiagnoseController {
             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;
         }
         executeInfo.setDataInfos(dataInfos);
         if (flag){
-            if (!trainFaultDiagnoseService.isComplete()) {
-                return JsonResult.error(4000, "已有正在预测的故障模型...");
+            if (!trainFileModeService.isComplete()) {
+                return JsonResult.error(4000, "已有正在训练的模型...");
             }
             synchronized (locker) {
-                taskExecutor.submit(this::execute);
+                taskExecutor.submit(this::execute2);
             }
             return JsonResult.success(ResultCode.SUCCESS);
         }else {
-            Map<String, Object> mp = dataDiagnoseService.getFormData(executeInfo);
+            Map<String, Object> mp = dataService.getFormData(executeInfo);
             return JsonResult.successData(ResultCode.SUCCESS, mp);
         }
     }
 
-
     /**
      * 调用执行脚本
      */
-    private void execute() {
-
-        fileName = dataDiagnoseService.getFormDataAll(executeInfo);
-        trainFaultDiagnoseService.exec();
-
+    private void execute2() {
+        fileName = dataService.getFormDataAll(executeInfo);
+        trainFileModeService.exec();
     }
 
-
-
     /**
-     * py 获取预测数据
+     * py 获取在线训练数据
      *
      * @return
      */
-    @GetMapping("/trainfaultdata")
+    @GetMapping("/traindata")
     public JSONObject getData() {
         Map<String, Object> map = new HashMap<>();
         map.put("info", this.executeInfo);
         map.put("filename", fileName);
         return JsonResult.successData(ResultCode.SUCCESS, map);
     }
+    /**   在线训练  **/
+
 
+    /**
+     * 生产控制台信息
+     * @param trainInfo
+     * @return
+     */
+    @PostMapping("/addtrainInfo")
+    public JSONObject addProducer(@RequestBody String trainInfo) {
+
+        try {
+            TrainInfo t = JSONObject.parseObject(trainInfo, TrainInfo.class);
+            trainFileModeService.produce(t);
+
+            return JsonResult.success(ResultCode.SUCCESS);
+        } catch (Exception e) {
+            return JsonResult.error(ResultCode.ERROR);
+        }
 
+    }
 
 
     /**
-     * 缓存训练预测模型结果
+     * 消费控制台信息
+     * @return
+     */
+    @GetMapping("/gettrainInfo")
+    @ResponseBody
+    public JSONObject getConsume() {
+        try {
+            List<TrainInfo> list = trainFileModeService.consume();
+            System.out.println(JsonResult.successData(ResultCode.SUCCESS, list));
+            return JsonResult.successData(ResultCode.SUCCESS, list);
+        } catch (Exception e) {
+            return JsonResult.error(ResultCode.ERROR);
+        }
+    }
+
+
+    /**
+     * 添加训练结果
      *
      * @param history
      * @return
@@ -154,7 +276,7 @@ public class TrainFaultDiagnoseController {
     public JSONObject putDiagnosetrainhistory(@RequestBody String history) {
         try {
             log.info("训练模型结果:" + history);
-            trainFaultDiagnoseService.putDiagnosetrainhistory(history);
+            trainFileModeService.putDiagnosetrainhistory(history);
             return JsonResult.success(ResultCode.SUCCESS);
         } catch (Exception e) {
             log.error("请求错误", e);
@@ -163,16 +285,14 @@ public class TrainFaultDiagnoseController {
     }
 
 
-
-
     /**
-     * 获取当前训练预测模型结果
+     * 获取当前训练结果
      * @return
      */
     @GetMapping("/getHistory")
     public JSONObject getHistory() {
         try {
-            Diagnosetrainhistory d = trainFaultDiagnoseService.getHistoryQueue();
+            Diagnosetrainhistory d = trainFileModeService.consumeHistory();
             return JsonResult.successData(ResultCode.SUCCESS, d);
         } catch (Exception e) {
             log.error("请求错误", e);
@@ -182,4 +302,23 @@ public class TrainFaultDiagnoseController {
 
 
 
+    /**
+     * 预测评估
+     *
+     * @param jsonObject
+     * @return
+     */
+    @PostMapping("/forecasts")
+    public JSONObject forecasts(@RequestBody JSONObject jsonObject) {
+        try {
+            log.warn("预估请求数据:" + jsonObject.toJSONString());
+            String resultvalue = trainFileModeService.forecasts(jsonObject);
+            return JsonResult.successData(ResultCode.SUCCESS, resultvalue);
+        } catch (Exception e) {
+            return JsonResult.error(ResultCode.ERROR);
+        }
+
+    }
+
+
 }

+ 185 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/TrainFaultPredictController.java

@@ -0,0 +1,185 @@
+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.util.DateUtil;
+import com.gyee.impala.model.custom.diagnose.DataInfo;
+import com.gyee.impala.model.custom.diagnose.ExecuteInfo;
+import com.gyee.impala.model.master.Casefault;
+import com.gyee.impala.model.master.diagnose.Diagnosepoint;
+import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
+import com.gyee.impala.service.custom.diagnose.DataPredictService;
+import com.gyee.impala.service.custom.diagnose.TrainFaultDiagnoseService;;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 故障预测模型训练
+ */
+@Slf4j
+@CrossOrigin
+@RestController
+@RequestMapping("/api/predict")
+public class TrainFaultPredictController {
+
+
+    @Autowired
+    private TrainFaultDiagnoseService trainFaultDiagnoseService;
+    /**
+     * 参数
+     */
+    private ExecuteInfo executeInfo;
+
+    /**
+     * 数据服务
+     */
+    @Autowired
+    private DataPredictService dataDiagnoseService;
+
+    /**
+     * 线程池
+     */
+    @Resource
+    private ThreadPoolTaskExecutor taskExecutor;
+
+    /**
+     * 预测生成文件名
+     */
+    private String fileName;
+
+
+    private static final Object locker = new Object();
+
+
+
+
+
+    /** 开始预测 查询 golden 所有原始数据
+     *  flag  ture: 所有数据 ;false: 前10条数据
+     * **/
+    @PostMapping("/pointfaultdata")
+    public JSONObject getPointData(@RequestBody JSONObject json){
+        if (json == null)
+            return JsonResult.error(ResultCode.PARAM_IS_BLANK);
+
+
+        log.info("进入预测程序");
+        boolean flag = json.getBooleanValue("flag");
+        List<Diagnosepoint> points = JSONObject.parseArray(json.getJSONArray("points").toString(), Diagnosepoint.class);
+        List<Casefault> faults = JSONObject.parseArray(json.getJSONArray("faults").toString(), Casefault.class);
+
+        /** 组装数据  删除添加的故障类型**/
+        dataDiagnoseService.formatUniformcode(points.stream().filter(a -> !a.getUniformcode().equals("faulttype")).collect(Collectors.toList()));
+        executeInfo = new ExecuteInfo();
+        Calendar cal = Calendar.getInstance();
+        DataInfo[] dataInfos = new DataInfo[faults.size()];
+        for (int i = 0; i < faults.size(); i++){
+            DataInfo data = new DataInfo();
+            data.setId(Long.valueOf(faults.get(i).getId()));
+            data.setStationId(faults.get(i).getStationen());
+            data.setThingId(faults.get(i).getWindturbineid());
+            data.setModelId(faults.get(i).getModel());
+            data.setTag(faults.get(i).getFaultcode());
+            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);
+            data.setStartTs(cal.getTimeInMillis() + "");
+            cal.add(Calendar.MINUTE, 30);
+            data.setEndTs(cal.getTimeInMillis() + "");
+            dataInfos[i] = data;
+        }
+        executeInfo.setDataInfos(dataInfos);
+        if (flag){
+            if (!trainFaultDiagnoseService.isComplete()) {
+                return JsonResult.error(4000, "已有正在预测的故障模型...");
+            }
+            synchronized (locker) {
+                taskExecutor.submit(this::execute);
+            }
+            return JsonResult.success(ResultCode.SUCCESS);
+        }else {
+            Map<String, Object> mp = dataDiagnoseService.getFormData(executeInfo);
+            return JsonResult.successData(ResultCode.SUCCESS, mp);
+        }
+    }
+
+
+    /**
+     * 调用执行脚本
+     */
+    private void execute() {
+
+        fileName = dataDiagnoseService.getFormDataAll(executeInfo);
+        trainFaultDiagnoseService.exec();
+
+    }
+
+
+
+    /**
+     * py 获取预测数据
+     *
+     * @return
+     */
+    @GetMapping("/trainfaultdata")
+    public JSONObject getData() {
+        Map<String, Object> map = new HashMap<>();
+        map.put("info", this.executeInfo);
+        map.put("filename", fileName);
+        return JsonResult.successData(ResultCode.SUCCESS, map);
+    }
+
+
+
+
+    /**
+     * 缓存训练预测模型结果
+     *
+     * @param history
+     * @return
+     */
+    @PostMapping("/putHistory")
+    public JSONObject putDiagnosetrainhistory(@RequestBody String history) {
+        try {
+            log.info("训练模型结果:" + history);
+            trainFaultDiagnoseService.putDiagnosetrainhistory(history);
+            return JsonResult.success(ResultCode.SUCCESS);
+        } catch (Exception e) {
+            log.error("请求错误", e);
+            return JsonResult.error(ResultCode.ERROR);
+        }
+    }
+
+
+
+
+    /**
+     * 获取当前训练预测模型结果
+     * @return
+     */
+    @GetMapping("/getHistory")
+    public JSONObject getHistory() {
+        try {
+            Diagnosetrainhistory d = trainFaultDiagnoseService.getHistoryQueue();
+            return JsonResult.successData(ResultCode.SUCCESS, d);
+        } catch (Exception e) {
+            log.error("请求错误", e);
+            return JsonResult.error(ResultCode.ERROR);
+        }
+    }
+
+
+
+}

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

@@ -1,324 +0,0 @@
-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.util.DateUtil;
-import com.gyee.impala.model.custom.diagnose.DataInfo;
-import com.gyee.impala.model.custom.diagnose.ExecuteInfo;
-import com.gyee.impala.model.master.Casefault;
-import com.gyee.impala.model.master.diagnose.Diagnosepoint;
-import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
-import com.gyee.impala.model.master.diagnose.TrainInfo;
-import com.gyee.impala.service.custom.diagnose.DataPointService;
-import com.gyee.impala.service.master.CasefaultService;
-import com.gyee.impala.service.custom.diagnose.TrainDataModeService;
-import com.gyee.impala.service.custom.diagnose.TrainFileModeService;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.kudu.client.ListTablesResponse;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import java.util.*;
-import java.util.stream.Collectors;
-
-
-/**
- * 模型训练
- */
-@Slf4j
-@CrossOrigin
-@RestController
-@RequestMapping("/api/filemode")
-public class TrainFileModeController {
-
-    @Autowired
-    private DataPointService dataService;
-    @Autowired
-    private CasefaultService casefaultService;
-    @Autowired
-    TrainDataModeService trainDataModeService;
-
-    /**
-     * 线程池
-     */
-    @Resource
-    private ThreadPoolTaskExecutor taskExecutor;
-
-    @Autowired
-    private TrainFileModeService trainFileModeService;
-
-    private static final Object locker = new Object();
-
-
-    private String name1;
-    private String forecastLabel1;
-    private String[] inputLabel1;
-    private String host1;
-    private MultipartFile file1;
-    private ExecuteInfo executeInfo;
-    private String fileName;
-
-
-    /**
-     * 文件模式训练接口
-     * @param request
-     * @param name
-     * @param forecastLabel
-     * @param inputLabel
-     * @param host
-     * @param file
-     * @return
-     */
-    @PostMapping("/trainfile")
-    @ResponseBody
-    public JSONObject getTrainfile(HttpServletRequest request, String name, String forecastLabel, String[] inputLabel, String host, MultipartFile file) {
-
-        if (!trainFileModeService.isComplete()) {
-            return JsonResult.error(4000, "命令正在执行...");
-        }
-
-        if (file.isEmpty()) {
-            return JsonResult.error(ResultCode.ERROR_FILE_NO);
-        }
-
-        try {
-            synchronized (locker) {
-                name1 = name;
-                forecastLabel1 = forecastLabel;
-                inputLabel1 = inputLabel;
-                host1 = host;
-                file1 = file;
-                taskExecutor.submit(this::execute);
-            }
-
-            return JsonResult.success(ResultCode.SUCCESS);
-        } catch (Exception e) {
-            return JsonResult.error(ResultCode.ERROR_DATA_FILE);
-        }
-    }
-
-
-    /**
-     * 调用执行脚本
-     */
-    private void execute() {
-        trainFileModeService.exec(name1, forecastLabel1, inputLabel1, host1, file1);
-    }
-
-    /**   在线训练  **/
-    /**
-     * 查询数据库的表
-     * @return
-     */
-    @GetMapping("/tables")
-    public JSONObject getListTables(){
-        List<Map<String, String>> list = new ArrayList<>();
-        try {
-            List<ListTablesResponse.TableInfo> tables = trainDataModeService.getListTables();
-            tables.stream().filter(a -> a.getTableName().equals("impala::gyee_sample_kudu.casefault")).forEach(obj -> {
-                Map<String, String> map = new HashMap<>();
-                String name = obj.getTableName().substring(obj.getTableName().lastIndexOf(".") + 1);
-                map.put("tableId", obj.getTableId());
-                map.put("tableName", name);
-                list.add(map);
-            });
-        } catch (Exception e) { e.getMessage(); }
-
-        return JsonResult.successData(ResultCode.SUCCESS,list);
-    }
-
-    /**
-     * 查询数据库表的列
-     * @param table
-     * @return
-     */
-    @GetMapping("/columns")
-    public JSONObject getColumns(String table){
-        Object columns = null;
-        try {
-            columns = trainDataModeService.getColumns(table);
-        } catch (Exception e) { e.getMessage(); }
-
-        return JsonResult.successData(ResultCode.SUCCESS, columns);
-    }
-
-
-    /** 查询样本数据 **/
-    @GetMapping("/data")
-    public JSONObject getData(String sql){
-        List<Casefault> list = casefaultService.executeSql(sql);
-        return JsonResult.successData(ResultCode.SUCCESS, list);
-    }
-
-
-    /** 开始训练 查询 golden 所有原始数据
-     *  flag  ture: 所有数据
-     *  flag  false: 前10条数据
-     * **/
-    @PostMapping("/pointdata")
-    public JSONObject getPointData(@RequestBody JSONObject json){
-        if (json == null)
-            return JsonResult.error(ResultCode.PARAM_IS_BLANK);
-
-        boolean flag = json.getBooleanValue("flag");
-        List<Diagnosepoint> points = JSONObject.parseArray(json.getJSONArray("points").toString(), Diagnosepoint.class);
-        List<Casefault> faults = JSONObject.parseArray(json.getJSONArray("faults").toString(), Casefault.class);
-
-        /** 组装数据  删除添加的故障类型**/
-        dataService.formatUniformcode(points.stream().filter(a -> !a.getUniformcode().equals("faulttype")).collect(Collectors.toList()));
-        executeInfo = new ExecuteInfo();
-        Calendar cal = Calendar.getInstance();
-        DataInfo[] dataInfos = new DataInfo[faults.size()];
-        for (int i = 0; i < faults.size(); i++){
-            DataInfo data = new DataInfo();
-            data.setId(Long.valueOf(faults.get(i).getId()));
-            data.setStationId(faults.get(i).getStationen());
-            data.setThingId(faults.get(i).getWindturbineid());
-            data.setModelId(faults.get(i).getModel());
-            data.setTag(faults.get(i).getFaultcode());
-            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, -10);
-            data.setStartTs(cal.getTimeInMillis() + "");
-            cal.add(Calendar.MINUTE, 10);
-            data.setEndTs(cal.getTimeInMillis() + "");
-            dataInfos[i] = data;
-        }
-        executeInfo.setDataInfos(dataInfos);
-        if (flag){
-            if (!trainFileModeService.isComplete()) {
-                return JsonResult.error(4000, "已有正在训练的模型...");
-            }
-            synchronized (locker) {
-                taskExecutor.submit(this::execute2);
-            }
-            return JsonResult.success(ResultCode.SUCCESS);
-        }else {
-            Map<String, Object> mp = dataService.getFormData(executeInfo);
-            return JsonResult.successData(ResultCode.SUCCESS, mp);
-        }
-    }
-
-    /**
-     * 调用执行脚本
-     */
-    private void execute2() {
-        fileName = dataService.getFormDataAll(executeInfo);
-        trainFileModeService.exec();
-    }
-
-    /**
-     * py 获取在线训练数据
-     *
-     * @return
-     */
-    @GetMapping("/traindata")
-    public JSONObject getData() {
-        Map<String, Object> map = new HashMap<>();
-        map.put("info", this.executeInfo);
-        map.put("filename", fileName);
-        return JsonResult.successData(ResultCode.SUCCESS, map);
-    }
-    /**   在线训练  **/
-
-
-    /**
-     * 生产控制台信息
-     * @param trainInfo
-     * @return
-     */
-    @PostMapping("/addtrainInfo")
-    public JSONObject addProducer(@RequestBody String trainInfo) {
-
-        try {
-            TrainInfo t = JSONObject.parseObject(trainInfo, TrainInfo.class);
-            trainFileModeService.produce(t);
-
-            return JsonResult.success(ResultCode.SUCCESS);
-        } catch (Exception e) {
-            return JsonResult.error(ResultCode.ERROR);
-        }
-
-    }
-
-
-    /**
-     * 消费控制台信息
-     * @return
-     */
-    @GetMapping("/gettrainInfo")
-    @ResponseBody
-    public JSONObject getConsume() {
-        try {
-            List<TrainInfo> list = trainFileModeService.consume();
-            System.out.println(JsonResult.successData(ResultCode.SUCCESS, list));
-            return JsonResult.successData(ResultCode.SUCCESS, list);
-        } catch (Exception e) {
-            return JsonResult.error(ResultCode.ERROR);
-        }
-    }
-
-
-    /**
-     * 添加训练结果
-     *
-     * @param history
-     * @return
-     */
-    @PostMapping("/putHistory")
-    public JSONObject putDiagnosetrainhistory(@RequestBody String history) {
-        try {
-            log.info("训练模型结果:" + history);
-            trainFileModeService.putDiagnosetrainhistory(history);
-            return JsonResult.success(ResultCode.SUCCESS);
-        } catch (Exception e) {
-            log.error("请求错误", e);
-            return JsonResult.error(ResultCode.ERROR);
-        }
-    }
-
-
-    /**
-     * 获取当前训练结果
-     * @return
-     */
-    @GetMapping("/getHistory")
-    public JSONObject getHistory() {
-        try {
-            Diagnosetrainhistory d = trainFileModeService.consumeHistory();
-            return JsonResult.successData(ResultCode.SUCCESS, d);
-        } catch (Exception e) {
-            log.error("请求错误", e);
-            return JsonResult.error(ResultCode.ERROR);
-        }
-    }
-
-
-
-    /**
-     * 预测评估
-     *
-     * @param jsonObject
-     * @return
-     */
-    @PostMapping("/forecasts")
-    public JSONObject forecasts(@RequestBody JSONObject jsonObject) {
-        try {
-            log.warn("预估请求数据:" + jsonObject.toJSONString());
-            String resultvalue = trainFileModeService.forecasts(jsonObject);
-            return JsonResult.successData(ResultCode.SUCCESS, resultvalue);
-        } catch (Exception e) {
-            return JsonResult.error(ResultCode.ERROR);
-        }
-
-    }
-
-
-}

+ 6 - 10
gyee-sample-impala/src/main/java/com/gyee/impala/service/custom/diagnose/DataDiagnoseService.java

@@ -5,22 +5,20 @@ import com.gyee.impala.common.config.GyeeConfig;
 import com.gyee.impala.common.feign.RemoteServiceBuilder;
 import com.gyee.impala.common.util.DateUtil;
 import com.gyee.impala.common.util.FileUtil;
-import com.gyee.impala.model.custom.diagnose.DataInfo;
-import com.gyee.impala.model.custom.diagnose.ExecuteInfo;
-import com.gyee.impala.model.custom.diagnose.PointData;
+import com.gyee.impala.model.custom.diagnose.*;
 import com.gyee.impala.model.master.diagnose.Diagnosepoint;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
-
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
 /**
- * 数据处理服务   在线工具
+ *
+ * 在线诊断数据处理服务   在线工具
  *
  * @author cmh
  */
@@ -62,7 +60,7 @@ public class DataDiagnoseService {
                 continue;
             }
             Map<String, List<PointData>> data = getData(di, true);
-            String s = getDataString(data, di.getTag(), isFirst,di.getThingId());
+            String s = getDataString(data, di.getTag(), isFirst);
             FileUtil.writeFile(fileName, s);
             isFirst = false;
         }
@@ -86,7 +84,7 @@ public class DataDiagnoseService {
             // 查询一台风机的原始数据
             if (count == 0){
                 Map<String, List<PointData>> data = getData(di, true);
-                String s = getDataString(data, di.getTag(), isFirst,di.getThingId());
+                String s = getDataString(data, di.getTag(), isFirst);
                 sb.append(s);
             }
 
@@ -101,7 +99,7 @@ public class DataDiagnoseService {
         return map;
     }
 
-    private String getDataString(Map<String, List<PointData>> data, String tag, boolean isFirst,String wt) {
+    private String getDataString(Map<String, List<PointData>> data, String tag, boolean isFirst) {
         List<List<PointData>> vals = new ArrayList<>(data.values());
         if(vals.size()<=0){
             return "";
@@ -120,7 +118,6 @@ public class DataDiagnoseService {
             StringBuilder sb = new StringBuilder();
             Date dt = new Date(vals.get(0).get(i).getTs());
             sb.append(sdf.format(dt)).append(',');
-            sb.append(wt).append(",");
             for (List<PointData> vv : vals) {
                 if (i >= vv.size()) {
                     sb.append(0).append(',');
@@ -169,7 +166,6 @@ public class DataDiagnoseService {
     private String getFileTitle(Set<String> keySet) {
         StringBuilder sb = new StringBuilder();
         sb.append("时间,");
-        sb.append("风机编号,");
         for (String st : keySet) {
             sb.append(st).append(',');
         }

+ 11 - 6
gyee-sample-impala/src/main/java/com/gyee/impala/service/custom/diagnose/DataPointService.java

@@ -5,25 +5,28 @@ import com.gyee.impala.common.config.GyeeConfig;
 import com.gyee.impala.common.feign.RemoteServiceBuilder;
 import com.gyee.impala.common.util.DateUtil;
 import com.gyee.impala.common.util.FileUtil;
-import com.gyee.impala.model.custom.diagnose.*;
+import com.gyee.impala.model.custom.diagnose.DataInfo;
+import com.gyee.impala.model.custom.diagnose.ExecuteInfo;
+import com.gyee.impala.model.custom.diagnose.PointData;
 import com.gyee.impala.model.master.diagnose.Diagnosepoint;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
 /**
- * 数据处理服务   在线工具
+ * 在线预测数据处理服务   在线工具
  *
  * @author cmh
  */
 @Slf4j
 @Component
-public class DataPointService {
+public class DataPredictService {
 
     @Autowired
     private GyeeConfig gyeeConfig;
@@ -59,7 +62,7 @@ public class DataPointService {
                 continue;
             }
             Map<String, List<PointData>> data = getData(di, true);
-            String s = getDataString(data, di.getTag(), isFirst);
+            String s = getDataString(data, di.getTag(), isFirst,di.getThingId());
             FileUtil.writeFile(fileName, s);
             isFirst = false;
         }
@@ -83,7 +86,7 @@ public class DataPointService {
             // 查询一台风机的原始数据
             if (count == 0){
                 Map<String, List<PointData>> data = getData(di, true);
-                String s = getDataString(data, di.getTag(), isFirst);
+                String s = getDataString(data, di.getTag(), isFirst,di.getThingId());
                 sb.append(s);
             }
 
@@ -98,7 +101,7 @@ public class DataPointService {
         return map;
     }
 
-    private String getDataString(Map<String, List<PointData>> data, String tag, boolean isFirst) {
+    private String getDataString(Map<String, List<PointData>> data, String tag, boolean isFirst,String wt) {
         List<List<PointData>> vals = new ArrayList<>(data.values());
         if(vals.size()<=0){
             return "";
@@ -117,6 +120,7 @@ public class DataPointService {
             StringBuilder sb = new StringBuilder();
             Date dt = new Date(vals.get(0).get(i).getTs());
             sb.append(sdf.format(dt)).append(',');
+            sb.append(wt).append(",");
             for (List<PointData> vv : vals) {
                 if (i >= vv.size()) {
                     sb.append(0).append(',');
@@ -165,6 +169,7 @@ public class DataPointService {
     private String getFileTitle(Set<String> keySet) {
         StringBuilder sb = new StringBuilder();
         sb.append("时间,");
+        sb.append("风机编号,");
         for (String st : keySet) {
             sb.append(st).append(',');
         }

+ 2 - 5
gyee-sample-impala/src/main/java/com/gyee/impala/service/impl/master/diagnose/DiagnosereportServiceImpl.java

@@ -18,7 +18,7 @@ import com.gyee.impala.model.custom.diagnose.DataInfo;
 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.DataPointService;
+import com.gyee.impala.service.custom.diagnose.DataDiagnoseService;
 import com.gyee.impala.service.master.diagnose.DiagnosereportService;
 import org.apache.kudu.client.*;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,9 +28,6 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Function;
-import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
 
@@ -41,7 +38,7 @@ public class DiagnosereportServiceImpl extends ServiceImpl<DiagnosereportMapper,
     private KuduDataSourceConfig kuduConfig;
 
     @Autowired
-    private DataPointService dataPointService;
+    private DataDiagnoseService dataPointService;
 
     /**
      * 保存脚本的位置