test contest
This commit is contained in:
@@ -435,6 +435,11 @@ def match_payload(match, user):
|
||||
if reveal_results and opponent_attempt
|
||||
else None
|
||||
),
|
||||
"duration_ms": (
|
||||
opponent_attempt.duration_ms
|
||||
if reveal_results and opponent_attempt
|
||||
else None
|
||||
),
|
||||
}
|
||||
if opponent
|
||||
else None
|
||||
@@ -481,12 +486,13 @@ def refresh_match_state(match_id):
|
||||
elif match.status == RealtimeMatch.Status.ACTIVE and match.started_at:
|
||||
deadline = match.started_at + timedelta(seconds=match.contest.duration_seconds)
|
||||
if timezone.now() >= deadline:
|
||||
elapsed_ms = match.contest.duration_seconds * 1000
|
||||
match.attempts.filter(status=ContestAttempt.Status.ACTIVE).update(
|
||||
status=ContestAttempt.Status.EXPIRED,
|
||||
duration_ms=elapsed_ms,
|
||||
submitted_at=timezone.now(),
|
||||
)
|
||||
now = timezone.now()
|
||||
for attempt in match.attempts.filter(status=ContestAttempt.Status.ACTIVE):
|
||||
elapsed_ms = max(0, int((now - attempt.started_at).total_seconds() * 1000))
|
||||
attempt.status = ContestAttempt.Status.EXPIRED
|
||||
attempt.duration_ms = elapsed_ms
|
||||
attempt.submitted_at = now
|
||||
attempt.save(update_fields=["status", "duration_ms", "submitted_at"])
|
||||
match = finalize_match(match.id)
|
||||
return match
|
||||
|
||||
@@ -516,7 +522,15 @@ def finalize_match(match_id):
|
||||
first_result, second_result = 0.0, 1.0
|
||||
match.winner_id = second.user_id
|
||||
else:
|
||||
first_result = second_result = 0.5
|
||||
diff = first.duration_ms - second.duration_ms
|
||||
if abs(diff) <= 100:
|
||||
first_result = second_result = 0.5
|
||||
elif diff < 0:
|
||||
first_result, second_result = 1.0, 0.0
|
||||
match.winner_id = first.user_id
|
||||
else:
|
||||
first_result, second_result = 0.0, 1.0
|
||||
match.winner_id = second.user_id
|
||||
|
||||
users = {
|
||||
user.id: user
|
||||
|
||||
Reference in New Issue
Block a user