예제 #1
0
 protected BoardViewModel(int cid, IRankingStrategy rule, ProblemCollection problems, IContestTime time)
 {
     ContestId       = cid;
     RankingStrategy = (rule as IRankingStrategyV2) ?? NullRank.Instance;
     Problems        = problems;
     ContestTime     = time;
 }
예제 #2
0
파일: TimeModel.cs 프로젝트: namofun/ccs
 /// <summary>
 /// Initialize an time only model from existing time.
 /// </summary>
 public TimeOnlyModel(IContestTime time)
 {
     StartTime    = time.StartTime;
     EndTime      = time.EndTime;
     FreezeTime   = time.FreezeTime;
     UnfreezeTime = time.UnfreezeTime;
 }
예제 #3
0
 public ScoreboardModel(
     int cid,
     IReadOnlyDictionary <int, IScoreboardRow> data,
     IReadOnlyDictionary <int, Category> categories,
     IReadOnlyDictionary <int, Affiliation> affiliations,
     ProblemCollection problems,
     IContestTime time,
     IRankingStrategy rankingStrategy)
     : this(
         cid,
         rankingStrategy,
         time,
         data,
         categories,
         affiliations,
         problems,
         new SortOrderLookup(categories, data, true, rankingStrategy),
         new SortOrderLookup(categories, data, false, rankingStrategy))
 {
 }
예제 #4
0
 public ScoreboardModel(
     int cid,
     IRankingStrategy rule,
     IContestTime time,
     IReadOnlyDictionary <int, IScoreboardRow> data,
     IReadOnlyDictionary <int, Category> categories,
     IReadOnlyDictionary <int, Affiliation> affiliations,
     ProblemCollection problems,
     SortOrderLookup @public,
     SortOrderLookup restricted)
 {
     ContestId       = cid;
     RankingStrategy = rule;
     Data            = data;
     RefreshTime     = DateTimeOffset.Now;
     Categories      = categories;
     Affiliations    = affiliations;
     Public          = @public;
     Restricted      = restricted;
     Problems        = problems;
     ContestTime     = time;
 }
예제 #5
0
 public Statistics(ProblemStatisticsModel[] model, IRankingStrategyV2 rule, ProblemCollection problems, IContestTime time)
 => (_model, _rule, _problems, _time) = (model, rule, problems, time);
예제 #6
0
        /// <summary>
        /// Gets the state of contest.
        /// </summary>
        /// <param name="time">The contest time.</param>
        /// <param name="nowTime">The current datetime.</param>
        /// <returns>The state of contest.</returns>
        public static ContestState GetState(IContestTime time, DateTimeOffset?nowTime = null)
        {
            // The implementation cannot depend on IContestTime.GetState().
            var            now   = nowTime ?? DateTimeOffset.Now;
            DateTimeOffset?start = time.StartTime;

            if (!start.HasValue)
            {
                return(ContestState.NotScheduled);
            }

            if (start.Value > now)
            {
                // not started yet
                return(ContestState.ScheduledToStart);
            }

            TimeSpan?end = time.EndTime, freeze = time.FreezeTime, unfreeze = time.UnfreezeTime;

            if (!end.HasValue)
            {
                // This is a special state. Usually this field
                // should not be null. But in some cases (like
                // problemset types), this may be null.
                return(ContestState.Started);
            }

            var timeSpan = now - start.Value;

            if (freeze.HasValue)
            {
                // unfreezed
                if (unfreeze.HasValue && unfreeze.Value <= timeSpan)
                {
                    return(ContestState.Finalized);
                }

                // ended, but not freezed
                if (end.Value <= timeSpan)
                {
                    return(ContestState.Ended);
                }

                // freezed, but not ended
                if (freeze.Value <= timeSpan)
                {
                    return(ContestState.Frozen);
                }

                // This contest may freeze later
                return(ContestState.Started);
            }
            else if (end.Value <= timeSpan)
            {
                return(ContestState.Finalized);
            }
            else
            {
                return(ContestState.Started);
            }
        }