public Test(string testCsvPath)
    {
        var allTestAnswers = File.ReadAllLines(testCsvPath).Skip(1).Select(answers => new TestAnswers(answers));

        AnswerKey      = allTestAnswers.Single(answers => answers.FirstName == AnswerKeyName);
        StudentAnswers = allTestAnswers.Where(answers => answers.FirstName != AnswerKeyName).ToArray();
    }
Пример #2
0
 public void RegisterAnswers(Dictionary <string, QueryResult[]> utterances)
 {
     foreach (var utterance in utterances)
     {
         TestAnswers.Add(utterance.Key, utterance.Value);
     }
 }
Пример #3
0
        public void GetTestResult_UserHasSentAnswers_ValidResult()
        {
            //arrange
            var dateTimeProdiver = new Mock <IDateTimeProvider>();
            var utcNow           = new DateTime(2020, 9, 5, 14, 8, 58, 0, DateTimeKind.Utc);

            dateTimeProdiver.Setup(x => x.UtcNow).Returns(utcNow);
            int userId        = 2;
            var scheduledTest = new ScheduledTest(1, utcNow.AddDays(-2), utcNow.AddMinutes(-60), utcNow.AddMinutes(-30), 10, new int[] { userId, 3, 4 });
            var userTest      = new UserTest(2, 0);

            userTest.SetStartDate(utcNow.AddMinutes(-50));
            userTest.SetEndDate(utcNow.AddMinutes(-40));
            var   testAnswers = new TestAnswers(scheduledTest, userTest, "UserName", dateTimeProdiver.Object);
            float maxScore    = 3f;
            int   questionId  = 1;

            testAnswers.AddAnswerPair(new WrittenUserAnswer("value", 0, questionId, userId), new WrittenAnswer(questionId, "value", maxScore));
            questionId = 2;
            testAnswers.AddAnswerPair(new WrittenUserAnswer("value2", 0, questionId, userId), new WrittenAnswer(questionId, "value2", maxScore));
            var expectedUserTestResult = new UserTestResult("UserName", 6f, userId, TestStatus.Completed);

            //act
            UserTestResult result = testAnswers.GetTestResult();

            //assert
            result.Should().BeEquivalentTo(expectedUserTestResult);
        }
Пример #4
0
        public Task <QueryResult[]> GetAnswersAsync(ITurnContext turnContext, QnAMakerOptions options, Dictionary <string, string> telemetryProperties, Dictionary <string, double> telemetryMetrics = null)
        {
            var text = turnContext.Activity.Text;

            var mockResult = TestAnswers.GetValueOrDefault(text, DefaultAnswer);

            return(Task.FromResult(mockResult));
        }
Пример #5
0
        public Task <QueryResult[]> GetAnswersAsync(ITurnContext context, QnAMakerOptions options = null)
        {
            var text = context.Activity.Text;

            var mockResult = TestAnswers.GetValueOrDefault(text, DefaultAnswer);

            return(Task.FromResult(mockResult));
        }
Пример #6
0
        public async Task GetAttemptedQuestionsByAttendeeAsyncTest()
        {
            var test = CreateTest("General Awareness");
            await _testRepository.CreateTestAsync(test, "5");

            var testAttendee = CreateTestAttendee(test.Id);
            await _testConductRepository.RegisterTestAttendeesAsync(testAttendee);

            var testConduct1 = new DomainModel.Models.TestConduct.TestConduct()
            {
                TestAttendeeId = testAttendee.Id,
                QuestionId     = 1,
                QuestionStatus = QuestionStatus.answered
            };
            var testConduct2 = new DomainModel.Models.TestConduct.TestConduct()
            {
                TestAttendeeId = testAttendee.Id,
                QuestionId     = 1,
                QuestionStatus = QuestionStatus.review
            };
            var testConduct3 = new DomainModel.Models.TestConduct.TestConduct()
            {
                TestAttendeeId = testAttendee.Id,
                QuestionId     = 1,
                QuestionStatus = QuestionStatus.review
            };

            _trappistDbContext.TestConduct.Add(testConduct1);
            _trappistDbContext.TestConduct.Add(testConduct2);
            _trappistDbContext.TestConduct.Add(testConduct3);
            await _trappistDbContext.SaveChangesAsync();

            var testAnswer1 = new TestAnswers()
            {
                AnsweredOption = 2,
                TestConductId  = testConduct1.Id
            };
            var testAnswer2 = new TestAnswers()
            {
                AnsweredOption = 4,
                TestConductId  = testConduct2.Id
            };
            var testAnswer3 = new TestAnswers()
            {
                AnsweredOption = null,
                TestConductId  = testConduct3.Id
            };

            _trappistDbContext.TestAnswers.Add(testAnswer1);
            _trappistDbContext.TestAnswers.Add(testAnswer2);
            _trappistDbContext.TestAnswers.Add(testAnswer3);
            await _trappistDbContext.SaveChangesAsync();

            var numberOfQuestionsAttemptedByAttendee = await _reportRepository.GetAttemptedQuestionsByAttendeeAsync(testAttendee.Id);

            Assert.Equal(2, numberOfQuestionsAttemptedByAttendee);
        }
