def get(self, project_id, solution_id): project = Project.find_project_with_id(project_id) user_id = get_jwt_identity() if not project or not project.belongs_to_user(user_id): return self.project_does_not_exist_response() solution = Solution.find_solution_with_id(project.type, solution_id) if not solution or not solution.if_belongs_to(project.id): return self.solution_does_not_exist_response() analytics = Analytics(solution) status = analytics.get_status() main_stats, secondary_stats = status["main_status"], status["secondary_status"] parameters = status["hyperparameters"] if not solution.analytics_filled(): if analytics.solution_has_completed(main_stats): solution.update_analytics(analytics.get_solution_metrics()) return { "type": project.type, "status": main_stats, "secondary_status": secondary_stats, "parameters": parameters, "solution": solution.json() }
def get(self, project_id): project = Project.find_project_with_id(project_id) user_id = get_jwt_identity() if not project or not project.belongs_to_user(user_id): return self.project_does_not_exist_response() return { "solution_ids": Solution.find_solutions_of_projects(project.type, project.id) }
def get(self, project_id): project = Project.find_project_with_id(project_id) user_id = get_jwt_identity() if not project or not project.belongs_to_user(user_id): return self.project_does_not_exist_response() project_data = Dataset.find_data_by_id(project.id) project_data_preview = self.get_data_preview(project_data) return {"project": project.json(), "data": project_data_preview}
def post(self, project_id): project = Project.find_project_with_id(project_id) if not project: return self.project_does_not_exist_message() deployment = DeploymentModel.find_by_project_id(project_id) if not deployment: return self.deployment_does_not_exist_message() predictor = Predictor(deployment.endpoint_name) data = self.parse_data() result = predictor.predict(data) result = self.parse_result(result) return {"result": result}
def get(self, project_id, solution_id): # Check if project belongs to correct user project = Project.find_project_with_id(project_id) user_id = get_jwt_identity() if not project or not project.belongs_to_user(user_id): return self.project_does_not_exist_response() # Check if solution belongs to project solution = Solution.find_solution_with_id(project.type, solution_id) if not solution or not solution.if_belongs_to(project.id): return self.solution_does_not_exist_response() # Get download link downloader = SolutionDownloader(solution) download_url = downloader.get_solution_url() # Return return { "url": download_url }, 201 # Created URL
def post(self, project_id): project = Project.find_project_with_id(project_id) user_id = get_jwt_identity() if not project or not project.belongs_to_user(user_id): return self.project_does_not_exist_response() # Check if user have enough tokens user = UserModel.find_user_with_id(user_id); if user.tokens == 0: return self.not_enough_tokens() algorithm_name, hyperparameters = self.parse_arguments() if not ModelCreator.if_algorithm_belongs_to_problem_type(project.type, algorithm_name): return self.wrong_class_of_algorithm() project_data = Dataset.find_data_by_id(project.id) ml_model = ModelCreator.create_model( algorithm_name, data_path=project_data.get_data_path(), hyperparameters=hyperparameters ) ml_model.fit() training_job_name = ml_model.get_training_name() ml_database_model = Solution( training_job_name=training_job_name, algorithm_name=algorithm_name, project_id=project_id, type=project.type ) ml_database_model.save() # One model trained -> Decrease user tokens by 1 user.increase_tokens(-1); return { "solution": ml_database_model.json() }, 201