Remove more unwrap
This commit is contained in:
1 parent
b5b1eb768c
commit
d836b57d2a
5 files changed
+74
-62
No files matched your search
+36
-33
@@ -1,12 +1,15 @@
|
||||
use crate::app::AppState;
|
||||
use crate::core::srs::{OrderMode, OrderModule, RandomSRSModule, SRSModule, SemiRandomSRSModule, WordOpenMode, WorstWordsSRSModule};
|
||||
use crate::core::srs::{
|
||||
OrderMode, OrderModule, RandomSRSModule, SRSModule, SemiRandomSRSModule, WordOpenMode,
|
||||
WorstWordsSRSModule,
|
||||
};
|
||||
use crate::data::entities::*;
|
||||
use crate::data_provider::card_stats::{load_stats_of_deck, update_stat_score};
|
||||
use crate::data_provider::history::push_note;
|
||||
use crate::notification::NotificationData;
|
||||
use chrono::Utc;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use crate::notification::NotificationData;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DeckData {
|
||||
@@ -18,7 +21,10 @@ pub struct DeckData {
|
||||
settings: DeckSettings,
|
||||
}
|
||||
impl DeckData {
|
||||
pub fn new(settings: &DeckSettings, state: Arc<Mutex<AppState>>) -> Result<Self, NotificationData> {
|
||||
pub fn new(
|
||||
settings: &DeckSettings,
|
||||
state: Arc<Mutex<AppState>>,
|
||||
) -> Result<Self, NotificationData> {
|
||||
let state_for = state.clone();
|
||||
let state_locked = state.lock();
|
||||
|
||||
@@ -83,42 +89,39 @@ impl DeckData {
|
||||
(self.words[index].clone(), self.set[index].clone())
|
||||
}
|
||||
pub fn open(&mut self, status: WordOpenMode) -> Result<(), NotificationData> {
|
||||
if self.current_word_index.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
let index = self.current_word_index.unwrap();
|
||||
if let Some(index) = self.current_word_index {
|
||||
let word: &mut CardStatistics = &mut self.set[index];
|
||||
let old_score = word.score;
|
||||
word.update(status);
|
||||
let new_score = word.score;
|
||||
|
||||
let word : &mut CardStatistics = &mut self.set[index];
|
||||
let old_score = word.score;
|
||||
word.update(status);
|
||||
let new_score = word.score;
|
||||
|
||||
match self.order_module {
|
||||
OrderModule::SemiRandomSRS(ref mut module) => {
|
||||
module.open(status, index, word);
|
||||
}
|
||||
OrderModule::RandomSRS(ref mut module) => {
|
||||
module.open(status, index, word);
|
||||
}
|
||||
OrderModule::WorstWordsSRS(ref mut module) => {
|
||||
module.open(status, index, word);
|
||||
match self.order_module {
|
||||
OrderModule::SemiRandomSRS(ref mut module) => {
|
||||
module.open(status, index, word);
|
||||
}
|
||||
OrderModule::RandomSRS(ref mut module) => {
|
||||
module.open(status, index, word);
|
||||
}
|
||||
OrderModule::WorstWordsSRS(ref mut module) => {
|
||||
module.open(status, index, word);
|
||||
}
|
||||
}
|
||||
update_stat_score(word, &self.state.lock().connection)?;
|
||||
let _ = push_note(
|
||||
self.settings.id,
|
||||
HistoryItem {
|
||||
timestamp: Utc::now(),
|
||||
word_id: word.word_id,
|
||||
mode: status,
|
||||
before: old_score,
|
||||
after: new_score,
|
||||
},
|
||||
);
|
||||
}
|
||||
update_stat_score(word, &self.state.lock().connection)?;
|
||||
let _ = push_note(
|
||||
self.settings.id,
|
||||
HistoryItem {
|
||||
timestamp: Utc::now(),
|
||||
word_id: word.word_id,
|
||||
mode: status,
|
||||
before: old_score,
|
||||
after: new_score,
|
||||
},
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
pub fn len(&self) -> usize {
|
||||
self.set.len()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ impl SRSModule for SemiRandomSRSModule {
|
||||
.iter()
|
||||
.map(|s| (100.0 / s.calculated_score()).powf(2.0) * 2.0)
|
||||
.collect::<Vec<f32>>();
|
||||
self.last_weights = WeightedIndex::new(weights).unwrap();
|
||||
self.last_weights = WeightedIndex::new(weights).expect("Incorrect weights update");
|
||||
}
|
||||
}
|
||||
impl SemiRandomSRSModule {
|
||||
|
||||
Reference in new issue
Block a user