Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestQuestionResultDTO"/> class.
 /// </summary>
 /// <param name="result">
 /// The result.
 /// </param>
 public TestQuestionResultDTO(TestQuestionResult result)
 {
     this.testQuestionResultId = result.Id;
     this.questionId           = result.QuestionRef.With(x => x.Id);
     this.question             = result.Question;
     this.questionTypeId       = result.QuestionType.With(x => x.Id);
     this.isCorrect            = result.IsCorrect;
 }
Example #2
0
        private TestQuestionResult ConvertDto(TestQuestionResultDTO resultDTO, TestResult testResult)
        {
            var instance = new TestQuestionResult
            {
                Question     = resultDTO.question,
                IsCorrect    = resultDTO.isCorrect,
                QuestionType = this.QuestionTypeModel.GetOneById(resultDTO.questionTypeId).Value,
                TestResult   = testResult,
                QuestionRef  = this.QuestionModel.GetOneById(resultDTO.questionId).Value
            };

            return(instance);
        }
Example #3
0
        /// <summary>
        /// The get quiz result by adobe connect session id.
        /// </summary>
        /// <param name="adobeConnectSessionId">
        /// The adobe connect session id.
        /// </param>
        /// <param name="smiId">
        /// The sub module item id.
        /// </param>
        /// <returns>
        /// The <see cref="QuizResultDataDTO"/>.
        /// </returns>
        public TestResultDataDTO GetTestResultByACSessionId(int adobeConnectSessionId, int smiId)
        {
            var                 test      = this.testRepository.FindOne(new DefaultQueryOver <Test, int>().GetQueryOver().Where(x => x.SubModuleItem.Id == smiId).Take(1)).Value;
            var                 res       = new TestResultDataDTO();
            Question            q         = null;
            SubModuleItem       smi       = null;
            QuestionType        qt        = null;
            QuestionForAdminDTO dto       = null;
            var                 queryOver = new DefaultQueryOver <Question, int>().GetQueryOver(() => q)
                                            .JoinQueryOver(x => x.SubModuleItem, () => smi, JoinType.InnerJoin)
                                            .JoinQueryOver(() => q.QuestionType, () => qt, JoinType.InnerJoin)
                                            .Where(() => q.SubModuleItem.Id == smiId && q.IsActive == true)
                                            .SelectList(result =>
                                                        result.Select(() => q.Id)
                                                        .WithAlias(() => dto.questionId)
                                                        .Select(() => q.QuestionName)
                                                        .WithAlias(() => dto.question)
                                                        .Select(() => q.QuestionType.Id)
                                                        .WithAlias(() => dto.questionTypeId)
                                                        .Select(() => qt.Type)
                                                        .WithAlias(() => dto.questionTypeName)
                                                        ).TransformUsing(Transformers.AliasToBean <QuestionForAdminDTO>());
            var questionqs = questionRepository.FindAll <QuestionForAdminDTO>(queryOver).ToList();

            TestResult         tr  = null;
            TestQuestionResult tqr = null;

            q = null;
            var queryOver1 = new DefaultQueryOver <TestResult, int>().GetQueryOver(() => tr)
                             .JoinQueryOver(x => x.Results, () => tqr, JoinType.LeftOuterJoin)
                             .JoinQueryOver(() => tqr.QuestionRef, () => q, JoinType.LeftOuterJoin)
                             .Where(() => tr.ACSessionId == adobeConnectSessionId)
                             .SelectList(res1 =>
                                         res1.SelectGroup(() => q.Id)
                                         .WithAlias(() => dto.questionId)
                                         .Select(Projections.Sum(Projections.Cast(NHibernateUtil.Int32, Projections.Property(() => tqr.IsCorrect))))
                                         .WithAlias(() => dto.correctAnswerCount))
                             .TransformUsing(Transformers.AliasToBean <QuestionForAdminDTO>());
            var questionqsWithCorrectAnswerCount = Repository.FindAll <QuestionForAdminDTO>(queryOver1).ToList();

            questionqs.ForEach(x => x.correctAnswerCount = (questionqsWithCorrectAnswerCount.Any(t => t.questionId == x.questionId)? questionqsWithCorrectAnswerCount.First(t => t.questionId == x.questionId).correctAnswerCount: 0));
            res.questions = questionqs.ToArray();
            res.players   =
                this.Repository.StoreProcedureForMany <TestPlayerFromStoredProcedureDTO>(
                    "getTestResultByACSessionId",
                    new StoreProcedureParam <int>("acSessionId", adobeConnectSessionId),
                    new StoreProcedureParam <int>("subModuleItemId", smiId))
                .ToList()
                .Select(x => new TestPlayerDTO(x))
                .ToArray();

            if (res.players != null && res.players.Any())
            {
                foreach (var player in res.players)
                {
                    long duration     = (player.endTime.ConvertFromUnixTimeStamp() - player.startTime.ConvertFromUnixTimeStamp()).Ticks;
                    var  passingScore = test.PassingScore.HasValue ? (res.questions.Length * (test.PassingScore.Value / 100)) : 0;
                    bool scorePassed  = !test.PassingScore.HasValue ? player.score > 0 : test.PassingScore == 0 || passingScore <= player.score;
                    bool timePassed   = !test.TimeLimit.HasValue || test.TimeLimit == 0 || test.TimeLimit > TimeSpan.FromTicks(duration).TotalMinutes;
                    player.passingScore = passingScore;
                    player.timeLimit    = test.TimeLimit;
                    player.scorePassed  = scorePassed;
                    player.timePassed   = timePassed;
                }
            }

            var questionIds = res.questions.Select(question => question.questionId).ToList();

            var distractorsQuery = new DefaultQueryOver <Distractor, int>().GetQueryOver().WhereRestrictionOn(x => x.Question.Id).IsIn(questionIds);

            var distractors = this.distractorRepository.FindAll(distractorsQuery).ToList();

            foreach (var questionForAdminDTO in res.questions)
            {
                questionForAdminDTO.distractors = distractors.Where(x => x.Question.Id == questionForAdminDTO.questionId).Select(x => new DistractorDTO(x)).ToArray();
            }

            return(res);
        }
        private void check()
        {
            // Unhighlight any highlighted from last check
            foreach (TextBox answerBox in answers)
            {
                answerBox.BorderThickness = new Thickness(1);
            }


            int i       = 0;
            int score   = 0;
            int major   = 0;
            int minor   = 0;
            int correct = 0;

            // Create a list of questionresults and a result object
            TestResult result = null;
            List <TestQuestionResult> questionResults = new List <TestQuestionResult>();

            // If they're taking the test for real, we instance the result object
            if (mode_ == TestMode.TESTMODE_TAKE)
            {
                result = new TestResult()
                {
                    Student = student_,
                    Test    = test_,
                };
            }

            foreach (TextBox answer in answers)
            {
                string check = answer.Text;
                // Get some helper variables which save repeatedly calling the methods getErrorStatus and ElementAt
                TestQuestion           question  = test_.TestQuestions.ElementAt(i);
                TestQuestion.ErrorType errorType = question.getErrorStatus(check);

                // If it's revision, we don't create results.
                // If it's a full test, we do.
                // Therefore we switch the type here.
                switch (mode_)
                {
                case TestMode.TESTMODE_TAKE:
                    // Check their results, inserted into the list below the switch block
                    TestQuestionResult questionResult = new TestQuestionResult()
                    {
                        Answer       = check,
                        TestQuestion = question,
                    };

                    // Check what type of error they made
                    switch (errorType)
                    {
                    case TestQuestion.ErrorType.CORRECT:
                        // +2 score
                        questionResult.Score = 2;
                        score += 2;
                        correct++;
                        break;

                    case TestQuestion.ErrorType.ERRORMAJOR:
                        // No score for a major error
                        questionResult.Score = 0;
                        major++;
                        break;

                    case TestQuestion.ErrorType.ERRORMINOR:
                        // +1 score for a minor error
                        questionResult.Score = 1;
                        score += 1;
                        minor++;
                        break;
                    }

                    questionResults.Add(questionResult);

                    break;

                case TestMode.TESTMODE_REVISE:
                    // Check and highlight mistakes.
                    // In revision mode, we don't track anything but
                    //  which ones they had wrong.
                    // We class all errors as 'major'.
                    if (errorType != TestQuestion.ErrorType.CORRECT)
                    {
                        answers.ElementAt(i).BorderThickness = new Thickness(2);
                        major++;
                    }
                    break;
                }

                i++; // Increase interator for finding the questions
            }

            // Give feedback
            switch (mode_)
            {
            case TestMode.TESTMODE_TAKE:
                int percent;
                // Percent formula is 100 / max * num
                percent = (int)((100.0f / test_.MaxScore) * score);

                // Stop timer before showing modal dialog
                timer_.Stop();

                // Show score to user
                App.Message("Score", "You had a score of " + score + " meaning you had a total of " + percent + "%.");

                // Set the score and update the database entry
                result.Score = score;
                App.db.SubmitChanges();

                // Set the foreign key for results since it was submitted into the database by SubmitChanges, and given
                //  a primary key.
                foreach (TestQuestionResult questionResult_i in questionResults)
                {
                    questionResult_i.ResultsID = result.ResultsID;
                }

                App.db.SubmitChanges();

                // Now we want to close this window.
                Close();
                break;

            case TestMode.TESTMODE_REVISE:
                // If revising, they get a boolean response - Either they get told how many were incorrect, or they get a well done message.
                if (major == 0)
                {
                    if (App.getBoolean("Well Done!", "You had them all right! Would you like to exit revision for this test now?"))
                    {
                        this.Close();
                    }
                }
                else
                {
                    // Notify them how many they had wrong
                    App.Message("Feedback", "You had " + major + " incorrect. They have been highlighted.");
                }
                break;
            }
        }