Пример #1
0
        public static void Remove(QuestSenVM_Deprecated vm)
        {
            //RemoveQuestionSentence(vm);
            var editedQuest = QuestControl.Get(vm.Type).First(x => x.Id == vm.IdQuest);

            editedQuest.LoadCrossData();
        }
Пример #2
0
        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 PopulateRows(Grid parent, Model type, List <ChalLine> lines, Microsoft.Office.Interop.Word.Application wordApp = null)
        {
            var watcher = new Stopwatch();

            watcher.Start();

            Footer.Log("Loading...");

            lines.Clear();

            var actual_chosen = new List <int>();

            for (int row = 0; row < 4; row++)
            {
                var quest = QuestControl.GetRandomAvailableQuestion(type, actual_chosen);
                actual_chosen.Add(quest.Id);

                var item = CreateChalLine(quest, row, parent, wordApp);
                lines.Add(item);
                Footer.Log("Loading... Challenge " + (row + 1) + " was loaded in " + watcher.Elapsed.TotalSeconds + " seconds.");
            }
            ;

            Footer.Log("4 challenges loaded in " + watcher.Elapsed.TotalSeconds + " seconds.");
        }
Пример #4
0
        private static void InsertQuestion(StackPanel stk_items, Model type)
        {
            var added = QuestControl.Get(type).Last();

            added.LoadCrossData();

            AddWpfItem(stk_items, added);
        }
Пример #5
0
        private static void InsertClick(StackPanel stk_items, SpellWpfHeader wpf_header)
        {
            var spell = new SpellVM(wpf_header.Txt_words.Text,
                                    (Importance)wpf_header.Cob_imp.SelectedIndex,
                                    wpf_header.Btn_isActive.IsActived);

            if (QuestControl.Insert(spell))
            {
                wpf_header.Txt_words.Text = string.Empty;
                InsertQuestion(stk_items, Model.Spell);
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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 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;
        }
Пример #10
0
        private static void InsertClick(StackPanel stk_items, PronWpfHeader wpf_header)
        {
            var pron = new PronVM(wpf_header.Txt_words.Text,
                                  wpf_header.Txt_phonemes.Text,
                                  (Importance)wpf_header.Cob_imp.SelectedIndex,
                                  wpf_header.Btn_isActive.IsActived);

            if (QuestControl.Insert(pron))
            {
                wpf_header.Txt_words.Text    = string.Empty;
                wpf_header.Txt_phonemes.Text = string.Empty;

                InsertQuestion(stk_items, Model.Pron);
            }
        }
Пример #11
0
        public static Button Chal_disable_quest(ChalLine line)
        {
            var btn = Get(line.Chal.Disable_quest, 0, 4, line.Chal.Row_4, "Disable quest");

            line.Chal.Disable_quest.Width     = 125;
            line.Chal.Disable_quest.IsEnabled = false;
            line.Chal.Disable_quest.Click    += (source, e) =>
            {
                line.Quest.Disable();
                QuestControl.Update(line.Quest);
                line.Chal.Disable_quest.IsEnabled = false;
            };

            return(btn);
        }
Пример #12
0
        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();
                }
            }
        }
Пример #13
0
        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);
        }
Пример #15
0
        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++;
                    //}
                }
            }
        }
Пример #16
0
        private static void InsertClick(StackPanel stk_items, VocWpfHeader wpf_header)
        {
            var Voc = new VocVM(wpf_header.Txt_words.Text,
                                wpf_header.Txt_answer.Text,
                                wpf_header.Txt_def.Text,
                                wpf_header.Txt_ptbr.Text,
                                (Importance)wpf_header.Cob_imp.SelectedIndex,
                                wpf_header.Btn_isActive.IsActived);

            if (QuestControl.Insert(Voc))
            {
                wpf_header.Txt_words.Text  = string.Empty;
                wpf_header.Txt_answer.Text = string.Empty;
                wpf_header.Txt_def.Text    = string.Empty;
                wpf_header.Txt_ptbr.Text   = string.Empty;

                InsertQuestion(stk_items, Model.Voc);
            }
        }
Пример #17
0
        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);
        }
Пример #19
0
        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);
        }
Пример #20
0
 private void Start()
 {
     questController = FindObjectOfType <QuestControl>();
     isDead          = false;
     StartCoroutine("xAxisSubtractionByTime");
 }
Пример #21
0
        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);
        }
 private void LoadRequirements()
 {
     QuestControl.LoadCrossData(Model.Spell);
 }
Пример #23
0
        public static Button Insert_Bulk(Grid parent, IQuestWpfHeader header)
        {
            var btn = new Button();

            btn.VerticalAlignment = VerticalAlignment.Center;
            btn.Margin            = new Thickness(1, 0, 1, 0);
            Get(btn, 1, 1, parent, "Insert");

            btn.Click += (source, e) =>
            {
                var watcher = new Stopwatch();
                watcher.Start();

                var lines = header.Txt_bulk_insert.Text.Replace("\r", "").Split('\n');

                header.Txt_bulk_insert.Text = "// format:  words;answer";

                var successful = new List <bool>();

                var inserts = new List <string>();
                var imp     = (Importance)header.Cob_bulk_imp.SelectedIndex;

                foreach (var line in lines)
                {
                    if (line.StartsWith("//") || line.StartsWith("Insert failed") || line.IsEmpty())
                    {
                        continue;
                    }

                    //if (line.Count(x => x == '1') != 1)
                    //{
                    //    successful.Add(false);
                    //    header.Txt_bulk_insert.Text += "\nInsert failed (must has 1 ';'): " + line;
                    //    continue;
                    //}

                    var parts = line.Split(';');

                    if (parts.Count() != 2 && !(header is SpellWpfController))
                    {
                        successful.Add(false);
                        header.Txt_bulk_insert.Text += "\nInsert failed (must has 2 parts): " + line;
                        continue;
                    }

                    var part1 = parts[0];
                    var part2 = parts[1];

                    if (header is VocWpfController)
                    {
                        if (!part1.IsLettersOnly() || !part2.IsLettersOnly())
                        {
                            successful.Add(false);
                            header.Txt_bulk_insert.Text += "\nInsert failed (parts must have only letters): " + line;
                            continue;
                        }
                    }

                    var vm = new QuestVM();

                    if (header is VocWpfHeader)
                    {
                        vm = new VocVM(part1, part2, "", "", imp, true);
                    }
                    if (header is PronWpfHeader)
                    {
                        vm = new PronVM(part1, part2, imp, true);
                    }
                    if (header is SpellWpfHeader)
                    {
                        vm = new SpellVM(part1, imp, true);
                    }

                    if (QuestControl.Insert(vm))
                    {
                        SuccessfulInserted(header, successful);
                    }
                    else
                    {
                        FailedInsert(header, successful, line);
                    }
                }
                Footer.Log("Of a total of " + successful.Count + " attempts, " +
                           successful.Where(x => x).Count() + " were inserted, while " +
                           successful.Where(x => !x).Count() + " failed. Time spent: " +
                           Math.Round(watcher.Elapsed.TotalSeconds, 2) + " seconds.");
            };

            return(btn);
        }
        private static void UpdateQuestionFromLastAttempt(int idQuestion, Model type)
        {
            var quest = QuestControl.Get(type).First(c => c.Id == idQuestion);

            quest.LoadCrossData();
        }
Пример #25
0
 private void LoadRequirements()
 {
     WordApp = new Microsoft.Office.Interop.Word.Application();
     QuestControl.LoadCrossData(Model.Voc);
 }