Пример #1
0
    def post(self):
        """
        """
        self.set_post_header()          # [设置],请求头.
        reqData = self.request.body     # [取],请求参数.
        mylog.info("[Train_Choiced_DataSource.Request]...[%s]/[%s]" % (type(reqData), reqData))


        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData,
            paramList=["modelType", "dataSourceName"]
        )
        mylog.info("[Train_Choiced_DataSource.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]" % (
            errno, errMsg, reqDict
        ))
        if errno < 0:   # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # [Mysql],取[ma_train]modeName列表.
        modelNameList = []
        modelNameRows = Mysql_MA_Train.find_modelNames_by_dataSouce(
            modelType=reqDict["modelType"],
            dataSourceName=reqDict["dataSourceName"],
        )
        print("..........", len(modelNameRows))
        if modelNameRows:
            for row in modelNameRows:
                # print("row...", row)
                modelNameList.append(row.modelName)


        # [Mysql],取数据源参数.
        paramRow = Mysql_MA_DataSource.find_one_by_name(
            dsName=reqDict["dataSourceName"],
        )
        if not paramRow:  # 无匹配记录,返回.
            self.write(json.dumps({
                "errorNo": -1,
                "errorMsg": "获取数据源参数异常!"
            }))
            return


        # [返回], 给前端数据.
        data = json.dumps({
            "errorNo": 0,
            "errorMsg": "成功",
            "dataSourceParmas": json.loads(paramRow.paramsJson),
            "modelNameList": modelNameList
        })

        print(data)
        self.write(data)
Пример #2
0
    def post(self):
        """
        """
        self.set_post_header()  # [设置],请求头.
        reqData = self.request.body  # [取],请求参数.
        mylog.info("[Predict_Compare_Result.Request]...[%s]/[%s]" %
                   (type(reqData), reqData))

        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData, paramList=["modelType", "modelNames"])
        mylog.info(
            "[Predict_Compare_Result.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]"
            % (errno, errMsg, reqDict))
        if errno < 0:  # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        compareRes = Mysql_MA_Result.soft_result_Compare()

        if not compareRes:  # 记录不存在,返回
            self.write(json.dumps({"errorNo": -1, "errorMsg": "没有结果更新!"}))
            return

        df = pd.read_sql(
            """SELECT a.modelName,a.time,a.prediction,b.Sample_TestResult,c.test_code 
        FROM soft_predict_result a,lims_data b,lim_dict c WHERE a.optColid=b.DICTIONARYID AND 
        b.DICTIONARYID=c.dictionaryid AND  a.time=b.Sampling_Date ORDER BY a.time""",
            engine.raw_connection())

        resultList = []
        if len(df) != 0:
            for modelName in reqDict["modelNames"]:
                resultDict = {}
                resJson = df[df['modelName'] == modelName][[
                    'time', 'prediction', 'Sample_TestResult', 'test_code'
                ]].to_json(orient='records')
                resultDict['modelName'] = modelName
                resultDict['data'] = json.loads(resJson)
                resultList.append(resultDict)
        else:
            self.write(json.dumps({"errorNo": -1, "errorMsg": "没有数据更新!"}))

        data = json.dumps({
            "errorNo": 0,
            "errorMsg": "成功",
            "Result": resultList
        })
        print(data)
        self.write(data)
Пример #3
0
    def post(self):
        """
        """
        self.set_post_header()  # [设置],请求头.
        reqData = self.request.body  # [取],请求参数.
        mylog.info("[Predict_Get_DataSource.Request]...[%s]/[%s]" %
                   (type(reqData), reqData))

        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData, paramList=["modelType"])
        mylog.info(
            "[Predict_Get_DataSource.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]"
            % (errno, errMsg, reqDict))
        if errno < 0:  # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # [Mysql],取记录.
        rows = Mysql_MA_DataSource.find_predict_dataSourceList(
            modelType=reqDict["modelType"])
        if not rows:  # 无匹配记录,返回.
            self.write(json.dumps({"errorNo": -1, "errorMsg": "没有匹配的数据源."}))
            return

        # [生成],数据源名称列表.
        dataSourceList = []
        for row in rows:
            # print(row)
            dataSourceList.append({
                "modelName": row.modelName,
                "dataSource": row.dsName
            })

        # [返回], 给前端数据.
        data = json.dumps({
            "errorNo": 0,
            "errorMsg": "成功",
            "dataSourceList": dataSourceList,
        })

        print(data)
        self.write(data)
