Date: Thu, 29 May 2025 19:16:16 +0300
Subject: [PATCH 007/628] fixes
---
.../pages/tournament/PlayersRankingPanel.jsx | 153 +++++++++---------
.../lib/codebattle/bot/playbook_player.ex | 4 +
.../tournament/ranking/by_player.ex | 2 +-
3 files changed, 83 insertions(+), 76 deletions(-)
diff --git a/services/app/apps/codebattle/assets/js/widgets/pages/tournament/PlayersRankingPanel.jsx b/services/app/apps/codebattle/assets/js/widgets/pages/tournament/PlayersRankingPanel.jsx
index 542049dda..c0cd72aef 100644
--- a/services/app/apps/codebattle/assets/js/widgets/pages/tournament/PlayersRankingPanel.jsx
+++ b/services/app/apps/codebattle/assets/js/widgets/pages/tournament/PlayersRankingPanel.jsx
@@ -28,6 +28,8 @@ const tableDataCellClassName = cn(
const PlayersRankingPanel = ({ playersCount, ranking }) => {
const currentUserClanId = useSelector(currentUserClanIdSelector);
+ const rankingItems = ranking?.entries || [];
+
return (
@@ -37,85 +39,86 @@ const PlayersRankingPanel = ({ playersCount, ranking }) => {
.
) : (
-
-
- {i18next.t('Ranking')}
-
-
-
-
-
- |
- {i18next.t('User')}
- |
-
- {i18next.t('Clan')}
- |
-
- {i18next.t('Score')}
- |
-
- {i18next.t('Place')}
- |
-
-
-
- {ranking?.entries?.map(item => (
-
- {item.place > 3 ? (
- <>
-
+ rankingItems.length !== 0 && (
+
+
+ {i18next.t('Ranking')}
+
+
+
+
+
+ |
+ {i18next.t('User')}
+ |
+
+ {i18next.t('Clan')}
+ |
+
+ {i18next.t('Score')}
+ |
+
+ {i18next.t('Place')}
+ |
+
+
+
+ {rankingItems.map(item => (
+
+ {item.place > 3 ? (
+ <>
+
+
+
+ >
+ ) : (
-
- >
- ) : (
-
- )}
-
-
-
+
- {item?.name.slice(0, 11) + (item?.name.length > 11 ? '...' : '')}
-
- |
-
-
+ {item?.name.slice(0, 11) + (item?.name.length > 11 ? '...' : '')}
+
+ |
+
+
+ {item?.clan?.slice(0, 11) + (item?.clan?.length > 11 ? '...' : '')}
+
+ |
+ {item.score} |
+
- {item?.clan?.slice(0, 11) + (item?.clan?.length > 11 ? '...' : '')}
-
- |
- {item.score} |
-
- {item.place}
- |
- |
-
- ))}
-
-
+ {item.place}
+
+
+
+ ))}
+
+
+
-
- )}
+ ))}
diff --git a/services/app/apps/codebattle/lib/codebattle/bot/playbook_player.ex b/services/app/apps/codebattle/lib/codebattle/bot/playbook_player.ex
index ffc153565..dee4f28d2 100644
--- a/services/app/apps/codebattle/lib/codebattle/bot/playbook_player.ex
+++ b/services/app/apps/codebattle/lib/codebattle/bot/playbook_player.ex
@@ -174,6 +174,10 @@ defmodule Codebattle.Bot.PlaybookPlayer do
round(k / (player_rating + b))
end
+ defp get_bot_time_ms(_, _) do
+ 1000 * 120
+ end
+
def stringify_keys(list) when is_list(list) do
Enum.map(list, &stringify_keys/1)
end
diff --git a/services/app/apps/codebattle/lib/codebattle/tournament/ranking/by_player.ex b/services/app/apps/codebattle/lib/codebattle/tournament/ranking/by_player.ex
index a2ed98b98..d00302768 100644
--- a/services/app/apps/codebattle/lib/codebattle/tournament/ranking/by_player.ex
+++ b/services/app/apps/codebattle/lib/codebattle/tournament/ranking/by_player.ex
@@ -13,7 +13,7 @@ defmodule Codebattle.Tournament.Ranking.ByPlayer do
end
def get_nearest_page_by_player(_tournament, _player) do
- []
+ %{ entries: [] }
end
def get_page(_tournament, _page, page_size) do
From e9590ed8b2f607db260fdbd76abc5f1d542c5927 Mon Sep 17 00:00:00 2001
From: ReDBrother
Date: Thu, 29 May 2025 19:47:44 +0300
Subject: [PATCH 008/628] fixes
---
.../codebattle/lib/codebattle/tournament/ranking/by_player.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/services/app/apps/codebattle/lib/codebattle/tournament/ranking/by_player.ex b/services/app/apps/codebattle/lib/codebattle/tournament/ranking/by_player.ex
index d00302768..aabfc17cb 100644
--- a/services/app/apps/codebattle/lib/codebattle/tournament/ranking/by_player.ex
+++ b/services/app/apps/codebattle/lib/codebattle/tournament/ranking/by_player.ex
@@ -13,7 +13,7 @@ defmodule Codebattle.Tournament.Ranking.ByPlayer do
end
def get_nearest_page_by_player(_tournament, _player) do
- %{ entries: [] }
+ %{entries: []}
end
def get_page(_tournament, _page, page_size) do
From 3289c7bc232767945242dceb7804b64f2cc4a65d Mon Sep 17 00:00:00 2001
From: ReDBrother
Date: Thu, 29 May 2025 20:06:45 +0300
Subject: [PATCH 009/628] fixe matchmaking
---
.../app/apps/codebattle/lib/codebattle/tournament/helpers.ex | 4 ++++
.../codebattle/lib/codebattle/tournament/strategy/swiss.ex | 4 ++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/services/app/apps/codebattle/lib/codebattle/tournament/helpers.ex b/services/app/apps/codebattle/lib/codebattle/tournament/helpers.ex
index cc87784b3..ae81b07fb 100644
--- a/services/app/apps/codebattle/lib/codebattle/tournament/helpers.ex
+++ b/services/app/apps/codebattle/lib/codebattle/tournament/helpers.ex
@@ -14,6 +14,8 @@ defmodule Codebattle.Tournament.Helpers do
def get_players(tournament, ids), do: Tournament.Players.get_players(tournament, ids)
+ def get_unbanned_players(tournament), do: tournament |> get_players() |> Enum.filter(&unbanned_player?(&1))
+
def get_tasks(%{tasks_table: nil} = _tournament), do: []
def get_tasks(tournament), do: Tournament.Tasks.get_tasks(tournament)
@@ -349,4 +351,6 @@ defmodule Codebattle.Tournament.Helpers do
end
def get_players_total_games_count(_tournament, player), do: Enum.count(player.matches_ids)
+
+ defp unbanned_player?(player), do: player.state != "banned"
end
diff --git a/services/app/apps/codebattle/lib/codebattle/tournament/strategy/swiss.ex b/services/app/apps/codebattle/lib/codebattle/tournament/strategy/swiss.ex
index f26c7f3c3..954a67299 100644
--- a/services/app/apps/codebattle/lib/codebattle/tournament/strategy/swiss.ex
+++ b/services/app/apps/codebattle/lib/codebattle/tournament/strategy/swiss.ex
@@ -82,7 +82,7 @@ defmodule Codebattle.Tournament.Swiss do
player_pairs =
tournament
- |> get_players()
+ |> get_unbanned_players()
|> Enum.sort_by(& &1.id)
|> Enum.chunk_every(2)
@@ -102,7 +102,7 @@ defmodule Codebattle.Tournament.Swiss do
sorted_players =
tournament
- |> get_players()
+ |> get_unbanned_players()
|> Enum.filter(&(&1.id > 0))
|> Enum.sort_by(& &1.score, :desc)
From f838cad6dab0e7839fd260a73cd2f0bfa17c01a1 Mon Sep 17 00:00:00 2001
From: ReDBrother
Date: Fri, 30 May 2025 09:58:48 +0300
Subject: [PATCH 010/628] fixe matchmaking
---
.../lib/codebattle/tournament/helpers.ex | 18 +++++++++++-------
.../codebattle_web/channels/game_channel.ex | 17 ++++++++++++++++-
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/services/app/apps/codebattle/lib/codebattle/tournament/helpers.ex b/services/app/apps/codebattle/lib/codebattle/tournament/helpers.ex
index ae81b07fb..120ec2e29 100644
--- a/services/app/apps/codebattle/lib/codebattle/tournament/helpers.ex
+++ b/services/app/apps/codebattle/lib/codebattle/tournament/helpers.ex
@@ -242,14 +242,17 @@ defmodule Codebattle.Tournament.Helpers do
def get_active_game_id(tournament, player_id) do
player = get_player(tournament, player_id)
- match_id = List.last(player.matches_ids)
- if match_id do
- tournament
- |> get_match(match_id)
- |> case do
- %{state: "playing"} -> match_id
- _ -> nil
+ if player do
+ match_id = List.last(player.matches_ids)
+
+ if match_id do
+ tournament
+ |> get_match(match_id)
+ |> case do
+ %{state: "playing"} -> match_id
+ _ -> nil
+ end
end
end
end
@@ -350,6 +353,7 @@ defmodule Codebattle.Tournament.Helpers do
t |> Tournament.Tasks.get_task_ids() |> Enum.count()
end
+ def get_players_total_games_count(_tournament, nil), do: 0
def get_players_total_games_count(_tournament, player), do: Enum.count(player.matches_ids)
defp unbanned_player?(player), do: player.state != "banned"
diff --git a/services/app/apps/codebattle/lib/codebattle_web/channels/game_channel.ex b/services/app/apps/codebattle/lib/codebattle_web/channels/game_channel.ex
index 3fc39d10f..d5bae6649 100644
--- a/services/app/apps/codebattle/lib/codebattle_web/channels/game_channel.ex
+++ b/services/app/apps/codebattle/lib/codebattle_web/channels/game_channel.ex
@@ -43,6 +43,8 @@ defmodule CodebattleWeb.GameChannel do
%{entries: ranking}
end)
+ banned? = current_player.state == 'banned'
+
{:ok,
%{
active_game_id: active_game_id,
@@ -63,6 +65,7 @@ defmodule CodebattleWeb.GameChannel do
},
assign(socket,
tournament_id: game.tournament_id,
+ banned?: banned?,
game_id: game_id,
follow_id: follow_id
)}
@@ -70,7 +73,7 @@ defmodule CodebattleWeb.GameChannel do
{:ok,
%{
game: GameView.render_game(game, score)
- }, assign(socket, game_id: game_id, tournament_id: nil, follow_id: nil)}
+ }, assign(socket, game_id: game_id, tournament_id: nil, follow_id: nil, banned?: false)}
end
rescue
e ->
@@ -320,11 +323,23 @@ defmodule CodebattleWeb.GameChannel do
end
def handle_info(%{event: "user:banned", payload: %{player: player}}, socket) do
+ user_id = socket.assigns.current_user.id
+
+ if (user_id == player.id) do
+ socket = assign(socket, banned?: true)
+ end
+
push(socket, "user:banned", %{user_id: player.id})
{:noreply, socket}
end
def handle_info(%{event: "user:unbanned", payload: %{player: player}}, socket) do
+ user_id = socket.assigns.current_user.id
+
+ if (user_id == player.id) do
+ socket = assign(socket, banned?: false)
+ end
+
push(socket, "user:unbanned", %{user_id: player.id})
{:noreply, socket}
end
From 434295a14e859c144334e144d9ffe4d7224c5cdc Mon Sep 17 00:00:00 2001
From: vtm
Date: Fri, 30 May 2025 09:04:03 +0200
Subject: [PATCH 011/628] add fixes
---
.../js/widgets/pages/game/EditorToolbar.jsx | 4 -
.../pages/game/TournamentStatisticsModal.jsx | 3 -
.../pages/game/TournamentUserGameScore.jsx | 35 -----
.../pages/tournament/PlayerStatsPanel.jsx | 6 -
.../pages/tournament/StatisticsCard.jsx | 16 ++-
.../pages/tournament/TournamentPlace.jsx | 4 +-
.../pages/tournament/UsersMatchList.jsx | 11 --
.../assets/js/widgets/selectors/index.js | 1 +
.../js/widgets/utils/useMatchesStatistics.js | 15 +--
.../codebattle/lib/codebattle/game/context.ex | 8 ++
.../codebattle/lib/codebattle/game/engine.ex | 10 +-
.../lib/codebattle/tournament/helpers.ex | 20 +--
.../codebattle/tournament/strategy/base.ex | 124 ++++++++----------
.../codebattle/tournament/strategy/swiss.ex | 10 +-
.../codebattle_web/channels/game_channel.ex | 1 +
.../codebattle_web/channels/main_channel.ex | 6 +-
.../channels/tournament_admin_channel.ex | 2 +-
17 files changed, 110 insertions(+), 166 deletions(-)
delete mode 100644 services/app/apps/codebattle/assets/js/widgets/pages/game/TournamentUserGameScore.jsx
diff --git a/services/app/apps/codebattle/assets/js/widgets/pages/game/EditorToolbar.jsx b/services/app/apps/codebattle/assets/js/widgets/pages/game/EditorToolbar.jsx
index 99e51caf3..ba90620ce 100644
--- a/services/app/apps/codebattle/assets/js/widgets/pages/game/EditorToolbar.jsx
+++ b/services/app/apps/codebattle/assets/js/widgets/pages/game/EditorToolbar.jsx
@@ -11,7 +11,6 @@ import GameActionButtons from './GameActionButtons';
import GameBanPlayerButton from './GameBanPlayerButton';
import GameReportButton from './GameReportButton';
import GameResultIcon from './GameResultIcon';
-import TournamentUserGameScore from './TournamentUserGameScore';
import UserGameScore from './UserGameScore';
import VimModeButton from './VimModeButton';
@@ -80,9 +79,6 @@ const EditorToolbar = ({
{mode === GameRoomModes.standard && (
)}
- {mode === GameRoomModes.tournament && (
-
- )}
diff --git a/services/app/apps/codebattle/assets/js/widgets/pages/game/TournamentStatisticsModal.jsx b/services/app/apps/codebattle/assets/js/widgets/pages/game/TournamentStatisticsModal.jsx
index 3657798a5..60e451950 100644
--- a/services/app/apps/codebattle/assets/js/widgets/pages/game/TournamentStatisticsModal.jsx
+++ b/services/app/apps/codebattle/assets/js/widgets/pages/game/TournamentStatisticsModal.jsx
@@ -74,7 +74,6 @@ const TournamentStatisticsModal = NiceModal.create(() => {
{firstPlayer?.name}
- {player.score}
{player.winMatches.length}
{Math.ceil(player.avgTests)}
@@ -87,14 +86,12 @@ const TournamentStatisticsModal = NiceModal.create(() => {
Player
- Score
Wins
AVG Tests
AVG Solving speed
{secondPlayer?.name}
-
{opponent.score}
{opponent.winMatches.length}
{Math.ceil(opponent.avgTests)}
diff --git a/services/app/apps/codebattle/assets/js/widgets/pages/game/TournamentUserGameScore.jsx b/services/app/apps/codebattle/assets/js/widgets/pages/game/TournamentUserGameScore.jsx
deleted file mode 100644
index 57a5d663a..000000000
--- a/services/app/apps/codebattle/assets/js/widgets/pages/game/TournamentUserGameScore.jsx
+++ /dev/null
@@ -1,35 +0,0 @@
-import React, { useMemo, memo } from 'react';
-
-import cn from 'classnames';
-import { useSelector } from 'react-redux';
-
-import { tournamentSelector } from '@/selectors';
-import useMatchesStatistics from '@/utils/useMatchesStatistics';
-
-function TournamentUserGameScore({ userId }) {
- const { type, matches, currentRoundPosition } = useSelector(tournamentSelector);
- const roundMatches = useMemo(() => (
- Object.values(matches || {}).filter(match => match.roundPosition === currentRoundPosition)
- ), [matches, currentRoundPosition]);
-
- const [player, opponent] = useMatchesStatistics(userId, roundMatches);
-
- if (type !== 'swiss' || roundMatches.length === 0) {
- return null;
- }
-
- const scoreResultClass = cn('ml-2', {
- 'cb-game-score-won': player.score > opponent.score,
- 'cb-game-score-lost': player.score < opponent.score,
- 'cb-game-score-draw': player.score === opponent.score,
- });
-
- return (
-
- Score:
- {player.score}
-
- );
-}
-
-export default memo(TournamentUserGameScore);
diff --git a/services/app/apps/codebattle/assets/js/widgets/pages/tournament/PlayerStatsPanel.jsx b/services/app/apps/codebattle/assets/js/widgets/pages/tournament/PlayerStatsPanel.jsx
index 24addfb79..00770aad9 100644
--- a/services/app/apps/codebattle/assets/js/widgets/pages/tournament/PlayerStatsPanel.jsx
+++ b/services/app/apps/codebattle/assets/js/widgets/pages/tournament/PlayerStatsPanel.jsx
@@ -115,9 +115,6 @@ function PlayerStatsPanel({
)}
-
-
-