public void AddQuestionMetric(QuestionMetric metric) { CheckDbFile.Check(DbFile); using (var cnn = SimpleDbConnection()) { cnn.Open(); cnn.Execute( @"INSERT INTO QuestionMetric ( WordId, Created, ElaspedMs, Result, Type, PreviousExam, ExamsPassed, AggregateScoreBefore, PassedScoreBefore) Values( @WordId, @Created, @ElaspedMs, @Result, @Type, @PreviousExam, @ExamsPassed, @AggregateScoreBefore, @PassedScoreBefore)", metric); } }
public QuestionMetric CreateQuestionMetric(UserWordForLearning pairModel, IExam exam) { var questionMetric = new QuestionMetric { WordId = pairModel.Id, Created = DateTime.Now, AggregateScoreBefore = pairModel.AggregateScore, ExamsPassed = pairModel.Examed, PassedScoreBefore = pairModel.PassedScore, PreviousExam = pairModel.LastExam, Type = exam.Name, }; return(questionMetric); }
private static QuestionMetric CreateQuestionMetric(PairModel pairModel, IExam exam) { var questionMetric = new QuestionMetric { AggregateScoreBefore = pairModel.AggregateScore, WordId = pairModel.Id, Created = DateTime.Now, ExamsPassed = pairModel.Examed, PassedScoreBefore = pairModel.PassedScore, PhrasesCount = pairModel.Phrases?.Count ?? 0, PreviousExam = pairModel.LastExam, Type = exam.Name, WordAdded = pairModel.Created }; return(questionMetric); }
public async Task EnterAsync() { if (!await _usersWordsService.HasWordsFor(Chat.User)) { await Chat.SendMessageAsync(Chat.Texts.NeedToAddMoreWordsBeforeLearning); return; } var startupScoreUpdate = _usersWordsService.UpdateCurrentScoreForRandomWords(Chat.User, _examSettings.MaxLearningWordsCountInOneExam * 2); var typing = Chat.SendTyping(); var c = Rand.RandomIn(_examSettings.MinLearningWordsCountInOneExam, _examSettings.MaxLearningWordsCountInOneExam); await startupScoreUpdate; await typing; var learningWords = await _usersWordsService.GetWordsForLearningWithPhrasesAsync(Chat.User, c, 3); var learningWordsCount = learningWords.Length; if (learningWords.Average(w => w.AbsoluteScore) <= WordLeaningGlobalSettings.FamiliarWordMinScore) { var sb = new StringBuilder($"{Emojis.Learning} " + Chat.Texts.LearningCarefullyStudyTheListMarkdown + "\r\n\r\n```\r\n"); foreach (var pairModel in learningWords.Shuffle()) { sb.AppendLine($"{pairModel.Word.EscapeForMarkdown()}\t\t:{pairModel.AllTranslationsAsSingleString.EscapeForMarkdown()}"); } sb.AppendLine($"\r\n```\r\n\\.\\.\\. {Chat.Texts.thenClickStartMarkdown}"); await Chat.SendMarkdownMessageAsync(sb.ToString(), new[] { new[] { new InlineKeyboardButton { CallbackData = "/startExamination", Text = Chat.Texts.StartButton }, new InlineKeyboardButton { CallbackData = BotCommands.Start, Text = Chat.Texts.CancelButton, } } }); var userInput = await Chat.WaitInlineKeyboardInput(); if (userInput != "/startExamination") { return; } } var started = DateTime.Now; var learningAndAdvancedWords = (await _usersWordsService.AppendAdvancedWordsToExamList( Chat.User, learningWords, _examSettings)); var distinctLearningWords = learningAndAdvancedWords.Distinct().ToArray(); var originWordsScore = new Dictionary <string, double>(); foreach (var word in distinctLearningWords) { if (!originWordsScore.ContainsKey(word.Word)) { originWordsScore.Add(word.Word, word.AbsoluteScore); } } var gamingScoreBefore = Chat.User.GamingScore; var questionsCount = 0; var questionsPassed = 0; var wordQuestionNumber = 0; QuestionResult lastExamResult = null; foreach (var word in learningAndAdvancedWords) { var allLearningWordsWereShowedAtLeastOneTime = wordQuestionNumber < learningWordsCount; var question = QuestionSelector.Singletone.GetNextQuestionFor(allLearningWordsWereShowedAtLeastOneTime, word); wordQuestionNumber++; var learnList = learningWords; if (!learningWords.Contains(word)) { learnList = learningWords.Append(word).ToArray(); } if (wordQuestionNumber > 1 && question.NeedClearScreen) { await WriteDontPeakMessage(lastExamResult?.ResultsBeforeHideousText); } Chat.User.OnAnyActivity(); var originRate = word.Score; var questionMetric = new QuestionMetric(word, question.Name); var result = await PassWithRetries(question, word, learnList, wordQuestionNumber); switch (result.Results) { case ExamResult.Passed: var succTask = _usersWordsService.RegisterSuccess(word); questionsCount++; questionsPassed++; questionMetric.OnExamFinished(word.Score, true); Botlog.SaveQuestionMetricInfo(questionMetric, Chat.ChatId); await succTask; Chat.User.OnQuestionPassed(word.Score - originRate); break; case ExamResult.Failed: var failureTask = _usersWordsService.RegisterFailure(word); questionMetric.OnExamFinished(word.Score, false); Botlog.SaveQuestionMetricInfo(questionMetric, Chat.ChatId); questionsCount++; await failureTask; Chat.User.OnQuestionFailed(word.Score - originRate); break; case ExamResult.Retry: case ExamResult.Impossible: throw new NotSupportedException(result.Results.ToString()); } if (!string.IsNullOrWhiteSpace(result.OpenResultsText)) { await Chat.SendMarkdownMessageAsync(result.OpenResultsText); } lastExamResult = result; Botlog.RegisterExamInfo(Chat.User.TelegramId, started, questionsCount, questionsPassed); } Chat.User.OnLearningDone(); var updateUserTask = _userService.Update(Chat.User); var finializeScoreUpdateTask = _usersWordsService.UpdateCurrentScoreForRandomWords(Chat.User, 10); //info after examination await SendExamResultToUser( distinctLearningWords : distinctLearningWords, originWordsScore : originWordsScore, questionsPassed : questionsPassed, questionsCount : questionsCount, learningWords : learningWords, gamingScoreBefore : gamingScoreBefore); await updateUserTask; await finializeScoreUpdateTask; }
public UserPairForExam CreateFromBaseUserPair(UserPair userPair, User user, QuestionMetric metric) { var userPairForExam = new UserPairForExam(); return(userPairForExam); }
//TODO разобраться с QuestionMetric public void SaveQuestionMetrics(QuestionMetric questionMetric) => _examsAndMetricService.SaveQuestionMetrics(questionMetric);
public void SaveQuestionMetrics(QuestionMetric questionMetric) { _repository.AddQuestionMetric(questionMetric); }
public void Enter(NewWordsService service) { service.UpdateAgingAndRandomize(50); Console.WriteLine("Examination"); var words = service.GetPairsForLearning(9, 3); Console.Clear(); Console.WriteLine("Examination: "); if (words.Average(w => w.PassedScore) <= 4) { foreach (var pairModel in words.Randomize()) { Console.WriteLine($"{pairModel.OriginWord}\t\t:{pairModel.Translation}"); } } Console.WriteLine(); Console.WriteLine("Press any key to start an examination"); Console.ReadKey(); Console.Clear(); int examsCount = 0; int examsPassed = 0; DateTime started = DateTime.Now; for (int i = 0; i < 3; i++) { foreach (var pairModel in words.Randomize()) { Console.WriteLine(); IExam exam; exam = ExamSelector.GetNextExamFor(i == 0, pairModel); bool retryFlag = false; do { retryFlag = false; Stopwatch sw = Stopwatch.StartNew(); var questionMetric = new QuestionMetric { AggregateScoreBefore = pairModel.AggregateScore, WordId = pairModel.Id, Created = DateTime.Now, ExamsPassed = pairModel.Examed, PassedScoreBefore = pairModel.PassedScore, PhrasesCount = pairModel.Phrases?.Count ?? 0, PreviousExam = pairModel.LastExam, Type = exam.Name, WordAdded = pairModel.Created }; var result = exam.Pass(service, pairModel, words); sw.Stop(); questionMetric.ElaspedMs = (int)sw.ElapsedMilliseconds; switch (result) { case ExamResult.Impossible: exam = ExamSelector.GetNextExamFor(i == 0, pairModel); retryFlag = true; break; case ExamResult.Passed: Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\r\n[PASSED]"); Console.ResetColor(); Console.WriteLine(); Console.WriteLine(); questionMetric.Result = 1; service.SaveQuestionMetrics(questionMetric); examsCount++; examsPassed++; break; case ExamResult.Failed: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\r\n[failed]"); Console.ResetColor(); Console.WriteLine(); Console.WriteLine(); questionMetric.Result = 0; service.SaveQuestionMetrics(questionMetric); examsCount++; break; case ExamResult.Retry: retryFlag = true; Console.WriteLine(); Console.WriteLine(); break; case ExamResult.Exit: return; } } while (retryFlag); service.RegistrateExam(started, examsCount, examsPassed); } } Console.WriteLine(); Console.WriteLine($"Test done: {examsPassed}/{examsCount}"); foreach (var pairModel in words) { Console.WriteLine(pairModel.OriginWord + " - " + pairModel.Translation + " (" + pairModel.PassedScore + ")"); } Console.WriteLine(); }
public async Task EnterAsync(User user) { if (!await _usersWordsService.HasWords(user)) { await _chatIo.SendMessageAsync("You need to add some more words before examination"); return; } //Randomization and jobs //if (RandomTools.Rnd.Next() % 30 == 0) // await _usersWordsService.AddMutualPhrasesToVocabAsync(user, 10); // else var startupScoreUpdate = _usersWordsService.UpdateCurrentScore(user, _examSettings.MaxLearningWordsCountInOneExam * 2); var typing = _chatIo.SendTyping(); var c = Random.RandomIn(_examSettings.MinLearningWordsCountInOneExam, _examSettings.MaxLearningWordsCountInOneExam); await startupScoreUpdate; await typing; var learningWords = await _usersWordsService.GetWordsForLearningWithPhrasesAsync(user, c, 3); var learningWordsCount = learningWords.Length; if (learningWords.Average(w => w.AbsoluteScore) <= 4) { var sb = new StringBuilder("Examination\r\n"); foreach (var pairModel in learningWords.Randomize()) { sb.AppendLine($"{pairModel.Word}\t\t:{pairModel.TranslationAsList}"); } await _chatIo.SendMessageAsync(sb.ToString(), new InlineKeyboardButton { CallbackData = "/startExamination", Text = "Start" }, new InlineKeyboardButton { CallbackData = "/start", Text = "Cancel", }); var userInput = await _chatIo.WaitInlineKeyboardInput(); if (userInput != "/startExamination") { return; } } var started = DateTime.Now; var learningAndAdvancedWords = await _usersWordsService.AppendAdvancedWordsToExamList(user, learningWords, _examSettings); var questionsCount = 0; var questionsPassed = 0; var i = 0; ExamResult?lastExamResult = null; foreach (var word in learningAndAdvancedWords) { var allLearningWordsWereShowedAtLeastOneTime = i < learningWordsCount; var exam = QuestionSelector.Singletone.GetNextQuestionFor(allLearningWordsWereShowedAtLeastOneTime, word); i++; var retryFlag = false; do { retryFlag = false; var sw = Stopwatch.StartNew(); var questionMetric = new QuestionMetric(word, exam.Name); var learnList = learningWords; if (!learningWords.Contains(word)) { learnList = learningWords.Append(word).ToArray(); } if (i > 1 && exam.NeedClearScreen && lastExamResult != ExamResult.Impossible) { await WriteDontPeakMessage(); if (lastExamResult == ExamResult.Passed) { await WritePassed(); } } var result = await exam.Pass(_chatIo, _usersWordsService, word, learnList); sw.Stop(); questionMetric.ElaspedMs = (int)sw.ElapsedMilliseconds; switch (result) { case ExamResult.Impossible: exam = QuestionSelector.Singletone.GetNextQuestionFor(i == 0, word); retryFlag = true; break; case ExamResult.Passed: await WritePassed(); Botlog.SaveQuestionMetric(questionMetric); questionsCount++; questionsPassed++; break; case ExamResult.Failed: await WriteFailed(); questionMetric.Result = 0; Botlog.SaveQuestionMetric(questionMetric); questionsCount++; break; case ExamResult.Retry: retryFlag = true; break; case ExamResult.Exit: return; } lastExamResult = result; } while (retryFlag); Botlog.RegisterExamAsync(user.TelegramId, started, questionsCount, questionsPassed); } var finializeScoreUpdateTask = _usersWordsService.UpdateCurrentScore(user, 10); var doneMessage = new StringBuilder($"Learning done: {questionsPassed}/{questionsCount}\r\n"); foreach (var pairModel in learningAndAdvancedWords.Distinct()) { doneMessage.Append(pairModel.Word + " - " + pairModel.TranslationAsList + " (" + pairModel.AbsoluteScore + ")\r\n"); } await _chatIo.SendMessageAsync(doneMessage.ToString()); }