Пример #7
0
 public bool CheckModelError()
 {
     if (TestAnswers.Count(a => a.UserAnswer) > 1)
     {
         ModelState.AddModelError(string.Format(""), "Выбрано более одного ответа");
         return(false);
     }
     if (TestAnswers.Count(a => a.UserAnswer) < 1)
     {
         ModelState.AddModelError(string.Format(""), "Не выбрано ни одного ответа");
         return(false);
     }
     return(true);
 }
Пример #8
0
        public static void AddNewAnswerRow(TestAnswers context)
        {
            var entities   = new aeghealthEntities();
            var answerdata = new tblAnswer
            {
                ConsumerHistoryID = context.ConsumerHistoryId,
                QuestionID        = context.QuestionId,
                Answer            = context.Answer,
                CreatedByID       = context.CreatedById,
                ModifiedByID      = context.ModifiedById
            };

            entities.tblAnswers.Add(answerdata);
            entities.SaveChanges();
        }
Пример #9
0
 /// <summary>
 /// This method is used to add the created answer to database
 /// </summary>
 /// <param name="answer">Object of TestAnswerAC type</param>
 /// <param name="testConductId">Test conduct id</param>
 private void AddTestAnswer(TestAnswerAC answer, int testConductId)
 {
     if (answer.OptionChoice.Count() > 0)
     {
         foreach (var option in answer.OptionChoice)
         {
             TestAnswers testAnswers = new TestAnswers()
             {
                 AnsweredOption = option,
                 TestConductId  = testConductId
             };
             _trappistDbContext.TestAnswers.Add(testAnswers);
             _trappistDbContext.SaveChanges();
         }
     }
 }
Пример #10
0
        public async Task GetTestAttendeeAnswersTest()
        {
            var test = CreateTest("Mathematics");
            await _testRepository.CreateTestAsync(test, "5");

            var testAttendee = CreateTestAttendee(test.Id);
            await _testConductRepository.RegisterTestAttendeesAsync(testAttendee);

            var testConduct1 = new DomainModel.Models.TestConduct.TestConduct()
            {
                TestAttendeeId = testAttendee.Id,
                QuestionId     = 1
            };
            var testConduct2 = new DomainModel.Models.TestConduct.TestConduct()
            {
                TestAttendeeId = testAttendee.Id,
                QuestionId     = 1
            };

            _trappistDbContext.TestConduct.Add(testConduct1);
            _trappistDbContext.TestConduct.Add(testConduct2);
            await _trappistDbContext.SaveChangesAsync();

            var testAnswer1 = new TestAnswers()
            {
                AnsweredOption = 2,
                TestConductId  = testConduct1.Id
            };
            var testAnswer2 = new TestAnswers()
            {
                AnsweredOption = 4,
                TestConductId  = testConduct2.Id
            };

            _trappistDbContext.TestAnswers.Add(testAnswer1);
            _trappistDbContext.TestAnswers.Add(testAnswer2);
            await _trappistDbContext.SaveChangesAsync();

            var testAnswersList = await _reportRepository.GetTestAttendeeAnswers(testAttendee.Id);

            Assert.Equal(2, testAnswersList.Count());
        }
