private List <UserRepetitionIntervalItem> ConvertToItems(long sourceLanguageId, long translationLanguageId, IEnumerable <Tuple <UserKnowledge, UserRepetitionInterval> > joinedData, DateTime unknownNextTimeToShow) { var userKnowledges = new List <UserKnowledge>(); var repetitionsByItemIds = new Dictionary <long, UserRepetitionInterval>(); foreach (var joinedRow in joinedData) { UserKnowledge uk = joinedRow.Item1; UserRepetitionInterval uri = joinedRow.Item2; userKnowledges.Add(uk); repetitionsByItemIds.Add(uk.Id, uri); } List <UserKnowledgeItem> items = _userKnowledgeQuery.ConvertEntitiesToItems(sourceLanguageId, translationLanguageId, userKnowledges); var innerResult = new List <UserRepetitionIntervalItem>(); foreach (UserKnowledgeItem userKnowledgeItem in items) { long id = userKnowledgeItem.Id; UserRepetitionInterval repetitionItem = repetitionsByItemIds[id]; var item = new UserRepetitionIntervalItem(repetitionItem, userKnowledgeItem, unknownNextTimeToShow); innerResult.Add(item); } return(innerResult); }
internal UserRepetitionIntervalItem(UserRepetitionInterval repetitionInterval, UserKnowledgeItem data, DateTime unknownNextTimeToShow) { if (repetitionInterval != null) { SourceType = (KnowledgeSourceType)repetitionInterval.SourceType; NextTimeToShow = repetitionInterval.NextTimeShow; } else { NextTimeToShow = unknownNextTimeToShow; } DataId = data.DataId; DataType = data.DataType; Data = data; }
/// <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); }
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); }
private Tuple <UserKnowledge, UserRepetitionInterval> ConvertRow(RepresentationArea area, UserRepetitionInterval userRepetitionInterval) { DateTime minDateTime = new DateTime().GetDbDateTime(); var userKnowledge = new UserKnowledge { Id = area.Id, DataId = area.WordTranslationId, DataType = _dataType, Data = null, UserId = _userId, LanguageId = _languageId, CreationDate = minDateTime, DeletedDate = minDateTime, Hash = null, Tip = null, SystemData = null, Status = (int)KnowledgeStatus.Unknown }; return(new Tuple <UserKnowledge, UserRepetitionInterval>(userKnowledge, userRepetitionInterval)); }