예제 #1
0
 public WordEventInfo(Word word, WordEvent wordEvent, WordState wordState, DateTime lastStateChange)
 {
     this.word            = word;
     this.wordEvent       = wordEvent;
     this.wordState       = wordState;
     this.lastStateChange = lastStateChange;
 }
예제 #2
0
 public WordEventInfo(Word word, WordEvent wordEvent, WordState wordState, DateTime lastStateChange)
 {
     this.word = word;
     this.wordEvent = wordEvent;
     this.wordState = wordState;
     this.lastStateChange = lastStateChange;
 }
예제 #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);
        }
예제 #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);
        }
예제 #5
0
 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);
 }
예제 #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);
 }
예제 #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);
        }
예제 #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);
                }
            }
        }
예제 #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));
        }
예제 #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);
        }
예제 #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;
            }
        }
예제 #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;
        }
예제 #13
0
파일: Word.cs 프로젝트: yu-kopylov/cramtool
        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);
        }
예제 #14
0
파일: Word.cs 프로젝트: yu-kopylov/cramtool
 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;
 }
예제 #15
0
파일: Word.cs 프로젝트: yu-kopylov/cramtool
        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);
        }
예제 #16
0
파일: Word.cs 프로젝트: yu-kopylov/cramtool
        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);
        }