Exemple #1
0
        public async Task <IEnumerable <T> > GetAsync(string collectionId, Expression <Func <T, bool> > condition = null, Expression <Func <T, object> > orderBy = null, bool orderByDescending = true)
        {
            Collection = Context.Database.GetCollection <T>(collectionId);

            if (condition == null)
            {
                condition = _ => true;
            }
            var query = Collection.Find <T>(condition);

            IOrderedFindFluent <T, T> SortedResults;

            if (orderBy != null && orderByDescending)
            {
                SortedResults = query.SortByDescending(orderBy);
            }
            else if (orderBy != null && !orderByDescending)
            {
                SortedResults = query.SortBy(orderBy);
            }
            else
            {
                SortedResults = query.SortByDescending(x => x.CreationDate);
            }

            return(await SortedResults.ToListAsync());
        }
        private List <SortedResults> UserFirstFilter(List <SortedResults> responsesAndCounts)
        {
            SortedResults        currentBestResult = null;
            List <SortedResults> sortedListbyMatch = new List <SortedResults>();

            if (responsesAndCounts.Count > 0)
            {
                currentBestResult = responsesAndCounts[0];
            }
            while (sortedListbyMatch.Count != responsesAndCounts.Count)
            {
                for (int i = 0; i < responsesAndCounts.Count; i++)
                {
                    if (currentBestResult == null || responsesAndCounts[i].data.value > currentBestResult.data.value)
                    {//change happens here for the user preference
                        currentBestResult = responsesAndCounts[i];
                    }
                }
                if (currentBestResult != null)
                {
                    sortedListbyMatch.Add(currentBestResult);
                    currentBestResult = null;
                }
            }
            return(sortedListbyMatch);
        }
Exemple #3
0
        public async Task <Tuple <IEnumerable <T>, long> > GetAsync(string collectionId, int currentPage, int pageSize, Expression <Func <T, bool> > condition = null, Expression <Func <T, object> > orderBy = null, bool orderByDescending = true)
        {
            Collection = Context.Database.GetCollection <T>(collectionId);

            if (condition == null)
            {
                condition = _ => true;
            }
            var  query      = Collection.Find <T>(condition);
            long totalCount = await query.CountDocumentsAsync();

            IOrderedFindFluent <T, T> SortedResults;

            if (orderBy != null && orderByDescending)
            {
                SortedResults = query.SortByDescending(orderBy);
            }
            else if (orderBy != null && !orderByDescending)
            {
                SortedResults = query.SortBy(orderBy);
            }
            else
            {
                SortedResults = query.SortByDescending(x => x.CreationDate);
            }

            List <T> records = await SortedResults.Skip((currentPage - 1) *pageSize).Limit(pageSize).ToListAsync();

            return(new Tuple <IEnumerable <T>, long>(records, totalCount));
        }
        public string responseSortedByOccurence(string words)
        {
            List <UseWords>      allWordswithContext = getWordsWithContext(words);
            List <SortedResults> allResponses        = new List <SortedResults>();

            //i need to fill up the responses and get the counts
            for (int i = 0; i < allWordswithContext.Count; i++)
            {
                List <LearningData> results = _db.getByWord(allWordswithContext[i].word).ToList();
                for (int k = 0; k < results.Count; k++)
                {
                    if (allResponses.Count == 0)
                    {
                        SortedResults newEntry = new SortedResults(results[k], 1);
                        allResponses.Add(newEntry);
                    }
                    else
                    {
                        for (int j = 0; j < allResponses.Count; j++)
                        {
                            SortedResults result = allResponses[j];
                            if (results[k].response.Equals(result.data.response))
                            {
                                allResponses[j].count = allResponses[j].count + 1;
                            }
                            else
                            {
                                SortedResults newEntry = new SortedResults(results[k], 1);
                                allResponses.Add(newEntry);
                            }
                        }
                    }
                }
            }
            //should now have a list of just the resulkts and there accurate counts

            //sorted results should now have all the responses and there values use these to sort
            string response = "I don't understand that";
            List <SortedResults> sortedByUser         = MatchFirstFilter(allResponses);
            List <SortedResults> sortedByMatchandUser = UserFirstFilter(sortedByUser);

            //i now know the bottom should be the number one answer because both have been sorted
            if (sortedByMatchandUser.Count > 0)
            {
                response = sortedByMatchandUser[0].data.response;//gives the response back
                return(response);
            }
            else
            {
                return(response);
            }
        }