From 1dc5480ecb136f179fa89f12081e0f447b76dad7 Mon Sep 17 00:00:00 2001 From: Daniel Lerch <36048059+daniel-lerch@users.noreply.github.com> Date: Tue, 11 Jul 2023 23:51:56 +0200 Subject: [PATCH] [WIP] Experiments --- src/Vocup.Core/Models/BookPracticeState.cs | 34 ++++++++++++++++++++ src/Vocup.Core/Models/Word.cs | 6 ++++ src/Vocup.Core/Models/WordPracticeState.cs | 25 ++++++++++++++ src/Vocup/Models/VocabularyWordController.cs | 2 +- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/Vocup.Core/Models/BookPracticeState.cs create mode 100644 src/Vocup.Core/Models/WordPracticeState.cs diff --git a/src/Vocup.Core/Models/BookPracticeState.cs b/src/Vocup.Core/Models/BookPracticeState.cs new file mode 100644 index 0000000..875a134 --- /dev/null +++ b/src/Vocup.Core/Models/BookPracticeState.cs @@ -0,0 +1,34 @@ +using DynamicData; +using DynamicData.Binding; +using ReactiveUI; +using ReactiveUI.Fody.Helpers; +using System; +using Vocup.Settings; + +namespace Vocup.Models; + +public class BookPracticeState : ReactiveObject +{ + private readonly IObservableList practiceStates; + + public BookPracticeState(Book book, IVocupSettings settings) + { + book.Words.ToObservableChangeSet() + .AutoRefresh(word => word.ForeignLanguagePracticeState) + .AutoRefresh(word => word.MotherTonguePracticeState) + .AutoRefreshOnObservable(_ => book.WhenAnyValue(x => x.PracticeMode)) + .AutoRefreshOnObservable(_ => settings.WhenAnyValue(x => x.MaxPracticeCount)) + .Transform(word => book.PracticeMode != PracticeMode.AskForMotherTongue ? word.ForeignLanguagePracticeState : word.MotherTonguePracticeState) + .Transform(practiceStateNumber => PracticeStateHelper.Parse(practiceStateNumber, settings.MaxPracticeCount)) + .BindToObservableList(out practiceStates) + .Subscribe(); + } + + public WordPracticeState this[Word word] => null; + + [ObservableAsProperty] public int Unpracticed { get; } + [ObservableAsProperty] public int WronglyPracticed { get; } + [ObservableAsProperty] public int CorrectlyPracticed { get; } + [ObservableAsProperty] public int FullyPracticed { get; } + [ObservableAsProperty] public int NotFullyPracticed { get; } +} diff --git a/src/Vocup.Core/Models/Word.cs b/src/Vocup.Core/Models/Word.cs index bbd6f25..e61aa83 100644 --- a/src/Vocup.Core/Models/Word.cs +++ b/src/Vocup.Core/Models/Word.cs @@ -75,7 +75,13 @@ public override int GetHashCode() return HashCode.Combine(CreationDate, MotherTongue, ForeignLanguage); } + /// + /// A comma separated list of mother tongue synonyms + /// public string MotherTongueCombined => motherTongueCombined.Value; + /// + /// A comma separated list of foreign language synonyms + /// public string ForeignLanguageCombined => foreignLanguageCombined.Value; public int MotherTonguePracticeState => motherTonguePracticeState.Value; public int ForeignLanguagePracticeState => foreignLanguagePracticeState.Value; diff --git a/src/Vocup.Core/Models/WordPracticeState.cs b/src/Vocup.Core/Models/WordPracticeState.cs new file mode 100644 index 0000000..e7159c1 --- /dev/null +++ b/src/Vocup.Core/Models/WordPracticeState.cs @@ -0,0 +1,25 @@ +using ReactiveUI; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reactive.Linq; +using Vocup.Settings; + +namespace Vocup.Models; + +public class WordPracticeState : ReactiveObject +{ + public WordPracticeState(Book book, Word word, IVocupSettings settings) + { + book.WhenAnyValue(x => x.PracticeMode) + .Select(practiceMode => practiceMode != PracticeMode.AskForMotherTongue ? word.ForeignLanguage : word.MotherTongue); + + //PracticeState = Reactive(() => + //{ + // ObservableCollection synonyms = book.PracticeMode != PracticeMode.AskForMotherTongue ? word.ForeignLanguage : word.MotherTongue; + // int practiceStateNumber = synonyms.MaxBy(synonym => synonym.PracticeState)?.PracticeState ?? 0; + // return PracticeStateHelper.Parse(practiceStateNumber, settings.MaxPracticeCount); + //}); + } + + PracticeState PracticeState { get; } +} diff --git a/src/Vocup/Models/VocabularyWordController.cs b/src/Vocup/Models/VocabularyWordController.cs index 77edbbd..3dc15e7 100644 --- a/src/Vocup/Models/VocabularyWordController.cs +++ b/src/Vocup/Models/VocabularyWordController.cs @@ -17,7 +17,7 @@ public VocabularyWordController(Word vocabularyWord) praticeDateColumn = ListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(ListViewItem, "")); VocabularyWord = vocabularyWord; - VocabularyWord.PropertyChanged += (a0, a1) => UpdateUI(); + VocabularyWord.PropertyChanged += (_, _) => UpdateUI(); UpdateUI(); }