Example #1
0
 def test_6_trainNNModel(self):
     logging.info("Test Case : Train NN model.")
     filePath = 'testUseCase/supportdata/irisNN.pmml'
     logFolder = 'testUseCase/supportdata/logs'
     payload = {
         "batchSize": 15,
         "epoch": 10,
         "stepPerEpoch": 10,
         "learningRate": 0.001,
         "loss": "categorical_crossentropy",
         "metrics": ["accuracy"],
         "optimizer": "Adam",
         "testSize": 0.3,
         "scriptOutput": "NA",
         "problemType": "classification",
         "filePath": os.path.abspath(filePath),
         "tensorboardLogFolder": os.path.abspath(logFolder),
         "tensorboardUrl": '',
         'dataFolder': ''
     }
     result = Training.trainNeuralNetworkModels(payload)
     result = json.loads(result.__dict__['_container'][0])
     self.assertEqual(result['pmmlFile'],
                      filePath.split('/')[-1].replace('.pmml', ''))
     self.assertEqual(result['idforData'],
                      filePath.split('/')[-1].replace('.pmml', ''))
     self.assertEqual(result['status'], 'In Progress')
     self.assertEqual('pID' in result, True)
     Utility.deleteTaskfromMemory(result['idforData'])
     logging.info("PASSED")
Example #2
0
File: views.py Project: vadgama/MLW
    def get(self, requests):
        try:
            filePath = requests.GET['filePath']
            if not filePath:
                raise Exception("Invalid Request Parameter")
        except:
            return JsonResponse({'error': 'Invalid Request Parameter'},
                                status=400)

        return Utility.downloadPMML(filePath)
Example #3
0
 def test_1_runningTasksList(self):
     logging.info("Test Case : Get all running tasks.")
     result = Utility.runningTaskList()
     self.assertEqual(result.status_code, 200)
     self.assertEqual(
         'runningTask' in json.loads(result.__dict__['_container'][0]),
         True)
     self.assertEqual(
         len(json.loads(result.__dict__['_container'][0])['runningTask']),
         0)
     logging.info("PASSED")
Example #4
0
File: views.py Project: vadgama/MLW
    def post(self, requests):
        try:
            oldFile = requests.POST.get('oldFilePath')
            if not oldFile:
                raise Exception("Invalid Request Parameter")
        except:
            return JsonResponse({'error': 'Invalid Request Parameter'},
                                status=400)

        try:
            newFile = requests.POST.get('newFilePath')
        except:
            newFile = None
        return Utility.convertZMKtoZS(oldFile, newFile)
Example #5
0
 def test_3_deleteARunningTask(self):
     logging.info("Test Case : Deleting a running tasks.")
     idforData = 'id'
     result = Utility.deleteTaskfromMemory(idforData)
     self.assertEqual(
         'idforData' in json.loads(result.__dict__['_container'][0]), True)
     self.assertEqual(
         'message' in json.loads(result.__dict__['_container'][0]), True)
     self.assertEqual(
         json.loads(result.__dict__['_container'][0])['idforData'], 'id')
     self.assertEqual(
         json.loads(result.__dict__['_container'][0])['message'],
         'Something went wrong. Please contact Admin')
     logging.info("PASSED")
Example #6
0
    def test_3_downloadPMMLFile(self):
        logging.info("Test Case : Test download file for pmml file.")
        with open('testUseCase/supportdata/test.pmml', 'w') as ff:
            ff.write('<?xml version="1.0" encoding="UTF-8"?>')

        filePath = os.path.abspath('testUseCase/supportdata/test.pmml')
        result = Utility.downloadPMML(filePath)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.__dict__['_container'][0].decode('utf-8'),
                         '<?xml version="1.0" encoding="UTF-8"?>')
        self.assertEqual(result.__dict__['_headers']['content-type'][1],
                         'application/xml')
        os.remove('testUseCase/supportdata/test.pmml')
        logging.info("PASSED")