Пример #4
0
    def post(self):
        """
        """
        self.set_post_header()  # [设置],请求头.
        reqData = self.request.body  # [取],请求参数.
        mylog.info("[Train_Get_ModelNameList.Request]...[%s]/[%s]" %
                   (type(reqData), reqData))

        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData, paramList=["modelType"])
        mylog.info(
            "[Train_Get_ModelNameList.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]"
            % (errno, errMsg, reqDict))
        if errno < 0:  # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # [Mysql],取[ma_train]记录.
        trainRow = Mysql_MA_Train.find_modelNames_by_modelType(
            modelType=reqDict["modelType"])
        # modify @2019-11-25,没有匹配modelName返回空列表.
        # if not trainRow:  # 记录不存在,返回
        #     self.write(json.dumps({
        #         "errorNo": -1,
        #         "errorMsg": "模型名称不存在异常!"
        #     }))
        #     return

        modelNameList = []
        if trainRow:
            for row in trainRow:
                modelNameList.append(row.modelName)

        # [返回], 给前端数据.
        data = json.dumps({
            "errorNo": 0,
            "errorMsg": "成功",
            "modelNameList": modelNameList
        })

        print(data)
        self.write(data)
Пример #5
0
    def post(self):
        """
        """
        self.set_post_header()  # [设置],请求头.
        reqData = self.request.body  # [取],请求参数.
        mylog.info("[Predict_Add_DataSource.Request]...[%s]/[%s]" %
                   (type(reqData), reqData))

        # [校验],请求参数.
        errno, errMsg, reqDict = self.verify_request(reqData=reqData)
        mylog.info(
            "[Predict_Add_DataSource.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]"
            % (errno, errMsg, reqDict))
        if errno < 0:  # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # [Mysql],判断[ma_data_source]记录是否存在.
        row = Mysql_MA_DataSource.find_one_by_name(
            dsName=reqDict.get('dataSourceName'))
        if row:  # 记录已存在,返回
            self.write(json.dumps({"errorNo": -1, "errorMsg": "该数据源已存在!"}))
            return

        # [Mysql],插入[ma_data_source]记录.
        row = Mysql_MA_DataSource.insert(
            modelType=reqDict.get('modelType'),
            dsName=reqDict.get('dataSourceName'),
            dsDesc=reqDict.get('dataSourceDesc'),
            useType=2,  # 用途类型。1训练,2预测
            dsDir=reqDict.get('dataSourceDir'),
            dsFile=reqDict.get('dataFileName'),
            mylog=mylog)
        if not row:  # 插入Mysql,异常.
            self.write(json.dumps({"errorNo": -1, "errorMsg": "Mysql插入失败!"}))
            return

        # [返回], 返回给前端数据.
        data = json.dumps({"errorNo": 0, "errorMsg": "成功"})

        print(data)
        self.write(data)
Пример #6
0
    def post(self):
        """
        """
        self.set_post_header()  # [设置],请求头.
        reqData = self.request.body  # [取],请求参数.
        mylog.info("[Train_Get_Model_Params.Request]...[%s]/[%s]" %
                   (type(reqData), reqData))

        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData, paramList=["modelType", "modelName"])
        mylog.info(
            "[Train_Get_Model_Params.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]"
            % (errno, errMsg, reqDict))
        if errno < 0:  # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # [Mysql],取[ma_train]记录.
        trainRow = Mysql_MA_Train.find_one(modelType=reqDict["modelType"],
                                           modelName=reqDict["modelName"])
        if not trainRow:  # 记录不存在,返回
            self.write(json.dumps({"errorNo": -1, "errorMsg": "模型记录不存在异常!"}))
            return

        # [Mysql],取[ma_data_source]记录.
        dsRow = Mysql_MA_DataSource.find_one_by_id(dsId=trainRow.dsId, )
        if not dsRow:  # 记录不存在,返回.
            self.write(json.dumps({"errorNo": -1, "errorMsg": "数据源记录不存在异常!"}))
            return

        # [返回], 给前端数据.
        data = json.dumps({
            "errorNo": 0,
            "errorMsg": "成功",
            "dataSourceParams": json.loads(dsRow.paramsJson),
            "modelParams": json.loads(trainRow.modelParams),
            "trainState": int(trainRow.trainState)
        })

        print(data)
        self.write(data)
