Exemplo n.º 1
0
        private void AssertCalculate(KnowledgeMark mark, double ratio, TimeSpan minTime, TimeSpan maxTime)
        {
            TimeSpan result = _nextTimeCalculator.Calculate(mark, ratio);

            Assert.That(result, Is.GreaterThanOrEqualTo(minTime));
            Assert.That(result, Is.LessThanOrEqualTo(maxTime));
        }
        public JsonResult SetMark(long userId,
                                  UserLanguages userLanguages,
                                  KnowledgeMark mark,
                                  TrainerItem item,
                                  RepetitionType repetitionType = RepetitionType.All)
        {
            var itemDataType = (KnowledgeDataType)(item != null ? item.DataType : int.MinValue);

            if (IsInvalid(userId, userLanguages) || EnumValidator.IsInvalid(mark) || item == null ||
                IdValidator.IsInvalid(item.DataId) || EnumValidator.IsInvalid(itemDataType) ||
                EnumValidator.IsInvalid(repetitionType))
            {
                //TODO: писать сообщение
                return(JsonResultHelper.Error());
            }

            IUserRepetitionIntervalQuery userRepetitionIntervalQuery = CreateUserRepetitionIntervalQuery(userId,
                                                                                                         repetitionType);

            var repetitionInterval = new UserRepetitionIntervalItem
            {
                DataId = item.DataId, DataType = itemDataType, SourceType = KnowledgeSourceType
            };

            var trainerHelper = new TrainerHelper(userRepetitionIntervalQuery, userLanguages);

            return(trainerHelper.SetMark(Request, mark, repetitionInterval));
        }
        public JsonResult SetMark(long userId,
                                  GroupForUser group,
                                  UserLanguages userLanguages,
                                  KnowledgeMark mark,
                                  TrainerItem item)
        {
            long groupId = GetGroupId(group);

            return(SetMarkAndGetModel(userId, userLanguages, groupId, mark, item));
        }
Exemplo n.º 4
0
 private void AssertCalculate(KnowledgeMark mark,
                              TimeSpan minTimeLower,
                              TimeSpan minTimeUpper,
                              TimeSpan maxTimeLower,
                              TimeSpan maxTimeUpper)
 {
     AssertCalculate(mark, 0, minTimeLower, minTimeUpper);
     AssertCalculate(mark, 0.5, minTimeLower, maxTimeUpper);
     AssertCalculate(mark, 1, maxTimeLower, maxTimeUpper);
 }
        public JsonResult SetMark(long userId,
                                  UserLanguages userLanguages,
                                  string group,
                                  KnowledgeMark mark,
                                  TrainerItem item)
        {
            long representationId = GetRepresentationId(group);

            return(SetMarkAndGetModel(userId, userLanguages, representationId, mark, item));
        }
