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); }
private void RankAll(RatingScope scope) { if (_progress.Cancellation) { return; } scope.Rank(RatingParams.RatingMethod); }
/// <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; }
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(); }
public static List <IRatingTarget> GroupBy(RatingScope scope) { Dictionary <string, IRatingTarget> targets = new Dictionary <string, IRatingTarget>(); foreach (Student eachStudent in scope) { foreach (SemsSubjectScore eachScore in eachStudent.SemsSubjects.Values) { if (!targets.ContainsKey(eachScore.ScoreName)) { targets.Add(eachScore.ScoreName, new SemsSubjectTarget(eachScore.ScoreName)); } } } return(new List <IRatingTarget>(targets.Values)); }
private void lvScopes_Click(object sender, EventArgs e) { if (lvScopes.FocusedItem == null) { return; } HighlighSelected(sender as ListView); RatingScope scope = lvScopes.FocusedItem.Tag as RatingScope; lvTargets.Items.Clear(); foreach (IRatingTarget eachTarget in scope.RatingTargets) { ListViewItem item = new ListViewItem(string.Format("{0}", eachTarget.Name)); item.Tag = eachTarget; lvTargets.Items.Add(item); } }
public override bool Update() { SubProgress progress = new SubProgress(MainProgress, WeightTable.GetJobWeight("SetYearSubject")); try { Utility.StartTime("SetYearSubject"); progress.ReportMessage("更新學年科目成績排名資料…"); List <List <Student> > packages = Utility.SplitUpdatePackage(Students, PackageSize); int offset = 1; foreach (List <Student> eachPackage in packages) { if (MainProgress.Cancellation) { return(false); //這個部份要看的必須是 MainProgress。 } DSXmlCreator request = new DSXmlCreator(false); bool updateRequired = false; request.CreateStartElement("Request"); foreach (Student eachStudent in eachPackage) { //代表沒有排名。 if (eachStudent.YearSubjects.Count <= 0) { continue; } updateRequired = true; request.CreateStartElement("SchoolYearSubjectRating"); //學期成績記錄的編號。 request.CreateElement("ScoreId", eachStudent.YearSubjects.ScoreRecordIdentity); RatingScope scopeClass = new RatingScope("ClassRating"); RatingScope scopeDept = new RatingScope("DeptRating"); RatingScope scopeYear = new RatingScope("YearRating"); foreach (YearSubjectScore eachScore in eachStudent.YearSubjects.Values) { foreach (ResultPlace eachPlace in eachScore.RatingResults.Values) { if (eachPlace.Scope.ScopeType == ScopeType.Class) { scopeClass.CreateRatingItem(eachScore, eachPlace); } else if (eachPlace.Scope.ScopeType == ScopeType.Dept) { scopeDept.CreateRatingItem(eachScore, eachPlace); } else if (eachPlace.Scope.ScopeType == ScopeType.GradeYear) { scopeYear.CreateRatingItem(eachScore, eachPlace); } } } scopeClass.FinalizeCreate(); scopeDept.FinalizeCreate(); scopeYear.FinalizeCreate(); request.CreateSubtree(scopeClass.GetResult()); request.CreateSubtree(scopeDept.GetResult()); request.CreateSubtree(scopeYear.GetResult()); request.CreateEndElement(); } request.CreateEndElement(); if (updateRequired) { EditRating.UpdateSchoolYearSubjectRating(request.GetResultAsDSXmlHelper()); } progress.ReportProgress((int)(((float)offset / packages.Count) * 100)); offset++; } progress.ReportProgress(100); Utility.EndTime("SetYearSubject"); return(true); } catch (Exception ex) { progress.ReportException(ex); return(false); } }