public async Task RefreshCache(DbContext db, RefreshScoreboardCacheRequest args) { int cid = args.ContestId; var scores = await db.Set <ContestProblem>() .Where(cp => cp.ContestId == cid) .Select(cp => new { cp.ProblemId, cp.Score }) .ToDictionaryAsync(a => a.ProblemId, a => a.Score); var query = from s in db.Set <Submission>() where s.ContestId == cid join t in db.Set <Team>() on new { s.ContestId, TeamId = s.Author } equals new { t.ContestId, t.TeamId } join j in db.Set <Judging>() on new { s.SubmissionId, Active = true } equals new { j.SubmissionId, j.Active } orderby s.Time ascending select new { s.SubmissionId, t.TeamId, s.ProblemId, s.Time, j.Status }; var results = await query.ToListAsync(); var rcc = new Dictionary <int, RankCache>(); var scc = new Dictionary <(int, int), ScoreCache>(); var endTime = args.Deadline; foreach (var s in results) { if (s.Time > endTime) { continue; } if (!scc.ContainsKey((s.TeamId, s.ProblemId))) { scc.Add((s.TeamId, s.ProblemId), new ScoreCache { ContestId = cid, TeamId = s.TeamId, ProblemId = s.ProblemId }); } var sc = scc[(s.TeamId, s.ProblemId)];
public async Task RefreshCache(DbContext db, RefreshScoreboardCacheRequest args) { int cid = args.ContestId; var query = from s in db.Set <Submission>() where s.ContestId == cid join t in db.Set <Team>() on new { s.ContestId, TeamId = s.Author } equals new { t.ContestId, t.TeamId } join tc in db.Set <TeamCategory>() on t.CategoryId equals tc.CategoryId join j in db.Set <Judging>() on new { s.SubmissionId, Active = true } equals new { j.SubmissionId, j.Active } orderby s.Time ascending select new { s.SubmissionId, t.TeamId, tc.SortOrder, s.ProblemId, s.Time, j.Status }; var results = await query.ToListAsync(); var rcc = new Dictionary <int, RankCache>(); var scc = new Dictionary <(int, int), ScoreCache>(); var fb = new HashSet <(int, int)>(); var oks = new List <int>(); var endTime = args.Deadline; foreach (var s in results) { if (s.Time > endTime) { continue; } if (!scc.ContainsKey((s.TeamId, s.ProblemId))) { scc.Add((s.TeamId, s.ProblemId), new ScoreCache { ContestId = cid, TeamId = s.TeamId, ProblemId = s.ProblemId }); } var sc = scc[(s.TeamId, s.ProblemId)];
public async Task RefreshCache(DbContext db, RefreshScoreboardCacheRequest args) { int cid = args.ContestId; var rebuildScoreQuery = from j in db.Set <Judging>() join s in db.Set <Submission>() on j.SubmissionId equals s.SubmissionId where s.ContestId == cid join d in db.Set <Detail>() on j.JudgingId equals d.JudgingId join t in db.Set <Testcase>() on d.TestcaseId equals t.TestcaseId group d.Status == Verdict.Accepted ? t.Point : 0 by j.JudgingId into g select new { JudgingId = g.Key, Score = g.Sum() }; await db.Set <Judging>().MergeAsync( sourceTable: rebuildScoreQuery, targetKey: j => j.JudgingId, sourceKey: j => j.JudgingId, updateExpression: (j, s) => new Judging { TotalScore = s.Score }, insertExpression: null, delete: false); var query = from s in db.Set <Submission>() where s.ContestId == cid join j in db.Set <Judging>() on new { s.SubmissionId, Active = true } equals new { j.SubmissionId, j.Active } orderby s.Time ascending select new { s.SubmissionId, TeamId = s.Author, s.ProblemId, s.Time, j.Status, j.TotalScore }; var results = await query.ToListAsync(); var scrs = from cp in db.Set <ContestProblem>() where cp.ContestId == cid join t in db.Set <Testcase>() on cp.ProblemId equals t.ProblemId select new { cp.ProblemId, t.Point }; var q = await scrs.ToListAsync(); var full = q.GroupBy(a => a.ProblemId).ToDictionary(a => a.Key, a => a.Sum(aa => aa.Point)); var rcc = new Dictionary <int, RankCache>(); var scc = new Dictionary <(int, int), ScoreCache>(); var lastop1 = new Dictionary <int, int>(); var lastop2 = new Dictionary <int, int>(); var endTime = args.Deadline; foreach (var s in results) { if (s.Time > endTime) { continue; } if (!scc.ContainsKey((s.TeamId, s.ProblemId))) { scc.Add((s.TeamId, s.ProblemId), new ScoreCache { ContestId = cid, TeamId = s.TeamId, ProblemId = s.ProblemId }); } var sc = scc[(s.TeamId, s.ProblemId)];