ChessPenguin 0.4.0: large ChessBase databases with a filter panel
Some checks failed
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run
Release / version (push) Has been cancelled
Release / linux (push) Has been cancelled
Release / flatpak (push) Has been cancelled
Release / windows (push) Has been cancelled
Release / publish (push) Has been cancelled
Some checks failed
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run
Release / version (push) Has been cancelled
Release / linux (push) Has been cancelled
Release / flatpak (push) Has been cancelled
Release / windows (push) Has been cancelled
Release / publish (push) Has been cancelled
Mega Database (11.7 million games) opens in under a second: a .cbh with 20,000 records or more is read in place, a game is converted to PGN when opened. Filter panel on the right (player with suggestions, colour, opponent, tournament, annotator, years, Elo rule, result, ECO, moves, comments, variations), applied live in the background with cancellation. Fixes: a ChessBase game unreadable from its first move (Chess960) crashed the import; databases mixing UTF-8 and single-byte texts were decoded as Cyrillic. Docs: decision 12, design (docs/design/large-databases.md), format research and acceptance criteria, QA report 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ff1a939ef3
commit
34a4a6ad15
23 changed files with 3525 additions and 46 deletions
|
|
@ -79,6 +79,302 @@ pub fn trf(key: &'static str, args: &[(&str, &dyn Display)]) -> String {
|
|||
|
||||
// [English, Русский, Français, Deutsch, Español, Italiano]
|
||||
const ROWS: &[[&str; 6]] = &[
|
||||
// --- large databases ---
|
||||
[
|
||||
"Reset filters",
|
||||
"Сбросить фильтры",
|
||||
"Réinitialiser les filtres",
|
||||
"Filter zurücksetzen",
|
||||
"Restablecer filtros",
|
||||
"Azzera filtri",
|
||||
],
|
||||
[
|
||||
"Reset filters ({n})",
|
||||
"Сбросить фильтры ({n})",
|
||||
"Réinitialiser les filtres ({n})",
|
||||
"Filter zurücksetzen ({n})",
|
||||
"Restablecer filtros ({n})",
|
||||
"Azzera filtri ({n})",
|
||||
],
|
||||
[
|
||||
"Players",
|
||||
"Игроки",
|
||||
"Joueurs",
|
||||
"Spieler",
|
||||
"Jugadores",
|
||||
"Giocatori",
|
||||
],
|
||||
[
|
||||
"Player",
|
||||
"Игрок",
|
||||
"Joueur",
|
||||
"Spieler",
|
||||
"Jugador",
|
||||
"Giocatore",
|
||||
],
|
||||
[
|
||||
"either colour",
|
||||
"любым",
|
||||
"toute couleur",
|
||||
"beliebig",
|
||||
"cualquier color",
|
||||
"qualsiasi colore",
|
||||
],
|
||||
[
|
||||
"as White",
|
||||
"белыми",
|
||||
"avec les Blancs",
|
||||
"mit Weiß",
|
||||
"con blancas",
|
||||
"con il Bianco",
|
||||
],
|
||||
[
|
||||
"as Black",
|
||||
"чёрными",
|
||||
"avec les Noirs",
|
||||
"mit Schwarz",
|
||||
"con negras",
|
||||
"con il Nero",
|
||||
],
|
||||
[
|
||||
"Enter a player first",
|
||||
"Сначала укажите игрока",
|
||||
"Indiquez d'abord un joueur",
|
||||
"Zuerst einen Spieler angeben",
|
||||
"Indique primero un jugador",
|
||||
"Indica prima un giocatore",
|
||||
],
|
||||
[
|
||||
"Opponent",
|
||||
"Соперник",
|
||||
"Adversaire",
|
||||
"Gegner",
|
||||
"Rival",
|
||||
"Avversario",
|
||||
],
|
||||
[
|
||||
"Tournament or place",
|
||||
"Турнир или место",
|
||||
"Tournoi ou lieu",
|
||||
"Turnier oder Ort",
|
||||
"Torneo o lugar",
|
||||
"Torneo o luogo",
|
||||
],
|
||||
[
|
||||
"Annotator",
|
||||
"Комментатор",
|
||||
"Commentateur",
|
||||
"Kommentator",
|
||||
"Comentarista",
|
||||
"Commentatore",
|
||||
],
|
||||
["Game", "Партия", "Partie", "Partie", "Partida", "Partita"],
|
||||
["Years", "Годы", "Années", "Jahre", "Años", "Anni"],
|
||||
[
|
||||
"Elo from",
|
||||
"Эло от",
|
||||
"Elo dès",
|
||||
"Elo ab",
|
||||
"Elo desde",
|
||||
"Elo da",
|
||||
],
|
||||
["both", "обоих", "les deux", "beide", "ambos", "entrambi"],
|
||||
[
|
||||
"either",
|
||||
"любого",
|
||||
"l'un",
|
||||
"einer",
|
||||
"cualquiera",
|
||||
"uno dei due",
|
||||
],
|
||||
["average", "среднее", "moyenne", "Schnitt", "media", "media"],
|
||||
[
|
||||
"opponent",
|
||||
"соперника",
|
||||
"adversaire",
|
||||
"Gegner",
|
||||
"rival",
|
||||
"avversario",
|
||||
],
|
||||
["Win", "Выигрыш", "Gain", "Sieg", "Victoria", "Vittoria"],
|
||||
[
|
||||
"Loss",
|
||||
"Проигрыш",
|
||||
"Perte",
|
||||
"Niederlage",
|
||||
"Derrota",
|
||||
"Sconfitta",
|
||||
],
|
||||
[
|
||||
"B90, B9 or C60-C99",
|
||||
"B90, B9 или C60-C99",
|
||||
"B90, B9 ou C60-C99",
|
||||
"B90, B9 oder C60-C99",
|
||||
"B90, B9 o C60-C99",
|
||||
"B90, B9 o C60-C99",
|
||||
],
|
||||
[
|
||||
"A code (B90), a prefix (B9) or a range (C60-C99), separated by commas",
|
||||
"Код (B90), начало кода (B9) или диапазон (C60-C99), через запятую",
|
||||
"Un code (B90), un préfixe (B9) ou une plage (C60-C99), séparés par des virgules",
|
||||
"Ein Code (B90), ein Präfix (B9) oder ein Bereich (C60-C99), durch Kommas getrennt",
|
||||
"Un código (B90), un prefijo (B9) o un rango (C60-C99), separados por comas",
|
||||
"Un codice (B90), un prefisso (B9) o un intervallo (C60-C99), separati da virgole",
|
||||
],
|
||||
[
|
||||
"Annotations",
|
||||
"Аннотации",
|
||||
"Annotations",
|
||||
"Anmerkungen",
|
||||
"Anotaciones",
|
||||
"Annotazioni",
|
||||
],
|
||||
[
|
||||
"with comments",
|
||||
"с комментариями",
|
||||
"avec commentaires",
|
||||
"mit Kommentaren",
|
||||
"con comentarios",
|
||||
"con commenti",
|
||||
],
|
||||
[
|
||||
"with variations",
|
||||
"с вариантами",
|
||||
"avec variantes",
|
||||
"mit Varianten",
|
||||
"con variantes",
|
||||
"con varianti",
|
||||
],
|
||||
[
|
||||
"show texts",
|
||||
"показывать тексты",
|
||||
"afficher les textes",
|
||||
"Texte zeigen",
|
||||
"mostrar textos",
|
||||
"mostra i testi",
|
||||
],
|
||||
[
|
||||
"Guiding texts of the database; left out by any condition on players, dates, ratings, results or moves",
|
||||
"Текстовые главы базы; скрываются при любом условии на игроков, даты, рейтинг, результат или ходы",
|
||||
"Textes de la base ; exclus par toute condition sur les joueurs, dates, classements, résultats ou coups",
|
||||
"Texte der Datenbank; ausgeblendet bei jeder Bedingung zu Spielern, Daten, Wertungen, Ergebnissen oder Zügen",
|
||||
"Textos de la base; se ocultan con cualquier condición sobre jugadores, fechas, Elo, resultados o jugadas",
|
||||
"Testi del database; esclusi da qualsiasi condizione su giocatori, date, Elo, risultati o mosse",
|
||||
],
|
||||
[
|
||||
"Exactly this name; edit the text to search by words again",
|
||||
"Точно это имя; измените текст, чтобы снова искать по словам",
|
||||
"Exactement ce nom ; modifiez le texte pour chercher à nouveau par mots",
|
||||
"Genau dieser Name; Text ändern, um wieder nach Wörtern zu suchen",
|
||||
"Exactamente este nombre; edite el texto para volver a buscar por palabras",
|
||||
"Esattamente questo nome; modifica il testo per cercare di nuovo per parole",
|
||||
],
|
||||
[
|
||||
"· ChessBase, read-only",
|
||||
"· ChessBase, только чтение",
|
||||
"· ChessBase, lecture seule",
|
||||
"· ChessBase, schreibgeschützt",
|
||||
"· ChessBase, solo lectura",
|
||||
"· ChessBase, sola lettura",
|
||||
],
|
||||
[
|
||||
"Read in place; the original files are not changed. Save a game to keep your edits.",
|
||||
"Читается на месте; исходные файлы не изменяются. Чтобы сохранить правки, сохраните партию.",
|
||||
"Lue sur place ; les fichiers d'origine ne sont pas modifiés. Enregistrez une partie pour garder vos modifications.",
|
||||
"Wird direkt gelesen; die Originaldateien bleiben unverändert. Speichern Sie eine Partie, um Ihre Änderungen zu behalten.",
|
||||
"Se lee en su sitio; los archivos originales no cambian. Guarde una partida para conservar sus cambios.",
|
||||
"Letto sul posto; i file originali non vengono modificati. Salva una partita per conservare le modifiche.",
|
||||
],
|
||||
[
|
||||
"Filters »",
|
||||
"Фильтры »",
|
||||
"Filtres »",
|
||||
"Filter »",
|
||||
"Filtros »",
|
||||
"Filtri »",
|
||||
],
|
||||
[
|
||||
"« Filters",
|
||||
"« Фильтры",
|
||||
"« Filtres",
|
||||
"« Filter",
|
||||
"« Filtros",
|
||||
"« Filtri",
|
||||
],
|
||||
[
|
||||
"« Filters ({n})",
|
||||
"« Фильтры ({n})",
|
||||
"« Filtres ({n})",
|
||||
"« Filter ({n})",
|
||||
"« Filtros ({n})",
|
||||
"« Filtri ({n})",
|
||||
],
|
||||
[
|
||||
"Nothing found",
|
||||
"Ничего не найдено",
|
||||
"Rien trouvé",
|
||||
"Nichts gefunden",
|
||||
"No se encontró nada",
|
||||
"Nessun risultato",
|
||||
],
|
||||
["Round", "Тур", "Ronde", "Runde", "Ronda", "Turno"],
|
||||
[
|
||||
"Chess960: the moves cannot be read; the header and result are shown",
|
||||
"Chess960: ходы не читаются, показаны заголовок и результат",
|
||||
"Chess960 : les coups ne peuvent pas être lus ; l'en-tête et le résultat sont affichés",
|
||||
"Chess960: Die Züge können nicht gelesen werden; Kopf und Ergebnis werden gezeigt",
|
||||
"Chess960: las jugadas no se pueden leer; se muestran la cabecera y el resultado",
|
||||
"Chess960: le mosse non possono essere lette; sono mostrati intestazione e risultato",
|
||||
],
|
||||
["decimal comma", ".", ",", ",", ",", ","],
|
||||
[
|
||||
"{n} more matches…",
|
||||
"ещё совпадений: {n}…",
|
||||
"{n} autres résultats…",
|
||||
"{n} weitere Treffer…",
|
||||
"{n} coincidencias más…",
|
||||
"altri {n} risultati…",
|
||||
],
|
||||
[
|
||||
"· found {n} of {total}",
|
||||
"· найдено {n} из {total}",
|
||||
"· {n} trouvées sur {total}",
|
||||
"· {n} von {total} gefunden",
|
||||
"· {n} de {total} encontradas",
|
||||
"· {n} trovate su {total}",
|
||||
],
|
||||
[
|
||||
"· {n} games · {t} texts",
|
||||
"· {n} партий · {t} текстов",
|
||||
"· {n} parties · {t} textes",
|
||||
"· {n} Partien · {t} Texte",
|
||||
"· {n} partidas · {t} textos",
|
||||
"· {n} partite · {t} testi",
|
||||
],
|
||||
[
|
||||
"· {n} games",
|
||||
"· {n} партий",
|
||||
"· {n} parties",
|
||||
"· {n} Partien",
|
||||
"· {n} partidas",
|
||||
"· {n} partite",
|
||||
],
|
||||
[
|
||||
"{n} thousand",
|
||||
"{n} тыс.",
|
||||
"{n} k",
|
||||
"{n} Tsd.",
|
||||
"{n} mil",
|
||||
"{n} mila",
|
||||
],
|
||||
[
|
||||
"{n} million",
|
||||
"{n} млн",
|
||||
"{n} M",
|
||||
"{n} Mio.",
|
||||
"{n} M",
|
||||
"{n} mln",
|
||||
],
|
||||
// --- board themes ---
|
||||
[
|
||||
"Tournament",
|
||||
|
|
@ -1576,6 +1872,7 @@ mod tests {
|
|||
include_str!("analysis.rs"),
|
||||
include_str!("game_view.rs"),
|
||||
include_str!("library.rs"),
|
||||
include_str!("large_db.rs"),
|
||||
include_str!("notation.rs"),
|
||||
include_str!("review.rs"),
|
||||
include_str!("engines.rs"),
|
||||
|
|
|
|||
1180
apps/desktop/src/large_db.rs
Normal file
1180
apps/desktop/src/large_db.rs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -8,10 +8,11 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
|||
use std::sync::mpsc::{Receiver, channel};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use chess_core::{GameEntry, PgnDatabase, ScanProgress};
|
||||
use chess_import::{Format, ImportError, Opened, Unsupported};
|
||||
use chess_core::{GameEntry, ScanProgress};
|
||||
use chess_import::{Database, Format, ImportError, Opened, Unsupported};
|
||||
use egui::{Color32, RichText, Sense, Stroke, Ui, vec2};
|
||||
|
||||
use crate::large_db::{self, LargeView};
|
||||
use crate::viewed::{self, Viewed};
|
||||
use egui_extras::{Column, TableBuilder};
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ enum Slot {
|
|||
cancel: Arc<AtomicBool>,
|
||||
rx: Receiver<Result<Opened, ImportError>>,
|
||||
},
|
||||
Ready(Arc<PgnDatabase>),
|
||||
Ready(Arc<Database>),
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
|
|
@ -56,9 +57,10 @@ struct ImportInfo {
|
|||
|
||||
pub struct Library {
|
||||
slots: HashMap<PathBuf, Slot>,
|
||||
/// Games the user has opened (by content), and the content key of each game per database.
|
||||
/// Games the user has opened (by content).
|
||||
viewed: Viewed,
|
||||
keys: HashMap<PathBuf, Vec<u64>>,
|
||||
/// Filters and game list of each large ChessBase database (for the session).
|
||||
large: HashMap<PathBuf, LargeView>,
|
||||
info: HashMap<PathBuf, ImportInfo>,
|
||||
/// Database whose import notes are shown.
|
||||
notes_open: Option<PathBuf>,
|
||||
|
|
@ -77,7 +79,7 @@ impl Library {
|
|||
Self {
|
||||
slots: HashMap::new(),
|
||||
viewed: Viewed::load(),
|
||||
keys: HashMap::new(),
|
||||
large: HashMap::new(),
|
||||
info: HashMap::new(),
|
||||
notes_open: None,
|
||||
selected_db: None,
|
||||
|
|
@ -150,6 +152,9 @@ impl Library {
|
|||
|
||||
/// Selects (and scrolls to) a game row, e.g. when returning from a game.
|
||||
pub fn reveal(&mut self, path: &Path, index: usize) {
|
||||
if let Some(view) = self.large.get_mut(path) {
|
||||
view.reveal(index);
|
||||
}
|
||||
if self.selected_db.as_deref() == Some(path) {
|
||||
self.selected_row = Some(index);
|
||||
self.scroll_to_selected = true;
|
||||
|
|
@ -158,7 +163,7 @@ impl Library {
|
|||
|
||||
pub fn forget(&mut self, path: &Path) {
|
||||
self.info.remove(path);
|
||||
self.keys.remove(path);
|
||||
self.large.remove(path);
|
||||
if let Some(Slot::Loading { cancel, .. }) = self.slots.remove(path) {
|
||||
cancel.store(true, Ordering::Relaxed);
|
||||
}
|
||||
|
|
@ -170,12 +175,12 @@ impl Library {
|
|||
|
||||
/// Remembers that a game was opened (shown with a check mark in the table).
|
||||
pub fn mark_viewed(&mut self, path: &Path, index: usize) {
|
||||
if let Some(&k) = self.keys.get(path).and_then(|k| k.get(index)) {
|
||||
self.viewed.set(k, true);
|
||||
if let Some(db) = self.database(path) {
|
||||
self.viewed.set(viewed::key(db.identity(index)), true);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn database(&self, path: &Path) -> Option<Arc<PgnDatabase>> {
|
||||
pub fn database(&self, path: &Path) -> Option<Arc<Database>> {
|
||||
match self.slots.get(path) {
|
||||
Some(Slot::Ready(db)) => Some(db.clone()),
|
||||
_ => None,
|
||||
|
|
@ -189,10 +194,11 @@ impl Library {
|
|||
{
|
||||
*slot = match res {
|
||||
Ok(o) => {
|
||||
let keys = (0..o.db.len())
|
||||
.map(|i| viewed::key(o.db.raw_bytes(i).unwrap_or_default()))
|
||||
.collect();
|
||||
self.keys.insert(path.clone(), keys);
|
||||
if matches!(o.db, Database::ChessBase(_)) {
|
||||
self.large
|
||||
.entry(path.clone())
|
||||
.or_insert_with(LargeView::new);
|
||||
}
|
||||
self.info.insert(
|
||||
path.clone(),
|
||||
ImportInfo {
|
||||
|
|
@ -213,6 +219,20 @@ impl Library {
|
|||
self.poll();
|
||||
let mut actions = Vec::new();
|
||||
egui::Panel::top("shelf").show(ui, |ui| self.shelf(ui, databases, &mut actions));
|
||||
// A large database has its filter panel on the right.
|
||||
if let Some(path) = self.selected_db.clone()
|
||||
&& let Some(Slot::Ready(db)) = self.slots.get(&path)
|
||||
&& db.as_chessbase().is_some()
|
||||
&& let Some(view) = self.large.get_mut(&path)
|
||||
&& view.panel_open()
|
||||
{
|
||||
let db = db.clone();
|
||||
egui::Panel::right("filters")
|
||||
.resizable(true)
|
||||
.default_size(280.0)
|
||||
.size_range(260.0..=380.0)
|
||||
.show(ui, |ui| view.panel(ui, &db));
|
||||
}
|
||||
egui::CentralPanel::default().show(ui, |ui| self.table_area(ui, &mut actions));
|
||||
self.notes_window(ui.ctx());
|
||||
actions
|
||||
|
|
@ -309,7 +329,16 @@ impl Library {
|
|||
.map(|s| s.to_string_lossy().into_owned())
|
||||
.unwrap_or_default();
|
||||
let detail = match self.slots.get(path) {
|
||||
Some(Slot::Ready(db)) => trf("{n} games", &[("n", &db.len())]),
|
||||
Some(Slot::Ready(db)) => match db.as_chessbase() {
|
||||
Some(b) => format!(
|
||||
"{} · 🔒",
|
||||
trf(
|
||||
"{n} games",
|
||||
&[("n", &large_db::short_count(b.games() + b.texts()))],
|
||||
)
|
||||
),
|
||||
None => trf("{n} games", &[("n", &db.len())]),
|
||||
},
|
||||
Some(Slot::Loading { progress, .. }) => {
|
||||
let p = progress.lock().map(|g| *g).unwrap_or(ScanProgress {
|
||||
bytes_done: 0,
|
||||
|
|
@ -448,6 +477,21 @@ impl Library {
|
|||
}
|
||||
};
|
||||
|
||||
if db.as_chessbase().is_some() {
|
||||
let view = self
|
||||
.large
|
||||
.entry(path.clone())
|
||||
.or_insert_with(LargeView::new);
|
||||
let notes = self.info.get(&path).map_or(0, |i| i.notes.len());
|
||||
if view.table(ui, &path, &db, &mut self.viewed, notes, actions) {
|
||||
self.notes_open = Some(path.clone());
|
||||
}
|
||||
return;
|
||||
}
|
||||
let Some(pgn) = db.as_pgn() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let mut search_focused = false;
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(
|
||||
|
|
@ -472,7 +516,7 @@ impl Library {
|
|||
));
|
||||
}
|
||||
_ => {
|
||||
let enc = db.encoding();
|
||||
let enc = pgn.encoding();
|
||||
ui.label(
|
||||
RichText::new(trf(
|
||||
"· {n} games · encoding {enc}",
|
||||
|
|
@ -509,7 +553,7 @@ impl Library {
|
|||
|
||||
let key = (path.clone(), self.search.clone(), self.sort.0, self.sort.1);
|
||||
if self.view_key.as_ref() != Some(&key) {
|
||||
self.view = filtered_sorted(db.entries(), &self.search, self.sort);
|
||||
self.view = filtered_sorted(pgn.entries(), &self.search, self.sort);
|
||||
self.view_key = Some(key);
|
||||
}
|
||||
|
||||
|
|
@ -581,8 +625,7 @@ impl Library {
|
|||
table = table.scroll_to_row(r, Some(egui::Align::Center));
|
||||
}
|
||||
let view = &self.view;
|
||||
let entries = db.entries();
|
||||
let keys = self.keys.get(&path);
|
||||
let entries = pgn.entries();
|
||||
let viewed = &self.viewed;
|
||||
let mut toggle_viewed = None;
|
||||
let mut clicked = None;
|
||||
|
|
@ -617,7 +660,7 @@ impl Library {
|
|||
return;
|
||||
};
|
||||
row.set_selected(self.selected_row == Some(e.index));
|
||||
let key = keys.and_then(|k| k.get(e.index)).copied();
|
||||
let key = Some(viewed::key(pgn.raw_bytes(e.index).unwrap_or_default()));
|
||||
let seen = key.is_some_and(|k| viewed.contains(k));
|
||||
let cells: [String; 10] = [
|
||||
(e.index + 1).to_string(),
|
||||
|
|
@ -708,7 +751,7 @@ impl Library {
|
|||
}
|
||||
|
||||
/// "2010.??.??" → "2010", "1997.05.??" → "05.1997", full dates as "dd.mm.yyyy".
|
||||
fn display_date(raw: &str) -> String {
|
||||
pub fn display_date(raw: &str) -> String {
|
||||
let parts: Vec<&str> = raw.split('.').collect();
|
||||
let known = |s: &&str| !s.is_empty() && s.chars().all(|c| c.is_ascii_digit());
|
||||
match parts.as_slice() {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ mod board;
|
|||
mod engines;
|
||||
mod game_view;
|
||||
mod i18n;
|
||||
mod large_db;
|
||||
mod library;
|
||||
mod notation;
|
||||
mod report;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue