Skip to content

Commit 85aaac1

Browse files
committed
fix tournament_results
1 parent fe676c9 commit 85aaac1

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

services/app/apps/codebattle/lib/codebattle/tournament/tournament_result.ex

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ defmodule Codebattle.Tournament.TournamentResult do
151151
tournament
152152
end
153153

154-
def upsert_results(%{type: type, ranking_type: "by_win_loss"} = tournament) when type in ["swiss", "arena"] do
154+
def upsert_results(%{type: type, ranking_type: "by_win_loss"} = tournament)
155+
when type in ["swiss", "arena"] do
155156
clean_results(tournament.id)
156157

157158
Repo.query!("""
@@ -254,6 +255,7 @@ defmodule Codebattle.Tournament.TournamentResult do
254255
}
255256
)
256257
|> Repo.all()
258+
|> Enum.sort_by(&(-&1.round_position))
257259
|> Enum.reduce(%{}, fn result, acc ->
258260
task_history = %{
259261
score: result.score,
@@ -342,8 +344,12 @@ defmodule Codebattle.Tournament.TournamentResult do
342344
where: r.tournament_id == ^tournament.id,
343345
where: r.round_position == ^round_position,
344346
group_by: [r.user_id],
345-
order_by: [desc: sum(r.score), asc: sum(r.duration_sec)],
346-
windows: [overall_partition: [order_by: [desc: sum(r.score), asc: sum(r.duration_sec)]]]
347+
order_by: [desc: sum(r.score), asc: sum(r.duration_sec), asc: r.user_id],
348+
windows: [
349+
overall_partition: [
350+
order_by: [desc: sum(r.score), asc: sum(r.duration_sec), asc: r.user_id]
351+
]
352+
]
347353
)
348354

349355
query
@@ -461,7 +467,7 @@ defmodule Codebattle.Tournament.TournamentResult do
461467
tournament_results tr
462468
WHERE
463469
tr.tournament_id = #{tournament.id}
464-
and score > 0
470+
and result_percent = 100.0
465471
GROUP BY
466472
tr.task_id
467473
)
@@ -471,14 +477,7 @@ defmodule Codebattle.Tournament.TournamentResult do
471477
tasks_data td
472478
INNER JOIN
473479
tasks t ON t.id = td.task_id
474-
ORDER BY
475-
CASE
476-
WHEN t.level = 'hard' THEN 1
477-
WHEN t.level = 'medium' THEN 2
478-
WHEN t.level = 'easy' THEN 3
479-
ELSE 4
480-
END,
481-
min DESC
480+
ORDER BY min DESC
482481
"""
483482
|> Repo.query!()
484483
|> map_repo_result()

0 commit comments

Comments
 (0)