예제 #1
0
        public PracticeModel(TopicModel topic)
            : base()
        {
            DataRowView grammar = AdoUtils.GetDataView(topic.RowView, Strings.TABLE_GRAMMAR)[0];

            CultureInfo nativeInfo = AdoUtils.GetCultureInfo(grammar, Strings.COL_NATIVE_LANG);
            if (nativeInfo != null)
                _nativeLang = nativeInfo.NativeName;

            CultureInfo targetInfo = AdoUtils.GetCultureInfo(grammar, Strings.COL_TARGET_LANG);
            if (targetInfo != null)
                _targetLang = targetInfo.NativeName;

            _showRuleText = (bool)grammar[Strings.COL_SHOWRULE];

            _state = PracticeState.Invalid;
            _examples = new Queue<DataRowView>();

            IList<DataRowView> list = new List<DataRowView>();
            AddTopic(list, topic.RowView);

            if ((bool)grammar[Strings.COL_SHUFFLE])
                ListUtils.Shuffle(list);

            foreach (DataRowView example in list)
                _examples.Enqueue(example);

            Next();
        }
예제 #2
0
        private void ComputeNextCardType(
            out PracticeState state,
            out bool lapsing)
        {
            int total = DueCount + LearnCount + NewCount;

            if (total == 0)
            {
                throw new InvalidOperationException("Card count exhausted");
            }

            int rnd = Random.Next(0, total);

            if (rnd < DueCount)
            {
                state = PracticeState.Due;
            }

            else if (rnd < DueCount + LearnCount)
            {
                state = PracticeState.Learning;
            }

            else
            {
                state = PracticeState.New;
            }

            if (LapseCount > 0 &&
                (state == PracticeState.Due ||
                 state == PracticeState.Learning))
            {
                int lapseTotal = DueCount + LearnCount;

                lapsing = Random.Next(0, lapseTotal) < LapseCount;

                if (lapsing)
                {
                    LapseCount--;
                }
            }
            else
            {
                lapsing = false;
            }
        }
예제 #3
0
        //
        // Misc helper

        public static Card MakeCard(
            CollectionConfig config,
            PracticeState state,
            int due       = -1,
            float eFactor = 2.5f,
            int interval  = 1,
            int reviews   = 0,
            int lapses    = 0)
        {
            return(new Card(config)
            {
                PracticeState = state,
                Due = due == -1 ? DateTime.Now.AddSeconds(60).ToUnixTimestamp() : due,
                EFactor = eFactor,
                Interval = interval,
                Reviews = reviews,
                Lapses = lapses
            });
        }
예제 #4
0
 public bool Equals(PracticeState other)
 {
     return(_value == other._value);
 }
예제 #5
0
        //
        // Core methods

        public override bool Equals(object obj)
        {
            PracticeState otherObj = (PracticeState)obj;

            return(otherObj._value == this._value);
        }
예제 #6
0
        public void Next()
        {
            if (_examples.Count > 0)
            {
                DataRowView previous = _current;
                _current = _examples.Dequeue();

                _state =  PracticeState.Question;
                _targetTextAnswer = PrepareAnswerTemplate((String)_current[Strings.COL_TARGET_TEXT]);

                NotifyPropertyChanged();

                if (previous == null || !previous[Strings.COL_RULE_ID].Equals(_current[Strings.COL_RULE_ID]))
                    if (_ruleTextChanged != null)
                        _ruleTextChanged(this, new EventArgs());
            }
        }
예제 #7
0
 public void Answer()
 {
     _state = PracticeState.Answer;
     _isAnswerCorrect = NormalizeString(TargetText) == NormalizeString(_targetTextAnswer);
     NotifyPropertyChanged();
 }
예제 #8
0
 public static bool IsValid(this PracticeState state)
 {
     return(state >= 0);
 }