/// <summary> /// 获取题目统计信息 /// </summary> /// <param name="cid">竞赛ID</param> /// <param name="pid">题目ID</param> /// <returns>题目统计信息实体</returns> public static ProblemStatistic GetProblemStatistic(Int32 cid, Int32 pid) { //此处不能验证cid,因为普通Problem的Statistic也经由此方法 if (pid < ConfigurationManager.ProblemSetStartID) { throw new InvalidRequstException(RequestType.Problem); } //验证pid有效性 if (cid < 0)//非竞赛题目 { ProblemEntity entity = ProblemManager.GetProblem(pid); pid = entity.ProblemID; } else//竞赛题目 { ProblemEntity entity = ContestProblemManager.GetProblem(cid, pid); //竞赛题目传入的pid是ContestProblemID } ProblemStatistic statistic = SolutionCache.GetProblemStatisticCache(cid, pid); if (statistic == null) { statistic = SolutionRepository.Instance.GetProblemStatistic(cid, pid);//一定有返回值 } return(statistic); }
public ActionResult Statistic(Int32 pid = 0, Int32 id = 1, String lang = "all", String order = "default") { ProblemStatistic ps = SolutionManager.GetProblemStatistic(-1, pid); String reallang = lang.ToByte(LanguageType.Null.ID).ToString(); String realorder = order.ToInt32(-1).ToString(); Dictionary <String, Byte> langs = LanguageManager.MainSubmitSupportLanguages; ViewBag.Languages = langs; PagedList <SolutionEntity> list = SolutionManager.GetSolutionList(id, -1, pid, null, reallang, ((Byte)ResultType.Accepted).ToString(), realorder); ViewBag.Language = lang; ViewBag.Order = order; return(ViewWithPager(list, ps, id)); }
public ActionResult Statistic(Int32 pid = 0, Int32 id = 1, String lang = "all", String order = "default") { ContestEntity contest = ViewData["Contest"] as ContestEntity; ProblemStatistic ps = SolutionManager.GetProblemStatistic(contest.ContestID, pid); String reallang = lang.ToByte(LanguageType.Null.ID).ToString(); String realorder = order.ToInt32(-1).ToString(); Dictionary <String, Byte> langs = LanguageManager.GetSupportLanguages(contest.SupportLanguage); ViewBag.Languages = langs; PagedList <SolutionEntity> list = SolutionManager.GetSolutionList(id, contest.ContestID, pid, null, reallang, ((Byte)ResultType.Accepted).ToString(), realorder); ViewBag.ContestProblemID = pid.ToString(); ViewBag.Language = lang; ViewBag.Order = order; return(ViewWithPager(list, ps, id)); }
/// <summary> /// 获取题目统计信息 /// </summary> /// <param name="cid">竞赛ID</param> /// <param name="pid">题目ID</param> /// <returns>题目统计信息实体</returns> public ProblemStatistic GetProblemStatistic(Int32 cid, Int32 pid) { return(this.UsingConnection <ProblemStatistic>(conn => { ProblemStatistic entity = new ProblemStatistic(); entity.ProblemID = pid; entity.SolvedCount = this.Select("T1", from => { from.Querys(USERNAME) .Distinct() .Where(c => { AbstractSqlCondition condition = c.Equal((cid > 0 ? CONTESTPROBLEMID : PROBLEMID), pid) & c.Equal(RESULT, (Byte)ResultType.Accepted); if (cid >= 0) //竞赛ID,非竞赛为0 { condition = condition & c.Equal(CONTESTID, cid); } return condition; }); }) .Count(conn);//计算AC的用户数 return this.Select() .Query(SqlAggregateFunction.Count, SOLUTIONID, "SOLU_COUNT") .Query(RESULT) .Where(c => { AbstractSqlCondition condition = c.Equal((cid >= 0 ? CONTESTPROBLEMID : PROBLEMID), pid); if (cid >= 0) //竞赛ID,非竞赛为0 { condition = condition & c.Equal(CONTESTID, cid); } return condition; }) .GroupBy(RESULT) .ToDataTable(conn) .Each(args => { Int32 count = this.LoadInt32(args, "SOLU_COUNT"); ResultType type = (ResultType)this.LoadByte(args, RESULT); entity.SubmitCount += count; switch (type) { case ResultType.Pending: entity.PendingCount = count; break; case ResultType.RejudgePending: entity.RejudgePendingCount = count; break; case ResultType.Judging: entity.JudgingCount = count; break; case ResultType.CompileError: entity.CompileErrorCount = count; break; case ResultType.RuntimeError: entity.RuntimeErrorCount = count; break; case ResultType.TimeLimitExceeded: entity.TimeLimitExceededCount = count; break; case ResultType.MemoryLimitExceeded: entity.MemoryLimitExceededCount = count; break; case ResultType.OutputLimitExceeded: entity.OutputLimitExceededCount = count; break; case ResultType.WrongAnswer: entity.WrongAnswerCount = count; break; case ResultType.PresentationError: entity.PresentationErrorCount = count; break; case ResultType.Accepted: entity.AcceptedCount = count; break; } }) .Done(entity); })); }
/// <summary> /// 向缓存中写入题目统计 /// </summary> /// <param name="cid">竞赛ID</param> /// <param name="pid">题目ID</param> /// <returns>题目统计信息实体</returns> public static void SetProblemStatisticCache(Int32 cid, Int32 pid, ProblemStatistic statistic) { CacheManager.Set(GetProblemStatisticCacheKey(cid, pid), statistic, PROBLEMSTATISTIC_CACHE_TIME); }