Пример #11
0
        public void GetTestResult_UserHasBeenWritingTestFor2Minutes_ValidResult()
        {
            //arrange
            var dateTimeProdiver = new Mock <IDateTimeProvider>();
            var utcNow           = new DateTime(2020, 9, 5, 14, 8, 58, 0, DateTimeKind.Utc);

            dateTimeProdiver.Setup(x => x.UtcNow).Returns(utcNow);
            int userId        = 2;
            var scheduledTest = new ScheduledTest(1, utcNow.AddDays(-2), utcNow.AddMinutes(-5), utcNow.AddMinutes(10), 10, new int[] { userId, 3, 4 });
            var userTest      = new UserTest(2, 0);

            userTest.SetStartDate(utcNow.AddMinutes(-2));
            var testAnswers            = new TestAnswers(scheduledTest, userTest, "UserName", dateTimeProdiver.Object);
            var expectedUserTestResult = new UserTestResult("UserName", null, userId, TestStatus.IsInProcess);

            //act
            UserTestResult result = testAnswers.GetTestResult();

            //assert
            result.Should().BeEquivalentTo(expectedUserTestResult);
        }
        /// <summary>
        /// It evaluates the responses provided by the student with the responses given by a instructor to grade a test using two separate XMLs.
        /// MCQs and Fill in the blanks type of questions are graded by comparing the responses, while Essay question is graded based on the 
        /// number of keywords or their synonyms used, grammatical errors, spellcheck, word limit and paragraphs.
        /// </summary>
        private void CalculateMarks()
        {
            XmlSerializer ser = new XmlSerializer(typeof(Test));

            finalTest = ser.Deserialize(new FileStream("D:\\test.xml", FileMode.Open)) as Test;
            totalQuestions = test.Question.Count();

            ser = new XmlSerializer(typeof(TestAnswers));

            finalTestAnswer = ser.Deserialize(new FileStream("D:\\StudentResponse.xml", FileMode.Open)) as TestAnswers;
            List<TestQuestion> quesList = new List<TestQuestion>();
            for (int i = 0; i < totalQuestions; i++)
            {
                quesList.Add(finalTest.Question[i]);
            }

            int j = 0;
            double essayMarks = 100.0f;
            foreach (var question in quesList)
            {
                if (question.Type == QuesTypeVal.MCQ.ToString())
                {
                    if (question.Option1.Answer == "Yes" && question.Option1.Value == finalTestAnswer.Answer[j].Value)
                    {
                        marks += 5;
                    }
                    else if (question.Option2.Answer == "Yes" && question.Option2.Value == finalTestAnswer.Answer[j].Value)
                    {
                        marks += 5;
                    }
                    else if (question.Option3.Answer == "Yes" && question.Option3.Value == finalTestAnswer.Answer[j].Value)
                    {
                        marks += 5;
                    }
                    else if (question.Option4.Answer == "Yes" && question.Option4.Value == finalTestAnswer.Answer[j].Value)
                    {
                        marks += 5;
                    }
                    j++;
                }
                else if (question.Type == QuesTypeVal.Text.ToString())
                {
                    if (question.Answer.Text == finalTestAnswer.Answer[j].Value)
                    {
                        marks += 5;
                    }
                    j++;
                }
                else if (question.Type == QuesTypeVal.EssayText.ToString())
                {
                    string essayResponse = finalTestAnswer.Answer[j].Value;
                    int nKeyword = question.Answer.Keyword.Count();                    
                    double keywordMark = 40.0 / (double)nKeyword;
                    int checkSynonym = 0;
                    double wordMarks = 0.0f;
                    List<string> essayList = new List<string>();
                    var essayString = Regex.Split(essayResponse, @"[\n]+");
                    int noParagraphs = essayString.Count();
                    bool nParaCorrect = false;
                    for (int i = 0; i < noParagraphs; i++)
                    {
                        if (essayString[i] != string.Empty)
                            essayList.Add(essayString[i]);
                    }
                    if (essayList.Count() != question.NumberOfParagraphs)
                    {
                        essayMarks = 20;
                    }
                    else
                    {
                        List<string> wordList = new List<string>();
                        foreach (string essayPara in essayList)
                        {
                            var s = Regex.Split(essayPara, @"[,\s\n]+");
                            foreach (string k in s)
                            {
                                wordList.Add(k);
                            }
                        }
                        if (wordList.Count >= question.TotalNumberOfWords)
                        {
                            essayMarks = 20;
                        }
                        else
                        {
                            bool grammarCheck = true;
                            Microsoft.Office.Interop.Word.Application myWord = new Microsoft.Office.Interop.Word.Application();
                            foreach (string essay in essayList)
                            {
                                grammarCheck = myWord.CheckGrammar(essay);
                                if (!grammarCheck)
                                {
                                    essayMarks -= 5;
                                }
                            }

                            wordMarks = 40.0 / (double)wordList.Count();
                            foreach (string word in wordList)
                            {
                                using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic"))
                                {
                                    if (!hunspell.Spell(word))
                                    {
                                        essayMarks -= wordMarks;
                                    }
                                }
                            }

                            bool keyPresent = false;
                            for (int i = 0; i < nKeyword; i++)
                            {
                                if (!essayResponse.Contains(question.Answer.Keyword[i]))
                                {
                                    List<string> stringArr = new List<string>();
                                    stringArr.Add(question.Answer.Keyword[i]);
                                    SynonymInfo theSynonyms = myWord.SynonymInfo[question.Answer.Keyword[i]];
                                    foreach (var Meaning in theSynonyms.MeaningList as Array)
                                    {
                                        if (stringArr.Contains(Meaning) == false) stringArr.Add((string)Meaning);
                                    }
                                    for (int ii = 0; ii < stringArr.Count; ii++)
                                    {
                                        theSynonyms = myWord.SynonymInfo[stringArr[ii]];
                                        foreach (string Meaning in theSynonyms.MeaningList as Array)
                                        {
                                            if (stringArr.Contains(Meaning)) continue;
                                            stringArr.Add(Meaning);
                                        }
                                        if (stringArr.Count >= 10)
                                        {
                                            stringArr.ToArray();
                                            break;
                                        }
                                    }
                                    foreach (string key in stringArr)
                                    {
                                        if (essayResponse.Contains(key))
                                        {
                                            keyPresent = true;
                                        }
                                    }
                                    if (!keyPresent)
                                    {
                                        essayMarks -= keywordMark;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            marks += essayMarks;
        }
Пример #13
0
        /// <summary>
        /// Transform Attendee's JSON formatted Answer stored in AttendeeAnswers table
        /// to reliable TestAnswer and TestConduct tables.
        /// </summary>
        /// <param name="attendeeId">Id of Test Attendee</param>
        private async Task TransformAttendeeAnswer(int attendeeId)
        {
            var attendeeAnswer = await _dbContext.AttendeeAnswers.AsNoTracking().SingleOrDefaultAsync(x => x.Id == attendeeId);

            var testAnswersList = new List <TestAnswers>();
            var testConductList = new List <DomainModel.Models.TestConduct.TestConduct>();

            if (attendeeAnswer != null)
            {
                if (attendeeAnswer.Answers != null)
                {
                    var deserializedAnswer = JsonConvert.DeserializeObject <TestAnswerAC[]>(attendeeAnswer.Answers).ToList();

                    //Remove existing transformation
                    var testConductExist = await _dbContext.TestConduct.AnyAsync(x => x.TestAttendeeId == attendeeId);

                    if (testConductExist)
                    {
                        var testConductListToRemove = await _dbContext.TestConduct.Where(x => x.TestAttendeeId == attendeeId).ToListAsync();

                        _dbContext.TestConduct.RemoveRange(testConductListToRemove);
                        await _dbContext.SaveChangesAsync();
                    }

                    foreach (var answer in deserializedAnswer)
                    {
                        var testAnswers = new TestAnswers();

                        var testConduct = new DomainModel.Models.TestConduct.TestConduct();
                        //Adding attempted Question to TestConduct table
                        testConduct = new DomainModel.Models.TestConduct.TestConduct()
                        {
                            QuestionId     = answer.QuestionId,
                            QuestionStatus = answer.QuestionStatus,
                            TestAttendeeId = attendeeId,
                            IsAnswered     = answer.IsAnswered
                        };
                        testConductList.Add(testConduct);

                        //Adding answer to TestAnswer Table
                        if (answer.OptionChoice.Count() > 0)
                        {
                            //A question can have multiple answer
                            foreach (var option in answer.OptionChoice)
                            {
                                testAnswers = new TestAnswers()
                                {
                                    AnsweredOption = option,
                                    TestConduct    = testConduct
                                };
                                testAnswersList.Add(testAnswers);
                            }
                        }
                        else
                        {
                            //Save answer for code snippet question
                            if (answer.Code != null)
                            {
                                testAnswers.AnsweredCodeSnippet = answer.Code.Source;
                            }

                            testAnswers.TestConduct = testConduct;
                            testAnswersList.Add(testAnswers);
                        }
                    }
                    await _dbContext.TestAnswers.AddRangeAsync(testAnswersList);

                    await _dbContext.TestConduct.AddRangeAsync(testConductList);

                    await _dbContext.SaveChangesAsync();
                }
            }
        }