Change TEXT to INTEGER in card_stats
This commit is contained in:
1 parent
e8c9e37ca1
commit
1406fc8f21
5 files changed
+42
-33
No files matched your search
@@ -1,3 +1,2 @@
|
||||
/target
|
||||
.idea
|
||||
.DS_Store
|
||||
+2
-2
@@ -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
|
||||
);
|
||||
+22
-18
@@ -40,25 +40,29 @@ pub fn load_groups(connection: &Connection) -> ImportData {
|
||||
.collect::<Vec<(i64, i64)>>();
|
||||
|
||||
for (_, collection) in sets {
|
||||
let fields = collection["flds"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|x| x["name"].as_str().unwrap().to_string())
|
||||
.collect();
|
||||
let mut group = ImportGroup {
|
||||
id: collection["id"].as_u64().unwrap(),
|
||||
name: collection["name"].as_str().unwrap().to_string(),
|
||||
fields,
|
||||
mapping: Default::default(),
|
||||
length: 0,
|
||||
imported: false,
|
||||
};
|
||||
if let Some((_, count)) = counts.iter().find(|(id, _)| *id == group.id as i64) {
|
||||
group.length = *count as u64
|
||||
let fields_property = collection.get("fields");
|
||||
if let Some(fields_property) = fields_property {
|
||||
let fields = fields_property
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|x| x["name"].as_str().unwrap().to_string())
|
||||
.collect();
|
||||
let mut group = ImportGroup {
|
||||
id: collection["id"].as_u64().unwrap(),
|
||||
name: collection["name"].as_str().unwrap().to_string(),
|
||||
fields,
|
||||
mapping: Default::default(),
|
||||
length: 0,
|
||||
imported: false,
|
||||
};
|
||||
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
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@ pub fn create_db() {
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_db_schema(connection: &Connection) {
|
||||
|
||||
}
|
||||
fn ensure_db_schema(_: &Connection) {}
|
||||
|
||||
fn create_tables(conn: &Connection) {
|
||||
make_card_set(conn).unwrap();
|
||||
|
||||
+17
-9
@@ -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()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user