First commit
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
.git/
|
||||||
|
.venv/
|
||||||
|
venv/
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
app/__pycache__
|
||||||
|
*.db
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends stockfish \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY app ./app
|
||||||
|
|
||||||
|
ENV STOCKFISH_PATH=/usr/games/stockfish
|
||||||
|
ENV ANALYSIS_DEPTH=14
|
||||||
|
ENV ANALYSIS_CONCURRENCY=2
|
||||||
|
ENV DATA_DIR=/app/data
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Chess
|
||||||
|
|
||||||
|
Pulls your games from the public chess.com API and runs them through Stockfish
|
||||||
|
to show the engine's best move. I'm tired of dealing with paid analysis websites.
|
||||||
|
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
Chess piece graphics (`app/static/pieces/`) are the "cburnett" set by
|
||||||
|
[Colin M.L. Burnett](https://en.wikipedia.org/wiki/User:Cburnett), used under the
|
||||||
|
BSD license (also available under GPLv2+ and CC BY-SA), obtained from the
|
||||||
|
[lichess-org/lila](https://github.com/lichess-org/lila/tree/master/public/piece/cburnett)
|
||||||
|
repository.
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
|
||||||
|
import io
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
import chess
|
||||||
|
import chess.engine
|
||||||
|
import chess.pgn
|
||||||
|
|
||||||
|
STOCKFISH_PATH = os.environ.get("STOCKFISH_PATH") or shutil.which("stockfish") or "/usr/games/stockfish"
|
||||||
|
DEFAULT_DEPTH = int(os.environ.get("ANALYSIS_DEPTH", "14"))
|
||||||
|
STOCKFISH_THREADS = int(os.environ.get("STOCKFISH_THREADS", "2"))
|
||||||
|
STOCKFISH_HASH_MB = int(os.environ.get("STOCKFISH_HASH_MB", "128"))
|
||||||
|
MAX_PLIES = int(os.environ.get("MAX_PLIES", "500"))
|
||||||
|
MATE_SCORE_CP = 100_000
|
||||||
|
|
||||||
|
|
||||||
|
def classify(loss_cp: int) -> str:
|
||||||
|
if loss_cp <= 10:
|
||||||
|
return "best"
|
||||||
|
if loss_cp <= 50:
|
||||||
|
return "good"
|
||||||
|
if loss_cp <= 100:
|
||||||
|
return "inaccuracy"
|
||||||
|
if loss_cp <= 200:
|
||||||
|
return "mistake"
|
||||||
|
return "blunder"
|
||||||
|
|
||||||
|
|
||||||
|
async def analyze_pgn(pgn_text: str, username: str | None = None, depth: int = DEFAULT_DEPTH) -> dict:
|
||||||
|
game = chess.pgn.read_game(io.StringIO(pgn_text))
|
||||||
|
if game is None:
|
||||||
|
raise ValueError("Could not parse PGN")
|
||||||
|
|
||||||
|
white = game.headers.get("White", "")
|
||||||
|
black = game.headers.get("Black", "")
|
||||||
|
user_color = None
|
||||||
|
if username:
|
||||||
|
if username.lower() == white.lower():
|
||||||
|
user_color = chess.WHITE
|
||||||
|
elif username.lower() == black.lower():
|
||||||
|
user_color = chess.BLACK
|
||||||
|
|
||||||
|
board = game.board()
|
||||||
|
moves = list(game.mainline_moves())
|
||||||
|
if len(moves) > MAX_PLIES:
|
||||||
|
raise ValueError(f"Game too long to analyze (over {MAX_PLIES} half-moves).")
|
||||||
|
limit = chess.engine.Limit(depth=depth)
|
||||||
|
|
||||||
|
transport, engine = await chess.engine.popen_uci(STOCKFISH_PATH)
|
||||||
|
try:
|
||||||
|
await engine.configure({"Threads": STOCKFISH_THREADS, "Hash": STOCKFISH_HASH_MB})
|
||||||
|
|
||||||
|
white_pov_evals: list[int] = []
|
||||||
|
best_moves: list[chess.Move | None] = []
|
||||||
|
|
||||||
|
info = await engine.analyse(board, limit)
|
||||||
|
white_pov_evals.append(info["score"].pov(chess.WHITE).score(mate_score=MATE_SCORE_CP))
|
||||||
|
best_moves.append(info["pv"][0] if info.get("pv") else None)
|
||||||
|
|
||||||
|
for move in moves:
|
||||||
|
board.push(move)
|
||||||
|
info = await engine.analyse(board, limit)
|
||||||
|
white_pov_evals.append(info["score"].pov(chess.WHITE).score(mate_score=MATE_SCORE_CP))
|
||||||
|
best_moves.append(info["pv"][0] if info.get("pv") else None)
|
||||||
|
finally:
|
||||||
|
await engine.quit()
|
||||||
|
|
||||||
|
board = game.board()
|
||||||
|
moves_out = []
|
||||||
|
for ply, move in enumerate(moves):
|
||||||
|
mover_is_white = board.turn == chess.WHITE
|
||||||
|
eval_before = white_pov_evals[ply]
|
||||||
|
eval_after = white_pov_evals[ply + 1]
|
||||||
|
|
||||||
|
san_played = board.san(move)
|
||||||
|
best_move = best_moves[ply]
|
||||||
|
san_best = board.san(best_move) if best_move and best_move in board.legal_moves else None
|
||||||
|
uci_best = best_move.uci() if best_move else None
|
||||||
|
|
||||||
|
loss_cp = None
|
||||||
|
if eval_before is not None and eval_after is not None:
|
||||||
|
loss_cp = (eval_before - eval_after) if mover_is_white else (eval_after - eval_before)
|
||||||
|
loss_cp = max(0, loss_cp)
|
||||||
|
|
||||||
|
board.push(move)
|
||||||
|
|
||||||
|
is_user_move = None
|
||||||
|
if user_color is not None:
|
||||||
|
is_user_move = mover_is_white == user_color
|
||||||
|
|
||||||
|
moves_out.append({
|
||||||
|
"ply": ply + 1,
|
||||||
|
"color": "white" if mover_is_white else "black",
|
||||||
|
"move_san": san_played,
|
||||||
|
"move_uci": move.uci(),
|
||||||
|
"best_move_san": san_best,
|
||||||
|
"best_move_uci": uci_best,
|
||||||
|
"eval_cp": eval_after,
|
||||||
|
"loss_cp": loss_cp,
|
||||||
|
"classification": classify(loss_cp) if loss_cp is not None else "unknown",
|
||||||
|
"is_user_move": is_user_move,
|
||||||
|
"fen_after": board.fen(),
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
"white": white,
|
||||||
|
"black": black,
|
||||||
|
"result": game.headers.get("Result", ""),
|
||||||
|
"initial_eval_cp": white_pov_evals[0],
|
||||||
|
"initial_fen": game.headers.get("FEN", chess.STARTING_FEN),
|
||||||
|
"user_color": "white" if user_color == chess.WHITE else ("black" if user_color == chess.BLACK else None),
|
||||||
|
"moves": moves_out,
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sqlite3
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
DATA_DIR = os.environ.get("DATA_DIR", str(Path(__file__).parent.parent / "data"))
|
||||||
|
DB_FILENAME = os.environ.get("DB_FILENAME", "analysis.db")
|
||||||
|
DB_PATH = os.environ.get("DB_PATH") or str(Path(DATA_DIR) / DB_FILENAME)
|
||||||
|
RETENTION_DAYS = float(os.environ.get("RETENTION_DAYS", "7"))
|
||||||
|
MAX_AGE_SECONDS = RETENTION_DAYS * 24 * 3600
|
||||||
|
|
||||||
|
|
||||||
|
def _purge_old(conn: sqlite3.Connection) -> None:
|
||||||
|
conn.execute("DELETE FROM games WHERE created_at < ?", (time.time() - MAX_AGE_SECONDS,))
|
||||||
|
|
||||||
|
|
||||||
|
def _connect() -> sqlite3.Connection:
|
||||||
|
conn = sqlite3.connect(DB_PATH)
|
||||||
|
conn.execute("PRAGMA journal_mode=WAL")
|
||||||
|
return conn
|
||||||
|
|
||||||
|
|
||||||
|
def init_db() -> None:
|
||||||
|
Path(DB_PATH).parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
conn = _connect()
|
||||||
|
try:
|
||||||
|
with conn:
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS games (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
username TEXT,
|
||||||
|
white TEXT,
|
||||||
|
black TEXT,
|
||||||
|
result TEXT,
|
||||||
|
depth INTEGER,
|
||||||
|
created_at REAL,
|
||||||
|
analysis_json TEXT NOT NULL
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
_purge_old(conn)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def get_game(game_id: str) -> dict | None:
|
||||||
|
conn = _connect()
|
||||||
|
try:
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT username, analysis_json FROM games WHERE id = ?", (game_id,)
|
||||||
|
).fetchone()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
if row is None:
|
||||||
|
return None
|
||||||
|
analysis = json.loads(row[1])
|
||||||
|
analysis["username"] = row[0]
|
||||||
|
return analysis
|
||||||
|
|
||||||
|
|
||||||
|
def save_game(game_id: str, username: str | None, depth: int, analysis: dict) -> None:
|
||||||
|
conn = _connect()
|
||||||
|
try:
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
INSERT OR REPLACE INTO games
|
||||||
|
(id, username, white, black, result, depth, created_at, analysis_json)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
game_id,
|
||||||
|
username,
|
||||||
|
analysis.get("white"),
|
||||||
|
analysis.get("black"),
|
||||||
|
analysis.get("result"),
|
||||||
|
depth,
|
||||||
|
time.time(),
|
||||||
|
json.dumps(analysis),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
_purge_old(conn)
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import os
|
||||||
|
from urllib.parse import quote
|
||||||
|
import httpx
|
||||||
|
from fastapi import HTTPException
|
||||||
|
|
||||||
|
BASE_URL = "https://api.chess.com/pub"
|
||||||
|
HEADERS = {"User-Agent": os.environ.get("CHESSCOM_USER_AGENT", "chess.sistav.com")}
|
||||||
|
|
||||||
|
|
||||||
|
async def get_archives(username: str) -> list[str]:
|
||||||
|
url = f"{BASE_URL}/player/{quote(username, safe='')}/games/archives"
|
||||||
|
async with httpx.AsyncClient(headers=HEADERS, timeout=15) as client:
|
||||||
|
resp = await client.get(url)
|
||||||
|
if resp.status_code == 404:
|
||||||
|
raise HTTPException(status_code=404, detail=f"No chess.com player found for '{username}'")
|
||||||
|
resp.raise_for_status()
|
||||||
|
archive_urls = resp.json().get("archives", [])
|
||||||
|
months = []
|
||||||
|
for archive_url in archive_urls:
|
||||||
|
# archive_url ends in .../games/YYYY/MM
|
||||||
|
parts = archive_url.rstrip("/").split("/")
|
||||||
|
year, month = parts[-2], parts[-1]
|
||||||
|
months.append(f"{year}-{month}")
|
||||||
|
return list(reversed(months))
|
||||||
|
|
||||||
|
|
||||||
|
async def get_games(username: str, year: str, month: str) -> list[dict]:
|
||||||
|
url = f"{BASE_URL}/player/{quote(username, safe='')}/games/{quote(year, safe='')}/{quote(month, safe='')}"
|
||||||
|
async with httpx.AsyncClient(headers=HEADERS, timeout=30) as client:
|
||||||
|
resp = await client.get(url)
|
||||||
|
if resp.status_code == 404:
|
||||||
|
return []
|
||||||
|
resp.raise_for_status()
|
||||||
|
games = resp.json().get("games", [])
|
||||||
|
return list(reversed(games))
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
import asyncio
|
||||||
|
import hashlib
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from fastapi import FastAPI, HTTPException
|
||||||
|
from fastapi.responses import FileResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
from app import db, fetch
|
||||||
|
from app.analysis import analyze_pgn
|
||||||
|
|
||||||
|
logger = logging.getLogger("chess_analyzer")
|
||||||
|
|
||||||
|
|
||||||
|
@asynccontextmanager
|
||||||
|
async def lifespan(app: FastAPI):
|
||||||
|
db.init_db()
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI(title="Chess Analyzer", lifespan=lifespan)
|
||||||
|
|
||||||
|
STATIC_DIR = Path(__file__).parent / "static"
|
||||||
|
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
||||||
|
|
||||||
|
ANALYSIS_CONCURRENCY = int(os.environ.get("ANALYSIS_CONCURRENCY", "2"))
|
||||||
|
MAX_DEPTH = int(os.environ.get("MAX_DEPTH", "20"))
|
||||||
|
analysis_semaphore = asyncio.Semaphore(ANALYSIS_CONCURRENCY)
|
||||||
|
|
||||||
|
|
||||||
|
def _game_id(pgn: str, username: str | None, depth: int) -> str:
|
||||||
|
h = hashlib.sha256()
|
||||||
|
h.update(pgn.encode("utf-8"))
|
||||||
|
h.update(b"\0")
|
||||||
|
h.update((username or "").encode("utf-8"))
|
||||||
|
h.update(b"\0")
|
||||||
|
h.update(str(depth).encode("utf-8"))
|
||||||
|
return h.hexdigest()[:16]
|
||||||
|
|
||||||
|
|
||||||
|
class AnalyzeRequest(BaseModel):
|
||||||
|
pgn: str = Field(max_length=65536)
|
||||||
|
username: str | None = Field(default=None, max_length=64)
|
||||||
|
depth: int | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
async def root():
|
||||||
|
return FileResponse(STATIC_DIR / "index.html")
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/game/{game_id}")
|
||||||
|
async def game_page(game_id: str):
|
||||||
|
return FileResponse(STATIC_DIR / "game.html")
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/u/{username}")
|
||||||
|
async def user_page(username: str):
|
||||||
|
return FileResponse(STATIC_DIR / "index.html")
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/health")
|
||||||
|
async def health():
|
||||||
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/archives/{username}")
|
||||||
|
async def archives(username: str):
|
||||||
|
months = await fetch.get_archives(username)
|
||||||
|
return {"username": username, "months": months}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/games/{username}/{year}/{month}")
|
||||||
|
async def games(username: str, year: str, month: str):
|
||||||
|
raw_games = await fetch.get_games(username, year, month)
|
||||||
|
games_out = []
|
||||||
|
for g in raw_games:
|
||||||
|
white = g.get("white", {})
|
||||||
|
black = g.get("black", {})
|
||||||
|
games_out.append({
|
||||||
|
"url": g.get("url"),
|
||||||
|
"end_time": g.get("end_time"),
|
||||||
|
"time_class": g.get("time_class"),
|
||||||
|
"time_control": g.get("time_control"),
|
||||||
|
"rated": g.get("rated"),
|
||||||
|
"white": {"username": white.get("username"), "rating": white.get("rating"), "result": white.get("result")},
|
||||||
|
"black": {"username": black.get("username"), "rating": black.get("rating"), "result": black.get("result")},
|
||||||
|
"pgn": g.get("pgn"),
|
||||||
|
})
|
||||||
|
return {"username": username, "year": year, "month": month, "games": games_out}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/game/{game_id}")
|
||||||
|
async def get_game(game_id: str):
|
||||||
|
result = await asyncio.to_thread(db.get_game, game_id)
|
||||||
|
if result is None:
|
||||||
|
raise HTTPException(status_code=404, detail="No analysis found for that game id.")
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/api/analyze")
|
||||||
|
async def analyze(req: AnalyzeRequest):
|
||||||
|
depth = req.depth or int(os.environ.get("ANALYSIS_DEPTH", "14"))
|
||||||
|
depth = max(1, min(depth, MAX_DEPTH))
|
||||||
|
|
||||||
|
# chess.com usernames are case-insensitive; normalize so "Foo" and "foo"
|
||||||
|
# hit the same cache entry.
|
||||||
|
username = req.username.strip().lower() if req.username else None
|
||||||
|
|
||||||
|
game_id = _game_id(req.pgn, username, depth)
|
||||||
|
|
||||||
|
cached = await asyncio.to_thread(db.get_game, game_id)
|
||||||
|
if cached is not None:
|
||||||
|
return {"id": game_id, **cached}
|
||||||
|
|
||||||
|
async with analysis_semaphore:
|
||||||
|
# Another request may have populated the cache while we waited for the semaphore.
|
||||||
|
cached = await asyncio.to_thread(db.get_game, game_id)
|
||||||
|
if cached is not None:
|
||||||
|
return {"id": game_id, **cached}
|
||||||
|
try:
|
||||||
|
result = await analyze_pgn(req.pgn, username=username, depth=depth)
|
||||||
|
except ValueError as e:
|
||||||
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Stockfish analysis failed")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=500,
|
||||||
|
detail="Analysis failed. Check server logs — this is usually a missing/misconfigured Stockfish binary.",
|
||||||
|
)
|
||||||
|
|
||||||
|
await asyncio.to_thread(db.save_game, game_id, username, depth, result)
|
||||||
|
return {"id": game_id, **result}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Chess.Sistav.com</title>
|
||||||
|
<link rel="icon" href="/static/pieces/wN.svg" type="image/svg+xml" />
|
||||||
|
<link rel="stylesheet" href="/static/style.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="masthead">
|
||||||
|
<div class="masthead-inner">
|
||||||
|
<a href="/">Chess.Sistav.com</a>
|
||||||
|
<a href="https://sistav.com">← sistav.com</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<a href="/" class="back-link">← Back to games</a>
|
||||||
|
<h1 id="game-title"></h1>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<p id="status" class="status"></p>
|
||||||
|
|
||||||
|
<section class="panel" id="analysis-panel" hidden>
|
||||||
|
<div class="analysis-layout">
|
||||||
|
<div class="board-column">
|
||||||
|
<div id="board-wrap">
|
||||||
|
<div id="board"></div>
|
||||||
|
<svg id="arrows" viewBox="0 0 100 100" preserveAspectRatio="none"></svg>
|
||||||
|
</div>
|
||||||
|
<div class="nav-row">
|
||||||
|
<button id="prev-btn">← Prev</button>
|
||||||
|
<span id="ply-label"></span>
|
||||||
|
<button id="next-btn">Next →</button>
|
||||||
|
</div>
|
||||||
|
<div id="eval-graph-wrap">
|
||||||
|
<svg id="eval-graph" role="img" aria-label="Evaluation over the course of the game"></svg>
|
||||||
|
<div id="eval-tooltip" class="eval-tooltip" hidden></div>
|
||||||
|
</div>
|
||||||
|
<div id="move-detail" class="move-detail" hidden></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="side-column">
|
||||||
|
<div id="summary" class="summary"></div>
|
||||||
|
<div id="move-list" class="move-list"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script src="/static/js/common.js"></script>
|
||||||
|
<script src="/static/js/game.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Chess.Sistav.com</title>
|
||||||
|
<link rel="icon" href="/static/pieces/wN.svg" type="image/svg+xml" />
|
||||||
|
<link rel="stylesheet" href="/static/style.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="masthead">
|
||||||
|
<div class="masthead-inner">
|
||||||
|
<a href="/">Chess.Sistav.com</a>
|
||||||
|
<a href="https://sistav.com">← sistav.com</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<h1>Chess Analysis</h1>
|
||||||
|
<p class="subtitle">"Jam a man of fortune, and J must seek my fortune." - Félix Lengyel</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section class="panel" id="lookup-panel">
|
||||||
|
<div class="row lookup-row">
|
||||||
|
<input id="player-search" name="player-search" type="search"
|
||||||
|
placeholder="chess.com username" autocomplete="off"
|
||||||
|
data-bwignore="true" data-lpignore="true" data-1p-ignore />
|
||||||
|
<button id="load-btn">Load</button>
|
||||||
|
</div>
|
||||||
|
<p id="status" class="status"></p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="panel" id="games-panel" hidden>
|
||||||
|
<div class="games-toolbar">
|
||||||
|
<div class="month-nav">
|
||||||
|
<button id="older-month-btn" class="month-step" title="Older month" disabled>◀</button>
|
||||||
|
<select id="month-select" disabled></select>
|
||||||
|
<button id="newer-month-btn" class="month-step" title="Newer month" disabled>▶</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<table id="games-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Opponent</th>
|
||||||
|
<th>Color</th>
|
||||||
|
<th>Result</th>
|
||||||
|
<th>Time control</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="games-body"></tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<div id="busy-overlay" hidden>
|
||||||
|
<div class="busy-box">
|
||||||
|
<div class="busy-spinner"></div>
|
||||||
|
<p>Running Stockfish analysis…</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="/static/js/common.js"></script>
|
||||||
|
<script src="/static/js/index.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
const STARTING_FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";
|
||||||
|
|
||||||
|
// CBurnett piece set by Colin M.L. Burnett (GPLv2+/BSD/CC BY-SA),
|
||||||
|
// via https://github.com/lichess-org/lila/tree/master/public/piece/cburnett
|
||||||
|
const PIECE_IMAGE_DIR = "/static/pieces";
|
||||||
|
|
||||||
|
// Classic traffic-light classification colors (for arrows on the board).
|
||||||
|
const CLASS_COLORS = {
|
||||||
|
best: "#3fae5b",
|
||||||
|
good: "#7fbf5f",
|
||||||
|
inaccuracy: "#d9b23c",
|
||||||
|
mistake: "#e08a3c",
|
||||||
|
blunder: "#d64545",
|
||||||
|
unknown: "#888888",
|
||||||
|
};
|
||||||
|
const BEST_MOVE_ARROW_COLOR = "#23242a"; // the editor's ink line
|
||||||
|
|
||||||
|
const el = (id) => document.getElementById(id);
|
||||||
|
|
||||||
|
async function apiGet(url) {
|
||||||
|
const resp = await fetch(url);
|
||||||
|
if (!resp.ok) {
|
||||||
|
const body = await resp.json().catch(() => ({}));
|
||||||
|
throw new Error(body.detail || `Request failed (${resp.status})`);
|
||||||
|
}
|
||||||
|
return resp.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function apiPost(url, payload) {
|
||||||
|
const resp = await fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
if (!resp.ok) {
|
||||||
|
const body = await resp.json().catch(() => ({}));
|
||||||
|
throw new Error(body.detail || `Request failed (${resp.status})`);
|
||||||
|
}
|
||||||
|
return resp.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatEval(cp) {
|
||||||
|
if (cp === null || cp === undefined) return "n/a";
|
||||||
|
// Server encodes "mate in N plies" as ±(100000 - N); render as chess notation.
|
||||||
|
if (Math.abs(cp) > 90000) {
|
||||||
|
const plies = 100000 - Math.abs(cp);
|
||||||
|
const label = plies <= 0 ? "#" : `M${Math.ceil(plies / 2)}`;
|
||||||
|
return (cp > 0 ? "+" : "-") + label;
|
||||||
|
}
|
||||||
|
const pawns = (cp / 100).toFixed(2);
|
||||||
|
return cp > 0 ? `+${pawns}` : pawns;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderBoard(fen, flip) {
|
||||||
|
const placement = fen.split(" ")[0] || STARTING_FEN;
|
||||||
|
const rows = placement.split("/"); // rows[0] = rank 8 ... rows[7] = rank 1
|
||||||
|
|
||||||
|
const board = el("board");
|
||||||
|
board.innerHTML = "";
|
||||||
|
|
||||||
|
const rankOrder = flip ? [...rows].reverse() : rows;
|
||||||
|
|
||||||
|
rankOrder.forEach((rowStr, displayRank) => {
|
||||||
|
const rankNumber = flip ? displayRank + 1 : 8 - displayRank;
|
||||||
|
const cells = [];
|
||||||
|
for (const ch of rowStr) {
|
||||||
|
if (/\d/.test(ch)) {
|
||||||
|
for (let i = 0; i < Number(ch); i++) cells.push(null);
|
||||||
|
} else {
|
||||||
|
cells.push(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const orderedCells = flip ? [...cells].reverse() : cells;
|
||||||
|
orderedCells.forEach((piece, fileIdx) => {
|
||||||
|
const fileNumber = flip ? 8 - fileIdx : fileIdx + 1;
|
||||||
|
const isLight = (fileNumber + rankNumber) % 2 === 0;
|
||||||
|
const square = document.createElement("div");
|
||||||
|
square.className = `square ${isLight ? "light" : "dark"}`;
|
||||||
|
if (piece) {
|
||||||
|
const isWhitePiece = piece === piece.toUpperCase();
|
||||||
|
const img = document.createElement("img");
|
||||||
|
img.className = "piece";
|
||||||
|
img.src = `${PIECE_IMAGE_DIR}/${isWhitePiece ? "w" : "b"}${piece.toUpperCase()}.svg`;
|
||||||
|
img.alt = piece;
|
||||||
|
img.draggable = false;
|
||||||
|
square.appendChild(img);
|
||||||
|
}
|
||||||
|
board.appendChild(square);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Center of a square (e.g. "e4") as {x, y} in a 0-100 viewBox, matching renderBoard's layout.
|
||||||
|
function squareToXY(square, flip) {
|
||||||
|
const file = square.charCodeAt(0) - "a".charCodeAt(0); // 0-7
|
||||||
|
const rank = Number(square[1]); // 1-8
|
||||||
|
const fileIdx = flip ? 7 - file : file;
|
||||||
|
const displayRank = flip ? rank - 1 : 8 - rank;
|
||||||
|
return { x: ((fileIdx + 0.5) / 8) * 100, y: ((displayRank + 0.5) / 8) * 100 };
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeArrow(from, to, color, opacity) {
|
||||||
|
const ns = "http://www.w3.org/2000/svg";
|
||||||
|
const dx = to.x - from.x;
|
||||||
|
const dy = to.y - from.y;
|
||||||
|
const len = Math.hypot(dx, dy) || 1;
|
||||||
|
const ux = dx / len;
|
||||||
|
const uy = dy / len;
|
||||||
|
const perpX = -uy;
|
||||||
|
const perpY = ux;
|
||||||
|
|
||||||
|
const headLen = 3;
|
||||||
|
const headHalfWidth = 1.8;
|
||||||
|
const tip = { x: to.x - ux * 1.5, y: to.y - uy * 1.5 };
|
||||||
|
const headBack = { x: tip.x - ux * headLen, y: tip.y - uy * headLen };
|
||||||
|
|
||||||
|
const group = document.createElementNS(ns, "g");
|
||||||
|
|
||||||
|
const line = document.createElementNS(ns, "line");
|
||||||
|
line.setAttribute("x1", from.x);
|
||||||
|
line.setAttribute("y1", from.y);
|
||||||
|
line.setAttribute("x2", headBack.x);
|
||||||
|
line.setAttribute("y2", headBack.y);
|
||||||
|
line.setAttribute("stroke", color);
|
||||||
|
line.setAttribute("stroke-width", "1.1");
|
||||||
|
line.setAttribute("stroke-linecap", "round");
|
||||||
|
line.setAttribute("opacity", String(opacity));
|
||||||
|
group.appendChild(line);
|
||||||
|
|
||||||
|
const poly = document.createElementNS(ns, "polygon");
|
||||||
|
const p1 = `${tip.x},${tip.y}`;
|
||||||
|
const p2 = `${headBack.x + perpX * headHalfWidth},${headBack.y + perpY * headHalfWidth}`;
|
||||||
|
const p3 = `${headBack.x - perpX * headHalfWidth},${headBack.y - perpY * headHalfWidth}`;
|
||||||
|
poly.setAttribute("points", `${p1} ${p2} ${p3}`);
|
||||||
|
poly.setAttribute("fill", color);
|
||||||
|
poly.setAttribute("opacity", String(opacity));
|
||||||
|
group.appendChild(poly);
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderArrows(move, flip) {
|
||||||
|
const svg = el("arrows");
|
||||||
|
svg.innerHTML = "";
|
||||||
|
if (!move) return;
|
||||||
|
|
||||||
|
if (move.move_uci) {
|
||||||
|
const from = squareToXY(move.move_uci.slice(0, 2), flip);
|
||||||
|
const to = squareToXY(move.move_uci.slice(2, 4), flip);
|
||||||
|
const color = CLASS_COLORS[move.classification] || CLASS_COLORS.unknown;
|
||||||
|
svg.appendChild(makeArrow(from, to, color, 0.9));
|
||||||
|
}
|
||||||
|
if (move.best_move_uci && move.best_move_uci !== move.move_uci) {
|
||||||
|
const from = squareToXY(move.best_move_uci.slice(0, 2), flip);
|
||||||
|
const to = squareToXY(move.best_move_uci.slice(2, 4), flip);
|
||||||
|
svg.appendChild(makeArrow(from, to, BEST_MOVE_ARROW_COLOR, 0.85));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,262 @@
|
|||||||
|
let analysis = null;
|
||||||
|
let currentPly = 0;
|
||||||
|
|
||||||
|
function setStatus(msg, isError = false) {
|
||||||
|
const status = el("status");
|
||||||
|
status.textContent = msg;
|
||||||
|
status.classList.toggle("error", isError);
|
||||||
|
}
|
||||||
|
|
||||||
|
function gameIdFromUrl() {
|
||||||
|
const parts = window.location.pathname.split("/").filter(Boolean);
|
||||||
|
return parts[parts.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
const id = gameIdFromUrl();
|
||||||
|
setStatus("Loading analysis...");
|
||||||
|
try {
|
||||||
|
analysis = await apiGet(`/api/game/${id}`);
|
||||||
|
el("game-title").textContent = `${analysis.white} vs ${analysis.black}`;
|
||||||
|
document.title = `${analysis.white} vs ${analysis.black}`;
|
||||||
|
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;
|
||||||
|
renderMoveList();
|
||||||
|
renderSummary();
|
||||||
|
renderEvalGraph();
|
||||||
|
currentPly = 0;
|
||||||
|
showPly(0);
|
||||||
|
setStatus("");
|
||||||
|
} catch (err) {
|
||||||
|
setStatus(err.message, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSummary() {
|
||||||
|
const counts = { best: 0, good: 0, inaccuracy: 0, mistake: 0, blunder: 0 };
|
||||||
|
for (const m of analysis.moves) {
|
||||||
|
if (analysis.user_color && !m.is_user_move) continue;
|
||||||
|
if (counts[m.classification] !== undefined) counts[m.classification]++;
|
||||||
|
}
|
||||||
|
const summary = el("summary");
|
||||||
|
summary.innerHTML = `
|
||||||
|
<span class="chip best">Best: ${counts.best}</span>
|
||||||
|
<span class="chip good">Good: ${counts.good}</span>
|
||||||
|
<span class="chip inaccuracy">Inaccuracy: ${counts.inaccuracy}</span>
|
||||||
|
<span class="chip mistake">Mistake: ${counts.mistake}</span>
|
||||||
|
<span class="chip blunder">Blunder: ${counts.blunder}</span>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print-style annotation marks; ordinary moves go unremarked, as in a column.
|
||||||
|
const NAG_MARKS = { best: "!", good: "", inaccuracy: "?!", mistake: "?", blunder: "??", unknown: "" };
|
||||||
|
|
||||||
|
function renderMoveList() {
|
||||||
|
const list = el("move-list");
|
||||||
|
list.innerHTML = "";
|
||||||
|
analysis.moves.forEach((m) => {
|
||||||
|
const row = document.createElement("div");
|
||||||
|
row.className = "move-row";
|
||||||
|
row.dataset.ply = m.ply;
|
||||||
|
const num = Math.ceil(m.ply / 2);
|
||||||
|
const label = m.color === "white" ? `${num}. ${m.move_san}` : `${num}... ${m.move_san}`;
|
||||||
|
const mark = NAG_MARKS[m.classification] || "";
|
||||||
|
row.innerHTML = `
|
||||||
|
<span>${label}<span class="tag ${m.classification}">${mark}</span></span>
|
||||||
|
<span class="row-eval">${formatEval(m.eval_cp)}</span>`;
|
||||||
|
row.addEventListener("click", () => showPly(m.ply));
|
||||||
|
list.appendChild(row);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function showPly(ply) {
|
||||||
|
if (!analysis) return;
|
||||||
|
ply = Math.max(0, Math.min(ply, analysis.moves.length));
|
||||||
|
currentPly = ply;
|
||||||
|
|
||||||
|
const fen = ply === 0 ? analysis.initial_fen : analysis.moves[ply - 1].fen_after;
|
||||||
|
const flip = analysis.user_color === "black";
|
||||||
|
renderBoard(fen, flip);
|
||||||
|
renderArrows(ply === 0 ? null : analysis.moves[ply - 1], flip);
|
||||||
|
|
||||||
|
el("prev-btn").disabled = ply === 0;
|
||||||
|
el("next-btn").disabled = ply === analysis.moves.length;
|
||||||
|
el("ply-label").textContent = `Position ${ply} / ${analysis.moves.length}`;
|
||||||
|
|
||||||
|
document.querySelectorAll(".move-row").forEach((row) => {
|
||||||
|
row.classList.toggle("active", Number(row.dataset.ply) === ply);
|
||||||
|
});
|
||||||
|
|
||||||
|
updateEvalMarker(ply);
|
||||||
|
|
||||||
|
const detail = el("move-detail");
|
||||||
|
detail.hidden = ply === 0;
|
||||||
|
if (ply > 0) {
|
||||||
|
const m = analysis.moves[ply - 1];
|
||||||
|
const bestLine = m.best_move_san && m.best_move_san !== m.move_san
|
||||||
|
? `Stockfish's best move here was <strong>${m.best_move_san}</strong>.`
|
||||||
|
: `This was the engine's top move.`;
|
||||||
|
const mark = NAG_MARKS[m.classification] || "";
|
||||||
|
detail.innerHTML = `
|
||||||
|
<div><strong>${m.color}</strong> played <strong>${m.move_san}</strong>
|
||||||
|
— <span class="tag ${m.classification}">${m.classification}${mark ? ` (${mark})` : ""}</span></div>
|
||||||
|
<div>${bestLine}</div>
|
||||||
|
<div>Eval after this move: ${formatEval(m.eval_cp)}</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Eval graph ----
|
||||||
|
// viewBox coordinates; the SVG scales uniformly to the board column's width.
|
||||||
|
const GRAPH = { W: 1000, H: 240, PAD: 10 };
|
||||||
|
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||||
|
let graphPts = null; // [{ply, cp}], index == ply
|
||||||
|
|
||||||
|
// Compress evals so ±1 pawn uses most of the height and mate scores don't
|
||||||
|
// flatten everything else (same idea as lichess's curve).
|
||||||
|
function evalToY(cp) {
|
||||||
|
const v = Math.atan((cp ?? 0) / 300) / (Math.PI / 2); // -1..1, + = white better
|
||||||
|
return GRAPH.PAD + ((1 - v) / 2) * (GRAPH.H - 2 * GRAPH.PAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
function graphX(ply) {
|
||||||
|
const n = Math.max(1, graphPts.length - 1);
|
||||||
|
return (ply / n) * GRAPH.W;
|
||||||
|
}
|
||||||
|
|
||||||
|
function svgEl(tag, attrs) {
|
||||||
|
const node = document.createElementNS(SVG_NS, tag);
|
||||||
|
for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, v);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderEvalGraph() {
|
||||||
|
const svg = el("eval-graph");
|
||||||
|
svg.innerHTML = "";
|
||||||
|
svg.setAttribute("viewBox", `0 0 ${GRAPH.W} ${GRAPH.H}`);
|
||||||
|
|
||||||
|
// Older cached analyses predate initial_eval_cp; fall back to level.
|
||||||
|
const startCp = analysis.initial_eval_cp ?? 0;
|
||||||
|
graphPts = [{ ply: 0, cp: startCp }];
|
||||||
|
let lastCp = startCp;
|
||||||
|
for (const m of analysis.moves) {
|
||||||
|
if (m.eval_cp !== null && m.eval_cp !== undefined) lastCp = m.eval_cp;
|
||||||
|
graphPts.push({ ply: m.ply, cp: lastCp });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ink on paper, like a stock listing: the faint shaded area is White's
|
||||||
|
// share of the game, the ink line is the story, red dots mark the sins.
|
||||||
|
const PAPER = "#f7f3e8";
|
||||||
|
const INK = "#23242a";
|
||||||
|
const AREA = "#e7dfc9";
|
||||||
|
const GOLD = "#a8892e";
|
||||||
|
const RED = "#9c2b23";
|
||||||
|
const HAIRLINE = "#c9c2ac";
|
||||||
|
|
||||||
|
let curve = "";
|
||||||
|
for (const p of graphPts) {
|
||||||
|
curve += `${curve ? " L" : "M"} ${graphX(p.ply).toFixed(1)} ${evalToY(p.cp).toFixed(1)}`;
|
||||||
|
}
|
||||||
|
svg.appendChild(svgEl("path", {
|
||||||
|
d: `M 0 ${GRAPH.H} ${curve.replace(/^M/, "L")} L ${GRAPH.W} ${GRAPH.H} Z`,
|
||||||
|
fill: AREA,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Equality midline — a solid hairline rule.
|
||||||
|
const midY = evalToY(0);
|
||||||
|
svg.appendChild(svgEl("line", {
|
||||||
|
x1: 0, y1: midY, x2: GRAPH.W, y2: midY,
|
||||||
|
stroke: HAIRLINE, "stroke-width": 1.5,
|
||||||
|
}));
|
||||||
|
|
||||||
|
svg.appendChild(svgEl("path", {
|
||||||
|
d: curve, fill: "none", stroke: INK, "stroke-width": 2.5,
|
||||||
|
"stroke-linejoin": "round",
|
||||||
|
}));
|
||||||
|
|
||||||
|
for (const m of analysis.moves) {
|
||||||
|
if (m.classification !== "blunder") continue;
|
||||||
|
svg.appendChild(svgEl("circle", {
|
||||||
|
cx: graphX(m.ply), cy: evalToY(m.eval_cp), r: 8,
|
||||||
|
fill: RED, stroke: PAPER, "stroke-width": 3,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hover crosshair + current-position marker.
|
||||||
|
svg.appendChild(svgEl("line", {
|
||||||
|
id: "eval-hover-line", x1: 0, y1: 0, x2: 0, y2: GRAPH.H,
|
||||||
|
stroke: "#6b6656", "stroke-width": 1.5, visibility: "hidden",
|
||||||
|
}));
|
||||||
|
svg.appendChild(svgEl("line", {
|
||||||
|
id: "eval-marker-line", x1: 0, y1: 0, x2: 0, y2: GRAPH.H,
|
||||||
|
stroke: GOLD, "stroke-width": 2.5,
|
||||||
|
}));
|
||||||
|
svg.appendChild(svgEl("circle", {
|
||||||
|
id: "eval-marker-dot", cx: 0, cy: midY, r: 9,
|
||||||
|
fill: GOLD, stroke: PAPER, "stroke-width": 2.5,
|
||||||
|
}));
|
||||||
|
|
||||||
|
svg.addEventListener("mousemove", onGraphHover);
|
||||||
|
svg.addEventListener("mouseleave", hideGraphHover);
|
||||||
|
svg.addEventListener("click", (e) => showPly(plyAtCursor(e)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function plyAtCursor(e) {
|
||||||
|
const rect = el("eval-graph").getBoundingClientRect();
|
||||||
|
const frac = (e.clientX - rect.left) / rect.width;
|
||||||
|
const n = graphPts.length - 1;
|
||||||
|
return Math.max(0, Math.min(n, Math.round(frac * n)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function onGraphHover(e) {
|
||||||
|
const ply = plyAtCursor(e);
|
||||||
|
const line = el("eval-hover-line");
|
||||||
|
const x = graphX(ply);
|
||||||
|
line.setAttribute("x1", x);
|
||||||
|
line.setAttribute("x2", x);
|
||||||
|
line.setAttribute("visibility", "visible");
|
||||||
|
|
||||||
|
const tip = el("eval-tooltip");
|
||||||
|
if (ply === 0) {
|
||||||
|
tip.textContent = "Start";
|
||||||
|
} else {
|
||||||
|
const m = analysis.moves[ply - 1];
|
||||||
|
const num = Math.ceil(m.ply / 2);
|
||||||
|
const label = m.color === "white" ? `${num}. ${m.move_san}` : `${num}... ${m.move_san}`;
|
||||||
|
tip.textContent = `${label} ${formatEval(m.eval_cp)}`;
|
||||||
|
}
|
||||||
|
tip.hidden = false;
|
||||||
|
const wrapRect = el("eval-graph-wrap").getBoundingClientRect();
|
||||||
|
const rect = el("eval-graph").getBoundingClientRect();
|
||||||
|
const px = rect.left - wrapRect.left + (x / GRAPH.W) * rect.width;
|
||||||
|
tip.style.left = `${Math.max(40, Math.min(wrapRect.width - 40, px))}px`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideGraphHover() {
|
||||||
|
el("eval-hover-line").setAttribute("visibility", "hidden");
|
||||||
|
el("eval-tooltip").hidden = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateEvalMarker(ply) {
|
||||||
|
if (!graphPts) return;
|
||||||
|
const x = graphX(ply);
|
||||||
|
const line = el("eval-marker-line");
|
||||||
|
line.setAttribute("x1", x);
|
||||||
|
line.setAttribute("x2", x);
|
||||||
|
const dot = el("eval-marker-dot");
|
||||||
|
dot.setAttribute("cx", x);
|
||||||
|
dot.setAttribute("cy", evalToY(graphPts[ply].cp));
|
||||||
|
}
|
||||||
|
|
||||||
|
el("prev-btn").addEventListener("click", () => showPly(currentPly - 1));
|
||||||
|
el("next-btn").addEventListener("click", () => showPly(currentPly + 1));
|
||||||
|
document.addEventListener("keydown", (e) => {
|
||||||
|
if (e.key === "ArrowLeft") showPly(currentPly - 1);
|
||||||
|
if (e.key === "ArrowRight") showPly(currentPly + 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
init();
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
let currentUsername = null;
|
||||||
|
let currentGames = [];
|
||||||
|
let months = []; // "YYYY-MM", newest first
|
||||||
|
|
||||||
|
function setStatus(msg, isError = false) {
|
||||||
|
const status = el("status");
|
||||||
|
status.textContent = msg;
|
||||||
|
status.classList.toggle("error", isError);
|
||||||
|
}
|
||||||
|
|
||||||
|
el("load-btn").addEventListener("click", loadArchivesAndGames);
|
||||||
|
el("player-search").addEventListener("keydown", (e) => {
|
||||||
|
if (e.key === "Enter") loadArchivesAndGames();
|
||||||
|
});
|
||||||
|
el("month-select").addEventListener("change", () => {
|
||||||
|
updateMonthButtons();
|
||||||
|
const [year, month] = el("month-select").value.split("-");
|
||||||
|
loadGames(currentUsername, year, month);
|
||||||
|
});
|
||||||
|
el("older-month-btn").addEventListener("click", () => stepMonth(1));
|
||||||
|
el("newer-month-btn").addEventListener("click", () => stepMonth(-1));
|
||||||
|
|
||||||
|
function monthLabel(value) {
|
||||||
|
const [year, month] = value.split("-");
|
||||||
|
const name = new Date(Number(year), Number(month) - 1, 1)
|
||||||
|
.toLocaleString(undefined, { month: "long" });
|
||||||
|
return `${name} ${year}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Months grouped by year so long histories don't become one endless flat list.
|
||||||
|
function buildMonthSelect() {
|
||||||
|
const select = el("month-select");
|
||||||
|
select.innerHTML = "";
|
||||||
|
let group = null;
|
||||||
|
for (const value of months) {
|
||||||
|
const year = value.split("-")[0];
|
||||||
|
if (!group || group.label !== year) {
|
||||||
|
group = document.createElement("optgroup");
|
||||||
|
group.label = year;
|
||||||
|
select.appendChild(group);
|
||||||
|
}
|
||||||
|
const opt = document.createElement("option");
|
||||||
|
opt.value = value;
|
||||||
|
opt.textContent = monthLabel(value);
|
||||||
|
group.appendChild(opt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateMonthButtons() {
|
||||||
|
const idx = months.indexOf(el("month-select").value);
|
||||||
|
el("newer-month-btn").disabled = idx <= 0;
|
||||||
|
el("older-month-btn").disabled = idx === -1 || idx >= months.length - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function stepMonth(delta) {
|
||||||
|
const select = el("month-select");
|
||||||
|
const idx = months.indexOf(select.value) + delta;
|
||||||
|
if (idx < 0 || idx >= months.length) return;
|
||||||
|
select.value = months[idx];
|
||||||
|
select.dispatchEvent(new Event("change"));
|
||||||
|
}
|
||||||
|
|
||||||
|
function usernameFromUrl() {
|
||||||
|
const match = window.location.pathname.match(/^\/u\/([^/]+)$/);
|
||||||
|
return match ? decodeURIComponent(match[1]).toLowerCase() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadArchivesAndGames() {
|
||||||
|
// chess.com usernames are case-insensitive — normalize so bookmarks and
|
||||||
|
// the analysis cache don't split on capitalization.
|
||||||
|
const username = el("player-search").value.trim().toLowerCase();
|
||||||
|
if (!username) return;
|
||||||
|
currentUsername = username;
|
||||||
|
// Keep the address bar bookmarkable: /u/<username> reloads straight into this view.
|
||||||
|
history.replaceState(null, "", `/u/${encodeURIComponent(username)}`);
|
||||||
|
el("games-panel").hidden = true;
|
||||||
|
setStatus("Loading archives...");
|
||||||
|
try {
|
||||||
|
const data = await apiGet(`/api/archives/${encodeURIComponent(username)}`);
|
||||||
|
months = data.months;
|
||||||
|
buildMonthSelect();
|
||||||
|
el("month-select").disabled = months.length === 0;
|
||||||
|
updateMonthButtons();
|
||||||
|
if (months.length === 0) {
|
||||||
|
setStatus("No games found for that username.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const [year, month] = months[0].split("-");
|
||||||
|
await loadGames(username, year, month);
|
||||||
|
} catch (err) {
|
||||||
|
setStatus(err.message, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let loadSeq = 0;
|
||||||
|
|
||||||
|
async function loadGames(username, year, month) {
|
||||||
|
const seq = ++loadSeq;
|
||||||
|
setStatus(`Loading games for ${year}-${month}...`);
|
||||||
|
try {
|
||||||
|
const data = await apiGet(`/api/games/${encodeURIComponent(username)}/${year}/${month}`);
|
||||||
|
if (seq !== loadSeq) return; // superseded by a newer month switch
|
||||||
|
currentGames = data.games;
|
||||||
|
renderGamesTable();
|
||||||
|
setStatus(currentGames.length ? `${currentGames.length} games loaded.` : "No games this month.");
|
||||||
|
el("games-panel").hidden = false;
|
||||||
|
} catch (err) {
|
||||||
|
setStatus(err.message, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// chess.com result codes that mean a draw; "win" means win, the rest are losses.
|
||||||
|
const DRAW_RESULTS = new Set([
|
||||||
|
"agreed", "repetition", "stalemate", "insufficient", "50move", "timevsinsufficient",
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Human words for chess.com's result codes.
|
||||||
|
const RESULT_REASONS = {
|
||||||
|
checkmated: "mate",
|
||||||
|
timeout: "time",
|
||||||
|
resigned: "resigned",
|
||||||
|
abandoned: "abandoned",
|
||||||
|
agreed: "agreed",
|
||||||
|
repetition: "repetition",
|
||||||
|
stalemate: "stalemate",
|
||||||
|
insufficient: "material",
|
||||||
|
"50move": "50-move",
|
||||||
|
timevsinsufficient: "time vs material",
|
||||||
|
};
|
||||||
|
|
||||||
|
// "600" -> "10 min", "180+2" -> "3+2", "1/86400" -> "daily"
|
||||||
|
function formatTimeControl(tc) {
|
||||||
|
if (!tc) return "";
|
||||||
|
if (tc.includes("/")) return "daily";
|
||||||
|
const [base, inc] = tc.split("+");
|
||||||
|
const mins = Number(base) / 60;
|
||||||
|
const minsText = Number.isInteger(mins) ? String(mins) : mins.toFixed(1);
|
||||||
|
return inc ? `${minsText}+${inc}` : `${minsText} min`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderGamesTable() {
|
||||||
|
const tbody = el("games-body");
|
||||||
|
tbody.innerHTML = "";
|
||||||
|
currentGames.forEach((game) => {
|
||||||
|
const tr = document.createElement("tr");
|
||||||
|
const date = game.end_time ? new Date(game.end_time * 1000).toLocaleDateString() : "";
|
||||||
|
|
||||||
|
// Everything from the searched player's point of view.
|
||||||
|
const whiteIsUser = (game.white.username || "").toLowerCase() === currentUsername;
|
||||||
|
const me = whiteIsUser ? game.white : game.black;
|
||||||
|
const opponent = whiteIsUser ? game.black : game.white;
|
||||||
|
let verdict, resultClass;
|
||||||
|
if (me.result === "win") {
|
||||||
|
verdict = "Win";
|
||||||
|
resultClass = "res-win";
|
||||||
|
} else if (DRAW_RESULTS.has(me.result)) {
|
||||||
|
verdict = "Draw";
|
||||||
|
resultClass = "res-draw";
|
||||||
|
} else {
|
||||||
|
verdict = "Loss";
|
||||||
|
resultClass = "res-loss";
|
||||||
|
}
|
||||||
|
const why = me.result === "win" ? "" : (RESULT_REASONS[me.result] || me.result);
|
||||||
|
|
||||||
|
tr.innerHTML = `
|
||||||
|
<td>${date}</td>
|
||||||
|
<td>${opponent.username} (${opponent.rating ?? "?"})</td>
|
||||||
|
<td>${whiteIsUser ? "White" : "Black"}</td>
|
||||||
|
<td class="${resultClass}">${verdict}${why ? ` <span class="res-why">${why}</span>` : ""}</td>
|
||||||
|
<td>${formatTimeControl(game.time_control)}</td>
|
||||||
|
`;
|
||||||
|
tr.addEventListener("click", () => analyzeGame(game, tr));
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const bookmarkedUsername = usernameFromUrl();
|
||||||
|
if (bookmarkedUsername) {
|
||||||
|
el("player-search").value = bookmarkedUsername;
|
||||||
|
loadArchivesAndGames();
|
||||||
|
}
|
||||||
|
|
||||||
|
let analyzing = false;
|
||||||
|
|
||||||
|
async function analyzeGame(game, row) {
|
||||||
|
if (analyzing) return;
|
||||||
|
analyzing = true;
|
||||||
|
row.classList.add("analyzing");
|
||||||
|
el("busy-overlay").hidden = false;
|
||||||
|
try {
|
||||||
|
const result = await apiPost("/api/analyze", { pgn: game.pgn, username: currentUsername });
|
||||||
|
window.location.href = `/game/${result.id}`;
|
||||||
|
} catch (err) {
|
||||||
|
el("busy-overlay").hidden = true;
|
||||||
|
setStatus(err.message, true);
|
||||||
|
row.classList.remove("analyzing");
|
||||||
|
analyzing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><g fill="none" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><g fill="#000" stroke-linecap="butt"><path d="M9 36c3.4-1 10.1.4 13.5-2 3.4 2.4 10.1 1 13.5 2 0 0 1.6.5 3 2-.7 1-1.6 1-3 .5-3.4-1-10.1.5-13.5-1-3.4 1.5-10.1 0-13.5 1-1.4.5-2.3.5-3-.5 1.4-2 3-2 3-2z"/><path d="M15 32c2.5 2.5 12.5 2.5 15 0 .5-1.5 0-2 0-2 0-2.5-2.5-4-2.5-4 5.5-1.5 6-11.5-5-15.5-11 4-10.5 14-5 15.5 0 0-2.5 1.5-2.5 4 0 0-.5.5 0 2z"/><path d="M25 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 1 1 5 0z"/></g><path stroke="#ececec" stroke-linejoin="miter" d="M17.5 26h10M15 30h15m-7.5-14.5v5M20 18h5"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 683 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><g fill="none" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path stroke-linejoin="miter" d="M22.5 11.6V6"/><path fill="#000" stroke-linecap="butt" stroke-linejoin="miter" d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5"/><path fill="#000" d="M11.5 37a22.3 22.3 0 0 0 21 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V27v-3.5c-3.5-7.5-13-10.5-16-4-3 6 5 10 5 10z"/><path stroke-linejoin="miter" d="M20 8h5"/><path stroke="#ececec" d="M32 29.5s8.5-4 6-9.7C34.1 14 25 18 22.5 24.6v2.1-2.1C20 18 9.9 14 7 19.9c-2.5 5.6 4.8 9 4.8 9"/><path stroke="#ececec" d="M11.5 30c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 783 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><g fill="none" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path fill="#000" d="M22 10c10.5 1 16.5 8 16 29H15c0-9 10-6.5 8-21"/><path fill="#000" d="M24 18c.38 2.91-5.55 7.37-8 9-3 2-2.82 4.34-5 4-1.04-.94 1.41-3.04 0-3-1 0 .19 1.23-1 2-1 0-4 1-4-4 0-2 6-12 6-12s1.89-1.9 2-3.5c-.73-1-.5-2-.5-3 1-1 3 2.5 3 2.5h2s.78-2 2.5-3c1 0 1 3 1 3"/><path fill="#ececec" stroke="#ececec" d="M9.5 25.5a.5.5 0 1 1-1 0 .5.5 0 1 1 1 0m5.43-9.75a.5 1.5 30 1 1-.86-.5.5 1.5 30 1 1 .86.5"/><path fill="#ececec" stroke="none" d="m24.55 10.4-.45 1.45.5.15c3.15 1 5.65 2.49 7.9 6.75S35.75 29.06 35.25 39l-.05.5h2.25l.05-.5c.5-10.06-.88-16.85-3.25-21.34s-5.79-6.64-9.19-7.16z"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 782 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><path stroke="#000" stroke-linecap="round" stroke-width="1.5" d="M22.5 9a4 4 0 0 0-3.22 6.38 6.48 6.48 0 0 0-.87 10.65c-3 1.06-7.41 5.55-7.41 13.47h23c0-7.92-4.41-12.41-7.41-13.47a6.46 6.46 0 0 0-.87-10.65A4.01 4.01 0 0 0 22.5 9z"/></svg>
|
||||||
|
After Width: | Height: | Size: 298 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><g fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><g stroke="none"><circle cx="6" cy="12" r="2.75"/><circle cx="14" cy="9" r="2.75"/><circle cx="22.5" cy="8" r="2.75"/><circle cx="31" cy="9" r="2.75"/><circle cx="39" cy="12" r="2.75"/></g><path stroke-linecap="butt" d="M9 26c8.5-1.5 21-1.5 27 0l2.5-12.5L31 25l-.3-14.1-5.2 13.6-3-14.5-3 14.5-5.2-13.6L14 25 6.5 13.5z"/><path stroke-linecap="butt" d="M9 26c0 2 1.5 2 2.5 4 1 1.5 1 1 .5 3.5-1.5 1-1.5 2.5-1.5 2.5-1.5 1.5.5 2.5.5 2.5 6.5 1 16.5 1 23 0 0 0 1.5-1 0-2.5 0 0 .5-1.5-1-2.5-.5-2.5-.5-2 .5-3.5 1-2 2.5-2 2.5-4-8.5-1.5-18.5-1.5-27 0z"/><path fill="none" stroke-linecap="butt" d="M11 38.5a35 35 1 0 0 23 0"/><path fill="none" stroke="#ececec" d="M11 29a35 35 1 0 1 23 0m-21.5 2.5h20m-21 3a35 35 1 0 0 22 0m-23 3a35 35 1 0 0 24 0"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 910 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><g fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path stroke-linecap="butt" d="M9 39h27v-3H9zm3.5-7 1.5-2.5h17l1.5 2.5zm-.5 4v-4h21v4z"/><path stroke-linecap="butt" stroke-linejoin="miter" d="M14 29.5v-13h17v13z"/><path stroke-linecap="butt" d="M14 16.5 11 14h23l-3 2.5zM11 14V9h4v2h5V9h5v2h5V9h4v5z"/><path fill="none" stroke="#ececec" stroke-linejoin="miter" stroke-width="1" d="M12 35.5h21m-20-4h19m-18-2h17m-17-13h17M11 14h23"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 557 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><g fill="none" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><g fill="#fff" stroke-linecap="butt"><path d="M9 36c3.39-.97 10.11.43 13.5-2 3.39 2.43 10.11 1.03 13.5 2 0 0 1.65.54 3 2-.68.97-1.65.99-3 .5-3.39-.97-10.11.46-13.5-1-3.39 1.46-10.11.03-13.5 1-1.35.49-2.32.47-3-.5 1.35-1.94 3-2 3-2z"/><path d="M15 32c2.5 2.5 12.5 2.5 15 0 .5-1.5 0-2 0-2 0-2.5-2.5-4-2.5-4 5.5-1.5 6-11.5-5-15.5-11 4-10.5 14-5 15.5 0 0-2.5 1.5-2.5 4 0 0-.5.5 0 2z"/><path d="M25 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 1 1 5 0z"/></g><path stroke-linejoin="miter" d="M17.5 26h10M15 30h15m-7.5-14.5v5M20 18h5"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 700 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><g fill="none" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path stroke-linejoin="miter" d="M22.5 11.63V6M20 8h5"/><path fill="#fff" stroke-linecap="butt" stroke-linejoin="miter" d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5"/><path fill="#fff" d="M11.5 37c5.5 3.5 15.5 3.5 21 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V27v-3.5c-3.5-7.5-13-10.5-16-4-3 6 5 10 5 10z"/><path d="M11.5 30c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 610 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><g fill="none" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path fill="#fff" d="M22 10c10.5 1 16.5 8 16 29H15c0-9 10-6.5 8-21"/><path fill="#fff" d="M24 18c.38 2.91-5.55 7.37-8 9-3 2-2.82 4.34-5 4-1.042-.94 1.41-3.04 0-3-1 0 .19 1.23-1 2-1 0-4.003 1-4-4 0-2 6-12 6-12s1.89-1.9 2-3.5c-.73-.994-.5-2-.5-3 1-1 3 2.5 3 2.5h2s.78-1.992 2.5-3c1 0 1 3 1 3"/><path fill="#000" d="M9.5 25.5a.5.5 0 1 1-1 0 .5.5 0 1 1 1 0m5.433-9.75a.5 1.5 30 1 1-.866-.5.5 1.5 30 1 1 .866.5"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 593 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><path fill="#fff" stroke="#000" stroke-linecap="round" stroke-width="1.5" d="M22.5 9c-2.21 0-4 1.79-4 4 0 .89.29 1.71.78 2.38C17.33 16.5 16 18.59 16 21c0 2.03.94 3.84 2.41 5.03-3 1.06-7.41 5.55-7.41 13.47h23c0-7.92-4.41-12.41-7.41-13.47 1.47-1.19 2.41-3 2.41-5.03 0-2.41-1.33-4.5-3.28-5.62.49-.67.78-1.49.78-2.38 0-2.21-1.79-4-4-4z"/></svg>
|
||||||
|
After Width: | Height: | Size: 400 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><g fill="#fff" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M8 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0m16.5-4.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0M41 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0M16 8.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0M33 9a2 2 0 1 1-4 0 2 2 0 1 1 4 0"/><path stroke-linecap="butt" d="M9 26c8.5-1.5 21-1.5 27 0l2-12-7 11V11l-5.5 13.5-3-15-3 15-5.5-14V25L7 14z"/><path stroke-linecap="butt" d="M9 26c0 2 1.5 2 2.5 4 1 1.5 1 1 .5 3.5-1.5 1-1.5 2.5-1.5 2.5-1.5 1.5.5 2.5.5 2.5 6.5 1 16.5 1 23 0 0 0 1.5-1 0-2.5 0 0 .5-1.5-1-2.5-.5-2.5-.5-2 .5-3.5 1-2 2.5-2 2.5-4-8.5-1.5-18.5-1.5-27 0z"/><path fill="none" d="M11.5 30c3.5-1 18.5-1 22 0M12 33.5c6-1 15-1 21 0"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 772 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45"><g fill="#fff" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path stroke-linecap="butt" d="M9 39h27v-3H9zm3-3v-4h21v4zm-1-22V9h4v2h5V9h5v2h5V9h4v5"/><path d="m34 14-3 3H14l-3-3"/><path stroke-linecap="butt" stroke-linejoin="miter" d="M31 17v12.5H14V17"/><path d="m31 29.5 1.5 2.5h-20l1.5-2.5"/><path fill="none" stroke-linejoin="miter" d="M11 14h23"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 476 B |
@@ -0,0 +1,374 @@
|
|||||||
|
/* "The Chess Column" — the app styled as a newspaper chess column.
|
||||||
|
Ivory paper, ink serif, one gold rule; move quality as annotation marks. */
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--paper: #f7f3e8;
|
||||||
|
--paper-shade: #efe8d6;
|
||||||
|
--ink: #23242a;
|
||||||
|
--muted: #6b6656;
|
||||||
|
--rule: #c9c2ac;
|
||||||
|
--gold: #a8892e;
|
||||||
|
--red: #9c2b23;
|
||||||
|
|
||||||
|
/* Classification colors — green is good, red is bad. Darkened a notch from
|
||||||
|
the board-arrow shades so they stay readable as text on paper. */
|
||||||
|
--best: #2f9e4f;
|
||||||
|
--good: #5a9e44;
|
||||||
|
--inaccuracy: #b98a00;
|
||||||
|
--mistake: #cf7420;
|
||||||
|
--blunder: #d64545;
|
||||||
|
|
||||||
|
--board-light: #f7f3e8;
|
||||||
|
--board-dark: #d6cfba;
|
||||||
|
}
|
||||||
|
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
|
||||||
|
html { overflow-y: scroll; scrollbar-gutter: stable; }
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
font-family: Georgia, "Times New Roman", serif;
|
||||||
|
font-size: 1.05rem;
|
||||||
|
color: var(--ink);
|
||||||
|
background: var(--paper);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- Masthead ---- */
|
||||||
|
.masthead { border-bottom: 4px double var(--ink); }
|
||||||
|
.masthead-inner {
|
||||||
|
max-width: 68rem;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0.9rem 1.5rem;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 1rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
font-variant: small-caps;
|
||||||
|
letter-spacing: 0.18em;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
.masthead a { color: var(--ink); text-decoration: none; }
|
||||||
|
.masthead a:hover { color: var(--gold); }
|
||||||
|
|
||||||
|
header { padding: 1.5rem 1.5rem 0; text-align: center; }
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-weight: 700;
|
||||||
|
font-style: italic;
|
||||||
|
font-size: clamp(1.7rem, 4vw, 2.5rem);
|
||||||
|
line-height: 1.15;
|
||||||
|
margin: 0 0 0.35rem;
|
||||||
|
text-wrap: balance;
|
||||||
|
}
|
||||||
|
.subtitle { margin: 0; color: var(--muted); font-style: italic; font-size: 1rem; }
|
||||||
|
.subtitle b, .subtitle strong { color: var(--gold); font-style: normal; }
|
||||||
|
|
||||||
|
.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 {
|
||||||
|
padding: 0.75rem 1.5rem 3rem;
|
||||||
|
max-width: 68rem;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row { display: flex; gap: 1.25rem; flex-wrap: wrap; align-items: flex-end; }
|
||||||
|
|
||||||
|
input, select {
|
||||||
|
font-family: Georgia, "Times New Roman", serif;
|
||||||
|
font-size: 1.05rem;
|
||||||
|
padding: 0.35rem 0.2rem;
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px solid var(--ink);
|
||||||
|
background: transparent;
|
||||||
|
color: var(--ink);
|
||||||
|
}
|
||||||
|
input:focus, select:focus { outline: none; border-bottom: 2px solid var(--gold); }
|
||||||
|
input::placeholder { color: var(--muted); font-style: italic; }
|
||||||
|
|
||||||
|
input { flex: 1; min-width: 200px; }
|
||||||
|
|
||||||
|
/* The username lookup is the front page's one job — let it read like a headline.
|
||||||
|
Always one line: the input flexes, the Load button holds the right edge. */
|
||||||
|
.lookup-row { max-width: 40rem; margin: 0 auto; flex-wrap: nowrap; }
|
||||||
|
#player-search {
|
||||||
|
font-size: 1.45rem;
|
||||||
|
padding: 0.4rem 0.3rem;
|
||||||
|
min-width: 0;
|
||||||
|
-webkit-appearance: none; /* keep the underline look for type="search" */
|
||||||
|
appearance: none;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
.lookup-row button { font-size: 1rem; padding: 0.55rem 1.4rem; flex: none; }
|
||||||
|
#lookup-panel .status { text-align: center; margin-top: 0.9rem; }
|
||||||
|
|
||||||
|
.games-toolbar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
.month-nav { display: flex; gap: 0.5rem; align-items: center; }
|
||||||
|
.month-step { padding: 0.3rem 0.55rem; font-size: 0.65rem; }
|
||||||
|
|
||||||
|
.res-win { color: var(--best); font-weight: 700; }
|
||||||
|
.res-draw { color: var(--muted); }
|
||||||
|
.res-loss { color: var(--blunder); font-weight: 700; }
|
||||||
|
.res-why { color: var(--muted); font-weight: 400; font-size: 0.85em; font-style: italic; }
|
||||||
|
|
||||||
|
/* Never let the table force the page to scroll sideways. */
|
||||||
|
#games-panel { overflow-x: auto; }
|
||||||
|
|
||||||
|
button {
|
||||||
|
font-family: Georgia, "Times New Roman", serif;
|
||||||
|
font-variant: small-caps;
|
||||||
|
letter-spacing: 0.14em;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
padding: 0.4rem 1.1rem;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--ink);
|
||||||
|
border: 1.5px solid var(--ink);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color .12s ease, color .12s ease;
|
||||||
|
}
|
||||||
|
button:hover { background: var(--ink); color: var(--paper); }
|
||||||
|
button:disabled {
|
||||||
|
opacity: 0.35; cursor: not-allowed;
|
||||||
|
background: transparent; color: var(--ink);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status { color: var(--muted); font-style: italic; min-height: 1.2em; margin: 0; }
|
||||||
|
.status.error { color: var(--red); }
|
||||||
|
|
||||||
|
table { width: 100%; border-collapse: collapse; }
|
||||||
|
th, td { text-align: left; padding: 0.5rem 0.4rem; }
|
||||||
|
th {
|
||||||
|
font-variant: small-caps;
|
||||||
|
font-weight: 400;
|
||||||
|
letter-spacing: 0.16em;
|
||||||
|
font-size: 0.82rem;
|
||||||
|
color: var(--muted);
|
||||||
|
border-bottom: 2px solid var(--ink);
|
||||||
|
}
|
||||||
|
td { border-bottom: 1px solid var(--rule); }
|
||||||
|
tbody tr { cursor: pointer; }
|
||||||
|
tbody tr:hover { background: var(--paper-shade); }
|
||||||
|
tbody tr.analyzing { background: var(--paper-shade); font-style: italic; cursor: wait; }
|
||||||
|
|
||||||
|
.analysis-layout { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
|
||||||
|
.board-column { width: 100%; display: flex; flex-direction: column; align-items: center; }
|
||||||
|
.side-column { width: 100%; max-width: 560px; }
|
||||||
|
|
||||||
|
#board-wrap {
|
||||||
|
position: relative;
|
||||||
|
width: 560px;
|
||||||
|
max-width: 90vw;
|
||||||
|
aspect-ratio: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#board {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(8, 1fr);
|
||||||
|
grid-template-rows: repeat(8, 1fr);
|
||||||
|
border: 2px solid var(--ink);
|
||||||
|
}
|
||||||
|
|
||||||
|
#arrows {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.square {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
user-select: none;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.square.light { background: var(--board-light); }
|
||||||
|
.square.dark { background: var(--board-dark); }
|
||||||
|
|
||||||
|
.piece {
|
||||||
|
width: 92%;
|
||||||
|
height: 92%;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-top: 1.25rem;
|
||||||
|
}
|
||||||
|
.nav-row button { flex: none; }
|
||||||
|
#ply-label {
|
||||||
|
color: var(--muted);
|
||||||
|
font-variant: small-caps;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- Eval graph: an ink line on paper, like a stock listing ---- */
|
||||||
|
#eval-graph-wrap {
|
||||||
|
position: relative;
|
||||||
|
width: 560px;
|
||||||
|
max-width: 90vw;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
#eval-graph {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
background: var(--paper);
|
||||||
|
border-top: 1px solid var(--rule);
|
||||||
|
border-bottom: 1px solid var(--rule);
|
||||||
|
}
|
||||||
|
.eval-tooltip {
|
||||||
|
position: absolute;
|
||||||
|
top: -1.9em;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
background: var(--ink);
|
||||||
|
color: var(--paper);
|
||||||
|
font-size: 0.8rem;
|
||||||
|
padding: 2px 9px;
|
||||||
|
pointer-events: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.move-detail {
|
||||||
|
width: 560px;
|
||||||
|
max-width: 90vw;
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding: 0.7rem 1rem;
|
||||||
|
background: var(--paper-shade);
|
||||||
|
border-left: 3px solid var(--gold);
|
||||||
|
font-size: 1rem;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.4rem 1.1rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin-bottom: 0.35rem;
|
||||||
|
}
|
||||||
|
.summary .chip {
|
||||||
|
font-variant: small-caps;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.move-list { max-height: 420px; overflow-y: auto; }
|
||||||
|
.move-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: baseline;
|
||||||
|
padding: 0.35rem 0.5rem;
|
||||||
|
border-bottom: 1px solid var(--rule);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.move-row:hover { background: var(--paper-shade); }
|
||||||
|
.move-row.active {
|
||||||
|
background: var(--paper-shade);
|
||||||
|
box-shadow: inset 3px 0 0 var(--gold);
|
||||||
|
}
|
||||||
|
.move-row .tag {
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
.row-eval {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Annotation marks carry the verdict in color, print-style. */
|
||||||
|
.tag.best, .chip.best { color: var(--best); }
|
||||||
|
.tag.good, .chip.good { color: var(--good); }
|
||||||
|
.tag.inaccuracy, .chip.inaccuracy { color: var(--inaccuracy); }
|
||||||
|
.tag.mistake, .chip.mistake { color: var(--mistake); }
|
||||||
|
.tag.blunder, .chip.blunder { color: var(--blunder); }
|
||||||
|
.tag.unknown, .chip.unknown { color: var(--muted); }
|
||||||
|
|
||||||
|
/* ---- Analysis-in-progress popup ---- */
|
||||||
|
#busy-overlay {
|
||||||
|
position: fixed; inset: 0; z-index: 100;
|
||||||
|
background: rgba(35, 36, 42, 0.5);
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
}
|
||||||
|
#busy-overlay[hidden] { display: none; }
|
||||||
|
.busy-box {
|
||||||
|
background: var(--paper);
|
||||||
|
border: 2px solid var(--ink);
|
||||||
|
padding: 1.6rem 2.2rem;
|
||||||
|
text-align: center;
|
||||||
|
max-width: 85vw;
|
||||||
|
}
|
||||||
|
.busy-box p { margin: 1rem 0 0; font-style: italic; }
|
||||||
|
.busy-spinner {
|
||||||
|
width: 36px; height: 36px;
|
||||||
|
margin: 0 auto;
|
||||||
|
border: 3px solid var(--rule);
|
||||||
|
border-top-color: var(--gold);
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: busy-spin 0.9s linear infinite;
|
||||||
|
}
|
||||||
|
@keyframes busy-spin { to { transform: rotate(360deg); } }
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.busy-spinner { animation: none; border-top-color: var(--rule); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- Mobile ---- */
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
body { font-size: 1rem; }
|
||||||
|
.masthead-inner {
|
||||||
|
padding: 0.7rem 1rem;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
letter-spacing: 0.12em;
|
||||||
|
}
|
||||||
|
header { padding: 1.25rem 1rem 0.25rem; }
|
||||||
|
main { padding: 1rem 0.9rem 2.5rem; }
|
||||||
|
|
||||||
|
#player-search { font-size: 1.2rem; }
|
||||||
|
|
||||||
|
/* Roomier listings: drop the time-control column, keep cells readable. */
|
||||||
|
th, td { padding: 0.6rem 0.35rem; font-size: 1rem; }
|
||||||
|
#games-table th:nth-child(5), #games-table td:nth-child(5) { display: none; }
|
||||||
|
#games-table td:nth-child(2) { overflow-wrap: anywhere; }
|
||||||
|
.games-toolbar { justify-content: center; }
|
||||||
|
.month-nav { width: 100%; }
|
||||||
|
.month-nav select { flex: 1; min-width: 0; }
|
||||||
|
|
||||||
|
.nav-row { width: 100%; max-width: 90vw; justify-content: space-between; gap: 0.5rem; }
|
||||||
|
#ply-label { font-size: 0.8rem; }
|
||||||
|
.move-list { max-height: 320px; }
|
||||||
|
.move-detail { font-size: 0.95rem; }
|
||||||
|
.summary { gap: 0.3rem 0.8rem; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Very narrow phones: drop the Color column too — Date, Opponent, Result is plenty. */
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
#games-table th:nth-child(3), #games-table td:nth-child(3) { display: none; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fastapi==0.115.6
|
||||||
|
uvicorn[standard]==0.32.1
|
||||||
|
httpx==0.28.1
|
||||||
|
python-chess==1.999
|
||||||