示例#1
0
 void IContestFeature.Contextualize(IContestContext context)
 {
     if (_contextualized)
     {
         throw new InvalidOperationException();
     }
     Context         = context;
     _contextualized = true;
 }
示例#2
0
        /// <summary>
        /// Applies the team name to the solution list.
        /// </summary>
        /// <param name="context">The <see cref="IContestContext"/>.</param>
        /// <param name="solutions">The list of <see cref="Solution"/>s.</param>
        /// <returns>The task for applying.</returns>
        public static async Task ApplyTeamNamesAsync(this IContestContext context, IReadOnlyList <Solution> solutions)
        {
            var tn = await context.GetTeamNamesAsync();

            foreach (var solu in solutions)
            {
                solu.AuthorName = tn.TryGetValue(solu.TeamId, out var an) ? an : string.Empty;
            }
        }
示例#3
0
        public static async Task <Team?> FindTeamByUserAsync(this IContestContext context, int userId)
        {
            var member = await context.FindMemberByUserAsync(userId);

            if (member == null)
            {
                return(null);
            }
            return(await context.FindTeamByIdAsync(member.TeamId));
        }
示例#4
0
        public ScoreboardRefreshEvent(IContestContext context, DateTimeOffset?overrideEndTime = null)
        {
            Context = context;
            var contest = context.Contest;

            Contest = contest;
            var now = DateTimeOffset.Now;

            StartTime = Contest.StartTime ?? now;
            var endTime = overrideEndTime ?? (Contest.StartTime + Contest.EndTime) ?? now;

            if (now < endTime)
            {
                endTime = now;
            }
            Deadline   = endTime;
            FreezeTime = Contest.StartTime + Contest.FreezeTime;
        }
示例#5
0
 /// <summary>
 /// Converts the store as a <see cref="IContestQueryableStore"/>.
 /// </summary>
 /// <param name="store">The <see cref="IContestContext"/>.</param>
 /// <returns>The <see cref="IContestQueryableStore"/>.</returns>
 public static IContestQueryableStore GetQueryableStore(this IContestContext store)
 => store as IContestQueryableStore
 ?? throw new InvalidOperationException("This store is not a IQueryable store.");
示例#6
0
 public ClarificationCreateEvent(IContestContext contest, Clarification entity)
 {
     Clarification = entity;
     Context       = contest;
 }
示例#7
0
 public ContestUpdateEvent(IContestInformation old, IContestInformation @new, IContestContext context)
 {
     OldContest = old;
     NewContest = @new;
     Context    = context;
 }
示例#8
0
        public static async Task <TeamReport> GenerateReport(this IContestContext context, int teamid)
        {
            var team = await context.FindTeamByIdAsync(teamid);

            if (team == null || team.Status != 1)
            {
                return(null);
            }
            var contest = context.Contest;

            if (!contest.StartTime.HasValue || !contest.EndTime.HasValue)
            {
                return(null);
            }
            if (contest.RankingStrategy == 2)
            {
                return(null);
            }

            var start    = contest.StartTime.Value;
            var end      = start + contest.EndTime.Value;
            var problems = await context.ListProblemsAsync();

            var scoreboard = await context.GetScoreboardAsync();

            var row  = scoreboard.Data[team.TeamId];
            var sols = await context.ListSolutionsAsync(teamid : team.TeamId);

            var solt     = sols.Where(s => s.Time >= start && s.Time < end).ToLookup(s => s.ProblemId);
            var sids     = new List <int>();
            var sid_jids = new Dictionary <int, (int pid, int jid)>();
            var details  = new Dictionary <int, IEnumerable <(JudgingRun, Testcase)> >();

            foreach (var prob in problems)
            {
                if (prob.Statement == null)
                {
                    var p2 = await context.FindProblemAsync(prob.ProblemId, true);

                    if (prob != p2)
                    {
                        prob.Statement = p2.Statement;
                    }
                }
            }

            foreach (var g in solt)
            {
                var a2 = g.OrderBy(s => s.Time);
                Polygon.Models.Solution fa = null;

                if (contest.RankingStrategy == 0)
                {
                    fa = a2.FirstOrDefault(s => s.Verdict == Verdict.Accepted);
                }

                fa ??= a2.Last();
                sids.Add(fa.SubmissionId);
                sid_jids.Add(fa.SubmissionId, (fa.ProblemId, fa.JudgingId));
            }

            var sq = await((ISubmissionContext)context).ListSubmissionsAsync(
                s => new { s.ProblemId, s.SourceCode, s.Id },
                s => sids.Contains(s.Id));

            foreach (var sc in sid_jids)
            {
                var rt = await((ISubmissionContext)context).GetDetailsAsync(sc.Value.pid, sc.Value.jid);
                details.Add(sc.Key, rt);
            }

            return(new TeamReport
            {
                TeamId = team.TeamId,
                TeamName = team.TeamName,
                ContestId = contest.Id,
                ContestName = contest.Name,
                Rule = contest.RankingStrategy,
                Problems = problems,
                RankCache = row.RankCache,
                ScoreCaches = row.ScoreCache,
                StartTime = start,
                EndTime = end,
                Solutions = solt,
                SourceCodes = sq.ToDictionary(a => a.ProblemId, a => (a.Id, a.SourceCode)),
                Details = details,
            });