Example #7
0
    def test_2_downloadCSVFile(self):
        logging.info("Test Case : Test download file for csv file.")
        with open('testUseCase/supportdata/test.csv', 'w') as ff:
            ff.write('This,is,a,Test,File')

        filePath = os.path.abspath('testUseCase/supportdata/test.csv')

        result = Utility.downloadPMML(filePath)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.__dict__['_container'][0].decode('utf-8'),
                         'This,is,a,Test,File')
        self.assertEqual(result.__dict__['_headers']['content-type'][1],
                         'text/csv')
        os.remove('testUseCase/supportdata/test.csv')
        logging.info("PASSED")
Example #8
0
    def test_1_downloadJSONFile(self):
        logging.info("Test Case : Test download file for json file.")
        content = {'content': 'This is a Test File'}
        with open('testUseCase/supportdata/test.json', 'w') as ff:
            ff.write(json.dumps(content))

        filePath = os.path.abspath('testUseCase/supportdata/test.json')

        result = Utility.downloadPMML(filePath)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(
            json.loads(result.__dict__['_container'][0])['content'],
            'This is a Test File')
        self.assertEqual(result.__dict__['_headers']['content-type'][1],
                         'application/json')
        os.remove('testUseCase/supportdata/test.json')
        logging.info("PASSED")
Example #9
0
 def test_4_CodeExecution(self):
     logging.info("Test Case : Test Code execution.")
     filePath = os.path.abspath(
         'testUseCase/supportdata/testScriptSimple.py')
     result = CodeUtilityClass.executeCode(filePath, [])
     import json
     self.assertEqual(
         json.loads(result.__dict__['_container'][0])['status'],
         "In Progress")
     self.assertEqual(result.status_code, 200)
     import time
     time.sleep(3)
     idForCheck = json.loads(result.__dict__['_container'][0])['idforData']
     result2 = Utility().runningTaskList()
     jLoad = json.loads(result2.__dict__['_container'][0])['runningTask']
     # print(jLoad)#=result2.__dict__['_container']
     for en in jLoad:
         if en['idforData'] == idForCheck:
             checkval = True
             break
     self.assertEqual(checkval, True)
     logging.info("PASSED")
Example #10
0
 def delete(self, requests, id_for_task):
     return Utility.deleteTaskfromMemory(id_for_task)
Example #11
0
 def get(self, requests):
     return Utility().runningTaskList()
Example #12
0
 def get(self, requests, taskName, idForData):
     return Utility().taskUpdateByTaskNameIdForData(taskName, idForData)
Example #13
0
 def get(self, requests, taskName):
     return Utility().taskUpdateByTaskName(taskName)
