public static bool IsUserInPrivateContest(Entity.User user, Entity.Contest contest)
 {
     if (DateTime.Now < contest.Begin || DateTime.Now >= contest.End)
         return true;
     if (string.IsNullOrEmpty(contest.Password))
         return true;
     if (user == null)
         return false;
     var joinlog = contest.JoinLogs.Where(x => x.UserID == user.ID).FirstOrDefault();
     if (joinlog == null)
     {
         if (user.Role >= Entity.UserRole.Master || (from cm in contest.Managers select cm.UserID).Contains(user.ID))
         {
             Database.DB DbContext = new Database.DB();
             DbContext.JoinLogs.Add(new Entity.JoinLog
             {
                 ContestID = contest.ID,
                 UserID = user.ID
             });
             DbContext.SaveChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
     return true;
 }
Beispiel #2
0
 public static void ThreadBusy(string JudgerName)
 {
     var index = Online.FindIndex(x => x.Username == JudgerName);
     if (index >= 0)
     {
         Online[index].CurrentThreads++;
         Database.DB DbContext = new Database.DB();
         var username = Online[index].Username;
         var user = (from u in DbContext.Users where u.Username == username select u).Single();
         SignalR.CodeCombHub.context.Clients.Group("System Judge").onJudgerStatusChanged(new Models.View.Judger(user, Online[index]));
     }
 }
Beispiel #3
0
 //contest id
 public static List<Models.View.Standing> Build(int id)
 {
     Database.DB db = new Database.DB();
     List<Models.View.Standing> standings = new List<Models.View.Standing>();
     var contest = db.Contests.Find(id);
     var users = (from s in db.Statuses
                  let pid = (from p in db.Problems
                             where p.ContestID == contest.ID
                             select p.ID).ToList()
                  where pid.Contains(s.ProblemID)
                  && s.Time >= contest.Begin
                  && s.Time < contest.End
                  select s.User).Distinct().ToList();
     foreach (var user in users)
         standings.Add(new Models.View.Standing(user, contest));
     Sort(contest.Format, ref standings);
     return standings;
 }
Beispiel #4
0
        public static void Update(int user_id,int contest_id, ref List<Models.View.Standing> standings)
        {
            Database.DB db = new Database.DB();
            var user = db.Users.Find(user_id);
            var contest = db.Contests.Find(contest_id);
            var index = standings.FindIndex(x => x.UserID == user_id);
            var new_standing = new Models.View.Standing(user, contest);
            if (index < 0)
            {
                standings.Add(new_standing);
            }
            else
            {
                standings[index] = new_standing;
            }
            Sort(contest.Format, ref standings);

            //推送排名变化
            SignalR.CodeCombHub.context.Clients.All.onStandingChanged(contest_id, new_standing);
        }
Beispiel #5
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
        }