Esempio n. 1
0
 public WordEventInfo(Word word, WordEvent wordEvent, WordState wordState, DateTime lastStateChange)
 {
     this.word            = word;
     this.wordEvent       = wordEvent;
     this.wordState       = wordState;
     this.lastStateChange = lastStateChange;
 }
Esempio n. 2
0
 public WordEventInfo(Word word, WordEvent wordEvent, WordState wordState, DateTime lastStateChange)
 {
     this.word = word;
     this.wordEvent = wordEvent;
     this.wordState = wordState;
     this.lastStateChange = lastStateChange;
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
 }
Esempio n. 6
0
 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);
 }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
                }
            }
        }
Esempio n. 9
0
        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));
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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;
            }
        }
Esempio n. 12
0
        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;
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
 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;
 }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }