-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathmigrate.rs
More file actions
109 lines (86 loc) · 2.88 KB
/
migrate.rs
File metadata and controls
109 lines (86 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use fsrs::{FSRS, FSRSItem, FSRSReview};
fn migrate_with_full_history() -> Result<(), Box<dyn std::error::Error>> {
// Create a new FSRS model
let fsrs = FSRS::default();
// Simulate a full review history for a card
let reviews = vec![
FSRSReview {
rating: 3,
delta_t: 0,
},
FSRSReview {
rating: 3,
delta_t: 1,
},
FSRSReview {
rating: 4,
delta_t: 3,
},
FSRSReview {
rating: 3,
delta_t: 7,
},
];
let item = FSRSItem { reviews };
// Calculate the current memory state
let memory_state = fsrs.memory_state(item, None)?;
println!("Migrated memory state: {:?}", memory_state);
Ok(())
}
fn migrate_with_partial_history() -> Result<(), Box<dyn std::error::Error>> {
// Create a new FSRS model
let fsrs = FSRS::default();
// Set the true retention of the original algorithm
let sm2_retention = 0.9;
// Simulate the earliest card state from the first review log of Anki's card
// - ease_factor: the ratio of the interval to the previous interval
// - interval: the interval of the first review
let ease_factor = 2.0;
let interval = 5.0;
// Calculate the earliest memory state
let initial_state = fsrs.memory_state_from_sm2(ease_factor, interval, sm2_retention)?;
// Simulate partial review history
let reviews = vec![
FSRSReview {
rating: 3,
delta_t: 5,
},
FSRSReview {
rating: 4,
delta_t: 10,
},
FSRSReview {
rating: 3,
delta_t: 20,
},
];
let item = FSRSItem { reviews };
// Calculate the current memory state, passing the initial state
let memory_state = fsrs.memory_state(item, Some(initial_state))?;
println!("Migrated memory state: {:?}", memory_state);
Ok(())
}
fn migrate_with_latest_state() -> Result<(), Box<dyn std::error::Error>> {
// Create a new FSRS model
let fsrs = FSRS::default();
// Set the true retention of the original algorithm
let sm2_retention = 0.9;
// Simulate the latest card state from Anki's card
// - ease_factor: the ratio of the interval to the previous interval
// - interval: the interval of the last review
let ease_factor = 2.5;
let interval = 10.0;
// Calculate the memory state
let memory_state = fsrs.memory_state_from_sm2(ease_factor, interval, sm2_retention)?;
println!("Migrated memory state: {:?}", memory_state);
Ok(())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Migrating with full history:");
migrate_with_full_history()?;
println!("\nMigrating with partial history:");
migrate_with_partial_history()?;
println!("\nMigrating with latest state only:");
migrate_with_latest_state()?;
Ok(())
}