Exemplo n.º 1
0
        public async Task ModifyAsync()
        {
            var adminId = (await UserUtils.GetAdmin()).Id;
            var stuId   = (await UserUtils.GetStudent()).Id;

            var contest = new Data.Contest
            {
                Name   = Guid.NewGuid().ToString(),
                UserId = adminId
            };
            var id = await contestService.CreateContestAsync(contest);

            Assert.AreNotEqual(0, id);

            var studentResult = await contestService.QueryContestAsync(stuId);

            Assert.IsTrue(studentResult.Any(i => i.Id == id && i.Name == contest.Name));

            var newName = Guid.NewGuid().ToString();

            contest.Name = newName;
            await contestService.UpdateContestAsync(contest);

            studentResult = await contestService.QueryContestAsync(stuId);

            Assert.IsTrue(studentResult /*.Cacheable()*/.Any(i => i.Id == id && i.Name == contest.Name));

            await contestService.RemoveContestAsync(id);

            studentResult = await contestService.QueryContestAsync(stuId);

            Assert.IsFalse(studentResult /*.Cacheable()*/.Any(i => i.Id == id));
        }
Exemplo n.º 2
0
 public Contest(Data.Contest c)
 {
     formal_name  = c.Name ?? "";
     name         = c.Name ?? "";
     shortname    = c.ShortName ?? "";
     id           = $"{c.ContestId}";
     penalty_time = 20;
     start_time   = c.StartTime ?? new DateTimeOffset(2050, 1, 1, 0, 0, 0, TimeSpan.FromHours(8));
     end_time     = c.EndTime ?? new DateTimeOffset(2050, 1, 1, 5, 0, 0, TimeSpan.FromHours(8));
     duration     = end_time - start_time;
     scoreboard_freeze_duration = c.EndTime - c.FreezeTime;
 }
Exemplo n.º 3
0
        public JuryEditModel(Data.Contest cont)
        {
            var startTime     = cont.StartTime?.ToString("yyyy-MM-dd HH:mm:ss zzz") ?? "";
            var startDateTime = cont.StartTime ?? DateTimeOffset.UnixEpoch;
            var stopTime      = (cont.EndTime - startDateTime)?.ToDeltaString() ?? "";
            var unfTime       = (cont.UnfreezeTime - startDateTime)?.ToDeltaString() ?? "";
            var freTime       = (cont.FreezeTime - startDateTime)?.ToDeltaString() ?? "";

            ContestId       = cont.ContestId;
            FreezeTime      = freTime;
            Name            = cont.Name;
            ShortName       = cont.ShortName;
            RankingStrategy = cont.RankingStrategy;
            StartTime       = startTime;
            StopTime        = stopTime;
            UnfreezeTime    = unfTime;
            DefaultCategory = cont.RegisterDefaultCategory;
            IsPublic        = cont.IsPublic;
            UsePrintings    = cont.PrintingAvaliable;
            UseBalloon      = cont.BalloonAvaliable;
            StatusAvailable = cont.StatusAvaliable;
        }
Exemplo n.º 4
0
        public async Task ConfigAsync()
        {
            var adminId = (await UserUtils.GetAdmin()).Id;
            var stuId   = (await UserUtils.GetStudent()).Id;

            var contest = new Data.Contest
            {
                Name   = Guid.NewGuid().ToString(),
                UserId = adminId
            };

            var cid = await contestService.CreateContestAsync(contest);

            Assert.AreNotEqual(0, cid);

            var problem = new Data.Problem
            {
                Name   = Guid.NewGuid().ToString(),
                UserId = adminId
            };

            var pid = await problemService.CreateProblemAsync(problem);

            Assert.AreNotEqual(0, pid);

            await contestService.UpdateContestProblemAsync(cid, new[] { pid, pid });

            var result = await problemService.QueryProblemAsync(stuId, cid);

            Assert.IsTrue(result /*.Cacheable()*/.Count(i => i.Id == pid) == 1);

            await contestService.UpdateContestProblemAsync(cid, new int[0]);

            result = await problemService.QueryProblemAsync(stuId, cid);

            Assert.IsFalse(result /*.Cacheable()*/.Any());
        }
Exemplo n.º 5
0
        public async Task ConfigAsync()
        {
            var adminId = (await UserUtils.GetAdmin()).Id;
            var stuId   = (await UserUtils.GetStudent()).Id;

            var group = new Data.Group
            {
                Name   = Guid.NewGuid().ToString(),
                UserId = adminId
            };

            var gid = await groupService.CreateGroupAsync(group);

            Assert.AreNotEqual(0, gid);

            var contest = new Data.Contest
            {
                Name   = Guid.NewGuid().ToString(),
                UserId = adminId
            };

            var cid = await contestService.CreateContestAsync(contest);

            Assert.AreNotEqual(0, cid);

            await groupService.UpdateGroupContestAsync(gid, new[] { cid, cid });

            var result = await contestService.QueryContestAsync(stuId, gid);

            Assert.IsTrue(result /*.Cacheable()*/.Count(i => i.Id == cid) == 1);

            await groupService.UpdateGroupContestAsync(gid, new int[0]);

            result = await contestService.QueryContestAsync(stuId, gid);

            Assert.IsFalse(result /*.Cacheable()*/.Any());
        }
