Профиль: «Основная фракция» — самая игранная с учётом рандома
Под любимой (только ручной выбор) — основная: max по всем партиям, включая рандомные раздачи. Есть у любого сыгравшего игрока. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -331,7 +331,9 @@ class ProfileStats(BaseModel):
|
||||
factions: list[FactionStat] = []
|
||||
best_faction: FactionStat | None = None
|
||||
worst_faction: FactionStat | None = None
|
||||
# Любимая — по партиям с ручным выбором фракции; основная — по всем (включая рандом).
|
||||
most_played_faction: FactionStat | None = None
|
||||
main_faction: FactionStat | None = None
|
||||
recent_form: list[RecentFormItem] = []
|
||||
# Порог «Новичков» (MIN_GAMES) — чтобы UI единообразно подсвечивал
|
||||
# неподтверждённый рейтинг, не дублируя константу на фронте.
|
||||
|
||||
@@ -206,6 +206,8 @@ def profile_stats(session: Session, user_id: int, group_id: int | None = None) -
|
||||
# рандомная раздача о предпочтениях не говорит. Нет ручных выборов — нет любимой.
|
||||
chosen = [f for f in factions if f["chosen_games"] > 0]
|
||||
most_played = max(chosen, key=lambda f: f["chosen_games"]) if chosen else None
|
||||
# Основная — просто самая игранная, включая рандомные раздачи.
|
||||
main = max(factions, key=lambda f: f["games"]) if factions else None
|
||||
return {
|
||||
"user_id": user_id,
|
||||
"overall": overall,
|
||||
@@ -213,6 +215,7 @@ def profile_stats(session: Session, user_id: int, group_id: int | None = None) -
|
||||
"best_faction": best,
|
||||
"worst_faction": worst,
|
||||
"most_played_faction": most_played,
|
||||
"main_faction": main,
|
||||
"recent_form": _recent_form(session, user_id, group_id),
|
||||
"min_games": MIN_GAMES,
|
||||
}
|
||||
|
||||
@@ -157,6 +157,7 @@ def test_most_played_faction_ignores_random(client: TestClient, engine):
|
||||
|
||||
stats = client.get("/api/users/me/stats").json()
|
||||
assert stats["most_played_faction"]["faction_id"] == fids[2] # B, хоть партий с A больше
|
||||
assert stats["main_faction"]["faction_id"] == fids[0] # основная — по всем партиям
|
||||
|
||||
# У соперника все фракции выбраны вручную — любимая считается как раньше.
|
||||
login(client, "Партнёр")
|
||||
@@ -183,3 +184,4 @@ def test_most_played_faction_absent_when_all_random(client: TestClient, engine):
|
||||
)
|
||||
stats = client.get("/api/users/me/stats").json()
|
||||
assert stats["most_played_faction"] is None
|
||||
assert stats["main_faction"]["faction_id"] == fids[0] # основная есть и у рандомщика
|
||||
|
||||
Vendored
+1
@@ -1882,6 +1882,7 @@ export interface components {
|
||||
best_faction?: components["schemas"]["FactionStat"] | null;
|
||||
worst_faction?: components["schemas"]["FactionStat"] | null;
|
||||
most_played_faction?: components["schemas"]["FactionStat"] | null;
|
||||
main_faction?: components["schemas"]["FactionStat"] | null;
|
||||
/**
|
||||
* Recent Form
|
||||
* @default []
|
||||
|
||||
@@ -44,6 +44,12 @@ export function ProfileStatsCard({
|
||||
<b>{stats.most_played_faction.name_ru}</b>
|
||||
</div>
|
||||
)}
|
||||
{stats.main_faction && (
|
||||
<div className="row-between">
|
||||
<div>Основная фракция</div>
|
||||
<b>{stats.main_faction.name_ru}</b>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user