@@ -103,15 +103,43 @@ 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+
106114 let guard =
107115 self . search_cards_into_table ( & input. search , crate :: search:: SortMode :: NoOrder ) ?;
108-
109- let revlogs = guard
110- . col
111- . storage
112- . get_revlog_entries_for_searched_cards_in_card_order ( ) ?;
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+ }
113122
114- let config = guard. col . get_optimal_retention_parameters ( revlogs) ?;
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+ ) ;
115143
116144 let costs = ( 70u32 ..=99u32 )
117145 . map ( |dr| {
@@ -120,7 +148,12 @@ impl crate::services::DeckConfigService for Collection {
120148 fsrs:: expected_workload (
121149 & input. w ,
122150 dr as f32 / 100. ,
123- & config
151+ LEARN_SPAN ,
152+ cost_success,
153+ cost_failure,
154+ cost_learn,
155+ initial_pass_rate,
156+ TERMINATION_PROB ,
124157 ) ?,
125158 ) )
126159 } )
0 commit comments