public EditPracticeItem(PracticeItem item) { InitializeComponent(); this.item = item; phrase.Text = item.Phrase; translation.Text = item.Translation; }
public static PracticeItem Show(PracticeItem item) { var dialog = new Dialogs.EditPracticeItem(item); if (dialog.ShowDialog() == DialogResult.OK) { var existed = DataStore.Database.UpdateWordListEntry( item.SetID, item.Phrase, item.Translation, dialog.Phrase, dialog.Translation); // TODO: This should possibly be made into an actual message, since it would go against // the user's expectations. However, explaining the reason why it didn't work would // be equally confusing. // A third (and perhaps best) option would be to modify the item based on its unique ID // (which word list entries do actually have, even though they are not currently // retrieved by SqliteWordList.) if (!existed) { ProgramLog.Default.AddMessage(LogType.Debug, "Attempting to update word list entry that no longer exists: {0}, {1}", item.Phrase, item.Translation); } return(new PracticeItem(item.SetID, dialog.Phrase, dialog.Translation)); } return(null); }
// Call this from inside a transaction. // The command should return the results as such: // SetID, Phrase, Translation void GetResults(DbCommand command, ICollection <PracticeItem> output) { using (var reader = command.ExecuteReader()) { if (reader.FieldCount != 3) { throw new StrongTypingException("Practice query should only return 3 columns"); } while (reader.Read()) { if (reader.IsDBNull(0) || reader.IsDBNull(1) || reader.IsDBNull(2)) { throw new StrongTypingException("Practice query returned a null value in one of the columns"); } var item = new PracticeItem( reader.GetInt64(0), reader.GetString(1), reader.GetString(2)); GetItemPracticeHistory(item); output.Add(item); } } }
public EditPracticeItem(PracticeItem item) { InitializeComponent(); this.item = item; phrase.Text = item.Phrase; translation.Text = item.Translation; }
// The user accepts that they are pathetic and worthless and will never amount to anything, // and continues their miserable existence. void AcceptFailure(PracticeItem item, string guess) { ReportGuess(item, false); currentRound.Add(new Attempt { Item = item, Guess = guess, Correct = false, Swapped = Swap }); NextPhrase(); }
void Correct(PracticeItem item, string guess) { ReportGuess(item, true); currentRound.Add(new Attempt { Correct = true, Guess = guess, Item = item, Swapped = Swap }); score++; NextPhrase(); }
public void ReplaceItem(PracticeItem existing, PracticeItem replacement) { var items = queue.AllItems; for (int i = 0; i < items.Count; i++) { if (items[i] == existing) { items[i] = replacement; } } }
private async Task CheckForNewPeriod() { var nextPeriodStartDate = this.CurrentPeriodRecord.CycleStartDate.AddDays(84); if (nextPeriodStartDate.Date <= this.CurrentDate.Date) { // create new cycle... this.CurrentPeriodRecord = new PracticeItem { CycleStartDate = nextPeriodStartDate }; await this.PracticeDataViewModel.PracticeItemDataStore.AddItemAsync(this.CurrentPeriodRecord); } }
public List <PracticeItem> GetItems(IList <ListSearchResult> items) { if (items.Count == 0) { return(new List <PracticeItem>()); } var results = new List <PracticeItem>(); using (Connection.BeginTransaction()) { var query = new StringBuilder( @"SELECT SetID, Phrase, Translation FROM VocabItems WHERE SetID IN (" ); bool hasListItems = false; foreach (var r in items.Where(r => !r.HasItem)) { query.Append(r.SetID).Append(", "); hasListItems = true; } if (hasListItems) { // Remove the final comma query.Length -= 2; query.Append(@") ORDER BY SetID, ListPosition;"); using (var cmd = Connection.CreateCommand()) { cmd.CommandText = query.ToString(); GetResults(cmd, results); } } foreach (var r in items) { if (!r.HasItem) { continue; } var item = new PracticeItem(r.SetID, r.Phrase, r.Translation); GetItemPracticeHistory(item); results.Add(item); } } return(results); }
public PracticeHistoryViewModel() { this.Title = "Practice History"; this.CurrentPeriodRecord = this.PracticeDataViewModel.PracticeItems.OrderByDescending(i => i.CycleStartDate).First(); this.CurrentDate = DateTime.Today.Date >= this.PeriodStartDate.Date ? DateTime.Today.Date : this.PeriodStartDate.Date; _ = this.CheckForNewPeriod(); this.PeriodStartDate = this.CurrentPeriodRecord.CycleStartDate; for (var colorIndex = 0; colorIndex < 84; colorIndex++) { this.DoneCollection.Add(this.CurrentPeriodRecord.SerializedRecord[colorIndex] == '1' ? this.Done : this.NotDone); } this.DoneSwitchToggledCommand = new Command(this.DoneSwitchToggled); }
internal void SetPracticeItem(PracticeItem practiceItem) { this.Reset(); this.OdaiText.Value = practiceItem?.OdaiText; this.YomiText.Value = practiceItem?.YomiText; var practiceKeyInfoViewModels = (practiceItem?.ExpectedKeysText ?? string.Empty) .ToUpperInvariant() .Select((expectedKey, index) => new PracticeKeyInfoViewModel(this.AppService, expectedKey, index == 0).AddTo(this.practiceKeyInfoViewModelsDisposable)) .ToList(); var firstPracticeKeyInfoViewModel = practiceKeyInfoViewModels.FirstOrDefault(); this.PracticeKeyInfoViewModels.AddRangeOnScheduler(practiceKeyInfoViewModels); this.SetCurrentBy(firstPracticeKeyInfoViewModel); this.startDateTime = DateTime.Now; }
void GetItemPracticeHistory(PracticeItem item) { if (getHistory == null) { getHistory = CreateCommand() .AddParam(ref getHistory_SetID) .AddParam(ref getHistory_Phrase) .AddParam(ref getHistory_Translation); getHistory.CommandText = "SELECT Created, Result FROM PracticeHistory WHERE SetID = ? AND Phrase = ? AND Translation = ? ORDER BY Created ASC"; } getHistory_SetID.Value = item.SetID; getHistory_Phrase.Value = item.Phrase; getHistory_Translation.Value = item.Translation; using (var reader = getHistory.ExecuteReader()) while (reader.Read()) { item.History.Add(reader.GetDateTime(0), reader.GetBoolean(1)); } }
public async Task LoadPracticeItemsAsync() { this.PracticeItems.Clear(); try { using (var file = File.OpenText(AppContextService.Filepath)) { var json = await file.ReadToEndAsync(); var loadedItems = JsonConvert.DeserializeObject <PracticeItem[]>(json)?.ToList(); //this.PracticeItems.AddRange(loadedItems); loadedItems?.ForEach(this.PracticeItems.Add); } } catch (Exception ex) { DebugLog.Print($"{ex}"); var defaultPracticeItems = PracticeItem.CreateDefaultPracticeItems().ToList(); await AppContextService.SavePracticeItemsAsync(defaultPracticeItems); //this.PracticeItems.AddRange(defaultPracticeItems); defaultPracticeItems.ForEach(this.PracticeItems.Add); } }
public static PracticeItem Show(PracticeItem item) { var dialog = new Dialogs.EditPracticeItem(item); if (dialog.ShowDialog() == DialogResult.OK) { var existed = DataStore.Database.UpdateWordListEntry( item.SetID, item.Phrase, item.Translation, dialog.Phrase, dialog.Translation); // TODO: This should possibly be made into an actual message, since it would go against // the user's expectations. However, explaining the reason why it didn't work would // be equally confusing. // A third (and perhaps best) option would be to modify the item based on its unique ID // (which word list entries do actually have, even though they are not currently // retrieved by SqliteWordList.) if (!existed) ProgramLog.Default.AddMessage(LogType.Debug, "Attempting to update word list entry that no longer exists: {0}, {1}", item.Phrase, item.Translation); return new PracticeItem(item.SetID, dialog.Phrase, dialog.Translation); } return null; }
private List <PracticeItem> GetPracticeItems() { using (var reader = SelectReader(@" SELECT vi.Phrase, vi.Translation, vi.SetID, ph.Result, ph.Created FROM VocabItems vi LEFT JOIN PracticeHistory ph ON ph.SetID = vi.SetID AND ph.Phrase = vi.Phrase AND ph.Translation = vi.Translation ORDER BY vi.SetID, vi.Phrase, vi.Translation, ph.Created" )) { var items = new List <PracticeItem>(); PracticeItem item = null; while (reader.Read()) { string phrase = reader.GetString(0); string translation = reader.GetString(1); long setID = reader.GetInt64(2); bool? correct = reader.IsDBNull(3) ? (bool?)null : reader.GetBoolean(3); DateTime?created = reader.IsDBNull(4) ? (DateTime?)null : reader.GetDateTime(4); if (item == null || item.Phrase != phrase || item.Translation != translation) { item = new PracticeItem(setID, phrase, translation, new PracticeHistory()); items.Add(item); } if (correct != null && created != null) { item.History.Add(created.Value, correct.Value); } } return(items); } }
public List<PracticeItem> GetItems(IList<ListSearchResult> items) { if (items.Count == 0) return new List<PracticeItem>(); var results = new List<PracticeItem>(); using (Connection.BeginTransaction()) { var query = new StringBuilder( @"SELECT SetID, Phrase, Translation FROM VocabItems WHERE SetID IN ("); bool hasListItems = false; foreach (var r in items.Where(r => !r.HasItem)) { query.Append(r.SetID).Append(", "); hasListItems = true; } if (hasListItems) { // Remove the final comma query.Length -= 2; query.Append(@") ORDER BY SetID, ListPosition;"); using (var cmd = Connection.CreateCommand()) { cmd.CommandText = query.ToString(); GetResults(cmd, results); } } foreach (var r in items) { if (!r.HasItem) continue; var item = new PracticeItem(r.SetID, r.Phrase, r.Translation); GetItemPracticeHistory(item); results.Add(item); } } return results; }
public void UpdateCurrentItem(PracticeItem newItem) { Source.ReplaceItem(CurrentItem, newItem); CurrentItem = newItem; }
public static string PercentageStats(this PracticeItem practiceItem) { return($"{practiceItem.SerializedRecord.Count(record => record == '1')}/{practiceItem.SerializedRecord.Length}"); }
private List<PracticeItem> GetPracticeItems() { using (var reader = SelectReader(@" SELECT vi.Phrase, vi.Translation, vi.SetID, ph.Result, ph.Created FROM VocabItems vi LEFT JOIN PracticeHistory ph ON ph.SetID = vi.SetID AND ph.Phrase = vi.Phrase AND ph.Translation = vi.Translation ORDER BY vi.SetID, vi.Phrase, vi.Translation, ph.Created")) { var items = new List<PracticeItem>(); PracticeItem item = null; while (reader.Read()) { string phrase = reader.GetString(0); string translation = reader.GetString(1); long setID = reader.GetInt64(2); bool? correct = reader.IsDBNull(3) ? (bool?)null : reader.GetBoolean(3); DateTime? created = reader.IsDBNull(4) ? (DateTime?)null : reader.GetDateTime(4); if (item == null || item.Phrase != phrase || item.Translation != translation) { item = new PracticeItem(setID, phrase, translation, new PracticeHistory()); items.Add(item); } if (correct != null && created != null) item.History.Add(created.Value, correct.Value); } return items; } }
public void ReplaceItem(PracticeItem existing, PracticeItem replacement) { var items = queue.AllItems; for (int i = 0; i < items.Count; i++) if (items[i] == existing) items[i] = replacement; }
// The user can override and say that they were actually right. void Override(PracticeItem item, string guess) { Correct(item, guess); }
public void MarkFailure(PracticeItem item) { }
static void ReportGuess(PracticeItem item, bool correct) { item.History.Add(DateTime.Now, correct); DataStore.Database.AddPracticeHistory(item.SetID, item.Phrase, item.Translation, correct); }
static void ReportGuess(PracticeItem item, bool correct) { item.History.Add(DateTime.Now, correct); DataStore.Database.AddPracticeHistory(item.SetID, item.Phrase, item.Translation, correct); }
void Correct(PracticeItem item, string guess) { ReportGuess(item, true); currentRound.Add(new Attempt { Correct = true, Guess = guess, Item = item, Swapped = Swap }); score++; NextPhrase(); }
// The user can override and say that they were actually right. void Override(PracticeItem item, string guess) { Correct(item, guess); }
public void MarkFailure(PracticeItem item) { }
public void MarkSuccess(PracticeItem item) { }
// The user accepts that they are pathetic and worthless and will never amount to anything, // and continues their miserable existence. void AcceptFailure(PracticeItem item, string guess) { ReportGuess(item, false); currentRound.Add(new Attempt { Item = item, Guess = guess, Correct = false, Swapped = Swap }); NextPhrase(); }
// Call this from inside a transaction. // The command should return the results as such: // SetID, Phrase, Translation void GetResults(DbCommand command, ICollection<PracticeItem> output) { using (var reader = command.ExecuteReader()) { if (reader.FieldCount != 3) throw new StrongTypingException("Practice query should only return 3 columns"); while (reader.Read()) { if (reader.IsDBNull(0) || reader.IsDBNull(1) || reader.IsDBNull(2)) throw new StrongTypingException("Practice query returned a null value in one of the columns"); var item = new PracticeItem( reader.GetInt64(0), reader.GetString(1), reader.GetString(2)); GetItemPracticeHistory(item); output.Add(item); } } }
void GetItemPracticeHistory(PracticeItem item) { if (getHistory == null) { getHistory = CreateCommand() .AddParam(ref getHistory_SetID) .AddParam(ref getHistory_Phrase) .AddParam(ref getHistory_Translation); getHistory.CommandText = "SELECT Created, Result FROM PracticeHistory WHERE SetID = ? AND Phrase = ? AND Translation = ? ORDER BY Created ASC"; } getHistory_SetID.Value = item.SetID; getHistory_Phrase.Value = item.Phrase; getHistory_Translation.Value = item.Translation; using (var reader = getHistory.ExecuteReader()) while (reader.Read()) item.History.Add(reader.GetDateTime(0), reader.GetBoolean(1)); }
public void UpdateCurrentItem(PracticeItem newItem) { Source.ReplaceItem(CurrentItem, newItem); CurrentItem = newItem; }
public void MarkSuccess(PracticeItem item) { }