|
@@ -4,12 +4,19 @@ package com.gyee.impala.controller.diagnose;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.gyee.impala.common.result.JsonResult;
|
|
import com.gyee.impala.common.result.JsonResult;
|
|
import com.gyee.impala.common.result.ResultCode;
|
|
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.service.custom.diagnose.DataPointService;
|
|
|
|
+import com.gyee.impala.service.master.CasefaultService;
|
|
import com.gyee.impala.service.master.diagnose.TrainDataModeService;
|
|
import com.gyee.impala.service.master.diagnose.TrainDataModeService;
|
|
import org.apache.kudu.client.ListTablesResponse;
|
|
import org.apache.kudu.client.ListTablesResponse;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 数据源方式训练模型
|
|
* 数据源方式训练模型
|
|
@@ -19,20 +26,107 @@ import java.util.List;
|
|
@RequestMapping("/api/traindatamode")
|
|
@RequestMapping("/api/traindatamode")
|
|
public class TrainDataModeController {
|
|
public class TrainDataModeController {
|
|
|
|
|
|
-
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private DataPointService dataService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CasefaultService casefaultService;
|
|
@Autowired
|
|
@Autowired
|
|
TrainDataModeService trainDataModeService;
|
|
TrainDataModeService trainDataModeService;
|
|
|
|
|
|
- @GetMapping("/getListTables")
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 查询数据库的表
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @GetMapping("/tables")
|
|
public JSONObject getListTables(){
|
|
public JSONObject getListTables(){
|
|
-
|
|
|
|
|
|
+ List<Map<String, String>> list = new ArrayList<>();
|
|
try {
|
|
try {
|
|
List<ListTablesResponse.TableInfo> tables = trainDataModeService.getListTables();
|
|
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,tables);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- return JsonResult.error(ResultCode.ERROR);
|
|
|
|
- }
|
|
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ json = json.getJSONObject("params");
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ /** 组装数据 **/
|
|
|
|
+ dataService.formatUniformcode(points);
|
|
|
|
+ ExecuteInfo 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());
|
|
|
|
+ data.setStartTs(DateUtil.covertDateTimestamp(faults.get(i).getStarttime()).toString());
|
|
|
|
+ if (flag){
|
|
|
|
+ data.setEndTs(DateUtil.covertDateTimestamp(faults.get(i).getEndtime()).toString());
|
|
|
|
+ }else{
|
|
|
|
+ //查看前10条数据时结束时间往后推10s
|
|
|
|
+ cal.setTime(DateUtil.parseStrtoDate(faults.get(i).getStarttime(), DateUtil.DATE_TIME_PATTERN));
|
|
|
|
+ cal.add(Calendar.SECOND, 10);
|
|
|
|
+ data.setEndTs(cal.getTimeInMillis() + "");
|
|
|
|
+ }
|
|
|
|
+ dataInfos[i] = data;
|
|
|
|
+ }
|
|
|
|
+ executeInfo.setDataInfos(dataInfos);
|
|
|
|
+ if (flag){
|
|
|
|
+ String file = dataService.getFormDataAll(executeInfo);
|
|
|
|
+ map.put("info", executeInfo);
|
|
|
|
+ map.put("filename", file);
|
|
|
|
+ return JsonResult.successData(ResultCode.SUCCESS, map);
|
|
|
|
+ }else {
|
|
|
|
+ Map<String, Object> mp = dataService.getFormData(executeInfo);
|
|
|
|
+ return JsonResult.successData(ResultCode.SUCCESS, mp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|