Example #1
0
        public RatingScope <T> GetTopPercentage(string scoreName, int top)
        {
            RatingScope <T> result           = new RatingScope <T>(Name);
            RatingScope <T> radixStuds       = new RatingScope <T>(Name);
            decimal         filterPercentage = top;

            //把有那項排名的學生獨立出來。
            foreach (T each in _students.Values)
            {
                PlaceCollection places = GetPlaceCollection(each);

                if (places.Contains(scoreName))
                {
                    radixStuds.Add(each);
                }
            }
            //計算要取的 Percentage。
            decimal extractPlace = Math.Ceiling((filterPercentage / 100m) * radixStuds.Count);

            foreach (T each in radixStuds)
            {
                PlaceCollection places = GetPlaceCollection(each);

                if (places[scoreName].Level <= extractPlace)
                {
                    result.Add(each);
                }
            }

            //之前的取百分比名次做法。
            //foreach (RatingStudent each in students)
            //{
            //    if (each.Places.Contains(ratingName))
            //    {
            //        Place p = each.Places[ratingName];
            //        decimal percentage = (100m * ((decimal)p.Level / (decimal)p.Radix));
            //        if (percentage <= 0) percentage = 1;
            //        if (percentage <= filterPercentage)
            //        {
            //            result.Add(each);
            //        }
            //    }
            //}

            return(result);
        }
Example #2
0
        /// <summary>
        /// 取得前 n 名次的學生。
        /// </summary>
        /// <param name="ratingName">排名的名稱,例如:國文。(與IScoreParser 實作之實體 Name 屬性值相同)</param>
        /// <param name="top">要取得名次。</param>
        /// <param name="placeNamespace">名次存放的 Namespace。</param>
        public RatingScope <T> GetTopPlaces(string ratingName, int top)
        {
            RatingScope <T> result = new RatingScope <T>(Name);

            foreach (T each in _students.Values)
            {
                PlaceCollection places = GetPlaceCollection(each);

                if (places.Contains(ratingName))
                {
                    if (places[ratingName].Level <= top)
                    {
                        result.Add(each);
                    }
                }
            }
            return(result);
        }
Example #3
0
        public RatingScope <T> GetLastPercentage(string scoreName, int last)
        {
            RatingScope <T> result = new RatingScope <T>(Name);
            //RatingScope<T> radixStuds = new RatingScope<T>(Name);
            decimal  filterPercentage = last;
            List <T> students         = new List <T>();

            //把有那項排名的學生獨立出來。
            foreach (T each in _students.Values)
            {
                PlaceCollection places = GetPlaceCollection(each);

                if (places.Contains(scoreName))
                {
                    students.Add(each);
                }
            }
            //計算要取的 Percentage。
            decimal extractPlace = Math.Ceiling((filterPercentage / 100m) * students.Count);

            students.Sort((x, y) =>
            {
                PlaceCollection placesX = GetPlaceCollection(x);
                PlaceCollection placesY = GetPlaceCollection(y);

                return(placesY[scoreName].Level.CompareTo(placesX[scoreName].Level));
            });

            if (students.Count <= 0)
            {
                return(result);
            }

            //取得最後一名的名次百分比。
            decimal lastLevel = students[0].Places[scoreName].Level - extractPlace;

            foreach (T student in students.Where(x => x.Places[scoreName].Level > lastLevel))
            {
                result.Add(student);
            }

            return(result);
        }
Example #4
0
        /// <summary>
        /// 取得後 n 名次的學生。
        /// </summary>
        /// <param name="ratingName">排名的名稱,例如:國文。(與IScoreParser 實作之實體 Name 屬性值相同)</param>
        /// <param name="last">要取得名次。</param>
        public RatingScope <T> GetLastPlaces(string scoreName, int last)
        {
            RatingScope <T> result = new RatingScope <T>(Name);

            List <T> students = new List <T>();

            foreach (T each in _students.Values)
            {
                PlaceCollection places = GetPlaceCollection(each);

                if (places.Contains(scoreName))
                {
                    students.Add(each);
                }
            }

            students.Sort((x, y) =>
            {
                PlaceCollection placesX = GetPlaceCollection(x);
                PlaceCollection placesY = GetPlaceCollection(y);

                return(placesY[scoreName].Level.CompareTo(placesX[scoreName].Level));
            });

            if (students.Count <= 0)
            {
                return(result);
            }

            //取得最後一名的名次。
            int lastLevel = students[0].Places[scoreName].Level - last;

            foreach (T student in students.Where(x => x.Places[scoreName].Level > lastLevel))
            {
                result.Add(student);
            }

            return(result);
        }