コード例 #1
0
 public ProblemInList(Entity.Problem problem, Entity.User user)
 {
     ID           = problem.ID;
     Title        = problem.Title;
     ContestTitle = problem.Contest.Title;
     ContestID    = problem.ContestID;
     AC           = problem.Statuses.Where(x => x.ResultAsInt == (int)Entity.JudgeResult.Accepted).Count();
     Submit       = problem.Statuses.Count;
     Difficulty   = "R";
     if (problem.Difficulty >= 1500 && problem.Difficulty < 1700)
     {
         Difficulty = "L3";
     }
     else if (problem.Difficulty >= 1700 && problem.Difficulty < 2000)
     {
         Difficulty = "L2";
     }
     else if (problem.Difficulty >= 2000 && problem.Difficulty < 2400)
     {
         Difficulty = "L1";
     }
     else if (problem.Difficulty >= 2400)
     {
         Difficulty = "S";
     }
     Flag    = "";
     FlagCss = "";
     if (user != null)
     {
         var statuses = problem.Statuses.Where(x => x.UserID == user.ID);
         if (statuses.Count() == 0)
         {
             return;
         }
         else
         {
             if (statuses.Where(x => x.ResultAsInt == (int)Entity.JudgeResult.Accepted).Count() > 0)
             {
                 Flag    = "Accepted";
                 FlagCss = "flag-green";
             }
             else
             {
                 Flag    = "Not Accepted";
                 FlagCss = "flag-red";
             }
         }
     }
 }
