private async Task AddManualCheckingsForOldSolutionsAsync(string courseId, string userId) { logger.Information($"Создаю ручные проверки для всех решения пользователя {userId} в курсе {courseId}"); var course = courseManager.GetCourse(courseId); /* For exercises */ var acceptedSubmissionsBySlide = userSolutionsRepo.GetAllAcceptedSubmissionsByUser(courseId, userId) .GroupBy(s => s.SlideId) .ToDictionary(g => g.Key, g => g.ToList()); foreach (var acceptedSubmissionsForSlide in acceptedSubmissionsBySlide.Values) { /* If exists at least one manual checking for at least one submissions on slide, then ignore this slide */ if (!acceptedSubmissionsForSlide.Any(s => s.ManualCheckings.Any())) { /* Otherwise found the latest accepted submission */ var lastSubmission = acceptedSubmissionsForSlide.OrderByDescending(s => s.Timestamp).First(); var slideId = lastSubmission.SlideId; var slide = course.FindSlideById(slideId) as ExerciseSlide; if (slide == null || !slide.Exercise.RequireReview) { continue; } logger.Information($"Создаю ручную проверку для решения {lastSubmission.Id}, слайд {slideId}"); await slideCheckingsRepo.AddManualExerciseChecking(courseId, slideId, userId, lastSubmission).ConfigureAwait(false); await visitsRepo.MarkVisitsAsWithManualChecking(slideId, userId).ConfigureAwait(false); } } /* For quizzes */ var passedQuizzesIds = userQuizzesRepo.GetIdOfQuizPassedSlides(courseId, userId); foreach (var quizSlideId in passedQuizzesIds) { var slide = course.FindSlideById(quizSlideId) as QuizSlide; if (slide == null || !slide.ManualChecking) { continue; } if (!userQuizzesRepo.IsWaitingForManualCheck(courseId, quizSlideId, userId)) { logger.Information($"Создаю ручную проверку для теста {slide.Id}"); await slideCheckingsRepo.AddQuizAttemptForManualChecking(courseId, quizSlideId, userId).ConfigureAwait(false); await visitsRepo.MarkVisitsAsWithManualChecking(quizSlideId, userId).ConfigureAwait(false); } } }
public static async Task <bool> SendToReviewAndUpdateScore(UserExerciseSubmission submission, CourseManager courseManager, SlideCheckingsRepo slideCheckingsRepo, GroupsRepo groupsRepo, VisitsRepo visitsRepo, MetricSender metricSender, bool startTransaction) { var userId = submission.User.Id; var courseId = submission.CourseId; var course = courseManager.GetCourse(courseId); var exerciseSlide = course.FindSlideById(submission.SlideId, true) as ExerciseSlide; // SlideId проверен в вызывающем методе if (exerciseSlide == null) { return(false); } var exerciseMetricId = GetExerciseMetricId(courseId, exerciseSlide); var automaticChecking = submission.AutomaticChecking; var isProhibitedUserToSendForReview = slideCheckingsRepo.IsProhibitedToSendExerciseToManualChecking(courseId, exerciseSlide.Id, userId); var sendToReview = exerciseSlide.Scoring.RequireReview && submission.AutomaticCheckingIsRightAnswer && !isProhibitedUserToSendForReview && groupsRepo.IsManualCheckingEnabledForUser(course, userId); if (sendToReview) { await slideCheckingsRepo.RemoveWaitingManualCheckings <ManualExerciseChecking>(courseId, exerciseSlide.Id, userId, false); await slideCheckingsRepo.AddManualExerciseChecking(courseId, exerciseSlide.Id, userId, submission); await visitsRepo.MarkVisitsAsWithManualChecking(courseId, exerciseSlide.Id, userId); metricSender.SendCount($"exercise.{exerciseMetricId}.sent_to_review"); metricSender.SendCount("exercise.sent_to_review"); } await visitsRepo.UpdateScoreForVisit(courseId, exerciseSlide, userId); if (automaticChecking != null) { var verdictForMetric = automaticChecking.GetVerdict().Replace(" ", ""); metricSender.SendCount($"exercise.{exerciseMetricId}.{verdictForMetric}"); } return(sendToReview); }
protected async Task <RunSolutionResult> CheckSolution(string courseId, ExerciseSlide exerciseSlide, string userCode, string userId, string userName, bool waitUntilChecked, bool saveSubmissionOnCompileErrors) { var slideTitleForMetric = exerciseSlide.LatinTitle.Replace(".", "_").ToLower(CultureInfo.InvariantCulture); if (slideTitleForMetric.Length > 25) { slideTitleForMetric = slideTitleForMetric.Substring(0, 25); } var exerciseMetricId = $"{courseId.ToLower(CultureInfo.InvariantCulture)}.{exerciseSlide.Id.ToString("N").Substring(32 - 25)}.{slideTitleForMetric}"; metricSender.SendCount("exercise.try"); metricSender.SendCount($"exercise.{courseId.ToLower(CultureInfo.InvariantCulture)}.try"); metricSender.SendCount($"exercise.{exerciseMetricId}.try"); var course = courseManager.GetCourse(courseId); var exerciseBlock = exerciseSlide.Exercise; var buildResult = exerciseBlock.BuildSolution(userCode); if (buildResult.HasErrors) { metricSender.SendCount($"exercise.{exerciseMetricId}.CompilationError"); } if (buildResult.HasStyleErrors) { metricSender.SendCount($"exercise.{exerciseMetricId}.StyleViolation"); } if (!saveSubmissionOnCompileErrors) { if (buildResult.HasErrors) { return new RunSolutionResult { IsCompileError = true, ErrorMessage = buildResult.ErrorMessage, ExecutionServiceName = "uLearn" } } ; } var compilationErrorMessage = buildResult.HasErrors ? buildResult.ErrorMessage : null; var dontRunSubmission = buildResult.HasErrors; var submissionLanguage = SubmissionLanguageHelpers.ByLangId(exerciseSlide.Exercise.LangId); var submission = await userSolutionsRepo.AddUserExerciseSubmission( courseId, exerciseSlide.Id, userCode, compilationErrorMessage, null, userId, "uLearn", GenerateSubmissionName(exerciseSlide, userName), submissionLanguage, dontRunSubmission?AutomaticExerciseCheckingStatus.Done : AutomaticExerciseCheckingStatus.Waiting ); if (buildResult.HasErrors) { return new RunSolutionResult { IsCompileError = true, ErrorMessage = buildResult.ErrorMessage, SubmissionId = submission.Id, ExecutionServiceName = "uLearn" } } ; try { if (submissionLanguage.HasAutomaticChecking()) { await userSolutionsRepo.RunAutomaticChecking(submission, executionTimeout, waitUntilChecked); } } catch (SubmissionCheckingTimeout) { log.Error($"Не смог запустить проверку решения, никто не взял его на проверку за {executionTimeout.TotalSeconds} секунд.\nКурс «{course.Title}», слайд «{exerciseSlide.Title}» ({exerciseSlide.Id})"); errorsBot.PostToChannel($"Не смог запустить проверку решения, никто не взял его на проверку за {executionTimeout.TotalSeconds} секунд.\nКурс «{course.Title}», слайд «{exerciseSlide.Title}» ({exerciseSlide.Id})\n\nhttps://ulearn.me/Sandbox"); return(new RunSolutionResult { IsCompillerFailure = true, ErrorMessage = "К сожалению, из-за большой нагрузки мы не смогли оперативно проверить ваше решение. " + "Мы попробуем проверить его позже, просто подождите и обновите страницу. ", ExecutionServiceName = "uLearn" }); } if (!waitUntilChecked) { metricSender.SendCount($"exercise.{exerciseMetricId}.dont_wait_result"); return(new RunSolutionResult { SubmissionId = submission.Id }); } /* Update the submission */ submission = userSolutionsRepo.FindNoTrackingSubmission(submission.Id); var automaticChecking = submission.AutomaticChecking; var isProhibitedUserToSendForReview = slideCheckingsRepo.IsProhibitedToSendExerciseToManualChecking(courseId, exerciseSlide.Id, userId); var sendToReview = exerciseBlock.RequireReview && submission.AutomaticCheckingIsRightAnswer && !isProhibitedUserToSendForReview && groupsRepo.IsManualCheckingEnabledForUser(course, userId); if (sendToReview) { await slideCheckingsRepo.RemoveWaitingManualExerciseCheckings(courseId, exerciseSlide.Id, userId); await slideCheckingsRepo.AddManualExerciseChecking(courseId, exerciseSlide.Id, userId, submission); await visitsRepo.MarkVisitsAsWithManualChecking(courseId, exerciseSlide.Id, userId); metricSender.SendCount($"exercise.{exerciseMetricId}.sent_to_review"); metricSender.SendCount("exercise.sent_to_review"); } await visitsRepo.UpdateScoreForVisit(courseId, exerciseSlide.Id, userId); if (automaticChecking != null) { var verdictForMetric = automaticChecking.GetVerdict().Replace(" ", ""); metricSender.SendCount($"exercise.{exerciseMetricId}.{verdictForMetric}"); } if (submission.AutomaticCheckingIsRightAnswer) { await CreateStyleErrorsReviewsForSubmission(submission, buildResult.StyleErrors, exerciseMetricId); } var result = new RunSolutionResult { IsCompileError = automaticChecking?.IsCompilationError ?? false, ErrorMessage = automaticChecking?.CompilationError.Text ?? "", IsRightAnswer = submission.AutomaticCheckingIsRightAnswer, ExpectedOutput = exerciseBlock.HideExpectedOutputOnError ? null : exerciseSlide.Exercise.ExpectedOutput.NormalizeEoln(), ActualOutput = automaticChecking?.Output.Text ?? "", ExecutionServiceName = automaticChecking?.ExecutionServiceName ?? "ulearn", SentToReview = sendToReview, SubmissionId = submission.Id, }; if (buildResult.HasStyleErrors) { result.IsStyleViolation = true; result.StyleMessage = string.Join("\n", buildResult.StyleErrors.Select(e => e.GetMessageWithPositions())); } return(result); }
private async Task <RunSolutionResult> CheckSolution(string courseId, ExerciseSlide exerciseSlide, string userCode) { var exerciseBlock = exerciseSlide.Exercise; var userId = User.Identity.GetUserId(); var solution = exerciseBlock.BuildSolution(userCode); if (solution.HasErrors) { return new RunSolutionResult { IsCompileError = true, ErrorMessage = solution.ErrorMessage, ExecutionServiceName = "uLearn" } } ; if (solution.HasStyleIssues) { return new RunSolutionResult { IsStyleViolation = true, ErrorMessage = solution.StyleMessage, ExecutionServiceName = "uLearn" } } ; var submission = await solutionsRepo.RunUserSolution( courseId, exerciseSlide.Id, userId, userCode, null, null, false, "uLearn", GenerateSubmissionName(exerciseSlide), executionTimeout ); var course = courseManager.GetCourse(courseId); if (submission == null) { log.Error($"Не смог запустить проверку решения, никто не взял его на проверку за {executionTimeout.TotalSeconds} секунд.\nКурс «{course.Title}», слайд «{exerciseSlide.Title}» ({exerciseSlide.Id})"); errorsBot.PostToChannel($"Не смог запустить проверку решения, никто не взял его на проверку за {executionTimeout.TotalSeconds} секунд.\nКурс «{course.Title}», слайд «{exerciseSlide.Title}» ({exerciseSlide.Id})\n\nhttps://ulearn.me/Sandbox"); return(new RunSolutionResult { IsCompillerFailure = true, ErrorMessage = "К сожалению, из-за большой нагрузки мы не смогли оперативно проверить ваше решение. " + "Мы попробуем проверить его позже, просто подождите и обновите страницу. ", ExecutionServiceName = "uLearn" }); } var automaticChecking = submission.AutomaticChecking; var isProhibitedUserToSendForReview = slideCheckingsRepo.IsProhibitedToSendExerciseToManualChecking(courseId, exerciseSlide.Id, userId); var sendToReview = exerciseBlock.RequireReview && automaticChecking.IsRightAnswer && !isProhibitedUserToSendForReview && groupsRepo.IsManualCheckingEnabledForUser(course, userId); if (sendToReview) { await slideCheckingsRepo.RemoveWaitingManualExerciseCheckings(courseId, exerciseSlide.Id, userId); await slideCheckingsRepo.AddManualExerciseChecking(courseId, exerciseSlide.Id, userId, submission); await visitsRepo.MarkVisitsAsWithManualChecking(exerciseSlide.Id, userId); } await visitsRepo.UpdateScoreForVisit(courseId, exerciseSlide.Id, userId); return(new RunSolutionResult { IsCompileError = automaticChecking.IsCompilationError, ErrorMessage = automaticChecking.CompilationError.Text, IsRightAnswer = automaticChecking.IsRightAnswer, ExpectedOutput = exerciseBlock.HideExpectedOutputOnError ? null : exerciseSlide.Exercise.ExpectedOutput.NormalizeEoln(), ActualOutput = automaticChecking.Output.Text, ExecutionServiceName = automaticChecking.ExecutionServiceName, SentToReview = sendToReview, SubmissionId = submission.Id, }); }