Ejemplo n.º 1
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.º 2
0
        /// <summary>
        /// 進行排名。
        /// </summary>
        /// <param name="scoreParser">要被排名的成績計算邏輯。</param>
        /// <param name="option">排名選項,接序 or 不接序排名。</param>
        /// <param name="provider">當相同名次時決定先後成績資料,所有排名範圍內的學生都應該供相同順序與數量的成績資料,否則會產生無法預期的結果。</param>
        public void Rank(IScoreParser <T> scoreParser, PlaceOptions option)
        {
            //取得有成績的學生。
            List <ScoredStudent> students = GetScoredStudents(scoreParser);

            //沒有成績就不用排名了。
            if (students.Count <= 0)
            {
                return;
            }

            //排序名次。
            students.Sort(delegate(ScoredStudent x, ScoredStudent y)
            {
                if (scoreParser is IScoresParser <T> )
                {
                    IScoresParser <T> p2 = scoreParser as IScoresParser <T>;

                    if (x.SecondScores.Count <= 0)
                    {
                        x.SecondScores = p2.GetSecondScores(x.Source);
                    }
                    if (y.SecondScores.Count <= 0)
                    {
                        y.SecondScores = p2.GetSecondScores(y.Source);
                    }
                }
                return(y.CompareTo(x));
            });

            int    radix     = students.Count;   //基數。
            string scorename = scoreParser.Name; //排名的名稱。

            //先把之前的排名結果清掉。
            foreach (T each in this)
            {
                PlaceCollection places = GetPlaceCollection(each);
                if (places.Contains(scorename))
                {
                    places.Remove(scorename);
                }
            }

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

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

            StandardPercentage percenAlg = new StandardPercentage();

            percenAlg.Initital(students.Count);

            foreach (ScoredStudent each in students)
            {
                int level  = placeAlg.NextLevel(each);
                int percen = percenAlg.NextPercentage(level);

                T student = _students[each.Id];

                PlaceCollection places = GetPlaceCollection(student);

                if (places.Contains(scorename))
                {
                    places[scorename] = new Place(level, percen, each.Score, radix, this.Count);
                }
                else
                {
                    places.Add(scorename, new Place(level, percen, each.Score, radix, this.Count));
                }
            }
        }