Просмотр исходного кода

feat: 训练模型前的接口对接完成

icenaked 3 лет назад
Родитель
Сommit
0963b4a499

+ 34 - 21
src/api/config.js

@@ -11,16 +11,16 @@ import {MOCK} from "./_prefix";
  */
 export const addConfig = payload => {
   const { fileInfoId, userId, learningType, configName, features, label} = payload;
-  // return axios.post(`${CONFIG_MODULE}`, {
-  //   fileInfoId, userId, learningType ,configName ,features, label
-  // }).then(res => {
-  //   return res;
-  // });
-  return axios.post(`${MOCK}/ml/configs`, {
+  return axios.post(`${CONFIG_MODULE}`, {
     fileInfoId, userId, learningType ,configName ,features, label
   }).then(res => {
     return res;
   });
+  // return axios.post(`${MOCK}/ml/configs`, {
+  //   fileInfoId, userId, learningType ,configName ,features, label
+  // }).then(res => {
+  //   return res;
+  // });
 }
 
 
@@ -31,11 +31,15 @@ export const addConfig = payload => {
  * @returns
  */
 export const getAllConfig = payload => {
-  const {uid} = payload;
-  // return axios.get(`${CONFIG_MODULE}/get/all?userId=${uid}`).then(res => {
-  //   return res;
-    return axios.get(`${MOCK}/ml/configs:useId=1`).then(res => {
-      return res;
+  const {userId} = payload;
+  return axios.get(`${CONFIG_MODULE}`,{
+    params:{
+      userId: userId
+    }
+  }).then(res => {
+    return res;
+  //   return axios.get(`${MOCK}/ml/configs:useId=1`).then(res => {
+  //     return res;
   });
 }
 
@@ -61,11 +65,15 @@ export const getAllNew = payload => {
  * @returns
  */
 export const getOneConfig = payload => {
-  const { configId } = payload;
-  // return axios.get(`${CONFIG_MODULE}/get/one/config?configId=${configId}`).then(res => {
-  //   return res;});
-  return axios.get(`${MOCK}/ml/configs/:configId`).then(res => {
+  const { configId, userId } = payload;
+  return axios.get(`${CONFIG_MODULE}/${configId}`,{
+    params:{
+      userId: userId
+    }
+  }).then(res => {
     return res;});
+  // return axios.get(`${MOCK}/ml/configs/:configId`).then(res => {
+  //   return res;});
 }
 
 /**
@@ -89,12 +97,17 @@ export const changeConfig = payload => {
  * @param {*} payload
  * @returns
  */
-export const deleteConfig = configId => {
-  // return axios.get(`${CONFIG_MODULE}/delete?configId=${configId}`).then(res => {
-  //   return res;
-    return axios.delete(`${MOCK}/ml/configs/${configId}`).then(res => {
-      return res;
-  });
+export const deleteConfig = payload => {
+  const {configId, userId} = payload
+  return axios.delete(`${CONFIG_MODULE}/${configId}`,{
+    params:{
+      userId: userId
+    }
+  }).then(res => {
+    return res;
+  //   return axios.delete(`${MOCK}/ml/configs/${configId}`).then(res => {
+  //     return res;
+   });
 }
 
 /**

+ 26 - 117
src/api/file.js

@@ -56,17 +56,17 @@ export const UploadFile = payload => {
  * @returns
  */
 export const GetAllFile = userId => {
-    // return axios.get(`${FILE_MODULE}`, {
-    //     params:{
-    //         userId: userId
-    //     }
-    // }).then( res => {
-    //     return res;
-    // });
-    return axios.get(`${MOCK}/files:userId=1`, {
-        }).then( res => {
-            return res;
-        });
+    return axios.get(`${FILE_MODULE}`, {
+        params:{
+            userId: userId
+        }
+    }).then( res => {
+        return res;
+    });
+    // return axios.get(`${MOCK}/files:userId=1`, {
+    //     }).then( res => {
+    //         return res;
+    //     });
 }
 
 // 直接返回数据
@@ -86,13 +86,18 @@ export const GetAllFile = userId => {
  * @param {*} fileId 文件Id
  * @returns
  */
-export const getFileDetail = fileId => {
-    // return axios.get(`${FILE_MODULE}/${fileId}`).then( res => {
-    //     return res;
-    // })
-    return axios.get(`${MOCK}/files/:fileInfoId`).then( res => {
+export const getFileDetail = payload => {
+    const {fileInfoId, userId} = payload;
+    return axios.get(`${FILE_MODULE}/${fileInfoId}`,{
+        params:{
+            userId: userId
+        }
+    }).then( res => {
         return res;
     })
+    // return axios.get(`${MOCK}/files/:fileInfoId`).then( res => {
+    //     return res;
+    // })
 }
 
 /**
@@ -101,107 +106,11 @@ export const getFileDetail = fileId => {
  * @returns
  */
 export const deleteFile = fileId => {
-    // return axios.delete(`${FILE_MODULE}/${fileId}`).then( res => {
-    //         return res;
-    // });
-    return axios.delete(`${MOCK}/files/:fileInfoId`).then( res => {
-        return res;
+    return axios.delete(`${FILE_MODULE}/${fileId}`).then( res => {
+            return res;
     });
+    // return axios.delete(`${MOCK}/files/:fileInfoId`).then( res => {
+    //     return res;
+    // });
 }
 
-/**
- *  文件分析 GET /analysis/fields
- * @param {*} payload
- * @returns
- */
-export const analysisFile = (fieldIds,funcId) => {
-    //fieldIds=JSON.stringify(fieldIds)
-    console.log(fieldIds)
-    fieldIds=JSON.parse(fieldIds)
-    console.log(fieldIds)
-    let url=`${FILE_MODULE}/analysis/fields?funcId=${funcId}`
-    for(let i=0;i<fieldIds.length;i++){
-        let fieldId=fieldIds[i]
-        url+=`&fieldIds=${fieldId}`
-    }
-    console.log(url)
-    return axios.get(url).then(res => {
-        return res;
-    });
-    // if (funcId==1){
-    //     return Promise.resolve({
-    //         "timestamp": 1649561125585,
-    //         "status": 200,
-    //         "data": {
-    //             "105_statistical": {
-    //                 "R": 330.0,
-    //                 "L": 424.0
-    //             },
-    //             "105_distribution": {
-    //                 "R": 0.4376657824933687,
-    //                 "L": 0.5623342175066314
-    //             }
-    //         }
-    //     });
-    // }
-    // if (funcId==2){
-    //     return Promise.resolve({
-    //         "timestamp": 1649561125585,
-    //         "status": 200,
-    //         "data":{
-    //             "103": [
-    //                 79.0,
-    //                 737.0,
-    //                 753.0],
-    //             "104": [
-    //                 3.16,
-    //                 29.48,
-    //                 30.12],
-    //             "108": [
-    //                 20.0,
-    //                 291.0,
-    //                 318.0]
-    //         }
-    //     });
-    // }
-    // if (funcId==3){
-    //     return Promise.resolve({
-    //         "timestamp": 1649561321298,
-    //         "status": 200,
-    //         "data": {
-    //             "frame_index": {
-    //                 "max": 89992.0,
-    //                 "variance": 6.474726567563616E8,
-    //                 "mean": 45439.82360742705,
-    //                 "stddev": 25445.484014975264
-    //             }
-    //         }
-    //     })
-    // }
-    // if (funcId==4){
-    //     return Promise.resolve({
-    //         "timestamp": 1649561409955,
-    //         "status": 200,
-    //         "data": {
-    //             "103": {
-    //                 "skewness": -0.010820149962232854,
-    //                 "kurtosis": -1.0998405481091291
-    //             }
-    //         }
-    //     })
-    // }
-    // if (funcId==5){
-    //     return Promise.resolve({
-    //         "timestamp": 1649561470265,
-    //         "status": 200,
-    //         "data": {
-    //             "Corr": 0.9999999999999994
-    //         }
-    //     })
-    // }
-    // return Promise.resolve({
-    //     "timestamp": 1649561470265,
-    //     "status": 400,
-    //     "data": ""
-    // })
-}

+ 19 - 10
src/api/model.js

@@ -9,7 +9,8 @@ import {MOCK} from "./_prefix";
  */
 export const addModel = async payload => {
     const {configId, userId, modelName, machineLearningAlgorithm, trainParams} = payload;
-    const res = await axios.post(`${MOCK}/ml/models`, {
+    // const res = await axios.post(`${MOCK}/ml/models`, {
+    const res = await axios.post(`${MODEL_MODULE}`, {
         configId,
         userId,
         modelName,
@@ -50,8 +51,12 @@ export const deleteModel=async modelId=>{
      */
     export const getAllModel = async payload => {
         const{ userId } = payload;
-        // const res = await axios.get(`${MODEL_MODULE}/get/all`, {params: {userId: userId}})
-        const res = await axios.get(`${MOCK}/ml/models:userId=1`)
+        const res = await axios.get(`${MODEL_MODULE}`, {
+            params: {
+                userId: userId
+            }
+        })
+        // const res = await axios.get(`${MOCK}/ml/models:userId=1`)
         return res
     }
 /**
@@ -60,9 +65,9 @@ export const deleteModel=async modelId=>{
  * @returns
  */
 export const getModelByConfigId = async payload => {
-    const{ config } = payload;
-    // const res = await axios.get(`${MODEL_MODULE}/get/all`, {params: {userId: userId}})
-    const res = await axios.get(`${MOCK}/ml/models/configs/:configId`)
+    const{ configId,userId } = payload;
+    const res = await axios.get(`${MODEL_MODULE}/configs/${configId}`, {params: {userId: userId}})
+    // const res = await axios.get(`${MOCK}/ml/models/configs/:configId`)
     return res
 }
 
@@ -117,14 +122,18 @@ export const getOneModel = async payload => {
         return res;
     }
     /**
-     * 训练 GET /model/train
+     * 训练 POST /model/train
      * @param modelId
      * @returns
      */
     export const train = async payload=>{
-        const { modelId } = payload;
-        // const res=await axios.get(`${MODEL_MODULE}/train`,{params:{modelId:modelId}});
-        const res=await axios.get(`${MOCK}/ml/models/:modelId/train`);
+        const { modelId, userId } = payload;
+        const res=await axios.post(`${MODEL_MODULE}/${modelId}/train?userId=1`,{
+            params:{
+                userId: userId
+            }
+        });
+        // const res=await axios.get(`${MOCK}/ml/models/:modelId/train`);
         return res;
     }
     /**

+ 8 - 5
src/views/file/FileDetail.vue

@@ -166,10 +166,9 @@
 </template>
 
 <script>
-import {ref, reactive, getCurrentInstance, onMounted} from "vue";
+import {ref, reactive} from "vue";
 import { ElMessage, ElMessageBox } from "element-plus";
-import { fetchData } from "../../api";
-import {getFileDetail,analysisFile} from "../../api/file";
+import {getFileDetail} from "../../api/file";
 import {useRoute}from "vue-router";
 import {useRouter}from "vue-router";
 import { toRaw } from '@vue/reactivity'
@@ -215,8 +214,12 @@ export default {
     const getData = () => {
       const route=useRoute()
       if(route.query.fileId!=null) {
-        getFileDetail(route.query.fileId).then(res => {
-          tableData.value = res.result.fileFieldList;
+        const payload ={
+          fileInfoId: route.query.fileId,
+          userId: 1
+        }
+        getFileDetail(payload).then(res => {
+          tableData.value = res.result.fileFields;
           fileId=route.query.fileId
         })
       }

+ 2 - 1
src/views/file/FileList.vue

@@ -91,7 +91,8 @@ export default {
     const getFileList=(userId)=>{
       GetAllFile(userId).then(res=>{
         if(res.msg === '成功'){
-          state.fileList=res.result.fileInfoVOList;
+          console.log(res)
+          state.fileList=res.result;
           console.log(state.fileList)
         }
         else{

+ 78 - 109
src/views/ml/ConfigDetail.vue

@@ -34,8 +34,8 @@
               </el-table-column>
               <el-table-column label="训练状态">
                 <template #default="scope" >
-                  <div v-if="scope.row.trainingState==='UNTRAINED'">未训练</div>
-                  <div v-else-if="scope.row.trainingState==='TRAINING'">训练中</div>
+                  <div v-if="scope.row.trainingState==='WAITING'">未训练</div>
+                  <div v-else-if="scope.row.trainingState==='ON_GOING'">训练中</div>
                   <div v-else-if="scope.row.trainingState==='SUCCESS'">训练成功</div>
                   <div v-else="">训练失败</div>
                 </template>
@@ -64,43 +64,31 @@
 
 
           <el-dialog title="新建模型" v-model="modelVisiable" width="30%">
-            <el-form label-width="120px">
+            <el-form >
               <el-form-item label="模型名称" required>
                 <el-input v-model="form.modelName"></el-input>
               </el-form-item>
-              <el-form-item label="算法名称" required>
-                <el-select v-model="form.machineLearningAlgorithm" placeholder="请选择一个算法" class="handle-select mr10">
-                  <el-option key="1" label="逻辑回归" value="LOGISTIC_REGRESSION_CLASSIFICATION"></el-option>
-                  <el-option key="2" label="决策树" value="DECISION_TREE_CLASSIFICATION"></el-option>
-                  <el-option key="3" label="梯度提升树分类" value="GRADIENT_BOOSTED_TREE_CLASSIFICATION"></el-option>
-                  <el-option key="4" label="多层感知器分类" value="MULTI_LAYER_PERCEPTRON_CLASSIFICATION"></el-option>
-                  <el-option key="5" label="朴素贝叶斯分类" value="NAIVE_BAYES_CLASSIFICATION"></el-option>
-                  <el-option key="6" label="随机森林分类" value="RANDOM_FOREST_CLASSIFICATION"></el-option>
-                  <el-option key="7" label="随机森林回归" value="RANDOM_FOREST_REGRESSION"></el-option>
-                  <el-option key="8" label="K均值聚类" value="K_MEANS_CLUSTERING"></el-option>
+              <el-form-item label="选择算法" required>
+                <el-select
+                    v-model="form.machineLearningAlgorithm"
+                    placeholder="请选择一个算法"
+                    value-key="self"
+                >
+                  <el-option
+                      v-for="(item,index) in enumList"
+                      :key="index"
+                      :label="item.algorithmName"
+                      :value="item"
+                  />
                 </el-select>
               </el-form-item>
-              <el-form-item label="MaxIter" v-model="showMaxIter" v-if="judgeAlgorithmType() === 1">
-                <el-input v-model="form.trainParams.MaxIter"></el-input>
-              </el-form-item>
-              <el-form-item label="RegParam" v-model="showRegParam" v-if="judgeAlgorithmType() === 1">
-                <el-input v-model="form.trainParams.RegParam"></el-input>
-              </el-form-item>
-              <el-form-item label="ElasticNetParam" v-model="showElasticNetParam" v-if="judgeAlgorithmType() === 1">
-                <el-input v-model="form.trainParams.ElasticNetParam"></el-input>
-              </el-form-item>
-              <el-form-item label="Category" v-model="showCategory" v-if="judgeAlgorithmType() === 3">
-                <el-input v-model="form.trainParams.Category"></el-input>
-              </el-form-item>
-              <el-form-item label="DataSetOccupy" v-model="showTrainingDataSetOccupy" v-if="judgeAlgorithmType() === 3">
-                <el-input v-model="form.trainParams.TrainingDataSetOccupy"></el-input>
-              </el-form-item>
-              <el-form-item label="NumOfCluster" v-model="showNumOfCluster" v-if="judgeAlgorithmType() === 2">
-                <el-input v-model="form.trainParams.NumOfCluster"></el-input>
-              </el-form-item>
-              <el-form-item label="Seed" v-model="showSeed" v-if="judgeAlgorithmType() === 2">
-                <el-input v-model="form.trainParams.Seed"></el-input>
-              </el-form-item>
+                <div v-for="(item,index) in form.machineLearningAlgorithm.trainParamEnums" :key="index">
+                  <el-tooltip  :content="item.description" >
+                    <el-form-item :label="item.paramName" >
+                      <el-input v-model="form.trainParams[index]" ></el-input>
+                    </el-form-item>
+                  </el-tooltip>
+                </div>
 
             </el-form>
             <template #footer>
@@ -112,16 +100,11 @@
           </el-dialog>
           </div>
         </div>
-
-
 <!--      <div class="pagination">-->
 <!--        <el-pagination background layout="total, prev, pager, next" :current-page="query.pageIndex"-->
 <!--                       :page-size="query.pageSize" :total="pageTotal" @current-change="handlePageChange"></el-pagination>-->
 <!--      </div>-->
 
-
-
-
     </div>
 
 
@@ -150,17 +133,6 @@ export default {
       pageSize: 10,
     });
     const fileId=ref(1);
-    //new TODO
-    //TODO
-    const fieldNameList=[]; //字段名
-    const aliasList=[];   //别名
-    const descList=[];      //描述
-    const aList=[];   //取值类型
-    const bList=[];   //分布类型
-    const cList=[];   //空值率
-    const dList=[];
-
-
     const tableData = ref([]);
     const selectData = ref([]);
     const pageTotal = ref(0);
@@ -175,56 +147,52 @@ export default {
     const showNumOfCluster=ref(false);
     const showSeed=ref(false);
 
-    // let form = reactive({
-    //   modelTypeId:"",
-    //   configId:route.query.configId,
-    //   fileInfoId:"",
-    //   modelName:"",
-    //   MaxIter:"",
-    //   RegParam:"",
-    //   ElasticNetParam:"",
-    //   Category:"",
-    //   TrainingDataSetOccupy:"",
-    //   NumOfCluster:"",
-    //   Seed:"",
-    // });
+    let enumList = ref([])
+
     let form = reactive({
       configId: route.query.configId,
       modelName: "",
-      machineLearningAlgorithm: "",
-      trainParams: {},
+      machineLearningAlgorithm: '',
+      trainParams: [],
     });
     // 获取表格数据
 
     const getData = () => {
-      // console.log("queryId",route.query.configId);
       if(route.query.configId!=null) {
-        getOneConfig({configId:route.query.configId}).then(res => {
-          // console.log("configdetail",route.query.configId);
+        const payload ={
+          configId: route.query.configId,
+          userId: 1
+        }
+        getOneConfig(payload).then(res => {
           config.value=res.result;
-          // form.modelTypeId=config.value.learningType;
-          // if (form.modelTypeId==='1') {
-          //   showMaxIter.value = true;
-          //   showRegParam.value = true;
-          //   showElasticNetParam.value = true;
-          // }else if (form.modelTypeId==='5') {
-          //   showNumOfCluster.value=true;
-          //   showSeed.value=true;
-          // }else {
-          //   showCategory.value=true;
-          //   showTrainingDataSetOccupy.value=true;
-          // }
-          // console.log("form",form);
           tableData.value = res.result.features;
-        });
-        getModelByConfigId({configId:route.query.configId}).then(res =>{
-          modelData.value=res.result.modelVOList;
+          getEnum().then(ress=>{
+            if (res.result.learningType === 'SUPERVISED_LEARNING'){
+              const tempArr = ress.result[0]
+              for (let j =0; j<tempArr.machineLearningAlgorithmTypeEnum.length;j++){
+                for (let k =0; k<tempArr.machineLearningAlgorithmTypeEnum[j].machineLearningAlgorithmEnums.length;k++){
+                  enumList.value.push(tempArr.machineLearningAlgorithmTypeEnum[j].machineLearningAlgorithmEnums[k])
+                }
+              }
+            }
+            else {
+              const tempArr = ress.result[1]
+              for (let j =0; j<tempArr.machineLearningAlgorithmTypeEnum.length;j++){
+                for (let k =0; k<tempArr.machineLearningAlgorithmTypeEnum[j].machineLearningAlgorithmEnums.length;k++){
+                  enumList.value.push(tempArr.machineLearningAlgorithmTypeEnum[j].machineLearningAlgorithmEnums[k])
+                }
+              }
+            }
+          })
+        })
+        const payloadModel={
+          configId:route.query.configId,
+          userId: 1
+        }
+        getModelByConfigId(payloadModel).then(res =>{
+          modelData.value=res.result;
         })
-        // getEnum().then(res=>{
-        //   console.log("enum: "+res)
-        // })
       }
-
     };
     getData();
 
@@ -256,29 +224,31 @@ export default {
         configId:form.configId,
         userId: 1,
         modelName:form.modelName,
-        machineLearningAlgorithm: form.machineLearningAlgorithm,
+        machineLearningAlgorithm: form.machineLearningAlgorithm.self,
         trainParams:{}
       }
-      const arg1={
-        MaxIter:form.trainParams.MaxIter,
-        RegParam:form.trainParams.RegParam,
-        ElasticNetParam:form.trainParams.ElasticNetParam
-      }
-      const arg3={
-        Category:form.trainParams.Category,
-        TrainingDataSetOccupy:form.trainParams.TrainingDataSetOccupy
-      }
-      const arg4={
-        NumOfCluster:form.trainParams.NumOfCluster,
-        Seed:form.trainParams.Seed
+      console.log(form.trainParams)
+      let key_arr=[]
+      let l = form.machineLearningAlgorithm.trainParamEnums.length
+      for (let i = 0;i<l;i++){
+          key_arr.push(form.machineLearningAlgorithm.trainParamEnums[i].self)
       }
-      if (judgeAlgorithmType() === 1){
-        payload.trainParams=arg1;
-      }else if (judgeAlgorithmType() === 5){
-        payload.trainParams=arg4;
-      }else{
-        payload.trainParams=arg3;
+      let param_obj={}
+      // for (let key in form.trainParams) {
+      //   param_obj[key] = form.trainParams[key];
+      // }
+      // let j=0
+      // for (let i of param_obj) {
+      //   i = key_arr[j]
+      //   j++
+      // }
+      for (let i=0;i<l;i++){
+        let temp = key_arr[i]
+        param_obj[temp]=form.trainParams[i]
       }
+      payload.trainParams = param_obj
+      console.log(payload)
+
       addModel(payload).then(res=>{
         console.log(res)
         if(res.msg === '成功') {
@@ -317,6 +287,7 @@ export default {
       form,
       fileId,
       showMaxIter,
+      enumList,
       saveModel,
 
       showRegParam,
@@ -333,8 +304,6 @@ export default {
       handlePageChange,
       createModel,
       handleEdit,
-
-
     };
   },
 };

+ 7 - 11
src/views/ml/ConfigList.vue

@@ -164,16 +164,9 @@ export default {
 
     const getpage=()=> {
       getAllConfig({
-        uid: 1
+        userId: 1
       }).then(res => {
-        tableData.value = res.result.configVOList;
-        // for (let i=0;i<tableData.value.length;i++){
-        //   tableData.value[i].name=[];
-        //   for (let j=0;j<tableData.value[i].featureList.length-1;j++){
-        //     tableData.value[i].name.push(tableData.value[i].featureList[j].fieldName);
-        //   }
-        //   tableData.value[i].target=tableData.value[i].featureList[tableData.value[i].featureList.length-1].fieldName;
-        // }
+        tableData.value = res.result;
       })
     };
      getpage();
@@ -202,9 +195,12 @@ export default {
                     // tableData.value.splice(index, 1);
                   let idx=tableData.value[index].id;
                   console.log(idx);
-                  deleteConfig(idx
+                  const payload ={
+                    configId: idx,
+                    userId: 1
+                  }
+                  deleteConfig(payload
                   ).then(res=>{
-                    //console.log("deleteres",res);
                     if(res.msg === '成功'){
                       ElMessage.success("删除成功!")
                       //location.reload();

+ 12 - 5
src/views/ml/ModelList.vue

@@ -231,12 +231,12 @@ export default {
     const getpage=()=> {
       const uid=1;
       GetAllFile(uid).then(res=>{
-        fileList.value=res.result.fileInfoVOList;
+        fileList.value=res.result;
       })
       getAllModel({
          userId: uid
       }).then(res => {
-        tableData.value = res.result.modelVOList;
+        tableData.value = res.result;
         pageTotal.value=tableData.value.length
         for(let i=0;i<tableData.value.length;i++) {
           const reg=new RegExp("\"","g");
@@ -281,9 +281,12 @@ export default {
             instance.confirmButtonText = '训练中...'
             let idx=modelId;
             console.log("modelId: "+idx);
-            train({
-              modelId: idx
-            }).then(res=>{
+            const payload={
+              modelId: idx,
+              userId: 1,
+            }
+            console.log(payload)
+            train(payload).then(res=>{
               instance.confirmButtonLoading = false
               console.log("train_res: ",res);
               if (res.msg === '成功')
@@ -312,6 +315,10 @@ export default {
           }
         },
       })
+      setTimeout(() => {
+        ElMessageBox.close()  //重要
+        ElMessage.error("超时!")
+      }, 10000);
     };
     const modelRes=ref();
     const resVisible = ref(false);