public WordEventInfo(Word word, WordEvent wordEvent, WordState wordState, DateTime lastStateChange) { this.word = word; this.wordEvent = wordEvent; this.wordState = wordState; this.lastStateChange = lastStateChange; }
public void MarkTranslation(WordEventType eventType, string translation) { Contract.Assert(eventType != WordEventType.Added); Contract.Assert(Events.Count > 0); WordEvent wordEvent = new WordEvent(DateTime.UtcNow, eventType, translation); AddEvent(wordEvent); }
public void Mark(WordEventType eventType) { Contract.Assert(eventType != WordEventType.Added || Events.Count == 0); Contract.Assert(eventType == WordEventType.Added || Events.Count > 0); WordEvent wordEvent = new WordEvent(DateTime.UtcNow, eventType); AddEvent(wordEvent); }
private static int CompareEventDates(WordEvent e1, WordEvent e2) { if (e1.EventType == WordEventType.Added && e2.EventType != WordEventType.Added) { return -1; } if (e1.EventType != WordEventType.Added && e2.EventType == WordEventType.Added) { return 1; } return e1.EventDate.CompareTo(e2.EventDate); }
private bool EventsOverllap(WordEvent oldEvent, WordEvent newEvent) { if (oldEvent.EventType == WordEventType.Added) { return(newEvent.EventDate < oldEvent.EventDate); } if (oldEvent.Translation != newEvent.Translation) { return(false); } return(newEvent.EventDate.AddMinutes(-5) < oldEvent.EventDate); }
private void AddEvent(WordEvent wordEvent) { List <WordEvent> cleanEvents = Events.Where(e => !EventsOverllap(e, wordEvent)).ToList(); events.Clear(); events.AddRange(cleanEvents); if (wordEvent.EventType != WordEventType.Added && Events.Count == 0) { Events.Add(new WordEvent(wordEvent.EventDate, WordEventType.Added)); } Events.Add(wordEvent); }
public void FilterTranslationEvents() { ArticleParser parser = new ArticleParser(); WordArticle article = parser.Parse(name, description); HashSet <string> translations = new HashSet <string>(article.GetAllTranslations()); for (int i = 0; i < Events.Count;) { WordEvent wordEvent = events[i]; if (wordEvent.Translation == null || translations.Contains(wordEvent.Translation)) { i++; } else { events.RemoveAt(i); } } }
private static WordEventInfo CreateEventInfo(Word word, WordEventInfo prevEventInfo, WordEvent wordEvent) { if (prevEventInfo == null || wordEvent.EventType != WordEventType.Remembered) { return(new WordEventInfo(word, wordEvent, WordState.Studied, wordEvent.EventDate)); } TimeSpan timeSinceLastStateChange = wordEvent.EventDate - prevEventInfo.LastStateChange; if (prevEventInfo.WordState == WordState.Studied && timeSinceLastStateChange >= WordInfo.TimeToMarkRepeated) { return(new WordEventInfo(word, wordEvent, WordState.Repeated, wordEvent.EventDate)); } if (prevEventInfo.WordState == WordState.Repeated && timeSinceLastStateChange >= WordInfo.TimeToMarkLearned) { return(new WordEventInfo(word, wordEvent, WordState.Learned, wordEvent.EventDate)); } if (prevEventInfo.WordState == WordState.Learned && timeSinceLastStateChange >= WordInfo.TimeToMarkVerified) { return(new WordEventInfo(word, wordEvent, WordState.Verified, wordEvent.EventDate)); } return(new WordEventInfo(word, wordEvent, prevEventInfo.WordState, prevEventInfo.LastStateChange)); }
private static WordEventInfo CreateEventInfo(Word word, WordEventInfo prevEventInfo, WordEvent wordEvent) { if (prevEventInfo == null || wordEvent.EventType != WordEventType.Remembered) { return new WordEventInfo(word, wordEvent, WordState.Studied, wordEvent.EventDate); } TimeSpan timeSinceLastStateChange = wordEvent.EventDate - prevEventInfo.LastStateChange; if (prevEventInfo.WordState == WordState.Studied && timeSinceLastStateChange >= WordInfo.TimeToMarkRepeated) { return new WordEventInfo(word, wordEvent, WordState.Repeated, wordEvent.EventDate); } if (prevEventInfo.WordState == WordState.Repeated && timeSinceLastStateChange >= WordInfo.TimeToMarkLearned) { return new WordEventInfo(word, wordEvent, WordState.Learned, wordEvent.EventDate); } if (prevEventInfo.WordState == WordState.Learned && timeSinceLastStateChange >= WordInfo.TimeToMarkVerified) { return new WordEventInfo(word, wordEvent, WordState.Verified, wordEvent.EventDate); } return new WordEventInfo(word, wordEvent, prevEventInfo.WordState, prevEventInfo.LastStateChange); }
private static void NormalizeEventsOrder(List<WordEvent> events) { if (events.Count == 0) { return; } events.Sort(CompareEventDates); WordEvent firstEvent = events[0]; if (firstEvent.EventType != WordEventType.Added) { firstEvent = new WordEvent(firstEvent.EventDate, WordEventType.Added); events.Insert(0, firstEvent); } WordEvent secondEvent = events.Count > 1 ? events[1] : null; if (secondEvent != null && secondEvent.EventDate < firstEvent.EventDate) { firstEvent = new WordEvent(secondEvent.EventDate, firstEvent.EventType); events[0] = firstEvent; } }
private static WordEventXml ConvertToXml(WordEvent wordEvent) { var wordEventXml = new WordEventXml(); wordEventXml.EventDate = wordEvent.EventDate; wordEventXml.EventType = ConvertToXml(wordEvent.EventType); wordEventXml.Translation = wordEvent.Translation; return wordEventXml; }
private bool EventsOverllap(WordEvent oldEvent, WordEvent newEvent) { if (oldEvent.EventType == WordEventType.Added) { return newEvent.EventDate < oldEvent.EventDate; } if (oldEvent.Translation != newEvent.Translation) { return false; } return newEvent.EventDate.AddMinutes(-5) < oldEvent.EventDate; }
private void AddEvent(WordEvent wordEvent) { List<WordEvent> cleanEvents = Events.Where(e => !EventsOverllap(e, wordEvent)).ToList(); events.Clear(); events.AddRange(cleanEvents); if (wordEvent.EventType != WordEventType.Added && Events.Count == 0) { Events.Add(new WordEvent(wordEvent.EventDate, WordEventType.Added)); } Events.Add(wordEvent); }