Exemplo n.º 1
0
        public void QuickSortDouble_Pass()
        {
            // Arrange
            var           _uadService = new UADService();
            bool          expected    = true;
            bool          actual      = false;
            List <double> numList     = new List <double> {
                5.5, 4.4, 3.3, 2.2, 1.1
            };
            List <string> wordList = new List <string> {
                "E", "D", "C", "B", "A"
            };

            // Act
            sortServicer.QuickSortDouble(numList, wordList);
            for (int i = 0; i < numList.Count; i++)
            {
                Console.WriteLine(numList[i]);
                Console.WriteLine(wordList[i]);
            }
            if ((numList[0] == 1.1 && wordList[0].Equals("A")) && (numList[1] == 2.2 && wordList[1].Equals("B")) && (numList[2] == 3.3 && wordList[2].Equals("C")) && (numList[3] == 4.4 && wordList[3].Equals("D")) && (numList[4] == 5.5 && wordList[4].Equals("E")))
            {
                actual = true;
            }
            Assert.AreEqual(actual, expected);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function that returns the top 5 page used for a month
        /// </summary>
        /// <param name="month">referenced month</param>
        /// <param name="year">referenced year</param>
        /// <returns>A list of objects that holds the top 5 page used for a month</returns>
        public List <UADObject> GetTop5AveragePageSession(string month, int year)
        {
            var sessions = new List <GNGLog>();
            var urlPages = new List <string> {
                "https://www.greetngroup.com/search", "https://www.greetngroup.com/createevent", "https://www.greetngroup.com", "https://www.greetngroup.com/help", "https://www.greetngroup.com/faq"
            };
            var averageTimeSpent = new List <double>();
            var monthIndex       = months.IndexOf(month);

            var loglist = _gngLoggerService.ReadLogsGivenMonthYear(months[monthIndex], year);

            // For every URL in the list get the average time spent on it
            for (int j = 0; j < urlPages.Count; j++)
            {
                // Get logs where user enters a url
                var entryToPage = _uadService.GetEntryLogswithURL(loglist, urlPages[j]);
                // Get Logs when user leaves a url
                var exitFromPage = _uadService.GetExitLogswithURL(loglist, urlPages[j]);
                // Pair the exit from pages with the entrance to a page
                sessions = _uadService.PairStartAndEndLogs(entryToPage, exitFromPage);
                if (sessions.Count == 0)
                {
                    averageTimeSpent.Add(0);
                }
                else
                {
                    // Get average time spent on the page
                    var average = _uadService.CalculateSessionInformation(sessions);
                    averageTimeSpent.Add(Convert.ToDouble(average[0]));
                }
                sessions.Clear();
            }
            //Sort Pages view time by shortest to longest
            _sortService.QuickSortDouble(averageTimeSpent, urlPages);
            // Transform list into UADObjects
            if (urlPages.Count >= 5)
            {
                for (int k = urlPages.Count - 1; k >= urlPages.Count - 5; k--)
                {
                    var sessionUADObject = new UADObject
                    {
                        Date     = months[monthIndex] + ' ' + year,
                        InfoType = urlPages[k],
                        Value    = averageTimeSpent[k].ToString()
                    };
                    uadObjects.Add(sessionUADObject);
                }
            }
            else
            {
                for (int k = urlPages.Count - 1; k >= 0; k--)
                {
                    var sessionUADObject = new UADObject
                    {
                        Date     = month + ' ' + year,
                        InfoType = urlPages[k],
                        Value    = averageTimeSpent[k].ToString()
                    };
                    uadObjects.Add(sessionUADObject);
                }
            }
            monthsUsed.Clear();

            return(uadObjects);
        }