コード例 #1
0
        /// <summary>
        /// descending quick sort by total visitor using recusrion
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public List <ReportsWeekly> QuickSortByTotalVisitor(List <ReportsWeekly> list)
        {
            if (list.Count <= 1)
            {
                return(list);
            }

            Random random                = new Random();
            List <ReportsWeekly> less    = new List <ReportsWeekly>();
            List <ReportsWeekly> greater = new List <ReportsWeekly>();

            int           pos   = random.Next(list.Count);
            ReportsWeekly pivot = list[pos];

            list.RemoveAt(pos);

            foreach (ReportsWeekly item in list)
            {
                double totalTimeSpent      = item.TotalTimeSpent;
                double totalTimeSpentPivot = pivot.TotalTimeSpent;
                if (totalTimeSpent < totalTimeSpentPivot)
                {
                    less.Add(item);
                }
                else
                {
                    greater.Add(item);
                }
            }
            return(ConcatWeekly(QuickSortByTotalVisitor(less), pivot, QuickSortByTotalVisitor(greater)));
        }
コード例 #2
0
        public List <ReportsWeekly> ConcatWeekly(List <ReportsWeekly> less, ReportsWeekly pivot, List <ReportsWeekly> greater)
        {
            List <ReportsWeekly> sorted = new List <ReportsWeekly>(greater);

            sorted.Add(pivot);

            foreach (ReportsWeekly i in less)
            {
                sorted.Add(i);
            }

            return(sorted);
        }
コード例 #3
0
        private List <ReportsWeekly> GetWeekReport(List <VisitorsInformation> list)
        {
            List <ReportsWeekly> resultList = new List <ReportsWeekly>();
            ReportsWeekly        monday     = new ReportsWeekly
            {
                Day            = "Monday",
                TotalVisitor   = 0,
                TotalTimeSpent = 0
            };
            ReportsWeekly tuesday = new ReportsWeekly
            {
                Day            = "Tuesday",
                TotalVisitor   = 0,
                TotalTimeSpent = 0
            };
            ReportsWeekly wednesday = new ReportsWeekly
            {
                Day            = "Wednesday",
                TotalVisitor   = 0,
                TotalTimeSpent = 0
            };
            ReportsWeekly thursday = new ReportsWeekly
            {
                Day            = "Thursday",
                TotalVisitor   = 0,
                TotalTimeSpent = 0
            };
            ReportsWeekly friday = new ReportsWeekly
            {
                Day            = "Friday",
                TotalVisitor   = 0,
                TotalTimeSpent = 0
            };

            foreach (VisitorsInformation i in list)
            {
                var date = DateTime.ParseExact(i.EntryDate, "dd/mm/yyyy", CultureInfo.InvariantCulture);
                int day  = (int)date.DayOfWeek;

                switch (day)
                {
                case 1:
                    monday.TotalVisitor++;
                    monday.TotalTimeSpent = monday.TotalTimeSpent + i.TotalDuration;
                    break;

                case 2:
                    tuesday.TotalVisitor++;
                    tuesday.TotalTimeSpent = tuesday.TotalTimeSpent + i.TotalDuration;
                    break;

                case 3:
                    wednesday.TotalVisitor++;
                    wednesday.TotalTimeSpent = wednesday.TotalTimeSpent + i.TotalDuration;
                    break;

                case 4:
                    thursday.TotalVisitor++;
                    thursday.TotalTimeSpent = thursday.TotalTimeSpent + i.TotalDuration;
                    break;

                case 5:
                    friday.TotalVisitor++;
                    friday.TotalTimeSpent = friday.TotalTimeSpent + i.TotalDuration;
                    break;

                default:
                    break;
                }
            }

            resultList.Add(monday);
            resultList.Add(tuesday);
            resultList.Add(wednesday);
            resultList.Add(friday);
            resultList.Add(thursday);
            return(resultList);
        }