private async Task<UserSolution> UpdateSubmission(UserSolution submission, RunningResults result) { var compilationErrorHash = (await textsRepo.AddText(result.CompilationOutput)).Hash; var outputHash = (await textsRepo.AddText(result.GetOutput().NormalizeEoln())).Hash; var webRunner = submission.CourseId == "web" && submission.SlideId == "runner"; var exerciseSlide = webRunner ? null : ((ExerciseSlide)courseManager.GetCourse(submission.CourseId).GetSlideById(submission.SlideId)); var updated = new UserSolution { Id = submission.Id, SolutionCodeHash = submission.SolutionCodeHash, CompilationErrorHash = compilationErrorHash, CourseId = submission.CourseId, SlideId = submission.SlideId, IsCompilationError = result.Verdict == Verdict.CompilationError, IsRightAnswer = result.Verdict == Verdict.Ok && (webRunner || exerciseSlide.Exercise.ExpectedOutput.NormalizeEoln() == result.GetOutput().NormalizeEoln()), OutputHash = outputHash, Timestamp = submission.Timestamp, UserId = submission.UserId, CodeHash = submission.CodeHash, Likes = submission.Likes, ExecutionServiceName = submission.ExecutionServiceName, Status = SubmissionStatus.Done, DisplayName = submission.DisplayName, Elapsed = DateTime.Now - submission.Timestamp }; return updated; }
private async Task<AutomaticExerciseChecking> UpdateAutomaticExerciseChecking(AutomaticExerciseChecking checking, RunningResults result) { var compilationErrorHash = (await textsRepo.AddText(result.CompilationOutput)).Hash; var output = result.GetOutput().NormalizeEoln(); var outputHash = (await textsRepo.AddText(output)).Hash; var isWebRunner = checking.CourseId == "web" && checking.SlideId == Guid.Empty; var exerciseSlide = isWebRunner ? null : (ExerciseSlide)courseManager.GetCourse(checking.CourseId).GetSlideById(checking.SlideId); var expectedOutput = exerciseSlide?.Exercise.ExpectedOutput.NormalizeEoln(); var isRightAnswer = result.Verdict == Verdict.Ok && output.Equals(expectedOutput); var score = isRightAnswer ? exerciseSlide.Exercise.CorrectnessScore : 0; var newChecking = new AutomaticExerciseChecking { Id = checking.Id, CourseId = checking.CourseId, SlideId = checking.SlideId, UserId = checking.UserId, Timestamp = checking.Timestamp, CompilationErrorHash = compilationErrorHash, IsCompilationError = result.Verdict == Verdict.CompilationError, OutputHash = outputHash, ExecutionServiceName = checking.ExecutionServiceName, Status = AutomaticExerciseCheckingStatus.Done, DisplayName = checking.DisplayName, Elapsed = DateTime.Now - checking.Timestamp, IsRightAnswer = isRightAnswer, Score = score, }; return newChecking; }