コード例 #1
0
        /// <summary>
        /// Returns the question to solve.
        /// </summary>
        private async Task <QuestionToSolve> GetQuestionToSolveAsync(
            UserQuestionData userQuestionData,
            Question resolvedQuestion,
            QuestionSubmission lastQuestionSubmission)
        {
            var userQuestionStatus = GetUserQuestionStatus(userQuestionData);
            var assignmentProgress = await GetAssignmentProgressAsync(userQuestionData);

            var seed            = GetSeedToDisplay(userQuestionData);
            var pastSubmissions = GetPastSubmissions(userQuestionData);

            return(new QuestionToSolve
                   (
                       userQuestionData.AssignmentQuestionId,
                       userQuestionData.AssignmentQuestion.Name,
                       resolvedQuestion,
                       seed,
                       userQuestionData.User,
                       lastQuestionSubmission,
                       userQuestionData.AssignmentQuestion.IsInteractive(),
                       pastSubmissions,
                       userQuestionStatus,
                       assignmentProgress
                   ));
        }
コード例 #2
0
        /// <summary>
        /// Grades a question submission (returning and storing the result).
        /// </summary>
        public async Task <GradeSubmissionResult> GradeSubmissionAsync(
            string classroomName,
            int assignmentId,
            int userId,
            QuestionSubmission submission)
        {
            var store = await LoadDataForSingleQuestionAsync
                        (
                classroomName,
                assignmentId,
                submission.AssignmentQuestionId,
                userId
                        );

            var dateSubmitted = _timeProvider.UtcNow;

            var result = await _questionSolver.GradeSubmissionAsync
                         (
                store,
                submission,
                dateSubmitted
                         );

            await _dbContext.SaveChangesAsync();

            return(result);
        }
コード例 #3
0
    IEnumerator SubmitMCQRequest()
    {
        // create answer list
        List <QuestionAnswer> answers = new List <QuestionAnswer>();

        answers.Add(new QuestionAnswer(choiceAInput.text, GetDropdownValue(answerDropdown) == "A"));
        answers.Add(new QuestionAnswer(choiceBInput.text, GetDropdownValue(answerDropdown) == "B"));
        answers.Add(new QuestionAnswer(choiceCInput.text, GetDropdownValue(answerDropdown) == "C"));
        answers.Add(new QuestionAnswer(choiceDInput.text, GetDropdownValue(answerDropdown) == "D"));


        QuestionSubmission submission = new QuestionSubmission(GlobalVars.email, questionBodyInput.text, answers);
        string             jsonToSend = JsonConvert.SerializeObject(submission);
        UnityWebRequest    req        = UnityWebRequest.Post("http://47.74.186.167:8000/api/questions/create", "");

        req.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonToSend));
        req.SetRequestHeader("Content-Type", "application/json");
        req.SetRequestHeader("Authorization", "Token " + GlobalVars.token);
        yield return(req.SendWebRequest());

        if (req.isNetworkError || req.isHttpError)
        {
            Debug.Log(req.error);
            //EditorUtility.DisplayDialog("Netowrk Error", "Please try again later", "Ok");
        }
        else
        {
            //EditorUtility.DisplayDialog("Success", "Your question has been posted!", "Ok");
            SceneManager.LoadScene("MainMenu");
        }
    }
コード例 #4
0
        /// <summary>
        /// Grades a question submission.
        /// </summary>
        public async Task <GradeSubmissionResult> GradeSubmissionAsync(
            UserQuestionDataStore store,
            QuestionSubmission submission,
            DateTime dateSubmitted)
        {
            var userQuestionData = store.GetUserQuestionData
                                   (
                submission.AssignmentQuestionId
                                   );

            var userQuestionStatus = GetUserQuestionStatus(userQuestionData);

            var resolvedQuestion = await ResolveUnsolvedQuestionAsync
                                   (
                userQuestionData
                                   );

            var scoredQuestionResult = await GradeSubmission
                                       (
                submission,
                resolvedQuestion,
                userQuestionData,
                userQuestionStatus,
                dateSubmitted
                                       );

            if (userQuestionData.AssignmentQuestion.IsInteractive())
            {
                return(new GradeSubmissionResult(scoredQuestionResult));
            }
            else
            {
                return(new GradeSubmissionResult(dateSubmitted));
            }
        }
コード例 #5
0
        /// <summary>
        /// Returns a mock JSON serializer.
        /// </summary>
        private IJsonSerializer GetMockJsonSerializer(
            string serializedSubmission,
            QuestionSubmission submission)
        {
            var serializer = new Mock <IJsonSerializer>();

            if (submission != null)
            {
                serializer
                .Setup(s => s.Deserialize <QuestionSubmission>(serializedSubmission))
                .Returns(submission);

                serializer
                .Setup(s => s.Serialize(submission))
                .Returns(serializedSubmission);
            }
            else
            {
                serializer
                .Setup(s => s.Deserialize <QuestionSubmission>(serializedSubmission))
                .Throws(new InvalidOperationException());
            }

            return(serializer.Object);
        }
