public void AddIfNeed(KnowledgeDataType dataType, long dataId) { if (IsSupportType(dataType)) { Ids.Add(dataId); } }
public static SpeakerDataType GetSpeakerType(KnowledgeDataType knowledgeDataType) { if (knowledgeDataType == KnowledgeDataType.WordTranslation) { return(SpeakerDataType.Word); } return(SpeakerDataType.Sentence); }
private static string GetHtml(ControllerContext controllerContext, KnowledgeDataType knowledgeDataType, List <SourceWithTranslation> items) { return(OurHtmlHelper.RenderRazorViewToString(controllerContext, "PartialKnowledgeItems", new Tuple <KnowledgeDataType, List <SourceWithTranslation> >( knowledgeDataType, items))); }
private void WriteShuffleWordsToResult(int count, List <GeneratedKnowledgeItem> result) { const KnowledgeDataType DATA_TYPE = KnowledgeDataType.WordTranslation; List <long> ids = Adapter.ExecuteStoredProcedure("get_shuffle_words", fields => (long)fields[0], _userId, (int)DATA_TYPE, _mainLanguageId, _translationLanguageId, count); WriteDataToResult(DATA_TYPE, result, ids); }
public SourceWithTranslation Find(KnowledgeDataType dataType, long dataId) { if (!IsSupportType(dataType)) { return(null); } SourceWithTranslation result; return(_sourceWithTranslations.TryGetValue(dataId, out result) ? result : null); }
private static void WriteDataToResult(KnowledgeDataType dataType, List <GeneratedKnowledgeItem> result, IEnumerable <long> ids) { if (ids != null) { result.AddRange(ids.Select(e => new GeneratedKnowledgeItem { DataId = e, DataType = dataType })); } }
private int WriteShuffledSentencesToResult(KnowledgeDataType dataType, SentenceType sentenceType, int count, List <GeneratedKnowledgeItem> result) { List <long> ids = Adapter.ExecuteStoredProcedure("get_shuffle_sentences", fields => (long)fields[0], _userId, (int)dataType, (int)sentenceType, _mainLanguageId, _translationLanguageId, count); WriteDataToResult(dataType, result, ids); return(ids != null ? ids.Count : 0); }
private static IEnumerable <GeneratedKnowledgeItem> GetGeneratedItems(KnowledgeDataType dataType, Dictionary <KnowledgeDataType, List <GeneratedKnowledgeItem> > items) { List <GeneratedKnowledgeItem> generatedItems; if (!items.TryGetValue(dataType, out generatedItems)) { generatedItems = new List <GeneratedKnowledgeItem>(); } return(generatedItems); }
public GroupModel(GroupForUser group, SpeakerDataType speakerDataType, KnowledgeDataType knowledgeDataType, GroupModelOptions options, UserLanguages userLanguages, List <SourceWithTranslation> groupElemsWithTranslations) : base(userLanguages, groupElemsWithTranslations) { SpeakerDataType = speakerDataType; KnowledgeDataType = knowledgeDataType; Id = group.Id; GroupName = group.Name; _options = options; }
public Dictionary <KnowledgeDataType, List <GeneratedKnowledgeItem> > Generate( Dictionary <KnowledgeDataType, int> counts) { var sourceItems = new List <GeneratedKnowledgeItem>(); int countWords = counts[KnowledgeDataType.WordTranslation]; WriteShuffleWordsToResult(countWords, sourceItems); int countPhrases = counts[KnowledgeDataType.PhraseTranslation]; WriteShuffledSentencesToResult(KnowledgeDataType.PhraseTranslation, SentenceType.FromGroup, countPhrases, sourceItems); int countSentences = counts[KnowledgeDataType.SentenceTranslation]; int countAddedSentences = WriteShuffledSentencesToResult(KnowledgeDataType.SentenceTranslation, SentenceType.Separate, countSentences, sourceItems); if (countAddedSentences < countSentences) { //добавили меньше, чем нужно - попробуем добрать из примеров предложений WriteShuffledSentencesToResult(KnowledgeDataType.SentenceTranslation, SentenceType.ComparisonExample, countSentences - countAddedSentences, sourceItems); } var knowledgesConverter = new KnowledgesParser(); knowledgesConverter.FillItemsParsedData(_mainLanguageId, _translationLanguageId, sourceItems); var result = new Dictionary <KnowledgeDataType, List <GeneratedKnowledgeItem> >(); foreach (GeneratedKnowledgeItem sourceItem in sourceItems) { KnowledgeDataType dataType = sourceItem.DataType; List <GeneratedKnowledgeItem> items; if (!result.TryGetValue(dataType, out items)) { items = new List <GeneratedKnowledgeItem>(); result.Add(dataType, items); } items.Add(sourceItem); } return(result); }
/// <summary> /// Возвращает идентификаторы, которые есть у пользователя в знаниях /// </summary> /// <param name="ids">идентификаторы, для которых нужно определить существование данных</param> /// <param name="dataType">тип данных, для которых переданы идентификаторы</param> /// <returns>идентификаторы данных, которые есть у пользователя в знаниях</returns> public List <long> GetExistenceIds(List <long> ids, KnowledgeDataType dataType) { DateTime minDate = GetDefaultDeletedDate(); var parsedDataType = (int)dataType; List <long> result = Adapter.ReadByContext(c => { return (c.UserKnowledge.Where( e => e.UserId == _userId && e.LanguageId == _languageId && e.DataType == parsedDataType && e.DataId != null && ids.Contains((long)e.DataId) && e.DeletedDate == minDate).Select( e => (long)e.DataId).ToList()); }, new List <long>(0)); return(result); }
public JsonResult GetExistenceIds(long userId, List <long> ids, KnowledgeDataType dataType) { /* List<long> ids = new List<long>(); * KnowledgeDataType dataType = KnowledgeDataType.SentenceTranslation;*/ List <long> parsedIds = ids != null?ids.Where(IdValidator.IsValid).ToList() : new List <long>(0); if (IdValidator.IsInvalid(userId) || EnumerableValidator.IsEmpty(parsedIds) || EnumValidator.IsInvalid(dataType)) { return(JsonResultHelper.Error(INVALID_DATA)); } IUserKnowledgeQuery userKnowledgeQuery = CreateUserKnowledgeQuery(userId); List <long> existenceIds = userKnowledgeQuery.GetExistenceIds(parsedIds, dataType); return(JsonResultHelper.GetUnlimitedJsonResult(existenceIds)); }
private static string GetImageUrl(HttpRequestBase request, long id, KnowledgeDataType dataType) { string controllerName; switch (dataType) { case KnowledgeDataType.WordTranslation: controllerName = RouteConfig.GROUP_WORD_CONTROLLER; break; case KnowledgeDataType.SentenceTranslation: controllerName = RouteConfig.GROUP_SENTENCE_CONTROLLER; break; default: controllerName = null; break; } return(controllerName != null ? UrlBuilder.GetImageUrlById(request, controllerName, id.ToString(CultureInfo.InvariantCulture)) : null); }
private bool IsSupportType(KnowledgeDataType dataType) { return(_types.Contains(dataType)); }
private static Tuple <string, string> GetTuple(KnowledgeDataType knowledgeDataType) { return(_headers.ContainsKey(knowledgeDataType) ? _headers[knowledgeDataType] : null); }
public static string GetHeader(KnowledgeDataType knowledgeDataType) { return(GeneratedKnowledgeDownloader.GetHeader(knowledgeDataType)); }
//TODO: создавать этот класс с помощью IoCModule public UserRepetitionKnowledgeQuery(long userId, long languageId, KnowledgeDataType dataType) { _userId = userId; _languageId = languageId; _dataType = dataType; }
public static string GetTableHeader(KnowledgeDataType knowledgeDataType) { Tuple <string, string> tuple = GetTuple(knowledgeDataType); return(tuple != null ? tuple.Item2 : null); }