コード例 #2
0
        public StandingCol(Entity.User user, Entity.Problem problem)
        {
            var contest  = problem.Contest;
            var statuses = problem.GetContestStatuses().Where(x => x.UserID == user.ID).OrderBy(x => x.Time).ToList();

            #region OI赛制逻辑
            if (contest.Format == Entity.ContestFormat.OI)
            {
                var status = statuses.LastOrDefault();
                if (status == null)
                {
                    StatusID = null;
                    Css      = "";
                    Display  = "";
                }
                else
                {
                    StatusID = status.ID;
                    var score = status.JudgeTasks.Where(x => x.ResultAsInt == (int)Entity.JudgeResult.Accepted).Count() * 100 / status.JudgeTasks.Count;
                    Display = score.ToString();
                    if (score == 0)
                    {
                        Css = "rank-red";
                    }
                    else if (score != 100)
                    {
                        Css = "rank-orange";
                    }
                    else
                    {
                        Css = "rank-green";
                    }
                    Key1 = score;
                    Key2 = status.JudgeTasks.Sum(x => x.TimeUsage);
                    Key3 = status.JudgeTasks.Sum(x => x.MemoryUsage);
                }
            }
            #endregion
            #region OPJOI赛制逻辑
            else if (contest.Format == Entity.ContestFormat.OPJOI)
            {
                var status = statuses.LastOrDefault();
                if (status == null)
                {
                    StatusID = null;
                    Css      = "";
                    Display  = "";
                }
                else
                {
                    StatusID = status.ID;
                    var score = status.JudgeTasks.Where(x => x.ResultAsInt == (int)Entity.JudgeResult.Accepted).Count() * 100 / status.JudgeTasks.Count;
                    Display = score.ToString() + "(" + statuses.Count + ")";
                    if (score == 0)
                    {
                        Css = "rank-red";
                    }
                    else if (score != 100)
                    {
                        Css = "rank-orange";
                    }
                    else
                    {
                        Css = "rank-green";
                    }
                    Key1 = score;
                    Key2 = statuses.Count;
                    Key3 = status.JudgeTasks.Sum(x => x.TimeUsage);
                }
            }
            #endregion
            #region ACM赛制逻辑
            else if (contest.Format == Entity.ContestFormat.ACM)
            {
                if (statuses.Count == 0)
                {
                    StatusID = null;
                    Css      = "";
                    Display  = "";
                }
                else
                {
                    var status        = statuses.Where(x => x.ResultAsInt == (int)Entity.JudgeResult.Accepted).FirstOrDefault();
                    var penalty_count = statuses.Where(x => !Entity.Status.FreeResults.Contains((Entity.JudgeResult)x.ResultAsInt)).Count();
                    if (status == null)
                    {
                        Display  = "(-" + penalty_count + ")";
                        Css      = "rank-red";
                        StatusID = null;
                        Key1     = 0;
                        Key2     = 0;
                        Key3     = penalty_count;
                    }
                    else
                    {
                        Css           = "rank-green";
                        StatusID      = status.ID;
                        penalty_count = statuses.Where(x => !Entity.Status.FreeResults.Contains((Entity.JudgeResult)x.ResultAsInt) && x.Time < status.Time).Count();
                        var penalty_time = (status.Time - status.Problem.Contest.Begin).Add(new TimeSpan(0, 20 * penalty_count, 0));
                        Display = penalty_time.ToString("c");
                        if (penalty_count > 0)
                        {
                            Display += "<br/>(-" + penalty_count + ")";
                        }
                        StatusID = status.ID;
                        Key1     = 1;
                        Key2     = (int)penalty_time.TotalSeconds;
                        Key3     = penalty_count;
                    }
                }
            }
            #endregion
            #region CF、TC赛制逻辑
            else if (contest.Format == Entity.ContestFormat.Codeforces || contest.Format == Entity.ContestFormat.TopCoder)
            {
                Database.DB db           = new Database.DB();
                var         hack_success = (from h in db.Hacks
                                            where h.Status.ProblemID == problem.ID &&
                                            h.HackerID == user.ID &&
                                            h.ResultAsInt == (int)Entity.HackResult.Success
                                            select h).Count();
                var hack_failed = (from h in db.Hacks
                                   where h.Status.ProblemID == problem.ID &&
                                   h.HackerID == user.ID &&
                                   h.ResultAsInt == (int)Entity.HackResult.Failure
                                   select h).Count();
                Key2 = hack_success;
                Key3 = hack_failed;
                if (statuses.Count == 0)
                {
                    StatusID = null;
                    Css      = "";
                    Display  = "";
                }
                else
                {
                    var status = statuses.Last();
                    if (status.Result == Entity.JudgeResult.Accepted)
                    {
                        var      max   = problem.Credit;
                        var      score = 0;
                        TimeSpan time;
                        if (contest.Format == Entity.ContestFormat.Codeforces)
                        {
                            score = Convert.ToInt32(max * (1 - 0.004 * (status.Time - problem.Contest.Begin).TotalMinutes));
                            time  = status.Time - contest.Begin;
                        }
                        else
                        {
                            var glance = (from g in problem.Glances
                                          where g.UserID == user.ID
                                          select g).SingleOrDefault();
                            score = Convert.ToInt32(max * (1 * 0.004 * (status.Time - glance.Time).TotalMinutes));
                            time  = status.Time - glance.Time;
                        }
                        score -= 50 * statuses.Where(x => !Entity.Status._FreeResults.Contains((Entity.JudgeResult)x.ResultAsInt)).Count();
                        if (score < max * 0.3)
                        {
                            score = Convert.ToInt32(max * 0.3);
                        }
                        Key1     = score;
                        Css      = "rank-green";
                        Display  = Key1 + "<br/>(" + time.ToString("hh':'mm") + ")";
                        StatusID = status.ID;
                    }
                    else
                    {
                        Css     = "rank-red";
                        Display = "(-" + statuses.Count + ")";
                    }
                }
            }
            #endregion
            #region CC赛制逻辑
            else//未实现
            {
            }
            #endregion
        }
コード例 #3
0
 public ClarProblem(Entity.Problem problem)
 {
     ID    = problem.ID;
     Title = problem.Title;
 }
