Ejemplo n.º 1
0
 private async Task NotifyAboutManualQuizChecking(ManualQuizChecking checking)
 {
     var notification = new PassedManualQuizCheckingNotification
     {
         Checking = checking,
     };
     await notificationsRepo.AddNotification(checking.CourseId, notification, User.Identity.GetUserId());
 }
Ejemplo n.º 2
0
        public async Task AddQuizAttemptForManualChecking(string courseId, Guid slideId, string userId)
        {
            var manualChecking = new ManualQuizChecking
            {
                CourseId  = courseId,
                SlideId   = slideId,
                UserId    = userId,
                Timestamp = DateTime.Now,
            };

            db.ManualQuizCheckings.Add(manualChecking);

            await db.SaveChangesAsync();
        }
Ejemplo n.º 3
0
		public ActionResult Quiz(QuizSlide slide, string courseId, string userId, bool isGuest, bool isLti = false, ManualQuizChecking manualQuizCheckQueueItem = null, int? groupId = null)
		{
			if (isGuest)
				return PartialView(GuestQuiz(slide, courseId));
			var slideId = slide.Id;
			var maxDropCount = GetMaxDropCount(slide);
			var state = GetQuizState(courseId, userId, slideId, maxDropCount);
			var quizState = state.Item1;
			var tryNumber = state.Item2;
			var resultsForQuizes = GetResultForQuizes(courseId, userId, slideId, state.Item1);

			log.Info($"Создаю тест для пользователя {userId} в слайде {courseId}:{slide.Id}, isLti = {isLti}");

			var quizVersion = quizzesRepo.GetLastQuizVersion(courseId, slideId);
			if (quizState != QuizState.NotPassed)
				quizVersion = userQuizzesRepo.FindQuizVersionFromUsersAnswer(courseId, slideId, userId);

			/* If we haven't quiz version in database, create it */
			if (quizVersion == null)
				quizVersion = quizzesRepo.AddQuizVersionIfNeeded(courseId, slide);

			/* Restore quiz slide from version stored in the database */
			var quiz = quizVersion.RestoredQuiz;
			slide = new QuizSlide(slide.Info, quiz);

			var userAnswers = userQuizzesRepo.GetAnswersForShowOnSlide(courseId, slide, userId);
			var canUserFillQuiz = CanUserFillQuiz(quizState);

			var model = new QuizModel
			{
				CourseId = courseId,
				Slide = slide,
				QuizState = quizState,
				TryNumber = tryNumber,
				MaxDropCount = maxDropCount,
				ResultsForQuizes = resultsForQuizes,
				AnswersToQuizes = userAnswers,
				IsLti = isLti,
				ManualQuizCheckQueueItem = manualQuizCheckQueueItem,
				CanUserFillQuiz = canUserFillQuiz,
				GroupId = groupId,
			};

			if (model.QuizState != QuizState.NotPassed && model.Score == quiz.MaxScore)
				model.QuizState = QuizState.Total;

			return PartialView(model);
		}
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public ActionResult Quiz(QuizSlide slide, string courseId, string userId, bool isGuest, bool isLti = false, ManualQuizChecking manualQuizCheckQueueItem = null, int?send = null)
        {
            metricSender.SendCount("quiz.show");
            if (isLti)
            {
                metricSender.SendCount("quiz.show.lti");
            }
            metricSender.SendCount($"quiz.show.{courseId}");
            metricSender.SendCount($"quiz.show.{courseId}.{slide.Id}");

            var course = courseManager.FindCourse(courseId);

            if (course == null)
            {
                return(HttpNotFound());
            }

            if (isGuest)
            {
                metricSender.SendCount("quiz.show.to.guest");
                return(PartialView(GuestQuiz(course, slide)));
            }
            var slideId          = slide.Id;
            var maxTriesCount    = GetMaxTriesCount(courseId, slide);
            var state            = GetQuizState(courseId, userId, slideId);
            var quizState        = state.Item1;
            var tryNumber        = state.Item2;
            var resultsForQuizes = GetResultForQuizes(courseId, userId, slideId, state.Item1);

            log.Info($"Создаю тест для пользователя {userId} в слайде {courseId}:{slide.Id}, isLti = {isLti}");

            var quizVersion = quizzesRepo.GetLastQuizVersion(courseId, slideId);

            if (quizState != QuizState.NotPassed)
            {
                quizVersion = userQuizzesRepo.FindQuizVersionFromUsersAnswer(courseId, slideId, userId);
            }

            /* If we haven't quiz version in database, create it */
            if (quizVersion == null)
            {
                quizVersion = quizzesRepo.AddQuizVersionIfNeeded(courseId, slide);
            }

            /* Restore quiz slide from version stored in the database */
            var quiz = quizVersion.GetRestoredQuiz(course, course.FindUnitBySlideId(slide.Id));

            slide = new QuizSlide(slide.Info, quiz);

            if (quizState == QuizState.Subtotal)
            {
                var score = resultsForQuizes?.AsEnumerable().Sum(res => res.Value) ?? 0;
                /* QuizState.Subtotal is partially obsolete. If user fully solved quiz, then show answers. Else show empty quiz for the new try... */
                if (score == quiz.MaxScore)
                {
                    quizState = QuizState.Total;
                }
                /* ... and show last try's answers only if argument `send` has been passed in query */
                else if (!send.HasValue)
                {
                    quizState = QuizState.NotPassed;
                    /* ... if we will show answers from last try then drop quiz */
                    userQuizzesRepo.DropQuiz(courseId, userId, slideId);
                }
            }

            var userAnswers     = userQuizzesRepo.GetAnswersForShowOnSlide(courseId, slide, userId);
            var canUserFillQuiz = CanUserFillQuiz(quizState);

            var questionAnswersFrequency = new DefaultDictionary <string, DefaultDictionary <string, int> >();

            if (User.HasAccessFor(courseId, CourseRole.CourseAdmin))
            {
                questionAnswersFrequency = quiz.Blocks.OfType <ChoiceBlock>().ToDictionary(
                    block => block.Id,
                    block => userQuizzesRepo.GetAnswersFrequencyForChoiceBlock(courseId, slide.Id, block.Id).ToDefaultDictionary()
                    ).ToDefaultDictionary();
            }

            var model = new QuizModel
            {
                Course                   = course,
                Slide                    = slide,
                QuizState                = quizState,
                TryNumber                = tryNumber,
                MaxTriesCount            = maxTriesCount,
                ResultsForQuizes         = resultsForQuizes,
                AnswersToQuizes          = userAnswers,
                IsLti                    = isLti,
                ManualQuizCheckQueueItem = manualQuizCheckQueueItem,
                CanUserFillQuiz          = canUserFillQuiz,
                GroupsIds                = Request.GetMultipleValuesFromQueryString("group"),
                QuestionAnswersFrequency = questionAnswersFrequency,
            };

            return(PartialView(model));
        }
