Author SHA1 Message Date
micialware 1406fc8f21 Change TEXT to INTEGER in card_stats 2026-08-20 18:53:13 +03:00
micialware e8c9e37ca1 Fix semirandom srs bug 2026-08-20 18:27:05 +03:00
5 changed files with 25 additions and 14 deletions

No files matched your search

-1
View File
@@ -1,3 +1,2 @@
/target
.idea
.DS_Store
+2 -2
View File
@@ -5,9 +5,9 @@ create table card_stats
word_id INTEGER not null
references words
on delete cascade,
set_id TEXT not null
set_id INTEGER not null
references card_set
on delete cascade,
score INTEGER default 1 not null,
last_opened integer not null
last_opened INTEGER not null
);
+5 -1
View File
@@ -40,7 +40,9 @@ pub fn load_groups(connection: &Connection) -> ImportData {
.collect::<Vec<(i64, i64)>>();
for (_, collection) in sets {
let fields = collection["flds"]
let fields_property = collection.get("fields");
if let Some(fields_property) = fields_property {
let fields = fields_property
.as_array()
.unwrap()
.iter()
@@ -60,6 +62,8 @@ pub fn load_groups(connection: &Connection) -> ImportData {
println!("{:?}", group);
total_data.0.push(group);
}
}
total_data
}
+1 -1
View File
@@ -542,7 +542,7 @@ impl SRSModule for SemiRandomSRSModule {
fn next(&mut self, set: &mut DeckData) -> usize {
let index = self.last_weights.sample(&mut self.generator);
if self.history.contains(&index) {
if self.history.contains(&index) && self.history.len() != 1 {
return self.next(set);
}
+17 -9
View File
@@ -25,7 +25,7 @@ pub struct RepetitionState {
current_statistic: CardStatistics,
open: bool,
can_play: bool,
sink: Arc<MixerDeviceSink>,
sink: Arc<Option<MixerDeviceSink>>,
opened: HashSet<Id>,
}
@@ -100,7 +100,12 @@ impl RepetitionState {
pub(crate) fn new(set: DeckSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
let mut card_set = DeckData::new(&set, state.clone());
let (word, stat) = card_set.next();
let sink_handle = rodio::DeviceSinkBuilder::open_default_sink().unwrap();
let sink_handle = if set.forward.contains("speech") || set.backward.contains("speech") {
rodio::DeviceSinkBuilder::open_default_sink().ok()
} else {
None
};
RepetitionState {
state,
@@ -138,11 +143,12 @@ impl RepetitionState {
self.current_word = next.0;
self.current_statistic = next.1;
if self.settings.require_speech() {
return Task::perform(
play_sound(self.sink.clone(), self.current_word.key.clone()),
|_| RootMessage::Repetition(RepetitionMessage::PlayFinished),
);
if self.settings.require_speech() && self.sink.is_some() {
let sink = self.sink.clone();
let task = play_sound(sink, self.current_word.key.clone());
return Task::perform(task, |_| {
RootMessage::Repetition(RepetitionMessage::PlayFinished)
});
}
self.increment_counter();
Task::none()
@@ -316,10 +322,12 @@ pub enum RepetitionMessage {
PlayFinished,
}
async fn play_sound(sink: Arc<MixerDeviceSink>, text: String) {
async fn play_sound(sink: Arc<Option<MixerDeviceSink>>, text: String) {
if let Ok(data) = get_voice(text.as_str()).await {
spawn_blocking(move || {
if let Ok(play) = rodio::play(sink.mixer(), data) {
if let Some(sink) = sink.as_ref()
&& let Ok(play) = rodio::play(sink.mixer(), data)
{
play.sleep_until_end()
}
})