コード例 #4
0
        public ProblemInContest(Entity.Problem problem, Entity.User user)
        {
            ID      = problem.ID;
            Title   = problem.Title;
            Status  = "";
            Credits = "";
            Lock    = "";
            if (problem.Contest.Format == Entity.ContestFormat.Codeforces || problem.Contest.Format == Entity.ContestFormat.TopCoder)
            {
                var max = problem.Credit;
                int current;
                if (problem.Contest.Format == Entity.ContestFormat.Codeforces)
                {
                    current = Convert.ToInt32(max * (1 - 0.004 * (DateTime.Now - problem.Contest.Begin).TotalMinutes));
                    if (current < max * 0.3)
                    {
                        current = Convert.ToInt32(max * 0.3);
                    }
                }
                else
                {
                    if (user == null)
                    {
                        current = max;
                    }
                    else
                    {
                        var glance = (from g in problem.Glances
                                      where g.UserID == user.ID
                                      select g).SingleOrDefault();
                        if (glance == null)
                        {
                            current = max;
                        }
                        else
                        {
                            current = Convert.ToInt32(max * (1 * 0.004 * (DateTime.Now - glance.Time).TotalMinutes));
                        }
                    }
                }
                Credits = String.Format(" / ({0}/{1})", current, max);
            }
            if (user == null)
            {
                return;
            }
            var statuses = (from s in problem.Statuses
                            where s.UserID == user.ID &&
                            !Entity.Status._FreeResults.Contains(s.Result) &&
                            s.Time >= problem.Contest.Begin &&
                            s.Time < problem.Contest.End
                            orderby s.Time ascending
                            select s).ToList();

            if (statuses.Count == 0)
            {
                Status = " / <a class='status-text-nul'>Not submited</a>";
                return;
            }
            if (problem.Contest.Format == Entity.ContestFormat.OI)
            {
                Status = " / <a class='status-text-ac'>Submited</a>";
                return;
            }
            else if (problem.Contest.Format == Entity.ContestFormat.OPJOI)
            {
                var count_ac  = statuses.Last().JudgeTasks.Where(x => x.Result == Entity.JudgeResult.Accepted).Count();
                var count_all = statuses.Last().JudgeTasks.Count;
                var points    = Convert.ToInt32(count_ac * 100 / count_all);
                if (count_all == count_ac)
                {
                    Status = " / <a class='status-text-ac'>" + points + "</a>";
                }
                else
                {
                    Status = " / <a class='status-text-tle'>" + points + "</a>";
                }
                return;
            }
            else if (problem.Contest.Format == Entity.ContestFormat.ACM)
            {
                var status = (from s in statuses
                              where s.Result == Entity.JudgeResult.Accepted
                              select s).FirstOrDefault();
                if (status != null)
                {
                    Status = " / <a class='status-text-ac'>Accepted</a>";
                    return;
                }
                Status = " / <a class='status-text-wa'>Not Accepted</a>";
                return;
            }
            else//CF TC
            {
                var status = statuses.Last();
                if (problem.Locks.Where(x => x.UserID == user.ID).Count() > 0)
                {
                    Lock = " / <a class='status-text-wa'>Locked</a>";
                }
                if (status.Result == Entity.JudgeResult.Accepted)
                {
                    Status = " / <a class='status-text-ac'>Accepted</a>";
                    return;
                }
                else if (status.Result == Entity.JudgeResult.Hacked)
                {
                    Status = " / <a class='status-text-wa'>Hacked</a>";
                    return;
                }
                else
                {
                    Status = " / <a class='status-text-tle'>Not Accepted</a>";
                    return;
                }
            }
        }
