27 lines
1.2 KiB
Rust
27 lines
1.2 KiB
Rust
//! The climb: levels by known lemmas, and which books a reader can take on.
|
|
|
|
/// Known lemmas needed for each level (level 1 at 500 … level 6 at 8,000). Tunable by the app.
|
|
pub const LEVELS: [u32; 6] = [500, 1_000, 2_000, 4_000, 6_000, 8_000];
|
|
|
|
/// Coverage a book needs to open at the reader's level.
|
|
pub const UNLOCK: f64 = 0.95;
|
|
/// … or, for a book the reader has read in their own language.
|
|
pub const UNLOCK_FAMILIAR: f64 = 0.90;
|
|
|
|
/// The level reached with `known` lemmas (0 below the first threshold), and the lemmas still needed for the next
|
|
/// (`None` at the top).
|
|
pub fn level(known: u32, levels: &[u32]) -> (usize, Option<u32>) {
|
|
let reached = levels.iter().take_while(|&&t| known >= t).count();
|
|
(reached, levels.get(reached).map(|&t| t - known))
|
|
}
|
|
|
|
/// Whether a book with this estimated coverage is open to the reader now.
|
|
pub fn unlocked(coverage: f64, read_in_own_language: bool) -> bool {
|
|
coverage.is_finite() && coverage >= if read_in_own_language { UNLOCK_FAMILIAR } else { UNLOCK }
|
|
}
|
|
|
|
/// "About 94%": whole percent, rounded down so 0.949 never reads as the 95% that unlocks.
|
|
pub fn percent(coverage: f64) -> u32 {
|
|
if !coverage.is_finite() || coverage <= 0.0 { 0 } else { ((coverage.min(1.0) * 100.0) + 1e-9).floor() as u32 }
|
|
}
|