Exemplo n.º 6
0
        public State(Data.Contest ctx)
        {
            id = $"{ctx.ContestId}";

            switch (ctx.GetState())
            {
            case ContestState.Finalized:
                end_of_updates = DateTimeOffset.Now;
                thawed         = ctx.UnfreezeTime;
                ended          = ctx.EndTime;
                finalized      = frozen.HasValue ? thawed : ended;
                frozen         = ctx.FreezeTime;
                started        = ctx.StartTime;
                break;

            case ContestState.Ended:
                ended   = ctx.EndTime;
                frozen  = ctx.FreezeTime;
                started = ctx.StartTime;
                break;

            case ContestState.Frozen:
                frozen  = ctx.FreezeTime;
                started = ctx.StartTime;
                break;

            case ContestState.Started:
                started = ctx.StartTime;
                break;

            case ContestState.NotScheduled:
            case ContestState.ScheduledToStart:
            default:
                break;
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> ChangeState(string target)
        {
            var now = DateTimeOffset.Now;

            var newcont = new Data.Contest
            {
                StartTime    = Contest.StartTime,
                EndTime      = Contest.EndTime,
                FreezeTime   = Contest.FreezeTime,
                UnfreezeTime = Contest.UnfreezeTime,
            };

            var state = newcont.GetState(now);

            if (target == "startnow")
            {
                if (!newcont.EndTime.HasValue)
                {
                    return(GoBackHome("Error no end time specified."));
                }
                now += TimeSpan.FromSeconds(30);
                DateTimeOffset old;

                if (newcont.StartTime.HasValue)
                {
                    // from scheduled to start
                    if (newcont.StartTime.Value < now)
                    {
                        return(GoBackHome("Error starting contest for the remaining time is less than 30 secs."));
                    }
                    old = newcont.StartTime.Value;
                }
                else
                {
                    // from delay to start
                    old = DateTimeOffset.UnixEpoch;
                }

                newcont.StartTime = now;
                newcont.EndTime   = now + (newcont.EndTime.Value - old);
                if (newcont.FreezeTime.HasValue)
                {
                    newcont.FreezeTime = now + (newcont.FreezeTime.Value - old);
                }
                if (newcont.UnfreezeTime.HasValue)
                {
                    newcont.UnfreezeTime = now + (newcont.UnfreezeTime.Value - old);
                }
            }
            else if (target == "freeze")
            {
                if (state != ContestState.Started)
                {
                    return(GoBackHome("Error contest is not started."));
                }
                newcont.FreezeTime = now;
            }
            else if (target == "endnow")
            {
                if (state != ContestState.Started && state != ContestState.Frozen)
                {
                    return(GoBackHome("Error contest has not started or has ended."));
                }
                newcont.EndTime = now;

                if (newcont.FreezeTime.HasValue && newcont.FreezeTime.Value > now)
                {
                    newcont.FreezeTime = now;
                }
            }
            else if (target == "unfreeze")
            {
                if (state != ContestState.Ended)
                {
                    return(GoBackHome("Error contest has not ended."));
                }
                newcont.UnfreezeTime = now;
            }
            else if (target == "delay")
            {
                if (state != ContestState.ScheduledToStart)
                {
                    return(GoBackHome("Error contest has been started."));
                }

                var old = newcont.StartTime.Value;
                newcont.StartTime = null;
                if (newcont.EndTime.HasValue)
                {
                    newcont.EndTime = DateTimeOffset.UnixEpoch + (newcont.EndTime.Value - old);
                }
                if (newcont.FreezeTime.HasValue)
                {
                    newcont.FreezeTime = DateTimeOffset.UnixEpoch + (newcont.FreezeTime.Value - old);
                }
                if (newcont.UnfreezeTime.HasValue)
                {
                    newcont.UnfreezeTime = DateTimeOffset.UnixEpoch + (newcont.UnfreezeTime.Value - old);
                }
            }

            await Store.UpdateAsync(Contest.ContestId,
                                    c => new Data.Contest
            {
                StartTime    = newcont.StartTime,
                EndTime      = newcont.EndTime,
                FreezeTime   = newcont.FreezeTime,
                UnfreezeTime = newcont.UnfreezeTime,
            });


            await HttpContext.AuditAsync("changed time", $"{Contest.ContestId}");

            return(GoBackHome("Contest state changed."));
        }
Exemplo n.º 8
0
 public static async Task <AnalysisTwoModel> AnalysisAsync(
     ISubmissionStore store,
     Data.Contest contest,
     ContestProblem prob,
     IReadOnlyDictionary <int, (string, string)> cls)