def predictForRevision(project_id, revision): # Init validation validation = ValidationResult([]); # Load project projectValidation = ProjectService.getDetail(project_id); # Check project validation if not validation.append(projectValidation): return validation # Get changes of given revision submissionValidation = RepositoryService.getRevisionDifference(projectValidation.data["repository"], revision + "^", revision) # Check submission validation if not validation.append(submissionValidation): return validation # Make prediction return ModelService.predict(project_id, submissionValidation.data)
def create(project_id): StateService.set("Getting project information") # Get detail about project validation = ProjectService.getDetail(project_id); # If getting detail failed, pass it if not validation.isValid: return validation; # Init tuple to hold data measurements = dict() # It went ok, so let us begin # We need to process each submission sortedSubmissions = sorted(validation.data["submissions"], key=lambda k: k['SequenceNumber']) for index, submission in enumerate(sortedSubmissions, start=0): StateService.set(validation.data["name"] + ": Processing submission (" + str(index + 1) + "/" + str(sortedSubmissions.__len__()) + ")") # Init api handler resultCloud = ResultCloud(config.RESULT_CLOUD_API) # Get submission with test cases from result cloud try: response = resultCloud.get_submission_by_id(submission["Id"]) except: # Prepare validation and return result validation.addError("Failed to load submission from ResultCloud") return validation # Failed to get response if not response: # Prepare validation and return result validation.addError("Failed to load submission from ResultCloud") return validation # Assign result rcSubmission = resultCloud.last_response['Result'] # Get changes of submission if index < 1: # There is no previous submission submissionValidation = RepositoryService.getRevisionDifference(validation.data["repository"], submission["GitHash"] + "^", submission["GitHash"]) else: submissionValidation = RepositoryService.getRevisionDifference(validation.data["repository"], sortedSubmissions[index-1]["GitHash"] , submission["GitHash"]) # Check if validation is ok if not validation.append(submissionValidation): return validation # We have all we need for testCase in ModelService._extractTestCases(rcSubmission): # Update measurements measurements = ModelService._updateModelMeasurements(measurements, ntpath.basename(testCase["Name"]), submissionValidation.data, testCase["ChangeFlag"]) StateService.set(validation.data["name"] + ":Saving models") # Calculate and save models classifiers = ModelService._calculate(measurements) ModelService._saveClassifiers(classifiers, "project_" + project_id) StateService.reset() # Return validation return validation