コード例 #6
0
        /// <summary>
        /// Grades the question submission.
        /// </summary>
        private ScoredQuestionResult GradeSubmission(QuestionSubmission submission)
        {
            var multSubmission = submission as MultipleChoiceQuestionSubmission;

            if (multSubmission == null)
            {
                throw new ArgumentException("Invalid submission type", nameof(submission));
            }

            int numCorrectAnswers = Question.Choices.Count
                                    (
                choice => choice.Correct == (multSubmission.SelectedChoices?.Contains(choice.Value) ?? false)
                                    );

            var result = new MultipleChoiceQuestionResult
                         (
                numCorrectAnswers == Question.Choices.Count
                         );

            return(new ScoredQuestionResult
                   (
                       result,
                       Question.AllowPartialCredit
                                        ? (numCorrectAnswers * 1.0) / Question.Choices.Count
                                        : (numCorrectAnswers == Question.Choices.Count) ? 1.0 : 0.0
                   ));
        }
コード例 #7
0
ファイル: SubmissionTests.cs プロジェクト: Ana00000/platform
        public void Evaluates_answer_submission(QuestionSubmission submission, List <bool> expectedCorrectness)
        {
            var results = _service.EvaluateAnswers(submission);

            var correctness = results.Select(a => a.SubmissionWasCorrect);

            correctness.ShouldBe(expectedCorrectness);
        }
コード例 #8
0
 /// <summary>
 /// Grades the given question.
 /// </summary>
 private async Task <ScoredQuestionResult> GradeQuestionAsync(
     Question resolvedQuestion,
     QuestionSubmission submissionContents)
 {
     return(await _questionGraderFactory
            .CreateQuestionGrader(resolvedQuestion)
            .GradeSubmissionAsync(submissionContents));
 }
コード例 #9
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public QuestionToSolve(
     Question question,
     QuestionSubmission questionSubmission,
     IList<Question> unsolvedPrereqs)
 {
     Question = question;
     LastSubmission = questionSubmission;
     UnsolvedPrerequisites = unsolvedPrereqs;
 }
