mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Fix importing of Mnemosyne due dates (#2936)
This commit is contained in:
parent
1613eae261
commit
57ec454847
2 changed files with 22 additions and 13 deletions
|
@ -26,6 +26,7 @@ use crate::notetype::CardTemplate;
|
||||||
use crate::notetype::NoteField;
|
use crate::notetype::NoteField;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::progress::ThrottlingProgressHandler;
|
use crate::progress::ThrottlingProgressHandler;
|
||||||
|
use crate::scheduler::timing::SchedTimingToday;
|
||||||
use crate::text::strip_html_preserving_media_filenames;
|
use crate::text::strip_html_preserving_media_filenames;
|
||||||
|
|
||||||
impl ForeignData {
|
impl ForeignData {
|
||||||
|
@ -73,7 +74,7 @@ struct Context<'a> {
|
||||||
deck_ids: DeckIdsByNameOrId,
|
deck_ids: DeckIdsByNameOrId,
|
||||||
usn: Usn,
|
usn: Usn,
|
||||||
normalize_notes: bool,
|
normalize_notes: bool,
|
||||||
today: u32,
|
timing: SchedTimingToday,
|
||||||
dupe_resolution: DupeResolution,
|
dupe_resolution: DupeResolution,
|
||||||
card_gen_ctxs: HashMap<(NotetypeId, DeckId), CardGenContext<Arc<Notetype>>>,
|
card_gen_ctxs: HashMap<(NotetypeId, DeckId), CardGenContext<Arc<Notetype>>>,
|
||||||
existing_checksums: ExistingChecksums,
|
existing_checksums: ExistingChecksums,
|
||||||
|
@ -179,7 +180,7 @@ impl<'a> Context<'a> {
|
||||||
fn new(data: &ForeignData, col: &'a mut Collection) -> Result<Self> {
|
fn new(data: &ForeignData, col: &'a mut Collection) -> Result<Self> {
|
||||||
let usn = col.usn()?;
|
let usn = col.usn()?;
|
||||||
let normalize_notes = col.get_config_bool(BoolKey::NormalizeNoteText);
|
let normalize_notes = col.get_config_bool(BoolKey::NormalizeNoteText);
|
||||||
let today = col.timing_today()?.days_elapsed;
|
let timing = col.timing_today()?;
|
||||||
let mut notetypes = HashMap::new();
|
let mut notetypes = HashMap::new();
|
||||||
notetypes.insert(
|
notetypes.insert(
|
||||||
NameOrId::default(),
|
NameOrId::default(),
|
||||||
|
@ -193,7 +194,7 @@ impl<'a> Context<'a> {
|
||||||
col,
|
col,
|
||||||
usn,
|
usn,
|
||||||
normalize_notes,
|
normalize_notes,
|
||||||
today,
|
timing,
|
||||||
dupe_resolution: data.dupe_resolution,
|
dupe_resolution: data.dupe_resolution,
|
||||||
notetypes,
|
notetypes,
|
||||||
deck_ids,
|
deck_ids,
|
||||||
|
@ -355,7 +356,7 @@ impl<'a> Context<'a> {
|
||||||
let mut note = Note::new(&ctx.notetype);
|
let mut note = Note::new(&ctx.notetype);
|
||||||
let mut cards = ctx
|
let mut cards = ctx
|
||||||
.note
|
.note
|
||||||
.into_native(&mut note, ctx.deck_id, self.today, ctx.global_tags);
|
.into_native(&mut note, ctx.deck_id, &self.timing, ctx.global_tags);
|
||||||
self.prepare_note(&mut note, &ctx.notetype)?;
|
self.prepare_note(&mut note, &ctx.notetype)?;
|
||||||
self.col.add_note_only_undoable(&mut note)?;
|
self.col.add_note_only_undoable(&mut note)?;
|
||||||
self.add_cards(&mut cards, ¬e, ctx.deck_id, ctx.notetype)?;
|
self.add_cards(&mut cards, ¬e, ctx.deck_id, ctx.notetype)?;
|
||||||
|
@ -392,7 +393,7 @@ impl<'a> Context<'a> {
|
||||||
let mut cards = ctx.note.clone().into_native(
|
let mut cards = ctx.note.clone().into_native(
|
||||||
&mut note,
|
&mut note,
|
||||||
ctx.deck_id,
|
ctx.deck_id,
|
||||||
self.today,
|
&self.timing,
|
||||||
ctx.global_tags.iter().chain(ctx.updated_tags.iter()),
|
ctx.global_tags.iter().chain(ctx.updated_tags.iter()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -543,7 +544,7 @@ impl ForeignNote {
|
||||||
self,
|
self,
|
||||||
note: &mut Note,
|
note: &mut Note,
|
||||||
deck_id: DeckId,
|
deck_id: DeckId,
|
||||||
today: u32,
|
timing: &SchedTimingToday,
|
||||||
extra_tags: impl IntoIterator<Item = &'tags String>,
|
extra_tags: impl IntoIterator<Item = &'tags String>,
|
||||||
) -> Vec<Card> {
|
) -> Vec<Card> {
|
||||||
// TODO: Handle new and learning cards
|
// TODO: Handle new and learning cards
|
||||||
|
@ -565,7 +566,7 @@ impl ForeignNote {
|
||||||
self.cards
|
self.cards
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, c)| c.into_native(NoteId(0), idx as u16, deck_id, today))
|
.map(|(idx, c)| c.into_native(NoteId(0), idx as u16, deck_id, timing))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,12 +610,18 @@ impl ForeignNote {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ForeignCard {
|
impl ForeignCard {
|
||||||
fn into_native(self, note_id: NoteId, template_idx: u16, deck_id: DeckId, today: u32) -> Card {
|
fn into_native(
|
||||||
|
self,
|
||||||
|
note_id: NoteId,
|
||||||
|
template_idx: u16,
|
||||||
|
deck_id: DeckId,
|
||||||
|
timing: &SchedTimingToday,
|
||||||
|
) -> Card {
|
||||||
Card {
|
Card {
|
||||||
note_id,
|
note_id,
|
||||||
template_idx,
|
template_idx,
|
||||||
deck_id,
|
deck_id,
|
||||||
due: self.native_due(today),
|
due: self.native_due(timing),
|
||||||
interval: self.interval,
|
interval: self.interval,
|
||||||
ease_factor: (self.ease_factor * 1000.).round() as u16,
|
ease_factor: (self.ease_factor * 1000.).round() as u16,
|
||||||
reps: self.reps,
|
reps: self.reps,
|
||||||
|
@ -625,10 +632,10 @@ impl ForeignCard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn native_due(self, today: u32) -> i32 {
|
fn native_due(self, timing: &SchedTimingToday) -> i32 {
|
||||||
let remaining_secs = self.interval as i64 - TimestampSecs::now().0;
|
let day_start = timing.next_day_at.0 as i32 - 86_400;
|
||||||
let remaining_days = remaining_secs / (60 * 60 * 24);
|
let due_delta = (self.due - day_start) / 86_400;
|
||||||
0.max(remaining_days as i32 + today as i32)
|
due_delta + timing.days_elapsed as i32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,9 @@ pub struct ForeignNote {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct ForeignCard {
|
pub struct ForeignCard {
|
||||||
|
/// Seconds-based timestamp
|
||||||
pub due: i32,
|
pub due: i32,
|
||||||
|
/// In days
|
||||||
pub interval: u32,
|
pub interval: u32,
|
||||||
pub ease_factor: f32,
|
pub ease_factor: f32,
|
||||||
pub reps: u32,
|
pub reps: u32,
|
||||||
|
|
Loading…
Reference in a new issue