コード例 #5
0
ファイル: InitData.cs プロジェクト: iJzFan/17HelpCore
        /// <summary>
        /// Add Proplems Data
        /// </summary>
        public async Task AddProblems()
        {
            Entity.User yezi = await _context.Users.Where(x => x.Name == "yezi").FirstOrDefaultAsync();

            Entity.User DK = await _context.Users.Where(x => x.Name == "DK").FirstOrDefaultAsync();

            List <Entity.Problem> list = new List <Entity.Problem>()
            {
                new Entity.Problem
                {
                    //CreateTime = Problem.PhoneGap_CreateTime,
                    Body   = Problem.PhoneGap_Body,
                    Reward = Problem.PhoneGap_Reward,
                    Title  = Problem.PhoneGap_Title,
                    UserId = yezi.Id,
                },
                new Entity.Problem
                {
                    //CreateTime = Problem.SSCE_CreateTime,
                    Body   = Problem.SSCE_Body,
                    Reward = Problem.SSCE_Reward,
                    Title  = Problem.SSCE_Title,
                    UserId = yezi.Id
                },
                new Entity.Problem
                {
                    //CreateTime = Problem.WebGrease_CreateTime,
                    Body   = Problem.WebGrease_Body,
                    Reward = Problem.WebGrease_Reward,
                    Title  = Problem.WebGrease_Title,
                    UserId = DK.Id
                },
                new Entity.Problem
                {
                    //CreateTime = Problem.WeChat_CreateTime,
                    Body   = Problem.WeChat_Body,
                    Reward = Problem.WeChat_Reward,
                    Title  = Problem.WeChat_Title,
                    UserId = yezi.Id
                },
                new Entity.Problem
                {
                    //CreateTime = Problem.Install_CreateTime,
                    Body   = Problem.Install_Body,
                    Reward = Problem.Install_Reward,
                    Title  = Problem.Install_Title,
                    UserId = DK.Id
                }
            };

            for (int i = 1; i < 20; i++)
            {
                Entity.Problem fakeproblem = new Entity.Problem
                {
                    Body  = "Fakeproblem" + i.ToString(),
                    Title = "FakeTitle" + i.ToString()
                };
                fakeproblem.SetPrivateFieldInBase("<CreateTime>k__BackingField", DateTime.Now.AddDays(-i));
                fakeproblem.UserId = yezi.Id;
                fakeproblem.Reward = i;
                list.Add(fakeproblem);
            }

            foreach (Entity.Problem problem in list)
            {
                await _context.Problems.AddAsync(problem);

                await _context.SaveChangesAsync();
            }
        }
コード例 #6
0
        public StatusSnapshot(Entity.Problem problem, Entity.User user)
        {
            //var problems = contest.Problems.OrderBy(x => x.Credit).ToList();
            //foreach (var problem in problems)
            //{
            ProblemID    = problem.ID;
            ProblemTitle = problem.Title;
            var contest = problem.Contest;

            if (user == null)
            {
                Result = "N/A";
                Css    = "nul";
                return;
            }
            var statuses = problem.GetContestStatuses().Where(x => x.UserID == user.ID).OrderBy(x => x.Time);

            if (statuses.Count() == 0)
            {
                Result = "N/A";
                Css    = "nul";
                return;
            }
            if (contest.Format == Entity.ContestFormat.OI)
            {
                Result = "HID";
                Css    = "ac";
                return;
            }
            else if (contest.Format == Entity.ContestFormat.OPJOI)
            {
                var count_ac  = statuses.Last().JudgeTasks.Where(x => x.Result == Entity.JudgeResult.Accepted).Count();
                var count_all = statuses.Last().JudgeTasks.Count;
                var points    = Convert.ToInt32(count_ac * 100 / count_all);
                Result = points.ToString();
                if (count_ac == count_all)
                {
                    Css = "ac";
                }
                else
                {
                    Css = "tle";
                }
                return;
            }
            else if (contest.Format == Entity.ContestFormat.ACM)
            {
                var status = statuses.Where(x => x.Result == Entity.JudgeResult.Accepted).FirstOrDefault();
                if (status == null)
                {
                    Result = "NoA";
                    Css    = "tle";
                }
                else
                {
                    Result = "AC";
                    Css    = "ac";
                }
                return;
            }
            else
            {
                var status = statuses.Last();
                if (status.Result == Entity.JudgeResult.Accepted)
                {
                    Result = "AC";
                    Css    = "ac";
                }
                else if (status.Result == Entity.JudgeResult.Hacked)
                {
                    Result = "HKD";
                    Css    = "wa";
                }
                else
                {
                    Result = "NoA";
                    Css    = "tle";
                }
                return;
            }
            //}
        }