protected TeamModel CreateTeamViewModel( IScoreboardRow row, Tenant.Entities.Affiliation?aff, Tenant.Entities.Category?cat, bool ispublic, ProblemStatisticsModel[]?stat = null) { var prob = new ScoreCellModel[Problems.Count]; foreach (var pp in row.ScoreCache) { var p = Problems.Find(pp.ProblemId); if (p == null) { continue; } var pid = p.Rank - 1; prob[pid] = RankingStrategy.ToCell(pp, ispublic); if (stat == null) { continue; } if (prob[pid].Score.HasValue) { var score = prob[pid].Score !.Value; if (prob[pid].IsFirstToSolve) { stat[pid].FirstSolve ??= score; } stat[pid].Accepted++; stat[pid].Rejected += prob[pid].JudgedCount - 1; stat[pid].Pending += prob[pid].PendingCount; stat[pid].MaxScore = System.Math.Max(stat[pid].MaxScore, score); } else { stat[pid].Rejected += prob[pid].JudgedCount; stat[pid].Pending += prob[pid].PendingCount; } } var(points, penalty, lastac) = RankingStrategy.GetRanks(row.RankCache, ispublic); return(new TeamModel { TeamId = row.TeamId, TeamName = row.TeamName, Affiliation = aff?.Name ?? "", AffiliationId = aff?.Abbreviation ?? "null", Category = cat?.Name ?? "", CategoryColor = cat?.Color ?? "#ffffff", Eligible = cat?.IsEligible ?? false, Points = points, Penalty = penalty, LastAc = lastac, Problems = prob, }); }
public static IDictionary<ScoredObject, int> Calculate(IEnumerable<ScoredObject> items, RankingStrategy strategy = RankingStrategy.Competition) { if (strategy != RankingStrategy.Competition && strategy != RankingStrategy.Ordinal) throw new NotImplementedException(string.Format("The RankingStrategy, {0}, is not implemented.", strategy)); var rankings = new Dictionary<ScoredObject, int>(); var sortedItems = items.OrderByDescending(i => i, new ScoreComparer()); var rank = 1; ScoredObject previousItem = null; foreach (var item in sortedItems) { if (previousItem != null && strategy == RankingStrategy.Competition && item.Score == previousItem.Score) { rankings[item] = rankings[previousItem]; } else { rankings[item] = rank; } rank++; previousItem = item; } return rankings; }
public static IDictionary <ScoredObject, int> Calculate(IEnumerable <ScoredObject> items, RankingStrategy strategy = RankingStrategy.Competition) { if (strategy != RankingStrategy.Competition && strategy != RankingStrategy.Ordinal) { throw new NotImplementedException(string.Format("The RankingStrategy, {0}, is not implemented.", strategy)); } var rankings = new Dictionary <ScoredObject, int>(); var sortedItems = items.OrderByDescending(i => i, new ScoreComparer()); var rank = 1; ScoredObject previousItem = null; foreach (var item in sortedItems) { if (previousItem != null && strategy == RankingStrategy.Competition && item.Score == previousItem.Score) { rankings[item] = rankings[previousItem]; } else { rankings[item] = rank; } rank++; previousItem = item; } return(rankings); }