예제 #1
0
    def POST(self, context_classes):
        
        print("--- InitClassifier POST request ---")

        classes_list = json.loads(context_classes) 

        model_exists_result = check_model_exists(classes_list)
        
        if model_exists_result == False:
            # This model does not exists on server yet, so we have to build it:
            
            # Create random ID for this request:
            id = str(randint(1e5,1e6))

            # Create an id, where the client can get the new classifier when the calculation is done:  
            filename_new_classifier = str(id) + ".json"
            
            valid_classes = []
            invalid_classes = []
            
	    waitOrNoWait = "no_wait"

            for el in classes_list:
                if (feasibilityCheck(el) == "not_feasible"): 
                    invalid_classes.append(el)
                    
                elif (feasibilityCheck(el) == "downloaded"):
                    valid_classes.append(el)
                    
                elif (feasibilityCheck(el) == "feasible"):
                    valid_classes.append(el)
                
                else:
                    print("feasibilityCheck returned invalid result")

	    if len(valid_classes) != 0:
                # Start training the classifier in the background (list is passed as String and converted back with Regex later):
                subprocess.Popen(["python", "server_create_initial_model.py", json.dumps(valid_classes), filename_new_classifier])
		waitOrNoWait = "wait"
	    else:
		# If not a single class is valid, don't do anything:
		waitOrNoWait = "no_wait"
	
            # Return new filename and the list of invalid classes:
            response = {"filename": filename_new_classifier, "wait": waitOrNoWait, "invalid_classes": invalid_classes}
   
        else:
            # The model already exisits and the location of the model can be send to server:
            filename_exisiting = "classifiers/" + model_exists_result
            
            #response = {"wait": "no_wait", "filename": filename_exisiting}
            response = {"filename": filename_exisiting, "wait": "no_wait", "invalid_classes": []}
            
        return response
예제 #2
0
 def POST(self, classname):
     
     print("--- FeasibilityCheck POST request ---")
     
     res = feasibilityCheck(classname)
     
     return res
예제 #3
0
    def POST(self, context_classes):
        
        print("--- ManageClasses POST request ---")

        context_classes_list = json.loads(context_classes)            
        
        classifier_json = cherrypy.request.json     
        
        # Create random ID for this request:
        id = str(randint(1e5,1e6))
        
        # Dump the GMM object we received from the client, as it is too large to parse as argument directly:
        filename_old_classifier = "tmp_" + id + ".json"
        json.dump(classifier_json, open(filename_old_classifier,"wb"))
        
        # Create an id, where the client can get the new classifier when the calculation is done:  
        filename_new_classifier = "Classifier_" + id + ".json"
        
        valid_classes = []
        invalid_classes = []
        
        for el in context_classes_list:
            if (feasibilityCheck(el) == "not_feasible"): 
                invalid_classes.append(el)
                waitOrNoWait = "no_wait"
                
            elif (feasibilityCheck(el) == "downloaded"):
                valid_classes.append(el)
                waitOrNoWait = "no_wait"
                
            elif (feasibilityCheck(el) == "feasible"):
                valid_classes.append(el)
                waitOrNoWait = "wait"
                
            else:
                print("feasibilityCheck returned invalid result")
                waitOrNoWait = "no_wait"
        
        # Start training the classifier in the background:
        subprocess.Popen(["python", "server_manage_classes.py", json.dumps(valid_classes), filename_old_classifier, filename_new_classifier])
        
        # Return new filename and the list of invalid classes:
        response = {"filename": filename_new_classifier, "wait": waitOrNoWait, "invalid_classes": invalid_classes}
        
        return response