public bool HasAnswer() { if (Answers != null && Answers.Count() > 0) { return(true); } return(false); }
public int SameAnswerCount() { var distinctAnswers = Answers.Distinct(); var allAnsweredSameCount = 0; foreach (var answer in distinctAnswers) { if (Answers.Count(x => x == answer) == PeopleCount) { allAnsweredSameCount++; } } return(allAnsweredSameCount); }
private void CalculateResult(int incorrectEliminationRate) { EmptyCount = Answers .Count(a => a.Result == QuestionAnswerResult.Empty); WrongCount = Answers .Count(a => a.Result == QuestionAnswerResult.Wrong || a.Result == QuestionAnswerResult.Invalid); CorrectCount = Answers .Count(a => a.Result == QuestionAnswerResult.Correct); Net = incorrectEliminationRate == 0 ? CorrectCount : CorrectCount - ((float)WrongCount / incorrectEliminationRate); }
public void UpdateGrades() { int correctCount = Answers.Count(a => a.Correct); if (correctCount == 1) { foreach (var answer in Answers) { answer.Grade = answer.Correct ? 100 : 0; } } else { double grade = 100; switch (correctCount) { case 2: grade = 50; break; case 3: grade = 33.33333; break; case 4: grade = 25; break; case 5: grade = 20; break; } foreach (var answer in Answers) { answer.Grade = answer.Correct ? grade : -100; } } }
private void UpdateResult() { int correct = Answers.Count(o => o.Correct); int total = Answers.Count; if (correct == total) { if (!ExclamationHasBeenPlayed) { resultCongrats.Visibility = Visibility.Visible; resultCongrats.Content = String.Format(PrgResources.WithoutErrorsMessage, correct, total); SystemSounds.Exclamation.Play(); ExclamationHasBeenPlayed = true; } } else { resultCongrats.Visibility = Visibility.Collapsed; } resultLbl.Content = String.Format(PrgResources.RightTestAnswers, correct, total, (int)Math.Round((double)correct / total * 100)); mistakesLbl.Text = String.Format(PrgResources.MistakesLabel, total - correct); correctLbl.Text = String.Format(PrgResources.CorrectLabel, correct); //Remove all old rows FrameworkElement[] toRemove = resultsPanel.Children.OfType <FrameworkElement>() .Where(o => o.Name == null) //The item that was added .ToArray(); foreach (FrameworkElement item in toRemove) { resultsPanel.Children.Remove(item); } resultPanel.Visibility = Visibility.Visible; foreach (TestAnswer ans in Answers.Reverse()) //To show answers in the order as they were given { var copy = (FrameworkElement)XamlReader.Parse(XamlWriter.Save(resultPanel)); copy.Name = null; //To show that it's a new item var newAsteriskLbl = (TextBlock)copy.FindName(nameof(asteriskLbl)); newAsteriskLbl.Text = ""; if (ans.Word.Asterisk != null && ans.Word.Asterisk.Type != AsteriskType.None) { newAsteriskLbl.Text = $"{ans.Word.Asterisk.Type.ToShortStr()}✶"; } newAsteriskLbl.MouseWheel += OnAsteriskLbl_MouseWheel; newAsteriskLbl.Tag = ans.Word; var newTimeLbl = (TextBlock)copy.FindName(nameof(timeLbl)); newTimeLbl.Text = $"{ans.Time.TotalSeconds:F0} s"; var newGroupLbl = (TextBlock)copy.FindName(nameof(groupLbl)); newGroupLbl.Text = ans.Word.Group.ToGradeStr(); newGroupLbl.MouseWheel += OnGroupLbl_MouseWheel; newGroupLbl.Tag = ans.Word; var newPlayBtn = (Button)copy.FindName(nameof(playBtn)); newPlayBtn.IsEnabled = !String.IsNullOrEmpty(ans.Word.Sound); newPlayBtn.Click += OnPlayBtn_Click; newPlayBtn.Tag = ans.Word; var newTriesLbl = (TextBlock)copy.FindName(nameof(triesLbl)); if (ans.Tries <= 0) { newTriesLbl.Visibility = Visibility.Collapsed; //Test without tries } else { newTriesLbl.Text = ans.Tries.ToString(); } var newWordLbl = (TextBlock)copy.FindName(nameof(wordLbl)); newWordLbl.Text = ans.Word.Word; newWordLbl.MouseLeftButtonUp += OnWordLbl_MouseLeftButtonUp; newWordLbl.Tag = ans.Word; var newTranslationsLbl = (TextBlock)copy.FindName(nameof(translationsLbl)); newTranslationsLbl.Text = ClauseToDataGridClauseMapper.MakeTranslationsString(ans.Word.Translations); if (newTranslationsLbl.Text?.Length > 55) //Truncate too long string { newTranslationsLbl.ToolTip = newTranslationsLbl.Text; newTranslationsLbl.Text = $"{newTranslationsLbl.Text.Substring(0, 50)}..."; } //Maybe to show the word data in the popup?.. if (ans.Deleted) { //For the deleted clause newWordLbl.TextDecorations.Clear(); newWordLbl.TextDecorations.Add(TextDecorations.Strikethrough); newTranslationsLbl.TextDecorations.Add(TextDecorations.Strikethrough); copy.IsEnabled = false; } int idx = resultsPanel.Children.IndexOf(ans.Correct ? correctLbl : mistakesLbl); resultsPanel.Children.Insert(idx + 1, copy); } resultPanel.Visibility = Visibility.Collapsed; }
/// <summary> /// Verifies that the provided answer string is correct and if so, if it qualifies for the bonus answer /// if there is one. /// </summary> /// <param name="answer">Answer string from user</param> /// <returns></returns> public AnswerResponse VerifyAnswer(string answer) { var response = new AnswerResponse { AnswerStatus = AnswerStatus.Incorrect, Points = Points, BonusPoints = BonusPoints }; bool AnswerContains(string item) => answer.Contains(item, StringComparison.InvariantCultureIgnoreCase); try { if (BonusPoints.HasValue && BonusPoints.Value != 0) { response.BonusPoints = BonusPoints; if (BonusAll ?? false) { if (BonusAnswers.All(AnswerContains)) { response.AnswerStatus = AnswerStatus.BonusCorrect; } else if (BonusAnswers.Any(AnswerContains)) { response.AnswerStatus = AnswerStatus.PartiallyCorrect; } } else if (BonusAnswers.Any(AnswerContains)) { response.AnswerStatus = AnswerStatus.BonusCorrect; } return(response); } if (AnswersRequired.HasValue) { if (Answers.All(AnswerContains)) { response.AnswerStatus = AnswerStatus.NormalCorrect; } else if (Answers.Any(AnswerContains)) { response.AnswerStatus = AnswerStatus.PartiallyCorrect; } } else if (Answers.Count(AnswerContains) >= AnswersRequired) { response.AnswerStatus = AnswerStatus.NormalCorrect; } else if (Answers.Count(AnswerContains) > 0) { response.AnswerStatus = AnswerStatus.PartiallyCorrect; } } catch (Exception e) // Handling any errors is the responsibility of the consumer { response.AnswerStatus = AnswerStatus.Error; response.Exception = e; } return(response); }
public List <QuestionItem> GetQuestionsOnLevel(int level) { return((from question in Questions where question.Complexity == level join option in Options on question.Id equals option.QuestionId into optionsGroup select new QuestionItem { Options = optionsGroup.ToList(), QuestionText = question.QuestionText, Answer = optionsGroup.FirstOrDefault(p => Answers.Count(a => a.OptionId == p.Id) == 1).OptionText }).ToList()); }
public int GetAnswersCount() => Answers .Count(a => a.Value == PeopleInGroup);
public void ComputeScore() { Score = Answers.Count(a => a.IsCorrect) * 100 / Answers.Count; }
public int GetQuestionCount() { return(Answers == null ? 0 : Answers.Count()); }
/// <summary> /// Determines if a SessionAnswer is correct. /// </summary> /// <returns><c>true</c>, if question correct answers matches with all session answers, /// <c>false</c> otherwise. /// </returns> public bool IsCorrect() { return(Answers.Count() == Question.GetCorrectAnswers().Count() && Answers.All(answer => answer.IsCorrect)); }