コード例 #1
0
        public static void Rank(RatingScope scope, IRatingTarget targetScore, RatingMethod method)
        {
            //int t1 = Environment.TickCount;

            List <Student> students = scope.GetContainTargetList(targetScore);

            //按成績高低排序。
            students.Sort(new ScoreComparer(targetScore));

            //實際有包含成績的人數。
            int actualBase = students.Count;

            //所有被排名的人數。
            int baseCount = scope.Count;

            //名次決定演算法。
            IRatingAlgorithm placeDecision = GetAlgorithm(method);

            foreach (Student eachStudent in students)
            {
                //決定名次
                int place = placeDecision.NextPlace(targetScore.GetScore(eachStudent));

                //寫入名次資訊。
                targetScore.SetPlace(eachStudent, new ResultPlace(scope, targetScore, baseCount, actualBase, place));
            }

            //string msg = "排名時間:{0} 範圍名稱:{1} 成績名稱:{2}";
            //Console.WriteLine(msg, Environment.TickCount - t1, scope.Name, targetScore.Name);
        }
コード例 #2
0
 /// <summary>
 /// 排名結果。
 /// </summary>
 /// <param name="ratingBase">排名的總人數。</param>
 /// <param name="actualBase">實際有成績,而排名的人數。</param>
 /// <param name="place">名次。</param>
 public ResultPlace(RatingScope scope, IRatingTarget target, int ratingBase, int actualBase, int place)
 {
     _scope       = scope;
     _target      = target;
     _rating_base = ratingBase;
     _actual_base = actualBase;
     _place       = place;
 }
コード例 #3
0
        private void lvTargets_Click(object sender, EventArgs e)
        {
            if (lvScopes.FocusedItem == null)
            {
                return;
            }
            if (lvTargets.FocusedItem == null)
            {
                return;
            }
            HighlighSelected(sender as ListView);

            IRatingTarget target = lvTargets.FocusedItem.Tag as IRatingTarget;
            RatingScope   scope  = lvScopes.FocusedItem.Tag as RatingScope;

            lvPlace.SuspendLayout();
            lvPlace.Items.Clear();
            List <ListViewItem> items = new List <ListViewItem>();

            foreach (Student eachStu in scope)
            {
                ListViewItem item = new ListViewItem();
                item.Text = eachStu.ClassName;
                item.SubItems.Add(eachStu.SeatNumber);
                item.SubItems.Add(eachStu.Name);

                decimal score = target.GetScore(eachStu);
                if (score == decimal.MinValue)
                {
                    item.SubItems.Add("無");
                }
                else
                {
                    item.SubItems.Add(score.ToString());
                }

                ResultPlace place = target.GetPlace(eachStu, scope.ScopeType);
                if (place == null)
                {
                    item.SubItems.Add("無");
                }
                else
                {
                    item.SubItems.Add(place.Place.ToString());
                }

                item.Tag = eachStu;

                items.Add(item);
            }
            lvPlace.Items.AddRange(items.ToArray());
            lvPlace.ResumeLayout();
        }
コード例 #4
0
        public List <Student> GetContainTargetList(IRatingTarget target)
        {
            List <Student> stus = new List <Student>();

            foreach (Student each in _students.Values)
            {
                if (target.ContainsScore(each))
                {
                    stus.Add(each);
                }
            }

            return(stus);
        }
コード例 #5
0
 public ScoreComparer(IRatingTarget target)
 {
     _target = target;
 }