подсветка команда в турнирке
This commit is contained in:
80
visual.py
80
visual.py
@@ -203,8 +203,6 @@ def process_player_data(team_json, player_index):
|
|||||||
"time": str(player_data["AvgCarPlayedTime"]),
|
"time": str(player_data["AvgCarPlayedTime"]),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [season_total, season_avg, career_total, career_avg], player_data
|
return [season_total, season_avg, career_total, career_avg], player_data
|
||||||
|
|
||||||
|
|
||||||
@@ -440,15 +438,9 @@ cached_referee = st.session_state.get("referee")
|
|||||||
# standings — может не быть тега/файла
|
# standings — может не быть тега/файла
|
||||||
league_tag = None
|
league_tag = None
|
||||||
if isinstance(cached_game_online, dict):
|
if isinstance(cached_game_online, dict):
|
||||||
league_tag = (cached_game_online.get("league") or {}).get(
|
league_tag = (cached_game_online.get("league") or {}).get("tag")
|
||||||
"tag"
|
|
||||||
)
|
|
||||||
print(cached_game_online.get("comp").get("name"))
|
print(cached_game_online.get("comp").get("name"))
|
||||||
comp_name = (
|
comp_name = (cached_game_online.get("comp") or {}).get("name").replace(" ", "_")
|
||||||
(cached_game_online.get("comp") or {})
|
|
||||||
.get("name")
|
|
||||||
.replace(" ", "_")
|
|
||||||
)
|
|
||||||
if league_tag:
|
if league_tag:
|
||||||
load_data_from_json(f"standings_{league_tag}_{comp_name}")
|
load_data_from_json(f"standings_{league_tag}_{comp_name}")
|
||||||
cached_standings = (
|
cached_standings = (
|
||||||
@@ -834,6 +826,7 @@ columns_game = [
|
|||||||
if cached_team1 and cached_team2:
|
if cached_team1 and cached_team2:
|
||||||
team1_data = process_team_data(cached_team1, columns_game)
|
team1_data = process_team_data(cached_team1, columns_game)
|
||||||
team2_data = process_team_data(cached_team2, columns_game)
|
team2_data = process_team_data(cached_team2, columns_game)
|
||||||
|
|
||||||
# Добавляем звездочку, если pts > PTS_Career_High
|
# Добавляем звездочку, если pts > PTS_Career_High
|
||||||
def _get_first_number(x):
|
def _get_first_number(x):
|
||||||
"""Безопасно вытащить число из строки/значения (например '12 (60%)' -> 12)."""
|
"""Безопасно вытащить число из строки/значения (например '12 (60%)' -> 12)."""
|
||||||
@@ -843,6 +836,7 @@ if cached_team1 and cached_team2:
|
|||||||
s = str(x)
|
s = str(x)
|
||||||
# заберём ведущие число/знак (поддержим +/-)
|
# заберём ведущие число/знак (поддержим +/-)
|
||||||
import re
|
import re
|
||||||
|
|
||||||
m = re.search(r"[-+]?\d+(\.\d+)?", s)
|
m = re.search(r"[-+]?\d+(\.\d+)?", s)
|
||||||
return float(m.group(0)) if m else None
|
return float(m.group(0)) if m else None
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -856,6 +850,7 @@ if cached_team1 and cached_team2:
|
|||||||
"reb": ["REB_Career_High", "CareerHighRebound", "career_high_reb"],
|
"reb": ["REB_Career_High", "CareerHighRebound", "career_high_reb"],
|
||||||
# если нужно — добавь ещё пары "df_column": ["possible_key1","possible_key2"...]
|
# если нужно — добавь ещё пары "df_column": ["possible_key1","possible_key2"...]
|
||||||
}
|
}
|
||||||
|
|
||||||
def _build_career_high_map(cached_team_list):
|
def _build_career_high_map(cached_team_list):
|
||||||
"""Вернёт словарь: player_id -> {stat_key: value} для всех доступных максимумов."""
|
"""Вернёт словарь: player_id -> {stat_key: value} для всех доступных максимумов."""
|
||||||
out = {}
|
out = {}
|
||||||
@@ -878,7 +873,9 @@ if cached_team1 and cached_team2:
|
|||||||
def _ensure_id_column(df, cached_team_list):
|
def _ensure_id_column(df, cached_team_list):
|
||||||
"""Присвоить игрокам id в том же порядке, что и в списке cached_team."""
|
"""Присвоить игрокам id в том же порядке, что и в списке cached_team."""
|
||||||
try:
|
try:
|
||||||
ids = [p.get("id") if isinstance(p, dict) else None for p in cached_team_list][:len(df)]
|
ids = [
|
||||||
|
p.get("id") if isinstance(p, dict) else None for p in cached_team_list
|
||||||
|
][: len(df)]
|
||||||
if "id" not in df.columns:
|
if "id" not in df.columns:
|
||||||
df["id"] = ids
|
df["id"] = ids
|
||||||
else:
|
else:
|
||||||
@@ -914,17 +911,24 @@ if cached_team1 and cached_team2:
|
|||||||
df[col] = new_vals # теперь это текст для отображения
|
df[col] = new_vals # теперь это текст для отображения
|
||||||
|
|
||||||
STAR_COLUMNS = [
|
STAR_COLUMNS = [
|
||||||
"pts", "ast", "stl", "blk", "reb",
|
"pts",
|
||||||
|
"ast",
|
||||||
|
"stl",
|
||||||
|
"blk",
|
||||||
|
"reb",
|
||||||
]
|
]
|
||||||
team1_data["_pts_num"] = pd.to_numeric(team1_data["pts"], errors="coerce")
|
team1_data["_pts_num"] = pd.to_numeric(team1_data["pts"], errors="coerce")
|
||||||
team1_data["_kpi_num"] = pd.to_numeric(team1_data["kpi"], errors="coerce")
|
team1_data["_kpi_num"] = pd.to_numeric(team1_data["kpi"], errors="coerce")
|
||||||
team2_data["_pts_num"] = pd.to_numeric(team2_data["pts"], errors="coerce")
|
team2_data["_pts_num"] = pd.to_numeric(team2_data["pts"], errors="coerce")
|
||||||
team2_data["_kpi_num"] = pd.to_numeric(team2_data["kpi"], errors="coerce")
|
team2_data["_kpi_num"] = pd.to_numeric(team2_data["kpi"], errors="coerce")
|
||||||
|
|
||||||
def highlight_max_by_refcol(df, view_col, ref_col):
|
def highlight_max_by_refcol(df, view_col, ref_col):
|
||||||
ref = pd.to_numeric(df[ref_col], errors="coerce")
|
ref = pd.to_numeric(df[ref_col], errors="coerce")
|
||||||
mx = ref.max()
|
mx = ref.max()
|
||||||
return [("background-color: green" if (pd.notna(v) and v == mx and v > 0) else "")
|
return [
|
||||||
for v in ref]
|
("background-color: green" if (pd.notna(v) and v == mx and v > 0) else "")
|
||||||
|
for v in ref
|
||||||
|
]
|
||||||
|
|
||||||
_mark_star_for_columns(team1_data, cached_team1, STAR_COLUMNS)
|
_mark_star_for_columns(team1_data, cached_team1, STAR_COLUMNS)
|
||||||
_mark_star_for_columns(team2_data, cached_team2, STAR_COLUMNS)
|
_mark_star_for_columns(team2_data, cached_team2, STAR_COLUMNS)
|
||||||
@@ -943,18 +947,34 @@ if cached_team1 and cached_team2:
|
|||||||
# .apply(highlight_max, subset="kpi")
|
# .apply(highlight_max, subset="kpi")
|
||||||
# )
|
# )
|
||||||
team1_styled = (
|
team1_styled = (
|
||||||
team1_data[columns_game].style
|
team1_data[columns_game]
|
||||||
.apply(highlight_grey, axis=1)
|
.style.apply(highlight_grey, axis=1)
|
||||||
.apply(highlight_foul, subset="foul")
|
.apply(highlight_foul, subset="foul")
|
||||||
.apply(lambda _: highlight_max_by_refcol(team1_data, "pts", "_pts_num"), axis=0, subset=["pts"])
|
.apply(
|
||||||
.apply(lambda _: highlight_max_by_refcol(team1_data, "kpi", "_kpi_num"), axis=0, subset=["kpi"])
|
lambda _: highlight_max_by_refcol(team1_data, "pts", "_pts_num"),
|
||||||
|
axis=0,
|
||||||
|
subset=["pts"],
|
||||||
|
)
|
||||||
|
.apply(
|
||||||
|
lambda _: highlight_max_by_refcol(team1_data, "kpi", "_kpi_num"),
|
||||||
|
axis=0,
|
||||||
|
subset=["kpi"],
|
||||||
|
)
|
||||||
)
|
)
|
||||||
team2_styled = (
|
team2_styled = (
|
||||||
team2_data[columns_game].style
|
team2_data[columns_game]
|
||||||
.apply(highlight_grey, axis=1)
|
.style.apply(highlight_grey, axis=1)
|
||||||
.apply(highlight_foul, subset="foul")
|
.apply(highlight_foul, subset="foul")
|
||||||
.apply(lambda _: highlight_max_by_refcol(team2_data, "pts", "_pts_num"), axis=0, subset=["pts"])
|
.apply(
|
||||||
.apply(lambda _: highlight_max_by_refcol(team2_data, "kpi", "_kpi_num"), axis=0, subset=["kpi"])
|
lambda _: highlight_max_by_refcol(team2_data, "pts", "_pts_num"),
|
||||||
|
axis=0,
|
||||||
|
subset=["pts"],
|
||||||
|
)
|
||||||
|
.apply(
|
||||||
|
lambda _: highlight_max_by_refcol(team2_data, "kpi", "_kpi_num"),
|
||||||
|
axis=0,
|
||||||
|
subset=["kpi"],
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_player_all_game(player_data_1):
|
def get_player_all_game(player_data_1):
|
||||||
@@ -1238,16 +1258,10 @@ if cached_standings:
|
|||||||
|
|
||||||
def highlight_teams(s):
|
def highlight_teams(s):
|
||||||
try:
|
try:
|
||||||
t1 = (
|
t1 = (cached_game_online or {}).get("team1", {}).get("teamId")
|
||||||
((cached_game_online or {}).get("result") or {})
|
t2 = (cached_game_online or {}).get("team2", {}).get("teamId")
|
||||||
.get("team1", {})
|
if s.iloc[0] in (t1, t2):
|
||||||
.get("teamId")
|
return ["background-color: #FF4B4B"] * len(s)
|
||||||
)
|
|
||||||
t2 = (
|
|
||||||
((cached_game_online or {}).get("result") or {})
|
|
||||||
.get("team2", {})
|
|
||||||
.get("teamId")
|
|
||||||
)
|
|
||||||
if s.iloc[0] in (t1, t2):
|
if s.iloc[0] in (t1, t2):
|
||||||
return ["background-color: #FF4B4B"] * len(s)
|
return ["background-color: #FF4B4B"] * len(s)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -1278,7 +1292,7 @@ if cached_standings:
|
|||||||
column_config={"logo": st.column_config.ImageColumn("logo")},
|
column_config={"logo": st.column_config.ImageColumn("logo")},
|
||||||
hide_index=True,
|
hide_index=True,
|
||||||
height=610,
|
height=610,
|
||||||
width="content"
|
width="content",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user