Ejemplo n.º 1
0
        private PlaceCollection GetPlaceCollection(T each)
        {
            PlaceCollection places = null;

            if (string.IsNullOrEmpty(PlaceNamespace))
            {
                places = each.Places;
            }
            else
            {
                places = each.Places.NS(PlaceNamespace);
            }
            return(places);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 進行排名。
        /// </summary>
        /// <param name="scoreParser">要被排名的成績計算邏輯。</param>
        /// <param name="option">排名選項,接序 or 不接序排名。</param>
        /// <param name="placeNamespace">存放排名結果的 Namespace。</param>
        public void Rank(IScoreParser <T> scoreParser, PlaceOptions option)
        {
            //取得有成績的學生。
            List <ScoredStudent> students = GetScoredStudents(scoreParser);

            //排序名次。
            students.Sort(delegate(ScoredStudent x, ScoredStudent y)
            {
                decimal X = x.Score;
                decimal Y = y.Score;

                //反過來排,由大到小。
                return(Y.CompareTo(X));
            });

            //決定排序。
            IPlaceAlgorithm algorithm = null;

            if (option == PlaceOptions.Sequence)
            {
                algorithm = new Sequence();
            }
            else
            {
                algorithm = new Unsequence();
            }

            int    radix     = students.Count;
            string scorename = scoreParser.Name;

            foreach (ScoredStudent each in students)
            {
                int level = algorithm.NextLevel(each.Score);

                T student = _students[each.Id];

                PlaceCollection places = GetPlaceCollection(student);

                if (places.Contains(scorename))
                {
                    places[scorename] = new Place(level, each.Score, radix);
                }
                else
                {
                    places.Add(scorename, new Place(level, each.Score, radix));
                }
            }
        }
Ejemplo n.º 3
0
        public RatingScope <T> GetTopPercentage(string ratingName, 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(ratingName))
                {
                    radixStuds.Add(each);
                }
            }
            //計算要取的 Percentage。
            decimal extractPlace = Math.Ceiling((filterPercentage / 100m) * radixStuds.Count);

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

                if (places[ratingName].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);
        }
Ejemplo n.º 4
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);
        }