Пример #7
0
    def post(self):
        """
        """
        self.set_post_header()          # [设置],请求头.
        reqData = self.request.body     # [取],请求参数.
        mylog.info("[Predict_Get_ModelNameList.Request]...[%s]/[%s]" % (type(reqData), reqData))

        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData, paramList=["modelType", "predictDataSourceName"]
        )

        mylog.info("[Predict_Get_ModelNameList.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]" % (
            errno, errMsg, reqDict
        ))
        if errno < 0:   # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # [Mysql],取[ma_predict]记录.
        predictRow = Mysql_MA_Predict.find_modelNames_by_modelType_dsName(
            modelType=reqDict["modelType"], dataSourceName=reqDict["predictDataSourceName"]
        )

        modelNameList = []
        if predictRow:
            for row in predictRow:
                modelNameList.append(row.modelName)

        # [返回], 给前端数据.
        data = json.dumps({
            "errorNo": 0,
            "errorMsg": "成功",
            "modelNameList":  modelNameList
        })

        print(data)
        self.write(data)
    def post(self):
        """
        """
        self.set_post_header()  # [设置],请求头.
        reqData = self.request.body  # [取],请求参数.
        mylog.info("[Predict_Commit_Task.Request]...[%s]/[%s]" %
                   (type(reqData), reqData))

        # [校验],请求参数.
        # errno, errMsg, reqDict = Optim_Public.verify_request(
        #     reqData=reqData,
        #     paramList=["modelType", "modelName"]
        # )
        # mylog.info("[Predict_Commit_Task.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]" % (
        #     errno, errMsg, reqDict
        # ))
        # if errno < 0:   # 校验异常,返回.
        #     self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
        #     return

        # stop
        val = os.popen('jps | grep maPredict | wc -l').read()  # 执行结果包含在val中

        if int(val) <= 0:
            self.write(json.dumps({"errorNo": 0, "errorMsg": "当前没有任务运行"}))

        else:
            res = os.system(
                "jps | grep maPredict | awk '{print $1}' | xargs kill -9")
            if res == 0:
                self.write(json.dumps({"errorNo": 0, "errorMsg": "stop执行成功!"}))
            else:
                self.write(json.dumps({
                    "errorNo": -1,
                    "errorMsg": "stop执行失败!"
                }))
Пример #9
0
    def post(self):
        """
        """
        self.set_post_header()          # [设置],请求头.
        reqData = self.request.body     # [取],请求参数.
        mylog.info("[Predict_Commit_Task.Request]...[%s]/[%s]" % (type(reqData), reqData))

        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData,
            paramList=["modelType", "modelName", "predictDataSourceName"]
        )
        mylog.info("[Predict_Commit_Task.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]" % (
            errno, errMsg, reqDict
        ))
        if errno < 0:   # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # [Mysql],[ma_predict]表记录是否存在.
        row = Mysql_MA_Predict.find_one(
            modelType=reqDict["modelType"],
            modelName=reqDict["modelName"],
            dataSourceName=reqDict["predictDataSourceName"],
        )
        if row:
            # 记录已存在,直接计算
            self.start_predict_compute(reqDict.get('modelType'), reqDict.get('modelName'))
            return

        # [Mysql],取[ma_data_source]数据源记录.
        dsRow = Mysql_MA_DataSource.find_one_by_name(
            dsName=reqDict["predictDataSourceName"],
        )
        if not dsRow:  # 无匹配记录,返回.
            self.write(json.dumps({
                "errorNo": -1,
                "errorMsg": "获取数据源记录异常!"
            }))
            return

        # [Mysql],取[ma_train]数据源记录.
        trainRow = Mysql_MA_Train.find_one(
            modelType=reqDict["modelType"],
            modelName=reqDict["modelName"],
        )
        if not trainRow:  # 无匹配记录,返回.
            self.write(json.dumps({
                "errorNo": -1,
                "errorMsg": "获取模型训练记录异常!"
            }))
            return


        # # [创建],目录
        # predictDir = Optim_Public_Predict.create_predict_dir(
        #     modelType=reqDict.get('modelType'),
        #     modelName=reqDict.get('modelName'),
        #     dsDataFileName="%s/%s" % (dsRow.dsDir, dsRow.dsFile),
        # )
        # if predictDir is None:  # 创建目录,异常.
        #     self.write(json.dumps({
        #         "errorNo": -1,
        #         "errorMsg": "创建预测目录异常!"
        #     }))
        #     return

        # [插入],Mysql记录.
        print("dsId={}...trainId={}".format(dsRow.id, trainRow.id))
        row = Mysql_MA_Predict.insert(
            trainId=trainRow.id,
            dsId=dsRow.id,
            modelType=reqDict.get('modelType'),
            modelName=reqDict.get('modelName'),
            dsName=dsRow.dsName,
            # predictDir=predictDir,
            predictState=0,     # 0未开始,1进行中,2已完成
            mylog=mylog
        )
        if not row:  # 插入Mysql,异常.
            self.write(json.dumps({
                "errorNo": -1,
                "errorMsg": "Mysql插入失败!"
            }))
            return

        self.start_predict_compute(reqDict.get('modelType'), reqDict.get('modelName'))
