Ejemplo n.º 1
0
        async Task ProcessFacts(List <Data.Model.TrendingTopic> trendingTopicsToAdd)
        {
            var trendingTopics = await _dwhRepository.GetAllAsync <TrendingTopic>();

            var geographies = await _dwhRepository.GetAllAsync <Geography>();

            var indexedTopics      = trendingTopics.ToDictionary(i => i.Name, i => i);
            var indexedGeographies = geographies.ToDictionary(i => i.Name, i => i);

            foreach (var trendingTopic in trendingTopicsToAdd)
            {
                var topic = new Topic
                {
                    DateId          = DateHelper.GetKeyFromDate(trendingTopic.Date),
                    GeographyId     = indexedGeographies[trendingTopic.Country].Id,
                    TrendingTopicId = indexedTopics[Sanitize(trendingTopic.Text)].Id
                };

                await _dwhRepository.AddFactAsync(topic);
            }
        }
Ejemplo n.º 2
0
        async Task ProcessFactTablesAsync(List <RAWMessage> messages)
        {
            var channels = await _dwhRepository.GetAllAsync <Channel>();

            var conversations = await _dwhRepository.GetAllAsync <ConversationTrack>();

            var languages = await _dwhRepository.GetAllAsync <Language>();

            var messageTypes = await _dwhRepository.GetAllAsync <MessageType>();

            var users = await _dwhRepository.GetAllAsync <User>();

            var words = await _dwhRepository.GetAllAsync <SingleWord>();

            var indexedChannels      = channels.ToDictionary(i => i.Name, i => i);
            var indexedConversations = conversations.ToDictionary(i => i.ConversationId, i => i);
            var indexedLanguages     = languages.ToDictionary(i => i.Name, i => i);
            var indexedMessageTypes  = messageTypes.ToDictionary(i => i.Name, i => i);
            var indexedUsers         = users.ToDictionary(i => i.UserId, i => i);
            var indexedWords         = words.ToDictionary(i => i.Text, i => i);

            foreach (var chat in messages)
            {
                // Get dimension values
                var channel           = GetChannelFrom(chat);
                var conversationTrack = GetConversationTrackFrom(chat);
                var sourceLanguage    = GetSourceLanguageFrom(chat);
                var requestMessage    = GetRequestMessageFrom(chat);
                var responseMessage   = GetRequestMessageTo(chat);
                var messageType       = GetMessageTypeFrom(chat);
                var userFrom          = GetUserFrom(chat);
                var userTo            = GetUserTo(chat);

                var channelId        = indexedChannels[channel.Name].Id;
                var conversationId   = indexedConversations[conversationTrack.ConversationId].Id;
                var sourceLanguageId = string.IsNullOrWhiteSpace(sourceLanguage.Name) ? -1 : indexedLanguages[sourceLanguage.Name].Id;
                var requestMessageId = await _dwhRepository.AddAsync(requestMessage);

                var responseMessageId = await _dwhRepository.AddAsync(responseMessage);

                var messageTypeId = indexedMessageTypes[messageType.Name].Id;
                var userFromId    = indexedUsers[userFrom.UserId].Id;
                var userToId      = indexedUsers[userTo.UserId].Id;

                var requestConversation = new Conversation
                {
                    ChannelId           = channelId,
                    ConversationTrackId = conversationId,
                    DateId          = DateHelper.GetKeyFromDate(chat.RequestTime),
                    FromUserId      = userFromId,
                    MessageId       = requestMessageId,
                    MessageTypeId   = messageTypeId,
                    MessageSourceId = 1,
                    Sentiment       = chat.Sentiment,
                    ToUserId        = userToId
                };

                var responseConversation = new Conversation
                {
                    ChannelId           = channelId,
                    ConversationTrackId = conversationId,
                    DateId          = DateHelper.GetKeyFromDate(chat.ResponseTime),
                    FromUserId      = userToId,
                    MessageId       = responseMessageId,
                    MessageTypeId   = messageTypeId,
                    MessageSourceId = 2,
                    ToUserId        = userFromId,
                    Sentiment       = chat.SentimentResponse
                };

                await _dwhRepository.AddFactAsync(requestConversation);

                await _dwhRepository.AddFactAsync(responseConversation);

                // Words fact table
                await ProcessWordsAsync(indexedWords, chat.Request, channelId, conversationId, chat.RequestTime, userFromId, requestMessageId, 1, messageTypeId, userToId);
                await ProcessWordsAsync(indexedWords, chat.Response, channelId, conversationId, chat.ResponseTime, userToId, responseMessageId, 2, messageTypeId, userFromId);
            }
        }