private void PerQuestion() { PerQuestionView model = null; Question question = null; if (_quiz.Type == QuizType.Adaptive) { question = _helper.GetQuestion_Adaptive(_quiz, null, null, out bool isFinish, true); model = new PerQuestionView() { Question = question, Test = _helper.CreateTestView(question), QuestionData = new AnswerBaseView() }; SessionSave = new TestSave(_cx); } else { var testSave = _helper.CreateWholeTest(_quiz); SessionSave = testSave; question = _cx.Questions.Find(SessionSave.QuestionOrders[0]); model = testSave.QuestionSaves[question.Id].View; } model = _helper.SetNavigation(model, question, SessionSave); PerQuestionModel = model; }
public void TestCreateObj() { var testObj = new TestSave() { A = 222, B = "333" }; new FileSavior().Set("test", testObj); }
public void Overwrite_Success() { var sm = new SaveManager <TestSave>(); var saveName = sm.GetDefaultSaveName(); var testSave = new TestSave(1); sm.Save(new TestSave(1000), saveName); sm.Save(testSave, saveName); Assert.AreEqual(testSave.Value, sm.Load(saveName).Value); }
public void Save_Load() { var sm = new SaveManager <TestSave>(); var saveName = sm.GetDefaultSaveName(); var testSave = new TestSave(1); sm.Save(testSave, saveName); Assert.AreEqual(testSave.Value, sm.Load(saveName).Value); }
public void ChooseAction(Question prevQuestion, string btnSubmit, TestSave testSave, out bool IsFinish, out Question question) { IsFinish = false; question = null; var quiz = cx.Quizzes.Find(prevQuestion.Quiz.Id); var prevOrder = testSave.QuestionOrders.IndexOf(prevQuestion.Id); int nextOrder = prevOrder; if (btnSubmit == "Next") { nextOrder++; } else if (btnSubmit == "Previous") { nextOrder--; } else if (btnSubmit == "Finish" || btnSubmit == "QuizTime") { IsFinish = true; return; } else if (btnSubmit == "QuestionTime") { if (prevOrder + 1 == testSave.QuestionOrders.Count) { IsFinish = true; return; } else { nextOrder++; } } else if (Int32.TryParse(btnSubmit, out int questionOrder)) { nextOrder = questionOrder - 1; } if (quiz.Type == QuizType.Adaptive) { question = this.GetQuestion_Adaptive( quiz, prevQuestion, testSave, out IsFinish); } else { question = cx.Questions.Find( testSave.QuestionOrders[nextOrder]); } }
/// <summary> /// Returns next section for adaptive quiz /// for first section get medium /// </summary> public Section GetSection_Adaptive(Quiz quiz, Section prevSection, TestSave testSave, out bool isFinish, bool isFirst = false) { isFinish = false; var sections = cx.Sections.Where(x => x.Quiz.Id == quiz.Id). OrderBy(y => y.Difficulty).ToList(); if (isFirst) { return(sections[sections.Count / 2]); } else { var passedSectionIds = testSave.Saves.Select(x => x.Key).ToList(); passedSectionIds.Remove(prevSection.Id); sections.RemoveAll(x => passedSectionIds.Contains(x.Id)); } var sectionSave = testSave.Saves[prevSection.Id]; var answers = new List <Answer>(); foreach (var questionIdAnswers in sectionSave.Answers) { var answer = ExamineQuestion(cx.Questions.Find(questionIdAnswers.Key), questionIdAnswers.Value); answers.Add(answer); } double maxPoints = answers.Sum(x => x.Question.Value); double scoredPoints = answers.Sum(x => x.Mark); var coef = scoredPoints / maxPoints; var passedSections = testSave.Saves.Select(x => cx.Sections.Find(x.Key)).ToList(); passedSections.RemoveAll(x => x.Id == prevSection.Id); var section = Adaptive_DesitionMaker(coef, prevSection, sections, passedSections); if (section == null) { isFinish = true; } return(section); }
/// <summary> /// Using for navigation buttons, finish button and end of time (quiz, section) /// </summary> public void ChooseAction(Section prevSection, string btnSubmit, TestSave testSave, out bool IsFinish, out Section section) { IsFinish = false; section = null; var quiz = cx.Quizzes.Find(prevSection.Quiz.Id); int nextOrder = 0; if (btnSubmit == "Next") { nextOrder = prevSection.Order + 1; } else if (btnSubmit == "Previous") { nextOrder = prevSection.Order - 1; } else if (btnSubmit == "Finish" || btnSubmit == "QuizTime") { IsFinish = true; return; } else if (btnSubmit == "SectionTime") { if (prevSection.Order == cx.Sections.Where(x => x.Quiz.Id == quiz.Id).Max(y => y.Order)) { IsFinish = true; } else { nextOrder = prevSection.Order + 1; } } if (quiz.Type == QuizType.Adaptive) { section = this.GetSection_Adaptive(quiz, prevSection, testSave, out IsFinish); } else { section = cx.Sections.Where(x => x.Quiz.Id == quiz.Id).Single(y => y.Order == nextOrder); } }
private void PerSection() { SectionView model = null; Section section = null; if (_quiz.Type == QuizType.Adaptive) { section = _helper.GetSection_Adaptive(_quiz, null, null, out bool isFinish, true); var questions = _helper.GetRandomSectionQuestions(section.Id); var testViews = _helper.CreateTestViews(questions, _quiz); model = new SectionView() { QuizId = _quiz.Id, SectionId = section.Id, Tests = testViews, Section = section }; SessionSave = new TestSave(_cx); } else { section = _cx.Sections.Where(x => x.Quiz.Id == _quiz.Id). OrderBy(y => y.Order). First(); var testSave = _helper.CreateWholeTest(_quiz); SessionSave = testSave; model = testSave.Saves[section.Id].View; } model = _helper.SetNavigation(model, section, _quiz); PerSectionModel = model; }
public Question GetQuestion_Adaptive(Quiz quiz, Question prevQuestion, TestSave testSave, out bool isFinish, bool isFirst = false) { isFinish = false; var availableQuestions = cx.Questions.Where(x => x.Quiz.Id == quiz.Id). OrderBy(y => y.Difficulty).ToList(); if (isFirst) { return(availableQuestions[availableQuestions.Count / 2]); } else { var passedQuestionIds = testSave.QuestionSaves.Select(x => x.Key).ToList(); availableQuestions.RemoveAll(x => passedQuestionIds.Contains(x.Id)); } var questionSave = testSave.QuestionSaves[prevQuestion.Id]; var answer = ExamineQuestion( cx.Questions.Find(prevQuestion.Id), questionSave.Answer); var coef = answer.Mark / answer.Question.Value; var passedQuestions = testSave.QuestionSaves.Select(x => cx.Questions.Find(x.Key)).ToList(); passedQuestions.RemoveAll(x => x.Id == prevQuestion.Id); var question = Adaptive_DesitionMaker(coef, prevQuestion, availableQuestions, passedQuestions); if (question == null) { isFinish = true; } return(question); }
public AttemptSaver(TestSave save, QuizContext context, QuizAttempt attempt, ControllerHelper helper) { _cx = context; _session = save; _attempt = attempt; _helper = helper; if (_attempt.Quiz.TestingType == QuizTestingType.PerSection) { PerSectionSave(); } else if (_attempt.Quiz.TestingType == QuizTestingType.PerQuestion) { PerQuestionSave(); } else { throw new NotImplementedException(); } }
void Awake() { s = this; }
public double ExamineQuiz(Quiz quiz, IEnumerable <Answer> answers, TestSave save) { var scoredPoints = answers.Sum(x => x.Mark); double maxPoints = 0; if (quiz.Type == QuizType.Adaptive) { if (quiz.TestingType == QuizTestingType.PerQuestion) { var coefDif = answers.Select(x => new { Coef = x.Mark / x.Question.Value, Difficulty = x.Question.Difficulty }).ToList().Where(y => y.Coef >= 0.5).ToList(); if (coefDif.Count == 0) { return(0); } return((double)coefDif.Max(x => x.Difficulty)); } else if (quiz.TestingType == QuizTestingType.PerSection) { var result = 0; foreach (var item in save.Saves) { var section = cx.Sections.Find(item.Key); var questions = item.Value.Answers. Select(x => cx.Questions.Find(x.Key)). ToList(); var ids = questions.Select(x => x.Id).ToList(); var sectionAnswers = answers. Where(x => ids.Contains(x.Question.Id)).ToList(); maxPoints = questions.Sum(x => x.Value); scoredPoints = sectionAnswers.Sum(x => x.Mark); var coef = scoredPoints / maxPoints; if (coef >= 0.5 && result < section.Difficulty) { result = section.Difficulty; } } return(result); } else { throw new Exception("You added some enum"); } } else if (quiz.Type == QuizType.Test) { maxPoints = answers.Select(x => x.Question.Value).Sum(); return(Math.Round(quiz.Value * (scoredPoints / maxPoints), 2)); } else { throw new Exception("You added some enum"); } }
public PerQuestionView SetNavigation(PerQuestionView model, Question question, TestSave testSave) { var quiz = question.Quiz; if (testSave.QuestionOrders.IndexOf(question.Id) == testSave.QuestionOrders.Count - 1) { model.IsFinish = true; if (testSave.QuestionOrders.Count > 1) { model.PrevVisibility = true; } } else { model.PrevVisibility = true; model.NextVisibility = true; if (testSave.QuestionOrders.IndexOf(question.Id) == 0) { model.PrevVisibility = false; } } if (quiz.Type == QuizType.Adaptive) { model.PrevVisibility = false; model.IsFinish = false; model.NextVisibility = true; } if (quiz.TimeLimitType == QuizTimeLimitType.QuestionLimited) { model.PrevVisibility = false; } return(model); }
private SaveSlot GetSaveSlot(TestSave testSave, int slotNumber) => testSaves[testSave].SaveSlots[slotNumber];