Пример #10
0
    def post(self):
        """
        """
        global trainResult0000
        self.set_post_header()          # [设置],请求头.
        reqData = self.request.body     # [取],请求参数.
        mylog.info("[Train_Query_Result.Request]...[%s]/[%s]" % (type(reqData), reqData))


        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData,
            paramList=["modelType", "modelName"]
        )
        mylog.info("[Train_Get_Model_Params.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]" % (
            errno, errMsg, reqDict
        ))
        if errno < 0:   # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # [Mysql],取[ma_train]记录.
        trainRow = Mysql_MA_Train.find_one(
            modelType=reqDict["modelType"],
            modelName=reqDict["modelName"]
        )
        if not trainRow:  # 记录不存在,返回
            self.write(json.dumps({
                "errorNo": -1,
                "errorMsg": "训练记录不存在异常!"
            }))
            return

        # [Mysql],取[ma_data_source]记录.
        dsRow = Mysql_MA_DataSource.find_one_by_id(
            dsId=trainRow.dsId,
        )
        if not dsRow:  # 记录不存在,返回.
            self.write(json.dumps({
                "errorNo": -1,
                "errorMsg": "数据源记录不存在异常!"
            }))
            return

        if trainRow.modelType == "优化分析":
            # [训练结果查询],未完成,或处理中。[0未开始,1进行中,2已完成]
            if trainRow.trainState == 0 or trainRow.trainState == 1:
                trainResult1 = None
                trainResult2 = None
                trainResult3 = None
            else:
                if conf.OS_TYPE == "window":
                    # trainResult1 = None
                    # trainResult3 = None
                    trainResult1 = Optim_Public_Train.fetch_train_result(
                        fileDir=trainRow.trainDir + r"/train_result/result_1", mylog=mylog)
                    trainResult2 = Optim_Public_Train.fetch_train_result(
                        fileDir=trainRow.trainDir + r"/train_result/result_2", paramOriJson=dsRow.paramOriJson, mylog=mylog)
                    trainResult3 = Optim_Public_Train.fetch_train_result(
                        fileDir=trainRow.trainDir + r"/train_result/result_3", paramOriJson=dsRow.paramOriJson, mylog=mylog)
                else:
                    trainResult1 = Optim_Public_Train.fetch_train_result(
                        fileDir=trainRow.trainDir + r"/train_result/\result_1", mylog=mylog)
                    trainResult2 = Optim_Public_Train.fetch_train_result(
                        fileDir=trainRow.trainDir + r"/train_result/\result_2", paramOriJson=dsRow.paramOriJson, mylog=mylog)
                    trainResult3 = Optim_Public_Train.fetch_train_result(
                        fileDir=trainRow.trainDir + r"/train_result/\result_3", paramOriJson=dsRow.paramOriJson, mylog=mylog)

            # [返回], 给前端数据.
            data = json.dumps({
                "errorNo": 0,
                "errorMsg": "成功",
                "dataSourceParams": json.loads(dsRow.paramsJson),
                "modelParams": json.loads(trainRow.modelParams),
                "trainState": int(trainRow.trainState),
                "trainResult1": trainResult1,
                "trainResult2": trainResult2,
                "trainResult3": trainResult3,
            })

            mylog.debug(data)
            self.write(data)

        elif trainRow.modelType == "产品质量软测量":
            if trainRow.trainState == 0 or trainRow.trainState == 1:
                trainResult = None

            else:
                trainResult = Optim_Public_Train.fetch_train_result(
                    fileDir=trainRow.trainDir + r"/train_result/\predict_xiaoguo.csv", mylog=mylog)

            # [返回], 给前端数据.
            data = json.dumps({
                "errorNo": 0,
                "errorMsg": "成功",
                "dataSourceParams": json.loads(dsRow.paramsJson),
                "modelParams": json.loads(trainRow.modelParams),
                "trainState": int(trainRow.trainState),
                "trainResult": trainResult
            })

            mylog.debug(data)
            self.write(data)

        elif trainRow.modelType == "生产预警分析" or trainRow.modelType == "三次平滑指数预警分析":
            if trainRow.trainState == 0 or trainRow.trainState == 1:
                predictSucessSta = None
                TimeSeq = None

            else:
                predictSucessSta = Optim_Public_Train.fetch_train_result(
                    fileDir=trainRow.trainDir + r"/train_result/predictSucessSta", mylog=mylog)
                TimeSeq = Optim_Public_Train.fetch_train_result(
                    fileDir=trainRow.trainDir + r"/train_result/TimeSeq", mylog=mylog)

            # [返回], 给前端数据.
            data = json.dumps({
                "errorNo": 0,
                "errorMsg": "成功",
                "dataSourceParams": json.loads(dsRow.paramsJson),
                "modelParams": json.loads(trainRow.modelParams),
                "trainState": int(trainRow.trainState),
                "predictSucessSta": predictSucessSta,
                "TimeSeq": TimeSeq
            })

            mylog.debug(data)
            self.write(data)