Ejemplo n.º 6
0
        public ActionResult Quiz(QuizSlide slide, string courseId, string userId, bool isGuest, bool isLti = false, ManualQuizChecking manualQuizCheckQueueItem = null)
        {
            if (isGuest)
            {
                return(PartialView(GuestQuiz(slide, courseId)));
            }
            var slideId          = slide.Id;
            var maxDropCount     = GetMaxDropCount(slide);
            var state            = GetQuizState(courseId, userId, slideId, maxDropCount);
            var quizState        = state.Item1;
            var tryNumber        = state.Item2;
            var resultsForQuizes = GetResultForQuizes(courseId, userId, slideId, state.Item1);

            log.Info($"Создаю тест для пользователя {userId} в слайде {courseId}:{slide.Id}, isLti = {isLti}");

            var quizVersion = quizzesRepo.GetLastQuizVersion(courseId, slideId);

            if (quizState != QuizState.NotPassed)
            {
                quizVersion = userQuizzesRepo.FindQuizVersionFromUsersAnswer(courseId, slideId, userId);
            }

            /* If we haven't quiz version in database, create it */
            if (quizVersion == null)
            {
                quizVersion = quizzesRepo.AddQuizVersionIfNeeded(courseId, slide);
            }

            /* Restore quiz slide from version stored in the database */
            var quiz = quizVersion.RestoredQuiz;

            slide = new QuizSlide(slide.Info, quiz);

            var userAnswers     = userQuizzesRepo.GetAnswersForShowOnSlide(courseId, slide, userId);
            var canUserFillQuiz = CanUserFillQuiz(quizState);

            var model = new QuizModel
            {
                CourseId                 = courseId,
                Slide                    = slide,
                QuizState                = quizState,
                TryNumber                = tryNumber,
                MaxDropCount             = maxDropCount,
                ResultsForQuizes         = resultsForQuizes,
                AnswersToQuizes          = userAnswers,
                IsLti                    = isLti,
                ManualQuizCheckQueueItem = manualQuizCheckQueueItem,
                CanUserFillQuiz          = canUserFillQuiz,
                GroupsIds                = Request.GetMultipleValues("group"),
            };

            if (model.QuizState == QuizState.Subtotal && model.Score == quiz.MaxScore)
            {
                model.QuizState = QuizState.Total;
            }

            return(PartialView(model));
        }
