Skip to content

Commit 02a24de

Browse files
committed
Add details
1 parent 026ad09 commit 02a24de

11 files changed

Lines changed: 86 additions & 19 deletions

File tree

apps/codebattle/assets/js/widgets/pages/event/ParticipantDashboard.jsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,15 @@ function ParticipantDashboard() {
205205
<div className="d-block d-xl-none me-2 font-weight-bold">
206206
{i18n.t("Score/Total")}:
207207
</div>
208-
<span>
209-
{stage.winsCount}/{stage.gamesCount}
210-
</span>
211-
<span style={{ marginLeft: "0.75rem" }}>{stage.aiScore}</span>
208+
<div className="d-flex flex-column align-items-center">
209+
<span>
210+
{stage.winsCount}/{stage.gamesCount}
211+
</span>
212+
<span>
213+
{stage.aiScore}
214+
{stage.maxScore != null ? `/${stage.maxScore}` : ""}
215+
</span>
216+
</div>
212217
</div>
213218
<div
214219
className={cn(
@@ -219,7 +224,10 @@ function ParticipantDashboard() {
219224
<div className="d-block d-xl-none me-2 font-weight-bold">
220225
{i18n.t("Time spent")}:
221226
</div>
222-
{stage.timeSpent}
227+
<div className="d-flex flex-column align-items-center">
228+
<span>{stage.tournamentTimeSpent}</span>
229+
<span>{stage.groupTournamentTimeSpent}</span>
230+
</div>
223231
</div>
224232
</>
225233
)}

apps/codebattle/assets/js/widgets/selectors/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ export const reportsSelector = createDraftSafeSelector(
489489

490490
export const selectDefaultAvatarUrl = () => logoSvg;
491491

492+
const formatDuration = (seconds) =>
493+
seconds > 0 ? moment.utc(seconds * 1000).format("HH:mm:ss") : "-";
494+
492495
// Participant data selector
493496
export const participantDataSelector = (state) => {
494497
const event = eventSelector(state);
@@ -507,9 +510,10 @@ export const participantDataSelector = (state) => {
507510
const gamesCount = userStage?.gamesCount ? userStage.gamesCount : "-";
508511
const zeroWinsCount = gamesCount === "-" ? "-" : "0";
509512
const winsCount = userStage?.winsCount ? userStage.winsCount : zeroWinsCount;
510-
const totalSeconds =
511-
(userStage?.timeSpentInSeconds || 0) + (userStage?.groupTournamentTimeSpentInSeconds || 0);
513+
const tournamentSeconds = userStage?.timeSpentInSeconds || 0;
514+
const groupTournamentSeconds = userStage?.groupTournamentTimeSpentInSeconds || 0;
512515
const aiScoreRaw = userStage?.groupTournamentScore;
516+
const totalScoreRaw = userStage?.groupTournamentTotalScore;
513517

514518
return {
515519
status: eventStage.status,
@@ -528,7 +532,10 @@ export const participantDataSelector = (state) => {
528532
gamesCount,
529533
winsCount,
530534
aiScore: typeof aiScoreRaw === "number" ? aiScoreRaw : "-",
531-
timeSpent: totalSeconds > 0 ? moment.utc(totalSeconds * 1000).format("HH:mm:ss") : "-",
535+
maxScore: typeof totalScoreRaw === "number" ? totalScoreRaw : null,
536+
tournamentTimeSpent: formatDuration(tournamentSeconds),
537+
groupTournamentTimeSpent: formatDuration(groupTournamentSeconds),
538+
timeSpent: formatDuration(tournamentSeconds + groupTournamentSeconds),
532539
actionButtonText: eventStage.actionButtonText,
533540
confirmationText: eventStage.confirmationText,
534541
nextRoundText: eventStage.nextRoundText,

apps/codebattle/lib/codebattle/event/user_event_stage.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ defmodule Codebattle.UserEvent.Stage do
2121
:place_in_total_rank,
2222
:place_in_category_rank,
2323
:group_tournament_score,
24+
:group_tournament_total_score,
2425
:games_count,
2526
:score,
2627
:time_spent_in_seconds,
@@ -43,6 +44,7 @@ defmodule Codebattle.UserEvent.Stage do
4344
field(:place_in_total_rank, :integer)
4445
field(:place_in_category_rank, :integer)
4546
field(:group_tournament_score, :integer)
47+
field(:group_tournament_total_score, :integer)
4648
field(:games_count, :integer)
4749
field(:score, :integer)
4850
field(:time_spent_in_seconds, :integer)
@@ -69,6 +71,7 @@ defmodule Codebattle.UserEvent.Stage do
6971
:games_count,
7072
:score,
7173
:group_tournament_score,
74+
:group_tournament_total_score,
7275
:time_spent_in_seconds,
7376
:group_tournament_time_spent_in_seconds,
7477
:wins_count,

apps/codebattle/lib/codebattle/group_tournament/group_tournament.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ defmodule Codebattle.GroupTournament do
4141
:template_id,
4242
:tournament_id,
4343
:slice_size,
44-
:slice_strategy
44+
:slice_strategy,
45+
:max_score
4546
]}
4647

4748
schema "group_tournaments" do
@@ -66,6 +67,7 @@ defmodule Codebattle.GroupTournament do
6667
field(:template_id, :string)
6768
field(:slice_size, :integer, default: 16)
6869
field(:slice_strategy, :string, default: "random")
70+
field(:max_score, :integer)
6971
field(:last_round_started_at, :naive_datetime)
7072
field(:last_round_ended_at, :naive_datetime)
7173
field(:meta, :map, default: %{})
@@ -104,7 +106,8 @@ defmodule Codebattle.GroupTournament do
104106
:slice_strategy,
105107
:last_round_started_at,
106108
:last_round_ended_at,
107-
:meta
109+
:meta,
110+
:max_score
108111
])
109112
|> validate_required([
110113
:group_task_id,

apps/codebattle/lib/codebattle/workers/save_group_tournament_results_worker.ex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ defmodule Codebattle.Workers.SaveGroupTournamentResultsWorker do
2727
defp save_results(%GroupTournament{id: group_tournament_id} = group_tournament) do
2828
now = DateTime.truncate(DateTime.utc_now(), :second)
2929
duration = duration_seconds(group_tournament)
30+
total_score = group_tournament.max_score
3031

3132
stages =
3233
UserEventStage
@@ -36,29 +37,30 @@ defmodule Codebattle.Workers.SaveGroupTournamentResultsWorker do
3637

3738
case stages do
3839
[] -> :ok
39-
_ -> update_stages(stages, group_tournament_id, now, duration)
40+
_ -> update_stages(stages, group_tournament_id, now, duration, total_score)
4041
end
4142
end
4243

43-
defp update_stages(stages, group_tournament_id, now, duration) do
44+
defp update_stages(stages, group_tournament_id, now, duration, total_score) do
4445
scores_by_user_id = best_scores_for(group_tournament_id)
4546

4647
Enum.each(stages, fn stage ->
4748
score = Map.get(scores_by_user_id, stage.user_event.user_id, 0)
48-
update_stage(stage, group_tournament_id, now, duration, score)
49+
update_stage(stage, group_tournament_id, now, duration, score, total_score)
4950
end)
5051

5152
:ok
5253
end
5354

54-
defp update_stage(stage, group_tournament_id, now, duration, score) do
55+
defp update_stage(stage, group_tournament_id, now, duration, score, total_score) do
5556
result =
5657
stage
5758
|> UserEventStage.changeset(%{
5859
status: :completed,
5960
finished_at: now,
6061
group_tournament_finished: true,
6162
group_tournament_score: score,
63+
group_tournament_total_score: total_score,
6264
group_tournament_time_spent_in_seconds: duration
6365
})
6466
|> Repo.update()

apps/codebattle/lib/codebattle_web/controllers/api/v1/group_tournament_controller.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ defmodule CodebattleWeb.Api.V1.GroupTournamentController do
158158
group_task_id: group_tournament.group_task_id,
159159
group_task_slug: group_tournament.group_task && group_tournament.group_task.slug,
160160
template_id: Map.get(group_tournament, :template_id),
161-
meta: group_tournament.meta
161+
meta: group_tournament.meta,
162+
max_score: Map.get(group_tournament, :max_score)
162163
}
163164
end
164165

apps/codebattle/lib/codebattle_web/controllers/group_tournament_controller.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ defmodule CodebattleWeb.GroupTournamentController do
4343
end
4444
end
4545

46-
defp handle_my_tournament(%{group_tournament: %{state: "active", id: id}}, conn, _params) do
47-
redirect(conn, to: Routes.group_tournament_path(conn, :show, id))
46+
defp handle_my_tournament(%{group_tournament: %{state: "canceled"}}, conn, _params) do
47+
redirect(conn, to: "/")
4848
end
4949

5050
defp handle_my_tournament(%{group_tournament: %{state: "waiting_participants", id: id}} = record, conn, %{
@@ -58,7 +58,7 @@ defmodule CodebattleWeb.GroupTournamentController do
5858
redirect(conn, to: Routes.group_tournament_path(conn, :show, id))
5959
end
6060

61-
defp handle_my_tournament(%{group_tournament: %{state: "waiting_participants", id: id}}, conn, _params) do
61+
defp handle_my_tournament(%{group_tournament: %{id: id}}, conn, _params) do
6262
redirect(conn, to: Routes.group_tournament_path(conn, :show, id))
6363
end
6464

apps/codebattle/lib/codebattle_web/templates/admin/group_tournament/_form.html.heex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@
6868
{error_tag(f, :round_timeout_seconds)}
6969
</div>
7070

71+
<div class="form-group">
72+
<div><span class="text-white">Max Score</span></div>
73+
{number_input(f, :max_score,
74+
class: "form-control form-control-lg cb-bg-panel cb-border-color text-white",
75+
min: "1"
76+
)}
77+
{error_tag(f, :max_score)}
78+
</div>
79+
7180
<div class="form-group form-check mb-4">
7281
{checkbox(f, :include_bots, class: "form-check-input")}
7382
<label class="form-check-label text-white" for={input_id(f, :include_bots)}>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule Codebattle.Repo.Migrations.AddMaxScoreToGroupTournaments do
2+
@moduledoc false
3+
use Ecto.Migration
4+
5+
def change do
6+
alter table(:group_tournaments) do
7+
add(:max_score, :integer)
8+
end
9+
end
10+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule Codebattle.Repo.Migrations.AddGroupTournamentTotalScoreToUserEventStages do
2+
@moduledoc false
3+
use Ecto.Migration
4+
5+
def change do
6+
alter table(:user_event_stages) do
7+
add(:group_tournament_total_score, :integer)
8+
end
9+
end
10+
end

0 commit comments

Comments
 (0)