Change TEXT to INTEGER in card_stats
This commit is contained in:
1 parent
e8c9e37ca1
commit
1406fc8f21
5 files changed
+43
-34
No files matched your search
+1
-2
@@ -1,3 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
.idea
|
.idea
|
||||||
.DS_Store
|
|
||||||
+2
-2
@@ -5,9 +5,9 @@ create table card_stats
|
|||||||
word_id INTEGER not null
|
word_id INTEGER not null
|
||||||
references words
|
references words
|
||||||
on delete cascade,
|
on delete cascade,
|
||||||
set_id TEXT not null
|
set_id INTEGER not null
|
||||||
references card_set
|
references card_set
|
||||||
on delete cascade,
|
on delete cascade,
|
||||||
score INTEGER default 1 not null,
|
score INTEGER default 1 not null,
|
||||||
last_opened integer not null
|
last_opened INTEGER not null
|
||||||
);
|
);
|
||||||
+22
-18
@@ -40,25 +40,29 @@ pub fn load_groups(connection: &Connection) -> ImportData {
|
|||||||
.collect::<Vec<(i64, i64)>>();
|
.collect::<Vec<(i64, i64)>>();
|
||||||
|
|
||||||
for (_, collection) in sets {
|
for (_, collection) in sets {
|
||||||
let fields = collection["flds"]
|
let fields_property = collection.get("fields");
|
||||||
.as_array()
|
if let Some(fields_property) = fields_property {
|
||||||
.unwrap()
|
let fields = fields_property
|
||||||
.iter()
|
.as_array()
|
||||||
.map(|x| x["name"].as_str().unwrap().to_string())
|
.unwrap()
|
||||||
.collect();
|
.iter()
|
||||||
let mut group = ImportGroup {
|
.map(|x| x["name"].as_str().unwrap().to_string())
|
||||||
id: collection["id"].as_u64().unwrap(),
|
.collect();
|
||||||
name: collection["name"].as_str().unwrap().to_string(),
|
let mut group = ImportGroup {
|
||||||
fields,
|
id: collection["id"].as_u64().unwrap(),
|
||||||
mapping: Default::default(),
|
name: collection["name"].as_str().unwrap().to_string(),
|
||||||
length: 0,
|
fields,
|
||||||
imported: false,
|
mapping: Default::default(),
|
||||||
};
|
length: 0,
|
||||||
if let Some((_, count)) = counts.iter().find(|(id, _)| *id == group.id as i64) {
|
imported: false,
|
||||||
group.length = *count as u64
|
};
|
||||||
|
if let Some((_, count)) = counts.iter().find(|(id, _)| *id == group.id as i64) {
|
||||||
|
group.length = *count as u64
|
||||||
|
}
|
||||||
|
println!("{:?}", group);
|
||||||
|
total_data.0.push(group);
|
||||||
}
|
}
|
||||||
println!("{:?}", group);
|
|
||||||
total_data.0.push(group);
|
|
||||||
}
|
}
|
||||||
total_data
|
total_data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ pub fn create_db() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_db_schema(connection: &Connection) {
|
fn ensure_db_schema(_: &Connection) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_tables(conn: &Connection) {
|
fn create_tables(conn: &Connection) {
|
||||||
make_card_set(conn).unwrap();
|
make_card_set(conn).unwrap();
|
||||||
|
|||||||
+17
-9
@@ -25,7 +25,7 @@ pub struct RepetitionState {
|
|||||||
current_statistic: CardStatistics,
|
current_statistic: CardStatistics,
|
||||||
open: bool,
|
open: bool,
|
||||||
can_play: bool,
|
can_play: bool,
|
||||||
sink: Arc<MixerDeviceSink>,
|
sink: Arc<Option<MixerDeviceSink>>,
|
||||||
opened: HashSet<Id>,
|
opened: HashSet<Id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,12 @@ impl RepetitionState {
|
|||||||
pub(crate) fn new(set: DeckSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
pub(crate) fn new(set: DeckSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
||||||
let mut card_set = DeckData::new(&set, state.clone());
|
let mut card_set = DeckData::new(&set, state.clone());
|
||||||
let (word, stat) = card_set.next();
|
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 {
|
RepetitionState {
|
||||||
state,
|
state,
|
||||||
@@ -138,11 +143,12 @@ impl RepetitionState {
|
|||||||
self.current_word = next.0;
|
self.current_word = next.0;
|
||||||
self.current_statistic = next.1;
|
self.current_statistic = next.1;
|
||||||
|
|
||||||
if self.settings.require_speech() {
|
if self.settings.require_speech() && self.sink.is_some() {
|
||||||
return Task::perform(
|
let sink = self.sink.clone();
|
||||||
play_sound(self.sink.clone(), self.current_word.key.clone()),
|
let task = play_sound(sink, self.current_word.key.clone());
|
||||||
|_| RootMessage::Repetition(RepetitionMessage::PlayFinished),
|
return Task::perform(task, |_| {
|
||||||
);
|
RootMessage::Repetition(RepetitionMessage::PlayFinished)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
self.increment_counter();
|
self.increment_counter();
|
||||||
Task::none()
|
Task::none()
|
||||||
@@ -316,10 +322,12 @@ pub enum RepetitionMessage {
|
|||||||
PlayFinished,
|
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 {
|
if let Ok(data) = get_voice(text.as_str()).await {
|
||||||
spawn_blocking(move || {
|
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()
|
play.sleep_until_end()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user