Example #14
0
    def test_5_AutoMLTrain(self):
        logging.info(
            "Test Case : Perform preprocessing and train AutoML model.")
        filePath = os.path.abspath(
            'testUseCase/supportdata/mpg_data_example2.csv')
        result = Training.autoMLdataprocess(filePath)
        tempa = json.loads(result.__dict__['_container'][0])
        newPMMLFileName = 'xyz.pmml'
        target_variable = 'mpg'
        true = True
        false = False
        dataPreprocessingsteps = {
            "data": [{
                "position": 1,
                "variable": "mpg",
                "dtype": "float64",
                "missing_val": 0,
                "changedataType": "Continuous",
                "imputation_method": "None",
                "data_transformation_step": "None",
                "use_for_model": true
            }, {
                "position": 2,
                "variable": "cylinders",
                "dtype": "int64",
                "missing_val": 0,
                "changedataType": "Continuous",
                "imputation_method": "None",
                "data_transformation_step": "None",
                "use_for_model": true
            }, {
                "position": 3,
                "variable": "displacement",
                "dtype": "float64",
                "missing_val": 0,
                "changedataType": "Continuous",
                "imputation_method": "None",
                "data_transformation_step": "None",
                "use_for_model": true
            }, {
                "position": 4,
                "variable": "horsepower",
                "dtype": "float64",
                "missing_val": 6,
                "changedataType": "Continuous",
                "imputation_method": "Mean",
                "data_transformation_step": "None",
                "use_for_model": true
            }, {
                "position": 5,
                "variable": "weight",
                "dtype": "int64",
                "missing_val": 0,
                "changedataType": "Continuous",
                "imputation_method": "None",
                "data_transformation_step": "None",
                "use_for_model": true
            }, {
                "position": 6,
                "variable": "acceleration",
                "dtype": "float64",
                "missing_val": 0,
                "changedataType": "Continuous",
                "imputation_method": "None",
                "data_transformation_step": "None",
                "use_for_model": true
            }, {
                "position": 7,
                "variable": "model year",
                "dtype": "int64",
                "missing_val": 0,
                "changedataType": "Categorical",
                "imputation_method": "None",
                "data_transformation_step": "None",
                "use_for_model": true
            }, {
                "position": 8,
                "variable": "origin",
                "dtype": "int64",
                "missing_val": 0,
                "changedataType": "Categorical",
                "imputation_method": "None",
                "data_transformation_step": "One Hot Encoding",
                "use_for_model": true
            }, {
                "position": 9,
                "variable": "car name",
                "dtype": "object",
                "missing_val": 0,
                "changedataType": "Categorical",
                "imputation_method": "None",
                "data_transformation_step": "None",
                "use_for_model": false
            }],
            "problem_type":
            "Regression",
            "target_variable":
            target_variable,
            "idforData":
            tempa['idforData'],
            'newPMMLFileName':
            newPMMLFileName,
            'filePath':
            filePath,
            "parameters": []
        }
        result2 = Training.autoMLtrainModel(dataPreprocessingsteps)
        result2 = json.loads(result2.__dict__['_container'][0])
        self.assertEqual('pID' in result2, True)
        self.assertEqual('status' in result2, True)
        self.assertEqual('newPMMLFileName' in result2, True)
        self.assertEqual('targetVar' in result2, True)
        self.assertEqual('problem_type' in result2, True)
        self.assertEqual('idforData' in result2, True)
        self.assertEqual(result2['status'], 'In Progress')
        self.assertEqual(result2['newPMMLFileName'], newPMMLFileName)
        self.assertEqual(result2['targetVar'], target_variable)
        self.assertEqual(result2['idforData'], tempa['idforData'])

        result = Utility.runningTaskList()
        self.assertEqual(result.status_code, 200)
        self.assertEqual(
            'runningTask' in json.loads(result.__dict__['_container'][0]),
            True)
        self.assertEqual(
            len(json.loads(result.__dict__['_container'][0])['runningTask']),
            1)

        idforData = tempa['idforData']
        result = Training.statusOfModel(idforData)
        self.assertEqual(result.status_code, 200)
        result = json.loads(result.__dict__['_container'][0])
        self.assertEqual('pID' in result, True)
        self.assertEqual('status' in result, True)
        self.assertEqual('idforData' in result, True)

        idforData = tempa['idforData']
        result = Utility.deleteTaskfromMemory(idforData)
        self.assertEqual(
            'idforData' in json.loads(result.__dict__['_container'][0]), True)
        self.assertEqual(
            'message' in json.loads(result.__dict__['_container'][0]), True)
        self.assertEqual(
            json.loads(result.__dict__['_container'][0])['idforData'],
            tempa['idforData'])
        self.assertEqual(
            json.loads(result.__dict__['_container'][0])['message'],
            'Deleted successfully')

        result = Utility.runningTaskList()
        self.assertEqual(result.status_code, 200)
        self.assertEqual(
            'runningTask' in json.loads(result.__dict__['_container'][0]),
            True)
        self.assertEqual(
            len(json.loads(result.__dict__['_container'][0])['runningTask']),
            0)
        logging.info("PASSED")