Beispiel #1
0
        public RankData GetTopByPercent(int percent)
        {
            RankData result = new RankData();

            result.Name = this.Name;
            if (this.Tag != null)
            {
                result.Tag = this.Tag;
            }

            foreach (string id in this.Keys)
            {
                decimal rank = (decimal)this[id].Rank;
                rank          = rank / this.Count * 100;
                rank          = decimal.Round(rank, 0, MidpointRounding.AwayFromZero);
                this[id].Rank = (int)rank;

                if (rank <= percent)
                {
                    result.Add(id, this[id]);
                }
            }

            return(result);
        }
Beispiel #2
0
 public void Merge(RankData other)
 {
     foreach (string id in other.Keys)
     {
         this.Add(id, other[id]);
     }
 }
Beispiel #3
0
        public RankData Perform(RankData source)
        {
            List <decimal> score_list = new List <decimal>();

            foreach (RankScore rs in source.Values)
            {
                score_list.Add(rs.Score);
            }
            score_list.Sort(delegate(decimal a, decimal b)
            {
                return(b.CompareTo(a));
            });

            List <string> id_list = new List <string>(new string[source.Count]);

            foreach (string id in source.Keys)
            {
                int index = score_list.IndexOf(source[id].Score);
                if (index < 0)
                {
                    throw new Exception("排名發生錯誤");
                }
                while (!string.IsNullOrEmpty(id_list[index]))
                {
                    index++;
                }
                id_list[index] = id;
            }

            int rank  = 0;
            int prank = 1;

            decimal last = decimal.MinValue;

            foreach (string id in id_list)
            {
                if (source[id].Score == last)
                {
                    if (!Sequence)
                    {
                        rank++;
                    }
                    source[id].Rank = prank;
                }
                else
                {
                    rank++;
                    source[id].Rank = rank;
                    prank           = rank;
                }

                last = source[id].Score;
                //prank = rank;
            }

            return(source);
        }
Beispiel #4
0
        public int CompareTo(object obj)
        {
            RankData      data = obj as RankData;
            List <string> list = new List <string>(new string[] { "語文", "國語文", "國文", "國語", "英文", "英語", "英語文", "數學" });
            int           a    = list.IndexOf(this.Name);
            int           b    = list.IndexOf(data.Name);

            if (a < 0)
            {
                a = int.MaxValue;
            }
            if (b < 0)
            {
                b = int.MaxValue;
            }
            return(a.CompareTo(b));
        }
Beispiel #5
0
        public RankData GetTopByRank(int rank)
        {
            RankData result = new RankData();

            result.Name = this.Name;
            if (this.Tag != null)
            {
                result.Tag = this.Tag;
            }

            foreach (string id in this.Keys)
            {
                if (this[id].Rank <= rank)
                {
                    result.Add(id, this[id]);
                }
            }

            return(result);
        }
Beispiel #6
0
        public void Perform()
        {
            List <RankData> rankData = new List <RankData>();

            foreach (RankData data in _rankData)
            {
                if (RankType == RankType.Class)
                {
                    #region 班排名
                    Dictionary <string, RankData> classRankData = new Dictionary <string, RankData>();
                    foreach (string id in data.Keys)
                    {
                        JHStudentRecord student   = _studentDict[id];
                        string          className = string.Empty;

                        if (student.Class != null)
                        {
                            className = student.Class.Name;
                        }

                        if (!classRankData.ContainsKey(className))
                        {
                            classRankData.Add(className, new RankData());
                        }
                        RankData eachClassRankData = classRankData[className];
                        eachClassRankData.Add(id, data[id]);
                    }

                    RankData all = new RankData();
                    all.Name = data.Name;
                    if (data.Tag != null)
                    {
                        all.Tag = data.Tag;
                    }
                    foreach (RankData each in classRankData.Values)
                    {
                        all.Merge(_ranker.Perform(each));
                    }
                    rankData.Add(all);
                    #endregion
                }
                else if (RankType == RankType.GradeYear)
                {
                    #region 年排名
                    Dictionary <string, RankData> gradeRankData = new Dictionary <string, RankData>();
                    foreach (string id in data.Keys)
                    {
                        JHStudentRecord student   = _studentDict[id];
                        string          gradeYear = string.Empty;

                        if (student.Class != null)
                        {
                            gradeYear = "" + student.Class.GradeYear;
                        }

                        if (!gradeRankData.ContainsKey(gradeYear))
                        {
                            gradeRankData.Add(gradeYear, new RankData());
                        }
                        RankData eachGradeRankData = gradeRankData[gradeYear];
                        eachGradeRankData.Add(id, data[id]);
                    }

                    RankData all = new RankData();
                    all.Name = data.Name;
                    foreach (RankData each in gradeRankData.Values)
                    {
                        all.Merge(_ranker.Perform(each));
                    }
                    rankData.Add(all);
                    #endregion
                }
            }
            _rankData.Clear();
            _rankData = rankData;
        }
Beispiel #7
0
 public void AddRankData(RankData data)
 {
     _rankData.Add(data);
 }