Пример #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);
                rank          = rank <= 0 ? 1 : rank;
                this[id].Rank = (int)rank;

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

            return(result);
        }
Пример #2
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);
        }
Пример #3
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)
                    {
                        RStudentRecord student   = _studentDict[id];
                        string         className = string.Empty;

                        className = student.ClassName;

                        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;
                    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)
                    {
                        RStudentRecord student   = _studentDict[id];
                        string         gradeYear = student.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;
                    all.Tag  = data.Tag;
                    foreach (RankData each in gradeRankData.Values)
                    {
                        all.Merge(_ranker.Perform(each));
                    }
                    rankData.Add(all);
                    #endregion
                }
            }
            _rankData.Clear();
            _rankData = rankData;
        }