Skip to content

Commit

Permalink
fix: scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Aug 6, 2022
1 parent dfdfe27 commit fe108d9
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions GZCTF/Repositories/GameRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,37 +116,42 @@ private static IEnumerable<ScoreboardItem> GenScoreboardItems(Data[] data, IDict
Name = j.Key.Team.Name,
Avatar = j.Key.Team.AvatarUrl,
Rank = 0,
SolvedCount = j.Count(s => s.Submission is not null),
Challenges = j.Select(s =>
{
var cid = s.Instance.ChallengeId;
SubmissionType status = SubmissionType.Normal;

if (s.Submission is null)
status = SubmissionType.Unaccepted;
else if (bloods[cid][0] is not null && s.Submission.SubmitTimeUTC <= bloods[cid][0]!.SubmitTimeUTC)
status = SubmissionType.FirstBlood;
else if (bloods[cid][1] is not null && s.Submission.SubmitTimeUTC <= bloods[cid][1]!.SubmitTimeUTC)
status = SubmissionType.SecondBlood;
else if (bloods[cid][2] is not null && s.Submission.SubmitTimeUTC <= bloods[cid][2]!.SubmitTimeUTC)
status = SubmissionType.ThirdBlood;

return new ChallengeItem
SolvedCount = j.GroupBy(s => s.Instance.ChallengeId)
.Count(c => c.Any(s => s.Submission?.Status == AnswerResult.Accepted)),
Challenges = j.GroupBy(s => s.Instance.ChallengeId)
.Select(c =>
{
Id = s.Instance.Challenge.Id,
Type = status,
SubmitTimeUTC = s.Submission?.SubmitTimeUTC,
Score = status switch
var cid = c.Key;
var s = c.OrderBy(s => s.Submission?.SubmitTimeUTC ?? DateTimeOffset.UtcNow)
.FirstOrDefault(s => s.Submission?.Status == AnswerResult.Accepted);

SubmissionType status = SubmissionType.Normal;

if (s?.Submission is null)
status = SubmissionType.Unaccepted;
else if (bloods[cid][0] is not null && s.Submission.SubmitTimeUTC <= bloods[cid][0]!.SubmitTimeUTC)
status = SubmissionType.FirstBlood;
else if (bloods[cid][1] is not null && s.Submission.SubmitTimeUTC <= bloods[cid][1]!.SubmitTimeUTC)
status = SubmissionType.SecondBlood;
else if (bloods[cid][2] is not null && s.Submission.SubmitTimeUTC <= bloods[cid][2]!.SubmitTimeUTC)
status = SubmissionType.ThirdBlood;

return new ChallengeItem
{
SubmissionType.Unaccepted => 0,
SubmissionType.FirstBlood => Convert.ToInt32(s.Instance.Challenge.CurrentScore * 1.05f),
SubmissionType.SecondBlood => Convert.ToInt32(s.Instance.Challenge.CurrentScore * 1.03f),
SubmissionType.ThirdBlood => Convert.ToInt32(s.Instance.Challenge.CurrentScore * 1.01f),
SubmissionType.Normal => s.Instance.Challenge.CurrentScore,
_ => throw new ArgumentException(nameof(status))
}
};
}).ToList()
Id = cid,
Type = status,
SubmitTimeUTC = s?.Submission?.SubmitTimeUTC,
Score = s is null ? 0 : status switch
{
SubmissionType.Unaccepted => 0,
SubmissionType.FirstBlood => Convert.ToInt32(s.Instance.Challenge.CurrentScore * 1.05f),
SubmissionType.SecondBlood => Convert.ToInt32(s.Instance.Challenge.CurrentScore * 1.03f),
SubmissionType.ThirdBlood => Convert.ToInt32(s.Instance.Challenge.CurrentScore * 1.01f),
SubmissionType.Normal => s.Instance.Challenge.CurrentScore,
_ => throw new ArgumentException(nameof(status))
}
};
}).ToList()
},
LastSubmissionTime = j.Select(s => s.Submission?.SubmitTimeUTC ?? DateTimeOffset.UtcNow)
.OrderByDescending(t => t).FirstOrDefault()
Expand Down

0 comments on commit fe108d9

Please sign in to comment.