Пример #11
0
    def post(self):
        """
        """
        self.set_post_header()  # [设置],请求头.
        reqData = self.request.body  # [取],请求参数.
        mylog.info("[Predict_Commit_Task.Request]...[%s]/[%s]" %
                   (type(reqData), reqData))

        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData,
            paramList=["modelType", "modelNames", "predictDataSourceName"])
        mylog.info(
            "[Predict_Commit_Task.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]"
            % (errno, errMsg, reqDict))
        if errno < 0:  # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # add by sip
        res = Mysql_MA_Predict.find_by_model_names(
            modelType=reqDict["modelType"],
            modelNames=reqDict["modelNames"],
            dataSourceName=reqDict["predictDataSourceName"],
        )

        # 将已经存在的模型名称存入列表
        exist_list = []
        for item in res:
            exist_list.append(item.modelName)

        # 新建模型名称列表
        new_mode_list = list(set(reqDict["modelNames"]) - set(exist_list))
        print(new_mode_list)

        # 没有新模型,直接启动算法进行计算
        if not new_mode_list:
            self.start_compute_via_modeNamelist(reqDict["modelType"],
                                                reqDict["modelNames"])
            return

        for modeName in new_mode_list:
            # [Mysql],取[ma_data_source]数据源记录.
            dsRow = Mysql_MA_DataSource.find_one_by_name(
                dsName=reqDict["predictDataSourceName"], )
            if not dsRow:  # 无匹配记录,返回.
                self.write(
                    json.dumps({
                        "errorNo": -1,
                        "errorMsg": "获取数据源记录异常!"
                    }))
                return

            # [Mysql],取[ma_train]数据源记录.
            trainRow = Mysql_MA_Train.find_one(
                modelType=reqDict["modelType"],
                modelName=modeName,
            )
            if not trainRow:  # 无匹配记录,返回.
                self.write(
                    json.dumps({
                        "errorNo": -1,
                        "errorMsg": "获取模型训练记录异常!"
                    }))
                return

            # # [创建],目录
            # predictDir = Optim_Public_Predict.create_predict_dir(
            #     modelType=reqDict.get('modelType'),
            #     modelName=modeName,
            #     dsDataFileName="%s/%s" % (dsRow.dsDir, dsRow.dsFile),
            # )
            # if predictDir is None:  # 创建目录,异常.
            #     self.write(json.dumps({
            #         "errorNo": -1,
            #         "errorMsg": "创建预测目录异常!"
            #     }))
            #     return

            # [插入],Mysql记录.
            print("dsId={}...trainId={}".format(dsRow.id, trainRow.id))
            row = Mysql_MA_Predict.insert(
                trainId=trainRow.id,
                dsId=dsRow.id,
                modelType=reqDict.get('modelType'),
                modelName=modeName,
                dsName=dsRow.dsName,
                predictState=0,  # 0未开始,1进行中,2已完成
                mylog=mylog)
            if not row:  # 插入Mysql,异常.
                self.write(
                    json.dumps({
                        "errorNo": -1,
                        "errorMsg": "Mysql插入失败!"
                    }))
                return

        # 启动算法进行计算
        self.start_compute_via_modeNamelist(reqDict["modelType"],
                                            reqDict["modelNames"])
