Browse Source

新增评估接口

wangchangsheng 2 years ago
parent
commit
a929c308d2

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

@@ -1,6 +1,7 @@
 package com.gyee.impala.controller.diagnose;
 
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.gyee.impala.common.result.JsonResult;
 import com.gyee.impala.common.result.ResultCode;
@@ -172,7 +173,21 @@ public class TrainFileModeController {
     }
 
 
+    /**
+     * 预测评估
+     * @param jsonObject
+     * @return
+     */
+    @PostMapping("/forecasts")
+    public JSONObject forecasts(@RequestBody JSONObject jsonObject){
+        try {
+           String resultvalue =  trainFileModeService.forecasts(jsonObject);
+           return JsonResult.successData(ResultCode.SUCCESS,resultvalue);
+        } catch (Exception e) {
+            return JsonResult.error(ResultCode.ERROR);
+        }
 
+    }
 
 
 

+ 46 - 1
gyee-sample-impala/src/main/java/com/gyee/impala/service/master/diagnose/TrainFileModeService.java

@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.*;
 import java.util.concurrent.BlockingQueue;
@@ -78,7 +79,6 @@ public class TrainFileModeService {
 //            String[] cmd = {"/bin/sh", "-c", "python " + cmdPath + name + ".py " + filePath};
             String[] cmd = {inst, c, "python " + cmdPath + name + ".py " + filePath};
 
-            Thread.sleep(3000);
             System.out.println(cmd[0] + " " + cmd[1] + " " + cmd[2]);
             p = Runtime.getRuntime().exec(cmd);
             BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
@@ -158,4 +158,49 @@ public class TrainFileModeService {
     }
 
 
+    public String forecasts(JSONObject jsonObject){
+
+
+        String resultvalue = null;
+        try {
+            String  name = jsonObject.get("name").toString();
+
+            String predict = jsonObject.get("predict").toString();
+            resultvalue = "";
+
+
+            String cmdPath = gyeeConfig.getDiagnosePath();
+            String inst = JudeSystem.isWindows() ? "cmd" : "/bin/sh";
+            String c = JudeSystem.isWindows() ? "/c" : "-c";
+            String[] cmd = {inst, c, "python " + cmdPath + name + ".py " + predict};
+
+            Process p;
+            System.out.println(cmd[0] + " " + cmd[1] + " " + cmd[2]);
+            p = Runtime.getRuntime().exec(cmd);
+            BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
+            BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+            String si = null, se = null;
+            while ((si = bri.readLine()) != null || (se = bre.readLine()) != null) {
+                if (si != null) {
+                    System.out.println(si);
+                    if (si.startsWith("resultvalue:")){
+                        resultvalue = si.replaceAll("resultvalue:","");
+                    }
+
+
+                }
+                if (se != null) {
+                    System.err.println(se);
+                }
+            }
+            p.waitFor();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return  resultvalue;
+
+
+    }
+
+
 }