public static Button Chal_remove_att(ChalLine line) { var btn = Get(line.Chal.Remove_att, 0, 0, line.Chal.Row_4, "Remove attempt"); line.Chal.Remove_att.Width = 125; line.Chal.Remove_att.Click += (source, e) => { AttemptsControl.RemoveLast(line.Quest.Type); line.Chal.Remove_att.IsEnabled = false; line.Chal.Disable_quest.IsEnabled = true; line.Chal.Grid_chal.Background = UtilWPF.Vocour_row_off; line.Quest.LoadCrossData(); var updated = QuestControl.Get(line.Quest.Type).First(x => x.Id == line.Quest.Id); line.Chal.Avg_w.Content = updated.Avg_week + "% (w)"; line.Chal.Avg_m.Content = updated.Avg_month + "% (m)"; line.Chal.Avg_all.Content = updated.Avg_all + "% (all)"; line.Chal.Tries.Content = updated.Tries.Count + " tries"; line.Chal.Chance.Content = updated.Chance + " (" + Math.Round(updated.Chance_real, 2) + ")"; }; return(btn); }
public static void Remove(QuestSenVM_Deprecated vm) { //RemoveQuestionSentence(vm); var editedQuest = QuestControl.Get(vm.Type).First(x => x.Id == vm.IdQuest); editedQuest.LoadCrossData(); }
private static void InsertQuestion(StackPanel stk_items, Model type) { var added = QuestControl.Get(type).Last(); added.LoadCrossData(); AddWpfItem(stk_items, added); }
private static void SuccessfulInserted(IQuestWpfHeader header, List <bool> successful) { var type = header is VocWpfHeader ? Model.Voc : header is PronWpfHeader ? Model.Pron : header is SpellWpfHeader ? Model.Spell : 0; var added = QuestControl.Get(type).Last(); added.LoadCrossData(); QuestWpfUtil.AddWpfItem(header.Stk_items, added); successful.Add(true); }
private static void EditQuestion(IQuest quest, IQuest edited, StackPanel item_line) { if (!QuestControl.Update(edited)) { return; } edited = QuestControl.Get(quest.Type).Where(q => q.Id == quest.Id).First(); edited.LoadCrossData(); UpdateWpfItem(item_line, edited); Footer.Log("The question has been edited."); }
public static Button Remove_quest(Button reference, int row, int Column, Grid parent, IQuest quest, StackPanel main_line) { var btn_remove = Remove(reference, row, Column, parent, main_line); btn_remove.Click += (source, e) => { var removed = QuestControl.Get(quest.Type).First(s => s.Id == quest.Id); QuestControl.Remove(removed); Footer.Log("The question has been removed."); }; return(btn_remove); }
public static void Verify(ChalLine line, Button btn_verify, Button btn_next) { line.Chal.Cb_Answer.IsEnabled = false; int score = 0; bool isCorrect = false; if (line.Quest.Type == Model.Voc) { isCorrect = line.Chal.Cb_Answer.IsCorrect(); } else if (line.Quest.Type == Model.Spell) { isCorrect = line.Chal.Txt_Spell.Text.ContainsInsensitive(line.Quest.Text); } if (isCorrect) { line.Chal.Grid_chal.Background = UtilWPF.Colour_Correct; score = 10; } else { line.Chal.Grid_chal.Background = UtilWPF.Colour_Incorrect; } var att = new AttemptVM(line.Quest.Id, score, DateTime.Now, line.Quest.Type); AttemptsControl.Insert(att); var updated_quest = QuestControl.Get(line.Quest.Type).First(x => x.Id == line.Quest.Id); line.Chal.Avg_w.Content = updated_quest.Avg_week + "% (w)"; line.Chal.Avg_m.Content = updated_quest.Avg_month + "% (m)"; line.Chal.Avg_all.Content = updated_quest.Avg_all + "% (all)"; line.Chal.Tries.Content = updated_quest.Tries.Count + " tries"; foreach (var lbl in line.Chal.Quest_words) { if (line.Quest.Text.SplitSentence().Contains(lbl.Content.ToString())) { lbl.FontWeight = FontWeights.Bold; } } TurnElemsVisible(line); btn_next.IsEnabled = true; btn_verify.IsEnabled = false; }
public static void Remove(SenVM_Deprecated sentence) { //RemoveSentence(sentence); var qs_from_sentence = QuestSenControl_Deprecated.Get(Model.Voc).Where(x => x.IdSen == sentence.Id).ToList(); if (qs_from_sentence.Any()) { foreach (var qs in qs_from_sentence) { QuestSenControl_Deprecated.Remove(qs); var changedVoc = QuestControl.Get(Model.Voc).Where(y => y.Id == qs.IdQuest).First(); changedVoc.LoadCrossData(); } } }
public void TestIsVerbIntegraty() { foreach (VocVM Voc in QuestControl.Get(Model.Voc)) { //if (Voc.IsComp1Verb && !Voc.Component1.IsVerb()) // Debug.WriteLine(Voc.Component1 + " is set as Verb, but the method said no"); //if (!Voc.IsComp1Verb && Voc.Component1.IsVerb()) // Debug.WriteLine(Voc.Component1 + " is NOT set as Verb, but the method said yes"); //if (Voc.IsComp2Verb && !Voc.Component2.IsVerb()) // Debug.WriteLine(Voc.Component2 + " is set as Verb, but the method said no"); //if (!Voc.IsComp2Verb && Voc.Component2.IsVerb()) // Debug.WriteLine(Voc.Component2 + " is NOT set as Verb, but the method said yes"); } }
private static List <string> GetInvalidSynonyms(IQuest quest) { var invalid_synonyms = new List <string>(); if (quest.Type == Model.Voc) { foreach (VocVM Voc in QuestControl.Get(Model.Voc)) { if (Voc.Text.Contains((quest as VocVM).Answer)) { var words = Voc.Text.SplitSentence(); invalid_synonyms.AddRange(words); } } } return(invalid_synonyms); }
private static void CheckVocs(ref int updated_questions) { var Vocs = QuestControl.Get(Model.Voc).ToList(); foreach (VocVM Voc in Vocs) { foreach (var sen in Get()) { //if (AutoGetSentences_Deprecated.DoesSenContainsVoc(Voc, sen.Text)) //{ // QuestSenControl_Deprecated.Insert(new QuestSenVM_Deprecated(Voc.Id, sen.Id, Voc.Type)); // Voc.LoadCrossData(); // Voc.Sentences_off.Add(sen); // QuestControl.Update(Voc); // updated_questions++; //} } } }
public void GetQuestions() { Questions = new List <SenQuest>(); foreach (var qs in QuestSenControl_Deprecated.Get(Model.Voc)) { if (qs.IdSen == Id) { var quest = QuestControl.Get(Model.Voc).First(x => x.Id == qs.IdQuest); var sq = new SenQuest(quest, qs.Id); if (!Questions.Any(x => x.QS_id == qs.Id)) { Questions.Add(sq); } } } // and so on [types] }
public async static Task <List <(int, int)> > LinkQuestToSentences(Model type, Stopwatch watcher) { var links_found = new List <(int, int)>(); var quests = QuestControl.Get(type);//.Where(x => x.Sentences.Count <= 5); int actual = 1; var task = quests.Select(quest => Task.Factory.StartNew(() => { foreach (var sen in SenControl_Deprecated.Get()) { if (type == Model.Voc) { //if (AutoGetSentences_Deprecated.DoesSenContainsVoc((VocVM)quest, sen.Text)) //{ // if (!QuestSenControl_Deprecated.Get(type).Any(qs => qs.IdQuest == quest.Id && qs.IdSen == sen.Id)) // links_found.Add((quest.Id, sen.Id)); //} } } var log = "Analysing " + type.ToDesc() + " " + actual + " of " + quests.Count() + ". "; log += links_found.Count + " sentences are suitable to " + type.ToDesc() + "s. " + "Time elapsed: " + Math.Round(watcher.Elapsed.TotalSeconds, 1) + " seconds. "; if (actual > 5) { var quant_missing = quests.Count() - actual; var time_to_finish = (watcher.Elapsed.TotalSeconds * quant_missing) / actual; log += "It must finish in " + Math.Round(time_to_finish, 1) + " seconds."; } Footer.Log(log); actual = actual + 1; })); await Task.WhenAll(task); return(links_found); }
private async static Task <List <string> > GetVocSentenceFromList(List <string> sentences) { var result = new List <string>(); var watcher = new Stopwatch(); watcher.Start(); int actual = 1; var tasks = QuestControl.Get(Model.Voc).Select(Voc => Task.Factory.StartNew(() => { foreach (var sen in sentences) { //if (DoesSenContainsVoc((VocVM)Voc, sen) && !result.Contains(sen)) // result.Add(sen); } var log = "Analysing " + sentences.Count + " sentences for Vocabulary " + actual + " of " + QuestControl.Get(Model.Voc).Count() + ". "; log += result.Count + " suitable sentences found in " + Math.Round(watcher.Elapsed.TotalMinutes, 2) + " minutes. "; if (actual > 10) { var quant_missing = QuestControl.Get(Model.Voc).Count() - actual; var time_to_finish = (watcher.Elapsed.TotalMinutes * quant_missing) / actual; log += "It must finish in " + Math.Round(time_to_finish, 2) + " minutes."; } Footer.Log(log); actual = actual + 1; })); await Task.WhenAll(tasks); return(result); }
private static void UpdateQuestionFromLastAttempt(int idQuestion, Model type) { var quest = QuestControl.Get(type).First(c => c.Id == idQuestion); quest.LoadCrossData(); }
public async Task CheckTimeSpentToValidBulkSentences() { var watcher = new Stopwatch(); watcher.Start(); Debug.WriteLine("CheckTimeSpentToValidBulkSentences has started"); string source = string.Empty; string[] filePaths = Directory.GetFiles(CakePaths.ResourceTxtBooks, "*.txt", searchOption: SearchOption.TopDirectoryOnly); foreach (var path in filePaths) { source += File.ReadAllText(path); } Debug.WriteLine(watcher.Elapsed.TotalSeconds + " sec to get all sources."); watcher.Restart(); //var maxSecondsToSpend = 20 * 60; var matchList = Regex.Matches(source, @"[A-Z]+(\w+\,*\;*[ ]{0,1}[\.\?\!]*)+"); var sentences = matchList.Cast <Match>().Select(match => match.Value).ToList(); sentences = sentences.Where(s => !Errors.IsNullSmallerOrBigger(s, SenVM_Deprecated.MinSize, SenVM_Deprecated.MaxSize, false) && ((s.EndsWith(".") && !s.EndsWith("Dr.") && !s.EndsWith("Mr.") && !s.EndsWith("Ms.")) || s.EndsWith("!") || s.EndsWith("?"))).ToList(); Debug.WriteLine(watcher.Elapsed.TotalSeconds + " sec to filter sources and suck " + sentences.Count + " sentences."); watcher.Restart(); var watcherQuest = new Stopwatch(); watcher.Start(); var found = new List <string>(); Task tasks = Task.Run(() => Parallel.ForEach(QuestControl.Get(Model.Voc).Take(50), Voc => { Debug.WriteLine("Voc started."); foreach (var sen in sentences) { System.Console.WriteLine((Voc as VocVM).Text + ": " + sen); if (Sentences.DoesSenContainsVoc((VocVM)Voc, sen) && !found.Contains(sen)) { found.Add(sen); } } Debug.WriteLine(watcher.Elapsed.TotalSeconds + " sec to finish Voc id " + Voc.Id); })); await Task.WhenAll(tasks); watcher.Stop(); Debug.WriteLine(watcher.Elapsed.TotalSeconds + " sec to finish everything. " + found.Count + " sentences found."); foreach (var sen in found) { Debug.WriteLine(sen); } //Assert.IsTrue(watcher.Elapsed.TotalSeconds > 10); //Assert.IsTrue(maxSecondsToSpend >= watcher.Elapsed.TotalSeconds); }