opening trainer: the «Learned» column has the card's two-segment bar and a hint on what «learned» takes; «no moves» for an empty repertoire; the summary shows «Learning +N»
This commit is contained in:
parent
8ca7f43c3c
commit
7cb0291e48
4 changed files with 145 additions and 7 deletions
|
|
@ -810,6 +810,50 @@ const ROWS: &[[&str; 9]] = &[
|
|||
"Shox: {path}",
|
||||
"Тармақ: {path}",
|
||||
],
|
||||
[
|
||||
"Learning",
|
||||
"Учится",
|
||||
"En cours",
|
||||
"In Arbeit",
|
||||
"En curso",
|
||||
"In corso",
|
||||
"Em andamento",
|
||||
"O‘rganilmoqda",
|
||||
"Үйренілуде",
|
||||
],
|
||||
[
|
||||
"no moves",
|
||||
"нет ходов",
|
||||
"aucun coup",
|
||||
"keine Züge",
|
||||
"sin jugadas",
|
||||
"nessuna mossa",
|
||||
"sem lances",
|
||||
"yurish yo‘q",
|
||||
"жүріс жоқ",
|
||||
],
|
||||
[
|
||||
"The repertoire has no moves yet: import a PGN or add a line from a game",
|
||||
"В репертуаре пока нет ходов: импортируйте PGN или добавьте линию из партии",
|
||||
"Le répertoire n’a pas encore de coups : importez un PGN ou ajoutez une ligne depuis une partie",
|
||||
"Das Repertoire hat noch keine Züge: PGN importieren oder eine Linie aus einer Partie hinzufügen",
|
||||
"El repertorio aún no tiene jugadas: importe un PGN o añada una línea desde una partida",
|
||||
"Il repertorio non ha ancora mosse: importa un PGN o aggiungi una linea da una partita",
|
||||
"O repertório ainda não tem lances: importe um PGN ou adicione uma linha de uma partida",
|
||||
"Repertuarda hali yurishlar yo‘q: PGN import qiling yoki partiyadan liniya qo‘shing",
|
||||
"Репертуарда әзірге жүріс жоқ: PGN импорттаңыз немесе партиядан желі қосыңыз",
|
||||
],
|
||||
[
|
||||
"Learned {x}, learning {z}, {y} moves in all. A move counts as learned after three correct answers in a row without a hint — usually over several days of reviews.",
|
||||
"Выучено {x}, учится {z}, всего {y} ходов. Ход считается выученным после трёх верных ответов подряд без подсказки — обычно за несколько дней повторений.",
|
||||
"Appris {x}, en cours {z}, {y} coups au total. Un coup est appris après trois bonnes réponses d’affilée sans indice — en général sur plusieurs jours de révisions.",
|
||||
"Gelernt {x}, in Arbeit {z}, insgesamt {y} Züge. Ein Zug gilt als gelernt nach drei richtigen Antworten in Folge ohne Hinweis — meist über mehrere Tage Wiederholung.",
|
||||
"Aprendidas {x}, en curso {z}, {y} jugadas en total. Una jugada se da por aprendida tras tres respuestas correctas seguidas sin pista; normalmente en varios días de repaso.",
|
||||
"Imparate {x}, in corso {z}, {y} mosse in tutto. Una mossa è imparata dopo tre risposte giuste di fila senza suggerimento — di solito in alcuni giorni di ripasso.",
|
||||
"Aprendidos {x}, em andamento {z}, {y} lances no total. Um lance conta como aprendido após três respostas certas seguidas sem dica — normalmente em vários dias de revisão.",
|
||||
"O‘rganilgan {x}, o‘rganilmoqda {z}, jami {y} yurish. Yurish ketma-ket uchta to‘g‘ri javobdan keyin (yordamsiz) o‘rganilgan hisoblanadi — odatda bir necha kunlik takrorlashda.",
|
||||
"Үйренілген {x}, үйренілуде {z}, барлығы {y} жүріс. Жүріс кеңессіз қатарынан үш дұрыс жауаптан кейін үйренілген саналады — әдетте бірнеше күндік қайталауда.",
|
||||
],
|
||||
[
|
||||
"New moves left",
|
||||
"Новых ходов осталось",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use trainer::repertoire::{
|
|||
LearningPresentation, LearningSessionError, LearningSessionPhase, LearningSessionSnapshot,
|
||||
LearningSessionTarget, LearningSide, LearningStore, Library, PersistedSessionAttempt,
|
||||
RepertoireId, SrsSettings, StatsScope, TrainingAttempt, TrainingEventType,
|
||||
active_learning_keys, fen4,
|
||||
active_learning_keys, aggregate_scope, fen4,
|
||||
};
|
||||
use web_time::{Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
|
|
@ -210,6 +210,9 @@ enum State {
|
|||
/// Computed once when the result is shown.
|
||||
struct Summary {
|
||||
next_review: String,
|
||||
/// How many more moves are learned, and learning, than when the session began.
|
||||
learnt_gain: usize,
|
||||
learning_gain: usize,
|
||||
/// Moves never shown yet, all of them (the «more new» button takes up to 10).
|
||||
unseen: usize,
|
||||
more_new: usize,
|
||||
|
|
@ -240,6 +243,10 @@ pub struct OpeningSessionUi {
|
|||
repertoire_answers: BTreeSet<LearningItemKey>,
|
||||
/// Active answers of the whole repertoire, for the result.
|
||||
repertoire_keys: BTreeSet<LearningItemKey>,
|
||||
/// The whole repertoire's scope (a branch session counts the whole repertoire too).
|
||||
whole_scope: StatsScope,
|
||||
/// (learned, learning) when the session began: the summary shows what it changed.
|
||||
start_progress: (usize, usize),
|
||||
/// The lines of a review, to count «line k of n».
|
||||
lines: Vec<Vec<String>>,
|
||||
line: usize,
|
||||
|
|
@ -363,6 +370,7 @@ impl OpeningSessionUi {
|
|||
} else {
|
||||
active_learning_keys(&library, &whole).map_err(|error| error.to_string())?
|
||||
};
|
||||
let start_progress = progress_counts(&library, &learning, &whole);
|
||||
let annotation_games: BTreeMap<_, _> = session
|
||||
.stats_scope
|
||||
.repertoire_ids
|
||||
|
|
@ -407,6 +415,8 @@ impl OpeningSessionUi {
|
|||
annotation_games,
|
||||
repertoire_answers,
|
||||
repertoire_keys,
|
||||
start_progress,
|
||||
whole_scope: whole,
|
||||
lines,
|
||||
line: 0,
|
||||
next_line_banner: false,
|
||||
|
|
@ -1616,8 +1626,11 @@ impl OpeningSessionUi {
|
|||
Some(at) => layout::when(at.max(now), now),
|
||||
None => tr("nothing scheduled").to_owned(),
|
||||
};
|
||||
let (learnt, learning) = progress_counts(&self.library, &self.learning, &self.whole_scope);
|
||||
self.summary = Some(Summary {
|
||||
next_review,
|
||||
learnt_gain: learnt.saturating_sub(self.start_progress.0),
|
||||
learning_gain: learning.saturating_sub(self.start_progress.1),
|
||||
unseen,
|
||||
more_new: unseen.min(layout::NEW_PER_SESSION),
|
||||
});
|
||||
|
|
@ -1902,6 +1915,12 @@ impl OpeningSessionUi {
|
|||
ui.separator();
|
||||
ui.add_space(4.0);
|
||||
if let Some(summary) = &self.summary {
|
||||
// Learned takes days: what the session did shows as «learning».
|
||||
if summary.learnt_gain > 0 {
|
||||
row(ui, tr("Learned"), format!("+{}", summary.learnt_gain));
|
||||
} else if summary.learning_gain > 0 {
|
||||
row(ui, tr("Learning"), format!("+{}", summary.learning_gain));
|
||||
}
|
||||
if self.kind == SessionKind::Daily && summary.unseen > 0 {
|
||||
row(ui, tr("New moves left"), summary.unseen.to_string());
|
||||
}
|
||||
|
|
@ -2459,3 +2478,14 @@ fn unique_id(prefix: &str) -> String {
|
|||
#[cfg(test)]
|
||||
#[path = "opening_session_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
/// (learned, learning) in a scope, by the core's statuses; zeros if it cannot be counted.
|
||||
fn progress_counts(
|
||||
library: &Library,
|
||||
learning: &LearningData,
|
||||
scope: &StatsScope,
|
||||
) -> (usize, usize) {
|
||||
aggregate_scope(library, learning, scope, &SrsSettings::default()).map_or((0, 0), |scoped| {
|
||||
(scoped.summary.learnt, scoped.summary.learning)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2211,3 +2211,23 @@ fn a_mistake_on_the_first_move_returns_it_once_and_keeps_the_count() {
|
|||
assert_eq!((summary.unseen, summary.more_new), (0, 0));
|
||||
assert!(!summary.next_review.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_summary_shows_learning_growth_when_nothing_is_learned_yet() {
|
||||
let mut f = Fixture::with(
|
||||
"1. e4 e5 2. Nf3 *",
|
||||
LearningSide::White,
|
||||
&[],
|
||||
&["e2e4", "g1f3"],
|
||||
"summary-learning",
|
||||
SessionKind::Daily,
|
||||
);
|
||||
for _ in 0..2 {
|
||||
f.ui.debug_moves("answer");
|
||||
f.ui.debug_settle();
|
||||
}
|
||||
assert!(f.ui.is_finished());
|
||||
f.ui.compute_summary();
|
||||
let summary = f.ui.summary.as_ref().unwrap();
|
||||
assert_eq!((summary.learnt_gain, summary.learning_gain), (0, 2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ const BOTTOM_W: f32 = 150.0;
|
|||
const MAIN_W: f32 = 170.0;
|
||||
const LINES_W: f32 = 110.0;
|
||||
const THIRD_W: f32 = 150.0;
|
||||
/// The «Learned» column: a small bar and «X/Y».
|
||||
const LEARNED_W: f32 = 104.0;
|
||||
const MINI_BAR_W: f32 = 44.0;
|
||||
const DIALOG_W: f32 = 460.0;
|
||||
/// A session appears at once when it is ready this fast; otherwise «Preparing…».
|
||||
const PREPARING_SHOWN_AFTER: Duration = Duration::from_millis(300);
|
||||
|
|
@ -1677,7 +1680,7 @@ impl RepertoireUi {
|
|||
.column(egui_extras::Column::remainder().at_least(80.0).clip(true))
|
||||
.column(egui_extras::Column::exact(22.0))
|
||||
.column(egui_extras::Column::exact(58.0))
|
||||
.column(egui_extras::Column::exact(70.0))
|
||||
.column(egui_extras::Column::exact(LEARNED_W))
|
||||
.column(egui_extras::Column::exact(26.0));
|
||||
if let Some(index) = scroll_row {
|
||||
table = table.scroll_to_row(index, None);
|
||||
|
|
@ -1713,9 +1716,12 @@ impl RepertoireUi {
|
|||
ui.label(layout::king(side))
|
||||
.on_hover_text(layout::you_play(side));
|
||||
});
|
||||
let has_moves = self.index.get(id).is_none_or(|row| row.has_moves);
|
||||
row.col(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
match stats {
|
||||
// An empty repertoire: «no moves» under «Learned» says it.
|
||||
Some(Ok(_)) if !has_moves => {}
|
||||
Some(Ok(stats)) if stats.today() > 0 => {
|
||||
ui.label(stats.today().to_string()).on_hover_text(trf(
|
||||
"{n} to review, {m} new",
|
||||
|
|
@ -1734,8 +1740,26 @@ impl RepertoireUi {
|
|||
row.col(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
match stats {
|
||||
Some(Ok(_)) if !has_moves => {
|
||||
ui.add(
|
||||
egui::Label::new(RichText::new(tr("no moves")).weak())
|
||||
.truncate(),
|
||||
)
|
||||
.on_hover_text(tr("The repertoire has no moves yet: import a PGN or add a line from a game"));
|
||||
}
|
||||
Some(Ok(stats)) if stats.total > 0 => {
|
||||
ui.label(format!("{}/{}", stats.learnt, stats.total));
|
||||
let hint = learned_hint(stats);
|
||||
ui.label(format!("{}/{}", stats.learnt, stats.total))
|
||||
.on_hover_text(&hint);
|
||||
let room = ui.available_width() - ui.spacing().item_spacing.x;
|
||||
if room >= 16.0 {
|
||||
let (bar, response) = ui.allocate_exact_size(
|
||||
vec2(room.min(MINI_BAR_W), 6.0),
|
||||
egui::Sense::hover(),
|
||||
);
|
||||
progress_bar(ui, bar, Some(stats));
|
||||
response.on_hover_text(hint);
|
||||
}
|
||||
}
|
||||
Some(_) => {
|
||||
ui.label(RichText::new("—").weak());
|
||||
|
|
@ -2449,9 +2473,20 @@ fn main_button(state: &CardState, side: LearningSide) -> (String, bool, Option<M
|
|||
}
|
||||
|
||||
/// Row 3 of the card: learnt, in progress, the rest.
|
||||
fn progress(ui: &mut Ui, stats: Option<&RowStats>) {
|
||||
let width = ui.available_width();
|
||||
let (bar, _) = ui.allocate_exact_size(vec2(width, 8.0), egui::Sense::hover());
|
||||
/// «Learned 3, learning 10, 75 moves in all» and what «learned» takes.
|
||||
fn learned_hint(stats: &RowStats) -> String {
|
||||
trf(
|
||||
"Learned {x}, learning {z}, {y} moves in all. A move counts as learned after three correct answers in a row without a hint — usually over several days of reviews.",
|
||||
&[
|
||||
("x", &stats.learnt),
|
||||
("z", &stats.learning),
|
||||
("y", &stats.total),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
/// The two segments: learned, then learning (paler).
|
||||
fn progress_bar(ui: &Ui, bar: egui::Rect, stats: Option<&RowStats>) {
|
||||
let painter = ui.painter();
|
||||
painter.rect_filled(bar, 2.0, ui.visuals().extreme_bg_color);
|
||||
if let Some(stats) = stats.filter(|stats| stats.total > 0) {
|
||||
|
|
@ -2470,6 +2505,12 @@ fn progress(ui: &mut Ui, stats: Option<&RowStats>) {
|
|||
fill.gamma_multiply(0.45),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn progress(ui: &mut Ui, stats: Option<&RowStats>) {
|
||||
let width = ui.available_width();
|
||||
let (bar, _) = ui.allocate_exact_size(vec2(width, 8.0), egui::Sense::hover());
|
||||
progress_bar(ui, bar, stats);
|
||||
ui.add_space(-2.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_height(20.0);
|
||||
|
|
@ -2482,7 +2523,10 @@ fn progress(ui: &mut Ui, stats: Option<&RowStats>) {
|
|||
if learning > 0 {
|
||||
text = format!("{text} · {}", trf("learning {k}", &[("k", &learning)]));
|
||||
}
|
||||
layout::line(ui, text);
|
||||
if let Some(stats) = stats {
|
||||
ui.add(egui::Label::new(text).truncate())
|
||||
.on_hover_text(learned_hint(stats));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue