protected void cmdStartQuiz_Click(object sender, EventArgs e) { if (!Page.IsValid) return; ClearTextControl(CurrentQuestionHistoryLabel); _currentQuiz = InitializeCurrentQuiz(); LabelCurrentQuestion.Text = $"#{_currentQuiz.QuestionNumber}: {_currentQuiz.CurrentQuestion.Key}"; QuizProcess.ProcessQuestion(ref _currentQuiz, LabelCurrentQuestion, ref LabelTotalSolutions); }
// todo: make labelTotalSolutions a non-ref term by changing UpdateTotalSolutionsLabelWhenCorrect public static string ProcessQuestion(ref Quiz currentQuiz, Label labelCurrentQuestion, ref Label labelTotalSolutions) { currentQuiz.CurrentQuestion = currentQuiz.QuizAlphaToWords[currentQuiz.QuestionNumber - 1]; currentQuiz.CurrentAnswerList = currentQuiz.CurrentQuestion.Value; var returnstring = "#" + currentQuiz.QuestionNumber + ": " + currentQuiz.CurrentQuestion.Key; if (currentQuiz.IsBlankBingos) returnstring += MondainUI.Embolden("?"); currentQuiz.ResetCurrentAnswerStats(); labelTotalSolutions = UpdateTotalSolutionsLabelWhenCorrect(currentQuiz.GetBooleanAnswersThisQuestion()[0], currentQuiz.GetBooleanAnswersThisQuestion()[0] + currentQuiz.GetBooleanAnswersThisQuestion()[1], labelTotalSolutions); return returnstring; }
protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) { // Restore variables. _currentQuiz = (Quiz)ViewState["currentQuiz"]; CurrentQuestionHistoryLabel.Text = (string)ViewState["answerSetText"]; } else // if not postback { FillStaticDropdowns(); MinDD.SelectedValue = Constants.WordLengthMinDefault.ToString(); MaxDD.SelectedValue = Constants.WordLengthMaxDefault.ToString(); MinProb.Text = Constants.ProbabilityMinDefault.ToString(); MaxProb.Text = Constants.ProbabilityMaxDefault.ToString(); TBQuizLength.Text = Constants.DefaultQuizLength.ToString(); } // do this regardless TBQuizAnswer.Focus(); }
public void UpdateStatsTest() { var mockAlphaToWords = new List<KeyValuePair<string, List<string>>>() { new KeyValuePair<string, List<string>>("AB", new List<string>() {"AB", "BA"}), new KeyValuePair<string, List<string>>("EFHRRTU", new List<string>() {"FURTHER"}), new KeyValuePair<string, List<string>>("AENORS", new List<string>() {"ARSENO", "REASON", "SENORA"}), }; var mockQuiz = new Quiz(3, mockAlphaToWords, false, false); mockQuiz.SetWordAsCorrect("AB"); mockQuiz.CurrentAnswerList.Remove("AB"); mockQuiz.IncrementCounts(false); string [] expected = new string[4]; expected[0] = "0/1"; expected[1] = "0%"; expected[2] = "1/2"; expected[3] = "50%"; Assert.AreEqual(expected[0], QuizProcess.UpdateStats(ref mockQuiz)["labelStatsCorrectAlphagramFraction"]); }
public static Dictionary<string, string> UpdateStats(ref Quiz currentQuiz) { var correct = currentQuiz.GetBooleanAnswersThisQuestion(); currentQuiz.CorrectWordCount += correct[0]; currentQuiz.IncorrectWordCount += correct[1]; var cc = currentQuiz.CorrectAlphagramCount; var ic = currentQuiz.IncorrectAlphagramCount; var ccw = currentQuiz.CorrectWordCount; var icw = currentQuiz.IncorrectWordCount; var dictionary = new Dictionary<string, string>(); dictionary.Add("labelStatsCorrectAlphagramFraction", cc.ToString() + '/' + (cc + ic)); dictionary.Add("labelStatsCorrectAlphagramPercent", Math.Round(((double)cc / (cc + ic)) * 100, 2).ToString(CultureInfo.CurrentCulture) + "%"); dictionary.Add("labelStatsCorrectWordFraction", ccw.ToString() + '/' + (ccw + icw)); dictionary.Add("labelStatsCorrectWordPercent", Math.Round(((double)ccw / (ccw + icw)) * 100, 2).ToString(CultureInfo.CurrentCulture) + "%"); return dictionary; }
private Quiz InitializeCurrentQuiz() { var quizLengthValue = TryIntParseWithDefault(TBQuizLength.Text, Constants.DefaultQuizLength); var minValue = TryIntParseWithDefault(MinDD.SelectedValue, Constants.WordLengthMinDefault); var maxValue = TryIntParseWithDefault(MaxDD.SelectedValue, Constants.WordLengthMaxDefault); var minProbValue = TryIntParseWithDefault(MinProb.Text, Constants.ProbabilityMinDefault); var maxProbValue = TryIntParseWithDefault(MaxProb.Text, Constants.ProbabilityMaxDefault); System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MondainDeploy"); if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0) { var connString = rootWebConfig.ConnectionStrings.ConnectionStrings["LocalSQLExpressConnectionString"]; _fullLexicon = new FullLexicon(new LexTableWrapper(connString, true)); } ClearTextControl(CurrentStatus); CurrentStatus.Text = ("test"); CurrentStatus.Text = PostpendLineTo(CurrentStatus.Text, "Lexicon words: " + _fullLexicon.GetWordCount()); CurrentStatus.Text = PostpendLineTo(CurrentStatus.Text, "Alphagrams: " + _fullLexicon.GetAlphagramCount()); List<KeyValuePair<string, List<string>>> tempQuizAlphaToWords; bool isBlankBingos = BlankBingoCheck.Checked; bool usingLexSymbols = LexSymbolCheck.Checked; if (!isBlankBingos) { tempQuizAlphaToWords = _fullLexicon.GetRandomQuizEntries(quizLengthValue, new Random(), minValue, maxValue, minProbValue, maxProbValue); } else tempQuizAlphaToWords = _fullLexicon.GetBlankBingoEntries(quizLengthValue, new Random(), minValue, maxValue); if (tempQuizAlphaToWords.Count != quizLengthValue) quizLengthValue = tempQuizAlphaToWords.Count; var quiz = new Quiz(quizLengthValue, tempQuizAlphaToWords, isBlankBingos, usingLexSymbols); CurrentStatus.Text = PostpendLineTo(CurrentStatus.Text, "Initialized quiz with " + quiz.QuizLength + " questions."); CurrentStatus.Text = PostpendLineTo(CurrentStatus.Text, "Using lexicon symbols: " + usingLexSymbols.ToString()); return quiz; }