Ejemplo n.º 7
0
        public ActionResult Quiz(QuizSlide slide, string courseId, string userId, bool isGuest, bool isLti = false, ManualQuizChecking manualQuizCheckQueueItem = null, int?send = null, bool attempt = false)
        {
            metricSender.SendCount("quiz.show");
            if (isLti)
            {
                metricSender.SendCount("quiz.show.lti");
            }
            metricSender.SendCount($"quiz.show.{courseId}");
            metricSender.SendCount($"quiz.show.{courseId}.{slide.Id}");

            var course = courseManager.FindCourse(courseId);

            if (course == null)
            {
                return(HttpNotFound());
            }

            if (isGuest)
            {
                metricSender.SendCount("quiz.show.to.guest");
                return(PartialView(GuestQuiz(course, slide)));
            }

            var slideId = slide.Id;
            var isManualCheckingEnabledForUser = slide.ManualChecking && groupsRepo.IsManualCheckingEnabledForUser(course, userId);
            var maxAttemptsCount = GetMaxAttemptsCount(courseId, slide);
            var userScores       = GetUserScoresForBlocks(courseId, userId, slideId, manualQuizCheckQueueItem?.Submission);

            var score = userScores?.AsEnumerable().Sum(res => res.Value) ?? 0;

            var state = GetQuizState(courseId, userId, slideId, score, slide.MaxScore, manualQuizCheckQueueItem?.Submission);

            log.Info($"Показываю тест для пользователя {userId} в слайде {courseId}:{slide.Id}, isLti = {isLti}");

            /* If it's manual checking, change quiz state to IsChecking for correct rendering */
            if (manualQuizCheckQueueItem != null)
            {
                state.Status = QuizStatus.IsCheckingByInstructor;
            }

            /* For manually checked quizzes show last attempt's answers until ?attempt=true is defined in query string */
            if (slide.ManualChecking && manualQuizCheckQueueItem == null && state.Status == QuizStatus.ReadyToSend && state.UsedAttemptsCount > 0 && !attempt)
            {
                state.Status = QuizStatus.Sent;
            }

            /* We also want to show user's answer if user sent answers just now */
            if (state.Status == QuizStatus.ReadyToSend && send.HasValue)
            {
                state.Status = QuizStatus.Sent;
            }

            var userAnswers     = userQuizzesRepo.GetAnswersForShowingOnSlide(courseId, slide, userId, manualQuizCheckQueueItem?.Submission);
            var canUserFillQuiz = (!slide.ManualChecking || isManualCheckingEnabledForUser) && CanUserFillQuiz(state.Status);

            var questionAnswersFrequency = new DefaultDictionary <string, DefaultDictionary <string, int> >();

            if (User.HasAccessFor(courseId, CourseRole.CourseAdmin))
            {
                var choiceBlocks     = slide.Blocks.OfType <ChoiceBlock>().ToList();
                var answersFrequency = userQuizzesRepo.GetAnswersFrequencyForChoiceBlocks(courseId, slide.Id, choiceBlocks);
                questionAnswersFrequency = answersFrequency.Keys.ToDictionary(
                    blockId => blockId,
                    blockId => answersFrequency[blockId].ToDefaultDictionary()
                    ).ToDefaultDictionary();
            }

            var model = new QuizModel
            {
                Course                     = course,
                Slide                      = slide,
                QuizState                  = state,
                MaxAttemptsCount           = maxAttemptsCount,
                UserScores                 = userScores,
                AnswersToQuizzes           = userAnswers,
                IsLti                      = isLti,
                Checking                   = manualQuizCheckQueueItem,
                ManualCheckingsLeftInQueue = manualQuizCheckQueueItem != null?GetManualCheckingsCountInQueue(course, slide) : 0,
                                                 CanUserFillQuiz                = canUserFillQuiz,
                                                 GroupsIds                      = Request.GetMultipleValuesFromQueryString("group"),
                                                 QuestionAnswersFrequency       = questionAnswersFrequency,
                                                 IsManualCheckingEnabledForUser = isManualCheckingEnabledForUser,
            };

            return(PartialView(model));
        }