Exemplo n.º 6
0
        public JsonResult SetMark(HttpRequestBase request, KnowledgeMark mark,
                                  UserRepetitionIntervalItem repetitionInterval)
        {
            //выставляем оценку
            if (!_userRepetitionIntervalQuery.SetMark(repetitionInterval, mark))
            {
                return(JsonResultHelper.Error());
            }

            TrainerModel model = GetTrainerModel(request);

            return
                (JsonResultHelper.GetUnlimitedJsonResult(
                     new { sourceLanguageId = _userLanguages.From.Id, items = model.Items }));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Выставляет оценку данным
        /// </summary>
        /// <param name="intervalItem">данные</param>
        /// <param name="mark">оценка</param>
        /// <returns>true - оценку удалось поставить, false - оценку не удалось поставить</returns>
        public bool SetMark(UserRepetitionIntervalItem intervalItem, KnowledgeMark mark)
        {
            bool result         = false;
            var  parsedDataType = (int)intervalItem.DataType;

            Adapter.ActionByContext(c => {
                UserRepetitionInterval userRepetitionInterval =
                    c.UserRepetitionInterval.FirstOrDefault(
                        e =>
                        e.UserId == _userId && e.LanguageId == _languageId && e.DataId == intervalItem.DataId &&
                        e.DataType == parsedDataType);
                if (userRepetitionInterval == null)
                {
                    userRepetitionInterval = new UserRepetitionInterval {
                        UserId       = _userId,
                        LanguageId   = _languageId,
                        DataId       = intervalItem.DataId,
                        DataType     = parsedDataType,
                        NextTimeShow = new DateTime().GetDbDateTime(),
                    };
                    userRepetitionInterval.SourceType |= (int)intervalItem.SourceType;
                    c.UserRepetitionInterval.Add(userRepetitionInterval);
                }

                var parsedMark = (int)mark;

                SetNextByMark(userRepetitionInterval, mark);
                if (parsedMark != userRepetitionInterval.Mark)
                {
                    //оценка не совпадает - кол-во повторений для оценки сбрасываем
                    userRepetitionInterval.RepetitionMark = 0;
                }
                else
                {
                    //оценка совпала - кол-во повторений для оценки установить
                    userRepetitionInterval.RepetitionMark++;
                }
                userRepetitionInterval.Mark = parsedMark;
                userRepetitionInterval.RepetitionTotal++;

                int count = c.SaveChanges();
                result    = count == 1;
            });
            return(result);
        }
Exemplo n.º 8
0
        private void SetNextByMark(UserRepetitionInterval userRepetitionInterval, KnowledgeMark mark)
        {
            int    prevMark = userRepetitionInterval.Mark;
            double ratio    = 0;

            if (prevMark == ((int)mark))
            {
                //оценка таже самая - взять отношение
                ratio = userRepetitionInterval.RepetitionMark / (double)userRepetitionInterval.RepetitionTotal;

                /*if (mark == KnowledgeMark.VeryEasy && userRepetitionInterval.RepetitionMark > 10 && ratio <= 0.2) {
                 *  //пользователь помнит слово хорошо уже более 10 раз ответил верно
                 *  userRepetitionInterval.RepetitionTotal = Math.Round(userRepetitionInterval.RepetitionTotal * 0.9);
                 * }*/
            }

            TimeSpan repeatInterval = _nextTimeCalculator.Calculate(mark, ratio);

            userRepetitionInterval.NextTimeShow = DateTime.Now.Add(repeatInterval);
        }
Exemplo n.º 9
0
        public TimeSpan Calculate(KnowledgeMark mark, double ratio)
        {
            TimeSpan minDate;
            TimeSpan maxDate;

            TimeSpan repeatInterval;

            if (mark == KnowledgeMark.VeryEasy)
            {
                minDate = new TimeSpan(10, _random.Next(0, 3), _random.Next(0, 60), _random.Next(0, 60));
                maxDate = new TimeSpan(365, _random.Next(0, 3), _random.Next(0, 60), _random.Next(0, 60));
                int countDays = GetRepeatInterval(minDate.TotalDays, maxDate.TotalDays, ratio);
                repeatInterval = new TimeSpan(countDays, 0, 0, 0);
            }
            else if (mark == KnowledgeMark.Normal)
            {
                minDate = new TimeSpan(2, _random.Next(0, 3), _random.Next(0, 60), _random.Next(0, 60));
                maxDate = new TimeSpan(10, _random.Next(20, 23), _random.Next(50, 60), _random.Next(0, 60));
                int countHours = GetRepeatInterval(minDate.TotalHours, maxDate.TotalHours, ratio);
                repeatInterval = new TimeSpan(countHours, 0, 0);
            }
            else if (mark == KnowledgeMark.DontRemember)
            {
                minDate = new TimeSpan(0, _random.Next(10, 15), _random.Next(0, 60));
                maxDate = new TimeSpan(1, _random.Next(20, 23), _random.Next(50, 60), _random.Next(0, 60));
                int countMinutes = GetRepeatInterval(minDate.TotalMinutes, maxDate.TotalMinutes, ratio);
                repeatInterval = new TimeSpan(0, countMinutes, 0);
            }
            else
            {
                LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat(
                    "UserRepetitionIntervalQuery.SetNextByMark передан некорректная оценка {0}", mark);
                minDate = new TimeSpan(0, _random.Next(20, 30), _random.Next(0, 60));
                maxDate = new TimeSpan(0, _random.Next(50, 60), _random.Next(0, 60));
                int countSeconds = GetRepeatInterval(minDate.TotalSeconds, maxDate.TotalSeconds, ratio);
                repeatInterval = new TimeSpan(0, 0, countSeconds);
            }

            return(repeatInterval);
        }