コード例 #10
0
        public async Task <QuestionSubmissionChallengeDto> Handle(SubmitAnswerCommand request, CancellationToken cancellationToken)
        {
            var team = await _context.Teams.Include(t => t.QuestionSubmissions)
                       .Include(t => t.Users)
                       .FirstOrDefaultAsync(t => t.EventId == request.EventId &&
                                            t.Users.Any(u => u.Id == _currentUserService.UserId), cancellationToken);

            if (team == null)
            {
                throw new NotFoundException("Team was not found for current user");
            }

            var question = await _context.Questions.Include(q => q.Challenge)
                           .ThenInclude(c => c.Questions)
                           .FirstOrDefaultAsync(q => q.Id == request.QuestionId, cancellationToken);

            var isCorrect = question.Answer == request.Answer;

            // Create or update submission
            var submissions = await _context.QuestionSubmissions.Where(qs => qs.QuestionId == request.QuestionId).ToListAsync(cancellationToken);

            var calculatedPoints = isCorrect ? CalculatePoints(submissions, question.Point) : 0;

            var submission = submissions.FirstOrDefault(qs => qs.TeamId == team.Id);

            if (submission == null)
            {
                submission = QuestionSubmission.Create(request.QuestionId, team.Id, isCorrect, request.Answer, calculatedPoints);

                await _context.QuestionSubmissions.AddAsync(submission, cancellationToken);
            }
            else
            {
                if (submission.IsCorrect)
                {
                    return(_mapper.Map <QuestionSubmissionChallengeDto>(submission));
                }

                submission.Update(isCorrect, request.Answer, calculatedPoints);
            }

            if (submission.IsCorrect)
            {
                await UpdateTeamResultAsync(request.EventId, team, submission, question);
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(_mapper.Map <QuestionSubmissionChallengeDto>(submission));
        }
コード例 #11
0
        private async Task UpdateTeamResultAsync(Guid eventId, Team team, QuestionSubmission submission, Question question)
        {
            var result = await _context.Results.FirstOrDefaultAsync(r => r.EventId == eventId && r.TeamId == team.Id);

            result.TotalPoints += submission.EarnedPoints;

            if (submission.IsCorrect)
            {
                result.SolvedQuestions++;
            }

            if (team.QuestionSubmissions.Count(qs => qs.IsCorrect) == question.Challenge.Questions.Count)
            {
                result.SolvedChallenges++;
            }
        }
コード例 #12
0
        public ActionResult CreateConceptQuestion([FromBody] QuestionSubmission req)
        {
            Question qsn = new Question
            {
                Uid         = Guid.NewGuid().ToString(),
                Text        = req.Text,
                Type        = req.Type,
                Notes       = req.Notes,
                DateCreated = DateTime.Now,
                Archived    = "No",
                Demographic = req.Demographic
            };

            _context.Question.Add(qsn);
            _context.SaveChanges();
            return(Ok(new { message = "Success!" }));
        }
コード例 #13
0
        /// <summary>
        /// Returns a mock QuestionResolver.
        /// </summary>
        private IQuestionGraderFactory GetMockQuestionGraderFactory(
            Question resolvedQuestion,
            QuestionSubmission submission,
            ScoredQuestionResult gradeResult)
        {
            var questionGraderFactory = new Mock <IQuestionGraderFactory>();

            questionGraderFactory
            .Setup
            (
                m => m
                .CreateQuestionGrader(resolvedQuestion)
                .GradeSubmissionAsync(submission)
            ).ReturnsAsync(gradeResult);

            return(questionGraderFactory.Object);
        }
コード例 #14
0
        /// <summary>
        /// Grades the submission.
        /// </summary>
        private async Task <ScoredQuestionResult> GradeSubmission(
            QuestionSubmission submission,
            Question resolvedQuestion,
            UserQuestionData userQuestionData,
            UserQuestionStatus userQuestionStatus,
            DateTime submissionDate)
        {
            if (!userQuestionStatus.AllowNewAttempt)
            {
                throw new InvalidOperationException("No attempts remaining.");
            }

            var scoredQuestionResult = await GradeQuestionAsync
                                       (
                resolvedQuestion,
                submission
                                       );

            if (userQuestionData.Submissions == null)
            {
                userQuestionData.Submissions = new List <UserQuestionSubmission>();
            }

            var submissionContents = _jsonSerializer.Serialize(submission);
            var savedSubmission    = new UserQuestionSubmission()
            {
                Score              = scoredQuestionResult.Score,
                DateSubmitted      = submissionDate,
                Seed               = userQuestionData.Seed,
                CachedQuestionData = userQuestionData.CachedQuestionData,
                SubmissionContents = submissionContents
            };

            userQuestionData.Submissions.Add(savedSubmission);
            userQuestionData.NumAttempts++;
            userQuestionData.Seed = null;

            if (userQuestionData.AssignmentQuestion.IsInteractive())
            {
                userQuestionData.LastQuestionSubmission = submissionContents;
            }

            return(scoredQuestionResult);
        }
コード例 #15
0
        public List <AnswerEvaluation> EvaluateAnswers(QuestionSubmission submission)
        {
            var question = _learningObjectRepository.GetQuestion(submission.QuestionId);

            if (!IsLearningObjectInLearnersCourses(question, submission.LearnerId))
            {
                throw new LearnerNotEnrolledInCourse(submission.LearnerId);
            }

            var evaluations = question.EvaluateAnswers(submission.SubmittedAnswerIds);

            if (evaluations.Select(a => a.SubmissionWasCorrect).All(c => c))
            {
                submission.MarkCorrect();
            }
            _submissionRepository.SaveQuestionSubmission(submission);

            return(evaluations);
        }
コード例 #16
0
        public async Task <IActionResult> SolveQuestion([FromBody] QuestionSubmission submission)
        {
            if (Assignment.CombinedSubmissions)
            {
                return(NotFound());
            }

            if (!CanSeeAssignment())
            {
                return(Forbid());
            }

            var result = await AssignmentQuestionService.GradeSubmissionAsync
                         (
                ClassroomName,
                AssignmentId,
                User.Id,
                submission
                         );

            if (result == null)
            {
                return(NotFound());
            }

            if (result.SubmissionDate.HasValue)
            {
                return(RedirectToAction
                       (
                           "ViewSubmission",
                           new
                {
                    id = submission.AssignmentQuestionId,
                    submissionDate = result.SubmissionDate.Value.ToEpoch()
                }
                       ));
            }
            else
            {
                return(Ok(result.ScoredQuestionResult));
            }
        }
コード例 #17
0
        /// <summary>
        /// Grades the question submission.
        /// </summary>
        private ScoredQuestionResult GradeSubmission(QuestionSubmission submission)
        {
            var shortSubmission = submission as ShortAnswerQuestionSubmission;

            if (shortSubmission == null)
            {
                throw new ArgumentException("Invalid submission type", nameof(submission));
            }

            var results = new List <bool>();
            var blanks  = new HashSet <ShortAnswerQuestionBlank>(Question.Blanks);

            foreach (var submissionBlank in shortSubmission.Blanks)
            {
                var foundBlank = blanks.Single(blank => blank.Name == submissionBlank.Name);

                results.Add
                (
                    submissionBlank.Answer != null &&
                    AnswerMatches(submissionBlank.Answer, foundBlank)
                );

                blanks.Remove(foundBlank);
            }

            if (blanks.Any())
            {
                throw new InvalidOperationException("Submission did not contain all blanks.");
            }

            return(new ScoredQuestionResult
                   (
                       new ShortAnswerQuestionResult(results.ToArray()),
                       Question.AllowPartialCredit
                                        ? (results.Count(c => c) * 1.0) / results.Count
                                        : results.All(c => c) ? 1.0 : 0.0
                   ));
        }
コード例 #18
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public QuestionToSolve(
     int assignmentQuestionId,
     string name,
     Question question,
     int?seed,
     User user,
     QuestionSubmission questionSubmission,
     bool interactive,
     IList <DateTime> pastSubmissions,
     UserQuestionStatus userQuestionStatus,
     AssignmentProgress assignmentProgress)
 {
     AssignmentQuestionId = assignmentQuestionId;
     Name               = name;
     Question           = question;
     Seed               = seed;
     User               = user;
     LastSubmission     = questionSubmission;
     Interactive        = interactive;
     PastSubmissions    = pastSubmissions;
     Status             = userQuestionStatus;
     AssignmentProgress = assignmentProgress;
 }
コード例 #19
0
 /// <summary>
 /// Grades the question submission.
 /// </summary>
 public override Task <ScoredQuestionResult> GradeSubmissionAsync(QuestionSubmission submission)
 {
     return(Task.FromResult(GradeSubmission(submission)));
 }
コード例 #20
0
		/// <summary>
		/// Grades a question submission (returning and storing the result).
		/// </summary>
		public async Task<ScoredQuestionResult> GradeSubmissionAsync(
			string classroomName,
			int userId,
			int questionId, 
			QuestionSubmission submission)
		{
			var question = await GetQuestionAsync(classroomName, questionId);
			var questionToSolve = await GetQuestionToSolveAsync(classroomName, userId, questionId);
			if (questionToSolve == null)
				return null;

			var scoredQuestionResult = await _questionGraderFactory
				.CreateQuestionGrader(questionToSolve.Question)
				.GradeSubmissionAsync(submission);

			var userQuestionData = await EnsureUserQuestionDataAsync(userId, question);

			if (userQuestionData.Submissions == null)
			{
				userQuestionData.Submissions = new List<UserQuestionSubmission>();
			}

			userQuestionData.Submissions.Add(new UserQuestionSubmission()
			{
				Score = scoredQuestionResult.Score,
				DateSubmitted = _timeProvider.UtcNow
			});

			userQuestionData.NumAttempts++;
			userQuestionData.LastQuestionSubmission = _jsonSerializer.Serialize(submission);

			await _dbContext.SaveChangesAsync();

			return scoredQuestionResult;
		}
コード例 #21
0
 /// <summary>
 /// Grades the question submission.
 /// </summary>
 public abstract Task <ScoredQuestionResult> GradeSubmissionAsync(
     QuestionSubmission submission);
コード例 #22
0
 public void SaveQuestionSubmission(QuestionSubmission submission)
 {
     _dbContext.QuestionSubmissions.Add(submission);
     _dbContext.SaveChanges();
 }
コード例 #23
0
        /// <summary>
        /// Grades the question submission.
        /// </summary>
        public override sealed async Task <ScoredQuestionResult> GradeSubmissionAsync(QuestionSubmission submission)
        {
            var codeQuestionSubmission = submission as CodeQuestionSubmission;

            if (codeQuestionSubmission == null)
            {
                throw new ArgumentException("Invalid submission type", nameof(submission));
            }

            if (string.IsNullOrEmpty(codeQuestionSubmission.Contents))
            {
                return(CreateNoSubmissionResult());
            }

            var preJobExecutionErrors = GetConstraintErrors(codeQuestionSubmission).ToList();

            if (preJobExecutionErrors.Count > 0)
            {
                return(new ScoredQuestionResult
                       (
                           new CodeQuestionResult(preJobExecutionErrors, testResults: null),
                           0.0              /*score*/
                       ));
            }

            var jobResult = await ExecuteJobAsync(codeQuestionSubmission);

            var postJobExecutionErrors = GetPostJobExecutionErrors
                                         (
                codeQuestionSubmission,
                jobResult
                                         ).ToList();

            var testResults = !postJobExecutionErrors.Any()
                                ? GetTestResults(jobResult, codeQuestionSubmission).ToList()
                                : null;

            return(new ScoredQuestionResult
                   (
                       new CodeQuestionResult(postJobExecutionErrors, testResults),
                       Question.AllowPartialCredit && testResults != null
                                        ? (testResults.Count(t => t.Succeeded) * 1.0) / testResults.Count
                                        : testResults?.All(t => t.Succeeded) ?? false ? 1.0 : 0.0
                   ));
        }