public async Task <UserQuizSubmission> AddSubmission(string courseId, Guid slideId, string userId, DateTime timestamp) { var submission = new UserQuizSubmission { CourseId = courseId, SlideId = slideId, UserId = userId, Timestamp = timestamp, }; db.UserQuizSubmissions.Add(submission); await db.SaveChangesAsync().ConfigureAwait(false); return(submission); }
public async Task <ManualQuizChecking> AddManualQuizChecking(UserQuizSubmission submission, string courseId, Guid slideId, string userId) { var manualChecking = new ManualQuizChecking { Submission = submission, CourseId = courseId, SlideId = slideId, UserId = userId, Timestamp = DateTime.Now, }; db.ManualQuizCheckings.Add(manualChecking); await db.SaveChangesAsync().ConfigureAwait(false); return(manualChecking); }
public async Task <AutomaticQuizChecking> AddAutomaticQuizChecking(UserQuizSubmission submission, string courseId, Guid slideId, string userId, int automaticScore) { var automaticChecking = new AutomaticQuizChecking { Submission = submission, CourseId = courseId, SlideId = slideId, UserId = userId, Timestamp = DateTime.Now, Score = automaticScore, }; db.AutomaticQuizCheckings.Add(automaticChecking); await db.SaveChangesAsync().ConfigureAwait(false); return(automaticChecking); }
public Dictionary <string, List <UserQuizAnswer> > GetAnswersForShowingOnSlide(string courseId, QuizSlide slide, string userId, UserQuizSubmission submission = null) { if (slide == null) { return(null); } if (submission == null) { submission = FindLastUserSubmission(courseId, slide.Id, userId); } var answer = new Dictionary <string, List <UserQuizAnswer> >(); foreach (var block in slide.Blocks.OfType <AbstractQuestionBlock>()) { if (submission != null) { var ans = db.UserQuizAnswers .Where(q => q.SubmissionId == submission.Id && q.BlockId == block.Id) .OrderBy(x => x.Id) .ToList(); answer[block.Id] = ans; } else { answer[block.Id] = new List <UserQuizAnswer>(); } } return(answer); }
public Dictionary <string, int> GetUserScores(string courseId, Guid slideId, string userId, UserQuizSubmission submission = null) { if (submission == null) { submission = FindLastUserSubmission(courseId, slideId, userId); if (submission == null) { return(new Dictionary <string, int>()); } } return(db.UserQuizAnswers .Where(q => q.SubmissionId == submission.Id) .ToList() .DistinctBy(q => q.BlockId) .ToDictionary(q => q.BlockId, q => q.QuizBlockScore)); }
public Dictionary <string, List <UserQuizAnswer> > GetAnswersForShowingOnSlide(string courseId, QuizSlide slide, string userId, UserQuizSubmission submission = null) { if (slide == null) { return(null); } if (submission == null) { submission = FindLastUserSubmission(courseId, slide.Id, userId); } var answer = new Dictionary <string, List <UserQuizAnswer> >(); if (submission == null) { foreach (var block in slide.Blocks.OfType <AbstractQuestionBlock>()) { answer[block.Id] = new List <UserQuizAnswer>(); } return(answer); } var blocks2Answers = db.UserQuizAnswers .Where(q => q.SubmissionId == submission.Id) .OrderBy(x => x.Id) .AsEnumerable() .GroupBy(a => a.BlockId) .ToDictionary(g => g.Key, g => g.ToList()); foreach (var block in slide.Blocks.OfType <AbstractQuestionBlock>()) { answer[block.Id] = blocks2Answers.ContainsKey(block.Id) ? blocks2Answers[block.Id] : new List <UserQuizAnswer>(); } return(answer); }
public async Task <Dictionary <string, int> > GetUserScoresAsync(string courseId, Guid slideId, string userId, UserQuizSubmission submission = null) { if (submission == null) { submission = await FindLastUserSubmissionAsync(courseId, slideId, userId).ConfigureAwait(false); if (submission == null) { return(new Dictionary <string, int>()); } } var submissionAnswers = await db.UserQuizAnswers.Where(q => q.SubmissionId == submission.Id).ToListAsync().ConfigureAwait(false); return(submissionAnswers .DistinctBy(q => q.BlockId) .ToDictionary(q => q.BlockId, q => q.QuizBlockScore)); }
private QuizState GetQuizState(string courseId, string userId, Guid slideId, int userScore, int maxScore, UserQuizSubmission submission = null) { log.Info($"Ищу статус прохождения теста {courseId}:{slideId} для пользователя {userId}"); var lastSubmission = userQuizzesRepo.FindLastUserSubmission(courseId, slideId, userId); var manualChecking = submission?.ManualChecking ?? lastSubmission?.ManualChecking; if (manualChecking != null) { /* For manually checked quizzes attempts are counting by manual checkings, not by user quiz submissions * (because user can resend quiz before instructor checked and score it) */ var manualCheckingCount = slideCheckingsRepo.GetQuizManualCheckingCount(courseId, slideId, userId, submission?.Timestamp); log.Info($"Статус прохождения теста {courseId}:{slideId} для пользователя {userId}: есть ручная проверка №{manualChecking.Id}, проверяется ли сейчас: {manualChecking.IsLocked}"); if (manualChecking.IsChecked) { return(new QuizState(QuizStatus.ReadyToSend, manualCheckingCount, userScore, maxScore)); } return(new QuizState(manualChecking.IsLocked ? QuizStatus.IsCheckingByInstructor : QuizStatus.WaitsForManualChecking, manualCheckingCount, userScore, maxScore)); } var usedAttemptsCount = userQuizzesRepo.GetUsedAttemptsCountForQuizWithAutomaticChecking(courseId, userId, slideId); return(new QuizState(QuizStatus.ReadyToSend, usedAttemptsCount, userScore, maxScore)); }
private Dictionary <string, int> GetUserScoresForBlocks(string courseId, string userId, Guid slideId, UserQuizSubmission submission) { return(userQuizzesRepo.GetUserScores(courseId, slideId, userId, submission)); }
private int GetManualCheckingCount(string courseId, string userId, Guid slideId, UserQuizSubmission beforeSubmissions = null) { var queue = slideCheckingsRepo.GetManualCheckingQueue <ManualQuizChecking>(new ManualCheckingQueueFilterOptions { CourseId = courseId, SlidesIds = new[] { slideId }, UserIds = new List <string> { userId }, OnlyChecked = null, // For calculating not checked submissions as well as checked ones }).ToList(); if (beforeSubmissions != null) { queue = queue.Where(s => s.Timestamp < beforeSubmissions.Timestamp).ToList(); } return(queue.Count()); }