iteration 1: report with game table, /getgamers state screen, silent-30-days prompt, /today as one message, stats port bound to localhost

- periodic report rebuilt in HTML: title with games count, mode lines, one <pre>
  table (± · colour · accuracy · opponent rating · opponent accuracy), 10-row cap,
  span note after catch-up; stats service returns tracked_rating_diff per game
- /getgamers shows player state from the DB (played today / N days quiet /
  closed / not found, report period) without Lichess calls; ratings on a button
- "player silent 30 days — keep?" prompt with keep/delete buttons, repeat 90 days
- /today, /yesterday, /week: one message edited into the result, nav buttons
- /year localised; active-gamer leftovers and N/A removed; one period wording
- docker-compose.prod.yml: stats port 8002 bound to 127.0.0.1
- product review docs: user journeys, concepts, Mini App feasibility, proposal

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-21 11:26:20 +00:00
parent 1bb779d71d
commit df6b582376
23 changed files with 3412 additions and 897 deletions

View file

@ -104,6 +104,15 @@ class Database:
# Column already exists
pass
# When the owner was last asked "player quiet for 30 days — keep
# following?" (unix seconds, see periodic.py); NULL = never. Asked
# again no sooner than 90 days later ("keep" refreshes it too).
try:
cursor.execute("ALTER TABLE user_gamers ADD COLUMN silent_prompt_at INTEGER")
except sqlite3.OperationalError:
# Column already exists
pass
# Latest bulk status of each tracked player from POST /api/users
# (player_status.py refreshes it every PLAYER_STATUS_REFRESH_MINUTES).
# One row per gamer, not per pair: the status is a property of the
@ -740,22 +749,74 @@ class Database:
'not_found': bool(row[5]),
}
def get_gamer_statuses(self, gamer_ids: List[int]) -> Dict[int, Dict[str, Any]]:
"""
get_gamer_status for several gamers in one query: {gamer_id: status};
gamers without a status row are absent from the result.
"""
ids = [int(g) for g in gamer_ids]
if not ids:
return {}
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
placeholders = ",".join("?" for _ in ids)
cursor.execute(
"SELECT gamer_id, disabled, seen_at, games_total, checked_at, missing_count, not_found "
f"FROM gamer_status WHERE gamer_id IN ({placeholders})",
ids
)
return {
int(row[0]): {
'disabled': bool(row[1]),
'seen_at': row[2],
'games_total': row[3],
'checked_at': int(row[4]),
'missing_count': int(row[5] or 0),
'not_found': bool(row[6]),
}
for row in cursor.fetchall()
}
def get_gamer_username(self, gamer_id: int) -> Optional[str]:
"""Username of a gamer by id, or None if the row is gone (nobody tracks it any more)."""
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("SELECT username FROM gamers WHERE id = ?", (gamer_id,))
row = cursor.fetchone()
return row[0] if row else None
def get_pair_check_state(self, user_id: int, gamer_id: int) -> Dict[str, Any]:
"""Per-pair skip state: games_total baseline from the last games request and whether the closed-account notice went out."""
"""
Per-pair skip state: games_total baseline from the last games request,
whether the closed-account notice went out, and when the "quiet for 30
days" question was last asked (unix seconds or None).
"""
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute(
"SELECT last_games_total, closed_notice_sent FROM user_gamers WHERE user_id = ? AND gamer_id = ?",
"SELECT last_games_total, closed_notice_sent, silent_prompt_at FROM user_gamers "
"WHERE user_id = ? AND gamer_id = ?",
(user_id, gamer_id)
)
row = cursor.fetchone()
if not row:
return {'last_games_total': None, 'closed_notice_sent': False}
return {'last_games_total': None, 'closed_notice_sent': False, 'silent_prompt_at': None}
return {
'last_games_total': int(row[0]) if row[0] is not None else None,
'closed_notice_sent': bool(row[1]),
'silent_prompt_at': int(row[2]) if row[2] is not None else None,
}
def set_pair_silent_prompt_at(self, user_id: int, gamer_id: int, ts: Optional[int]):
"""Remember when the owner was asked about this quiet player (None clears it)."""
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute(
"UPDATE user_gamers SET silent_prompt_at = ? WHERE user_id = ? AND gamer_id = ?",
(ts, user_id, gamer_id)
)
conn.commit()
def set_pair_last_games_total(self, user_id: int, gamer_id: int, games_total: Optional[int]):
"""Remember the player's games_total as of this pair's last successful games request."""
with sqlite3.connect(self.db_path) as conn: