public async Task AddManualCheckingsForOldSolutionsAsync(string courseId, string userId) { log.Info($"Создаю ручные проверки для всех решения пользователя {userId} в курсе {courseId}"); var course = await courseManager.GetCourseAsync(courseId); /* For exercises */ var acceptedSubmissionsBySlide = userSolutionsRepo.GetAllAcceptedSubmissionsByUser(courseId, userId) .ToList() .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, false) as ExerciseSlide; if (slide == null || !slide.Scoring.RequireReview) { continue; } log.Info($"Создаю ручную проверку для решения {lastSubmission.Id}, слайд {slideId}"); await slideCheckingsRepo.AddManualExerciseChecking(courseId, slideId, userId, lastSubmission.Id).ConfigureAwait(false); await visitsRepo.MarkVisitsAsWithManualChecking(courseId, slideId, userId).ConfigureAwait(false); } } /* For quizzes */ var passedQuizzesIds = await userQuizzesRepo.GetPassedSlideIdsAsync(courseId, userId).ConfigureAwait(false); foreach (var quizSlideId in passedQuizzesIds) { var slide = course.FindSlideById(quizSlideId, false) as QuizSlide; if (slide == null || !slide.ManualChecking) { continue; } if (!await userQuizzesRepo.IsWaitingForManualCheckAsync(courseId, quizSlideId, userId).ConfigureAwait(false)) { log.Info($"Создаю ручную проверку для теста {slide.Id}"); var submission = await userQuizzesRepo.FindLastUserSubmissionAsync(courseId, quizSlideId, userId).ConfigureAwait(false); if (submission == null || submission.ManualChecking != null) { continue; } await slideCheckingsRepo.AddManualQuizChecking(submission, courseId, quizSlideId, userId).ConfigureAwait(false); await visitsRepo.MarkVisitsAsWithManualChecking(courseId, quizSlideId, userId).ConfigureAwait(false); } } }
public static async Task <bool> SendToReviewAndUpdateScore(UserExerciseSubmission submissionNoTracking, IWebCourseManager courseManager, ISlideCheckingsRepo slideCheckingsRepo, IGroupsRepo groupsRepo, IVisitsRepo visitsRepo, MetricSender metricSender) { var userId = submissionNoTracking.UserId; var courseId = submissionNoTracking.CourseId; var course = await courseManager.GetCourseAsync(courseId); var exerciseSlide = course.FindSlideById(submissionNoTracking.SlideId, true) as ExerciseSlide; // SlideId проверен в вызывающем методе if (exerciseSlide == null) { return(false); } var exerciseMetricId = GetExerciseMetricId(courseId, exerciseSlide); var automaticCheckingNoTracking = submissionNoTracking.AutomaticChecking; var isProhibitedUserToSendForReview = await slideCheckingsRepo.IsProhibitedToSendExerciseToManualChecking(courseId, exerciseSlide.Id, userId); var sendToReview = exerciseSlide.Scoring.RequireReview && submissionNoTracking.AutomaticCheckingIsRightAnswer && !isProhibitedUserToSendForReview && await groupsRepo.IsManualCheckingEnabledForUserAsync(course, userId); if (sendToReview) { await slideCheckingsRepo.RemoveWaitingManualCheckings <ManualExerciseChecking>(courseId, exerciseSlide.Id, userId, false); await slideCheckingsRepo.AddManualExerciseChecking(courseId, exerciseSlide.Id, userId, submissionNoTracking.Id); 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 (automaticCheckingNoTracking != null) { var verdictForMetric = automaticCheckingNoTracking.GetVerdict().Replace(" ", ""); metricSender.SendCount($"exercise.{exerciseMetricId}.{verdictForMetric}"); } return(sendToReview); }