mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Limit time studied today to minutes (#4242)
* Limit time studied today to minutes * Update timespan.rs * Update today.rs * Update timespan.rs * Update today.rs * Update today.rs * Update time.ts * Update time.ts * Update timespan.rs * Update timespan.rs * Update timespan.rs * Update today.rs
This commit is contained in:
parent
ab55440a05
commit
5c6e2188e2
3 changed files with 18 additions and 6 deletions
|
@ -57,10 +57,10 @@ const SECOND: f32 = 1.0;
|
|||
const MINUTE: f32 = 60.0 * SECOND;
|
||||
const HOUR: f32 = 60.0 * MINUTE;
|
||||
const DAY: f32 = 24.0 * HOUR;
|
||||
const MONTH: f32 = 30.417 * DAY; // 365/12 ≈ 30.417
|
||||
const YEAR: f32 = 365.0 * DAY;
|
||||
const MONTH: f32 = YEAR / 12.0;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub(crate) enum TimespanUnit {
|
||||
Seconds,
|
||||
Minutes,
|
||||
|
@ -111,6 +111,13 @@ impl Timespan {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_unit(self, unit: TimespanUnit) -> Timespan {
|
||||
Timespan {
|
||||
seconds: self.seconds,
|
||||
unit,
|
||||
}
|
||||
}
|
||||
|
||||
/// Round seconds and days to integers, otherwise
|
||||
/// truncates to one decimal place.
|
||||
pub fn as_rounded_unit(self) -> f32 {
|
||||
|
|
|
@ -5,17 +5,18 @@ use anki_i18n::I18n;
|
|||
|
||||
use crate::prelude::*;
|
||||
use crate::scheduler::timespan::Timespan;
|
||||
use crate::scheduler::timespan::TimespanUnit;
|
||||
|
||||
pub fn studied_today(cards: u32, secs: f32, tr: &I18n) -> String {
|
||||
let span = Timespan::from_secs(secs).natural_span();
|
||||
let amount = span.as_unit();
|
||||
let unit = span.unit().as_str();
|
||||
let unit = std::cmp::min(span.unit(), TimespanUnit::Minutes);
|
||||
let amount = span.to_unit(unit).as_unit();
|
||||
let secs_per_card = if cards > 0 {
|
||||
secs / (cards as f32)
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
tr.statistics_studied_today(unit, secs_per_card, amount, cards)
|
||||
tr.statistics_studied_today(unit.as_str(), secs_per_card, amount, cards)
|
||||
.into()
|
||||
}
|
||||
|
||||
|
@ -41,5 +42,9 @@ mod test {
|
|||
&studied_today(3, 13.0, &tr).replace('\n', " "),
|
||||
"Studied 3 cards in 13 seconds today (4.33s/card)"
|
||||
);
|
||||
assert_eq!(
|
||||
&studied_today(300, 5400.0, &tr).replace('\n', " "),
|
||||
"Studied 300 cards in 90 minutes today (18s/card)"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ export function naturalWholeUnit(secs: number): TimespanUnit {
|
|||
}
|
||||
|
||||
export function studiedToday(cards: number, secs: number): string {
|
||||
const unit = naturalUnit(secs);
|
||||
const unit = Math.min(naturalUnit(secs), TimespanUnit.Minutes);
|
||||
const amount = unitAmount(unit, secs);
|
||||
const name = unitName(unit);
|
||||
|
||||
|
|
Loading…
Reference in a new issue