@@ -103,43 +103,15 @@ impl crate::services::DeckConfigService for Collection {
103103 & mut self ,
104104 input : anki_proto:: deck_config:: GetRetentionWorkloadRequest ,
105105 ) -> Result < anki_proto:: deck_config:: GetRetentionWorkloadResponse > {
106- const LEARN_SPAN : usize = 365 ;
107- const TERMINATION_PROB : f32 = 1e-5 ;
108- // the default values are from https://github.com/open-spaced-repetition/Anki-button-usage/blob/881009015c2a85ac911021d76d0aacb124849937/analysis.ipynb
109- const DEFAULT_LEARN_COST : f32 = 19.4698 ;
110- const DEFAULT_PASS_COST : f32 = 7.8454 ;
111- const DEFAULT_FAIL_COST : f32 = 23.185 ;
112- const DEFAULT_INITIAL_PASS_RATE : f32 = 0.7645 ;
113-
114106 let guard =
115107 self . search_cards_into_table ( & input. search , crate :: search:: SortMode :: NoOrder ) ?;
116- let costs = guard. col . storage . get_costs_for_retention ( ) ?;
117-
118- fn smoothing ( obs : f32 , default : f32 , count : u32 ) -> f32 {
119- let alpha = count as f32 / ( 50.0 + count as f32 ) ;
120- obs * alpha + default * ( 1.0 - alpha)
121- }
108+
109+ let revlogs = guard
110+ . col
111+ . storage
112+ . get_revlog_entries_for_searched_cards_in_card_order ( ) ?;
122113
123- let cost_success = smoothing (
124- costs. average_pass_time_ms / 1000.0 ,
125- DEFAULT_PASS_COST ,
126- costs. pass_count ,
127- ) ;
128- let cost_failure = smoothing (
129- costs. average_fail_time_ms / 1000.0 ,
130- DEFAULT_FAIL_COST ,
131- costs. fail_count ,
132- ) ;
133- let cost_learn = smoothing (
134- costs. average_learn_time_ms / 1000.0 ,
135- DEFAULT_LEARN_COST ,
136- costs. learn_count ,
137- ) ;
138- let initial_pass_rate = smoothing (
139- costs. initial_pass_rate ,
140- DEFAULT_INITIAL_PASS_RATE ,
141- costs. pass_count ,
142- ) ;
114+ let config = guard. col . get_optimal_retention_parameters ( revlogs) ?;
143115
144116 let costs = ( 70u32 ..=99u32 )
145117 . map ( |dr| {
@@ -148,12 +120,7 @@ impl crate::services::DeckConfigService for Collection {
148120 fsrs:: expected_workload (
149121 & input. w ,
150122 dr as f32 / 100. ,
151- LEARN_SPAN ,
152- cost_success,
153- cost_failure,
154- cost_learn,
155- initial_pass_rate,
156- TERMINATION_PROB ,
123+ & config
157124 ) ?,
158125 ) )
159126 } )
0 commit comments