Add openings

This commit is contained in:
sistav committed 2026-07-08 21:24:56 -04:00
1 parent 9c5c599a26
commit 3f8dacfe1c
5 files changed
+22 -24

No files matched your search

+12
View File
@@ -16,6 +16,17 @@ MAX_PLIES = int(os.environ.get("MAX_PLIES", "500"))
MATE_SCORE_CP = 100_000 MATE_SCORE_CP = 100_000
def _opening_name(headers) -> str | None:
url = headers.get("ECOUrl", "")
slug = url.rstrip("/").rsplit("/", 1)[-1]
words = []
for token in slug.split("-"):
if token[:1].isdigit():
break
words.append(token)
return " ".join(words) or headers.get("ECO") or None
def _win_pct(cp: int) -> float: def _win_pct(cp: int) -> float:
return 50 + 50 * (2 / (1 + math.exp(-0.00368208 * cp)) - 1) return 50 + 50 * (2 / (1 + math.exp(-0.00368208 * cp)) - 1)
@@ -115,6 +126,7 @@ async def analyze_pgn(pgn_text: str, username: str | None = None, depth: int = D
"white_rating": white_rating if white_rating.isdigit() else None, "white_rating": white_rating if white_rating.isdigit() else None,
"black_rating": black_rating if black_rating.isdigit() else None, "black_rating": black_rating if black_rating.isdigit() else None,
"game_url": link if link.startswith("https://www.chess.com/") else None, "game_url": link if link.startswith("https://www.chess.com/") else None,
"opening": _opening_name(game.headers),
"result": game.headers.get("Result", ""), "result": game.headers.get("Result", ""),
"initial_eval_cp": white_pov_evals[0], "initial_eval_cp": white_pov_evals[0],
"initial_fen": game.headers.get("FEN", chess.STARTING_FEN), "initial_fen": game.headers.get("FEN", chess.STARTING_FEN),
+3 -3
View File
@@ -4,20 +4,20 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Chess.Sistav.com</title> <title>Chess.Sistav.com</title>
<link rel="icon" href="/static/pieces/wN.svg" type="image/svg+xml" /> <link rel="icon" href="/static/pieces/bQ.svg" type="image/svg+xml" />
<link rel="stylesheet" href="/static/style.css" /> <link rel="stylesheet" href="/static/style.css" />
</head> </head>
<body> <body>
<div class="masthead"> <div class="masthead">
<div class="masthead-inner"> <div class="masthead-inner">
<a href="/">Chess.Sistav.com</a> <a href="/" class="brand" aria-label="Chess.Sistav.com"><img src="/static/pieces/bQ.svg" alt="Chess.Sistav.com" width="26" height="26" /></a>
<a href="https://sistav.com">&larr; sistav.com</a> <a href="https://sistav.com">&larr; sistav.com</a>
</div> </div>
</div> </div>
<header> <header>
<a href="/" class="back-link">&larr; Back to games</a>
<h1 id="game-title"></h1> <h1 id="game-title"></h1>
<p id="game-opening" class="subtitle"></p>
</header> </header>
<main> <main>
+2 -2
View File
@@ -4,13 +4,13 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Chess.Sistav.com</title> <title>Chess.Sistav.com</title>
<link rel="icon" href="/static/pieces/wN.svg" type="image/svg+xml" /> <link rel="icon" href="/static/pieces/bQ.svg" type="image/svg+xml" />
<link rel="stylesheet" href="/static/style.css" /> <link rel="stylesheet" href="/static/style.css" />
</head> </head>
<body> <body>
<div class="masthead"> <div class="masthead">
<div class="masthead-inner"> <div class="masthead-inner">
<a href="/">Chess.Sistav.com</a> <a href="/" class="brand" aria-label="Chess.Sistav.com"><img src="/static/pieces/bQ.svg" alt="Chess.Sistav.com" width="26" height="26" /></a>
<a href="https://sistav.com">&larr; sistav.com</a> <a href="https://sistav.com">&larr; sistav.com</a>
</div> </div>
</div> </div>
+1 -5
View File
@@ -20,12 +20,8 @@ async function init() {
const title = `${analysis.white} vs ${analysis.black}`; const title = `${analysis.white} vs ${analysis.black}`;
document.title = title; document.title = title;
el("game-title").replaceChildren(gameLink(title)); el("game-title").replaceChildren(gameLink(title));
el("game-opening").textContent = analysis.opening || "";
renderPlayerPlates(); renderPlayerPlates();
const back = document.querySelector(".back-link");
if (back && analysis.username) {
back.href = `/u/${encodeURIComponent(analysis.username)}`;
back.textContent = `← Back to ${analysis.username}'s games`;
}
el("analysis-panel").hidden = false; el("analysis-panel").hidden = false;
renderMoveList(); renderMoveList();
renderSummary(); renderSummary();
+4 -14
View File
@@ -34,10 +34,10 @@ body {
.masthead-inner { .masthead-inner {
max-width: 68rem; max-width: 68rem;
margin: 0 auto; margin: 0 auto;
padding: 0.9rem 1.5rem; padding: 0.6rem 1.5rem;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: baseline; align-items: center;
gap: 1rem; gap: 1rem;
flex-wrap: wrap; flex-wrap: wrap;
font-variant: small-caps; font-variant: small-caps;
@@ -46,6 +46,7 @@ body {
color: var(--muted); color: var(--muted);
} }
.masthead a { color: var(--ink); text-decoration: none; } .masthead a { color: var(--ink); text-decoration: none; }
.masthead .brand img { height: 26px; display: block; }
.masthead a:hover { color: var(--gold); } .masthead a:hover { color: var(--gold); }
header { padding: 1.5rem 1.5rem 0; text-align: center; } header { padding: 1.5rem 1.5rem 0; text-align: center; }
@@ -53,7 +54,7 @@ header { padding: 1.5rem 1.5rem 0; text-align: center; }
h1 { h1 {
font-weight: 700; font-weight: 700;
font-style: italic; font-style: italic;
font-size: clamp(1.7rem, 4vw, 2.5rem); font-size: clamp(1.45rem, 3.2vw, 2.1rem);
line-height: 1.15; line-height: 1.15;
margin: 0 0 0.35rem; margin: 0 0 0.35rem;
text-wrap: balance; text-wrap: balance;
@@ -63,17 +64,6 @@ h1 {
.quiet-link { color: inherit; text-decoration: none; } .quiet-link { color: inherit; text-decoration: none; }
.quiet-link:hover { color: var(--gold); } .quiet-link:hover { color: var(--gold); }
.back-link {
display: inline-block;
color: var(--muted);
text-decoration: none;
font-variant: small-caps;
letter-spacing: 0.14em;
font-size: 0.85rem;
margin-bottom: 0.5rem;
}
.back-link:hover { color: var(--gold); }
main { main {
padding: 0.75rem 1.5rem 3rem; padding: 0.75rem 1.5rem 3rem;
max-width: 68rem; max-width: 68rem;