def create_ml_models_single_problem(problem): """ Celery task called by create_ml_models to create a single model """ transaction.commit_unless_managed() lock_id = "celery-model-creation-{0}".format(problem.id) acquire_lock = lambda: cache.add(lock_id, "true", settings.MODEL_CREATION_CACHE_LOCK_TIME) release_lock = lambda: cache.delete(lock_id) if acquire_lock(): try: handle_single_problem(problem) finally: release_lock()
def test_ml_creation(self): """ Test to see if an ml model can be created and then if essays can be graded """ # Create 10 training essays that are scored problem_resource_uri = create_ml_problem_and_essays("train", 10) # Get the problem so that we can pass it to ml model generation engine problem = lookup_object(problem_resource_uri) problem_id = problem['id'] problem_model = Problem.objects.get(id=problem_id) # Create the ml model creator_success, message = ml_model_creation.handle_single_problem( problem_model) # Create some test essays and see if the model can score them essay_list = create_ml_essays_only("test", 10, problem_resource_uri) # Lookup the first essay and try to score it essay = lookup_object(essay_list[0]) essay_id = essay['id'] essay_model = Essay.objects.get(id=essay_id) # Try to score the essay grader_success, message = ml_grader.handle_single_essay(essay_model) self.assertEqual(creator_success, settings.FOUND_ML) self.assertEqual(grader_success, settings.FOUND_ML)
def test_ml_creation(self): """ Test to see if an ml model can be created and then if essays can be graded """ #Create 10 training essays that are scored problem_resource_uri = create_ml_problem_and_essays("train",10) #Get the problem so that we can pass it to ml model generation engine problem = lookup_object(problem_resource_uri) problem_id = problem['id'] problem_model = Problem.objects.get(id=problem_id) #Create the ml model creator_success, message = ml_model_creation.handle_single_problem(problem_model) #Create some test essays and see if the model can score them essay_list = create_ml_essays_only("test",10, problem_resource_uri) #Lookup the first essay and try to score it essay = lookup_object(essay_list[0]) essay_id = essay['id'] essay_model = Essay.objects.get(id=essay_id) #Try to score the essay grader_success, message = ml_grader.handle_single_essay(essay_model) self.assertEqual(creator_success, settings.FOUND_ML) self.assertEqual(grader_success, settings.FOUND_ML)
def create_ml_models_single_problem(problem): """ Celery task called by create_ml_models to create a single model """ transaction.commit_unless_managed() handle_single_problem(problem)