Write SqlDbLayer

This commit is contained in:
micialware committed 2026-08-30 20:32:16 +03:00
1 parent 8ec7c8f05d
commit 45830a7985
7 files changed
+150 -19

No files matched your search

+13 -9
View File
@@ -23,7 +23,7 @@ pub fn load_stats_of_deck(
score: row.get(2)?,
fsrs_opened: NaiveDate::from_epoch_days(row.get::<usize, i32>(4)?)
.expect("Incorrect date encoding"),
fsrs_memory: Some(get_memory(row.get(5)?)),
fsrs_memory: get_memory(row.get(5)?),
last_open: row.get(3)?,
fsrs_open_day: NaiveDate::from_epoch_days(row.get::<usize, i32>(6)?)
.expect("Incorrect date encoding"),
@@ -37,14 +37,21 @@ pub fn load_stats_of_deck(
Ok(buffer)
}
fn get_memory(value: i64) -> MemoryState {
MemoryState {
fn get_memory(value: i64) -> Option<MemoryState> {
if value == 0 {
return None;
}
Some(MemoryState {
stability: f32::from_bits(value as u32),
difficulty: f32::from_bits((value >> 32) as u32),
}
})
}
fn memory_to_i64(value: &MemoryState) -> i64 {
fn memory_to_i64(value: &Option<MemoryState>) -> i64 {
let Some(value) = &value else {
return 0;
};
value.stability.to_bits() as i64 | ((value.difficulty.to_bits() as i64) << 32)
}
@@ -69,10 +76,7 @@ pub fn add_stat_list(stats: &mut [CardStatistics], connection: &mut Connection)
stat.score,
stat.last_open.timestamp(),
stat.fsrs_opened.to_epoch_days(),
memory_to_i64(&stat.fsrs_memory.unwrap_or(MemoryState {
difficulty: 0.0,
stability: 0.0
})),
memory_to_i64(&stat.fsrs_memory),
stat.fsrs_open_day.to_epoch_days()
])
.map_err(|_| DbSaveError)?;