Пример #12
0
    def post(self):
        """
        """
        self.set_post_header()          # [设置],请求头.
        reqData = self.request.body     # [取],请求参数.
        mylog.info("[Train_Save_Model.Request]...{}...{}".format(type(reqData), reqData))

        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData,
            paramList=["modelType", "dataSourceName", "modelName", "modelParams"]
        )
        mylog.info("[Train_Save_Model.Verify]...errno=[{}]...errMsg=[{}]...reqDict=[{}]".format(
            errno, errMsg, reqDict
        ))
        if errno < 0:   # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # [校验], [优化分析]“op_w”权重值之和应该是1.
        if reqDict["modelType"] == "优化分析":
            sumVal = self.verify_op_w(modelParams=reqDict["modelParams"])
            if sumVal != 1:
                self.write(json.dumps({
                    "errorNo": -1,
                    "errorMsg": "(优化目标)权重值之和应该等于1!"
                }))
                return

        # [Mysql],[ma_train]表modelName记录是否存在.
        row = Mysql_MA_Train.find_one(
            modelType=reqDict["modelType"],
            modelName=reqDict["modelName"]
        )
        if row:  # 记录已存在,返回
            self.write(json.dumps({
                "errorNo": -1,
                "errorMsg": "模型名称已存在!"
            }))
            return

        # [Mysql],取[ma_data_source]数据源记录.
        dsRow = Mysql_MA_DataSource.find_one_by_name(
            dsName=reqDict["dataSourceName"],
        )
        if not dsRow:  # 无匹配记录,返回.
            self.write(json.dumps({
                "errorNo": -1,
                "errorMsg": "获取数据源异常!"
            }))
            return


        # [创建],训练目录
        trainDir = Optim_Public_Train.create_train_dir(
            modelType=reqDict.get('modelType'),
            modelName=reqDict.get('modelName'),
            modelParams=reqDict.get("modelParams"),
            dsDataFileName = "%s/%s" % (dsRow.dsDir, dsRow.dsFile),
            dsParamFileName = "%s/%s" % (dsRow.dsDir, dsRow.paramsFile),
        )
        if trainDir is None:  # 创建目录,异常.
            self.write(json.dumps({
                "errorNo": -1,
                "errorMsg": "创建训练目录异常!"
            }))
            return


        # [插入],Mysql记录.
        # print(dsRow.id)
        # 将模型参数转换为 算法API可用参数.
        modelParams4ml = Optim_Public_Train.convert_modelParams_4ml(
            modelType=reqDict.get('modelType'),
            modelParams=reqDict.get('modelParams')
        )
        print("...........", modelParams4ml)
        # 插入DB.
        row = Mysql_MA_Train.insert(
            modelType=reqDict.get('modelType'),
            modelName=reqDict.get('modelName'),
            dsId=dsRow.id,
            modelParams=json.dumps(reqDict.get('modelParams')),
            modelParams4ml=modelParams4ml,
            trainDir=trainDir,
            trainState=0,  # 0未开始,1进行中,2已完成
            mylog=mylog
        )
        if not row:  # 插入Mysql,异常.
            self.write(json.dumps({
                "errorNo": -1,
                "errorMsg": "Mysql插入失败!"
            }))
            return

        # [返回], 给前端数据.
        data = json.dumps({
            "errorNo": 0,
            "errorMsg": "成功"
        })

        print(data)
        self.write(data)
    def post(self):
        """
        """
        self.set_post_header()  # [设置],请求头.
        reqData = self.request.body  # [取],请求参数.
        mylog.info("[Predict_Query_Result.Request]...[%s]/[%s]" %
                   (type(reqData), reqData))

        # [校验],请求参数.
        errno, errMsg, reqDict = Optim_Public.verify_request(
            reqData=reqData,
            paramList=["modelType", "modelNames", "predictDataSourceName"])
        mylog.info(
            "[Predict_Query_Result.Verify]...errno=[%s]...errMsg=[%s]...reqDict=[%s]"
            % (errno, errMsg, reqDict))
        if errno < 0:  # 校验异常,返回.
            self.write(json.dumps({"errorNo": errno, "errorMsg": errMsg}))
            return

        # # [Mysql],取[ma_predict]记录.
        # predictRow = Mysql_MA_Predict.find_one(
        #     modelType=reqDict["modelType"],
        #     modelName=reqDict["modelName"],
        #     dataSourceName=reqDict["predictDataSourceName"],
        # )
        # if not predictRow:  # 记录不存在,返回
        #     self.write(json.dumps({
        #         "errorNo": -1,
        #         "errorMsg": "模型预测记录不存在异常!"
        #     }))
        #     return

        # add by sjp
        predictRows = Mysql_MA_Predict.find_by_model_names(
            modelType=reqDict["modelType"],
            modelNames=reqDict["modelNames"],
            dataSourceName=reqDict["predictDataSourceName"],
        )
        if not predictRows:  # 记录不存在,返回
            self.write(json.dumps({"errorNo": -1, "errorMsg": "模型预测记录不存在异常!"}))
            return

        Result = []
        for predictRow in predictRows:
            # [Mysql],取[ma_train]记录.
            trainRow = Mysql_MA_Train.find_one(modelType=reqDict["modelType"],
                                               modelName=predictRow.modelName)
            if not trainRow:  # 记录不存在,返回
                self.write(
                    json.dumps({
                        "errorNo": -1,
                        "errorMsg": "模型训练记录不存在异常!"
                    }))
                return

            # [Mysql],取[ma_data_source]记录.
            trainDSRow = Mysql_MA_DataSource.find_one_by_id(
                dsId=trainRow.dsId, )
            if not trainDSRow:  # 记录不存在,返回.
                self.write(
                    json.dumps({
                        "errorNo": -1,
                        "errorMsg": "数据源记录不存在异常!"
                    }))
                return
            predictDSRow = Mysql_MA_DataSource.find_one_by_id(
                dsId=predictRow.dsId, )
            if not predictDSRow:  # 记录不存在,返回.
                self.write(
                    json.dumps({
                        "errorNo": -1,
                        "errorMsg": "数据源记录不存在异常!"
                    }))
                return

            if trainRow.modelType == "优化分析":
                # 判断目录是否存在
                result_dir = predictRow.predictDir + r"/predict_result/\result_2"

                if not os.path.isdir(result_dir):
                    predictResult = {"time": {}, "prediction": {}}
                else:
                    Files = os.listdir(result_dir)
                    if not Files or len(Files) < 4:
                        predictResult = {}
                    else:
                        predictResult = Optim_Public_Predict.real_compute_fetch_predict_result(
                            result1_Dir=predictRow.predictDir +
                            r"/predict_result/\result_1",
                            result2_Dir=predictRow.predictDir +
                            r"/predict_result/\result_2",
                            paramOriJson=trainDSRow.paramOriJson,
                            mylog=mylog)

                # [返回], 给前端数据.
                data = json.dumps({
                    "errorNo":
                    0,
                    "errorMsg":
                    "成功",
                    "dataSourceParams":
                    json.loads(trainDSRow.paramsJson),
                    "modelParams":
                    json.loads(trainRow.modelParams),
                    "predictState":
                    int(predictRow.predictState),
                    "predictResult":
                    predictResult
                })

                print(data)
                self.write(data)

            elif trainRow.modelType == "产品质量软测量":
                # if predictRow.predictState == 0 or predictRow.predictState == 1:
                #     predictResult = None
                #     ResultFileName = None
                #
                # else:
                #     predictResult, ResultFileName = Optim_Public_Predict.fetch_predict_result(
                #         predictRow.predictDir + r"/predict_result/\predict_result",
                #         mylog=mylog
                #     )

                # 判断目录是否存在
                result_dir = predictRow.predictDir + r"/predict_result/\predict_result"

                if not os.path.isdir(result_dir):
                    predictResult = {"time": {}, "prediction": {}}
                else:
                    Files = os.listdir(result_dir)
                    if not Files or len(Files) < 4:
                        predictResult = {"time": {}, "prediction": {}}
                    else:
                        predictResult, ResultFileName = Optim_Public_Predict.fetch_predict_result(
                            result_dir, mylog=mylog)
                tempResult = {
                    "modelName": predictRow.modelName,
                    "dataSourceParams": json.loads(trainDSRow.paramsJson),
                    "modelParams": json.loads(trainRow.modelParams),
                    "predictState": int(predictRow.predictState),
                    "predictResult": predictResult,
                }
                Result.append(tempResult)

        data = json.dumps({"errorNo": 0, "errorMsg": "成功", "Result": Result})
        print(data)
        self.write(data)