release repetitions

This commit is contained in:
2026-04-16 09:56:57 +03:00
parent 7cbb974d3b
commit 1c4bdf372d
9 changed files with 34 additions and 45 deletions
+4 -18
View File
@@ -2,7 +2,7 @@ use crate::data_provider::words::{delete_word, update_word};
use crate::dictionary::DictionaryMessage::Test;
use crate::dictionary_test::DictionaryQuizState;
use crate::lang::DictionaryElement;
use crate::{AppState, NavigatedPage, Page, RootMessage};
use crate::{AppState, NavigatedPage, Page, RootMessage, DEFAULT_SPACING};
use iced::alignment::Vertical::Center;
use iced::widget::button::Style;
use iced::widget::*;
@@ -34,7 +34,6 @@ pub enum DictionaryMessage {
NewWord,
Include(usize, bool),
IncludeTag(String, bool),
Save,
Test,
ResetTags,
SetReverse(bool),
@@ -126,15 +125,6 @@ impl DictionaryState {
self.tag_map.iter_mut().for_each(|(_, v)| *v = false);
self.include_map.iter_mut().for_each(|x| *x = false)
}
DictionaryMessage::Save => {
/* let dir = dict_file();
let dict = &self.state.lock().unwrap().dictionary;
let content = serde_json::to_string_pretty(&dict.clone()).unwrap();
fs::write(dir, content.clone())
.unwrap_or_else(|e| println!("Can't write file: {}", e));*/
}
DictionaryMessage::SetReverse(v) => self.reverse = v,
DictionaryMessage::Search(s) => {
self.search = s;
@@ -160,16 +150,12 @@ impl DictionaryState {
iced::widget::column![
button("Назад").on_press(Back),
self.words_list(),
row![
button("Добавить слово").on_press(DictionaryMessage::NewWord),
button("Сохранить словарь").on_press(DictionaryMessage::Save),
]
.spacing(10)
button("Добавить слово").on_press(DictionaryMessage::NewWord),
]
.spacing(5),
self.filters()
]
.spacing(10),
.spacing(DEFAULT_SPACING),
)
.padding(10)
.into()
@@ -266,7 +252,7 @@ impl DictionaryState {
.width(Length::Fill),
]
.width(250)
.spacing(10)
.spacing(DEFAULT_SPACING)
.into()
}
+5 -5
View File
@@ -1,7 +1,7 @@
use crate::dictionary::{split_with_coma};
use crate::quiz::Score;
use crate::Page::PreviousPage;
use crate::RootMessage;
use crate::{RootMessage, DEFAULT_SPACING};
use crate::{NavigatedPage, Page};
use iced::border::Radius;
use iced::widget::container::Style;
@@ -102,14 +102,14 @@ impl DictionaryQuizState {
.color(iced::Color::from_rgb8(255, 79, 0))
.size(25),
]
.spacing(10),
.spacing(DEFAULT_SPACING),
row![
button("Закончить").on_press(DictionaryQuizMessage::Back),
self.appeal_button()
]
.spacing(10),
.spacing(DEFAULT_SPACING),
]
.spacing(10)
.spacing(DEFAULT_SPACING)
.align_x(alignment::Horizontal::Center),
)
.center_y(Fill)
@@ -199,7 +199,7 @@ impl DictionaryQuizState {
},
));
}
col.spacing(10).into()
col.spacing(DEFAULT_SPACING).into()
}
fn appeal_button(&self) -> Element<'_, DictionaryQuizMessage> {
+4 -3
View File
@@ -257,7 +257,6 @@ pub struct CardStatistics {
impl CardStatistics {
pub fn update(&mut self, status: WordOpenMode) {
self.last_open = Utc::now();
match status {
WordOpenMode::Easy => {
self.score = (self.calculated_score() + 5.0).round() as i32;
@@ -278,6 +277,8 @@ impl CardStatistics {
} else if self.score > MAX_SCORE {
self.score = MAX_SCORE
}
self.last_open = Utc::now();
}
pub fn calculated_score(&self) -> f32 {
@@ -340,7 +341,7 @@ impl CardSet {
index += 1;
}
let weights = current_set.iter().map(|s| (100.0 / s.calculated_score()).powi(2)).collect::<Vec<f32>>();
let weights = current_set.iter().map(|s| (100.0 / s.calculated_score()).powf(1.5)).collect::<Vec<f32>>();
let indexes = WeightedIndex::new(weights).unwrap();
Self {
@@ -366,7 +367,7 @@ impl CardSet {
let word = &mut self.set[self.current_word_index.unwrap()];
word.update(status);
let new_weight = (100.0 / word.calculated_score()).powi(2);
let new_weight = (100.0 / word.calculated_score()).powf(1.5);
self.last_weights.update_weights(&[(self.current_word_index.unwrap(), &new_weight)]).unwrap();
{
update_stat_score(word, &self.state.lock().unwrap().connection)
+2
View File
@@ -31,6 +31,8 @@ use std::sync::{Arc, Mutex};
use iced::keyboard::Event;
use crate::RootMessage::Keyboard;
const DEFAULT_SPACING: f32 = 10.0;
fn main() -> iced::Result {
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view).subscription(subscription)
.title("Kana learn app")
+3 -3
View File
@@ -1,6 +1,6 @@
use crate::lang::KanaSet;
use crate::Page::PreviousPage;
use crate::{NavigatedPage, Page, RootMessage};
use crate::{NavigatedPage, Page, RootMessage, DEFAULT_SPACING};
use iced::widget::*;
use iced::{alignment, Element, Fill, Task};
use rand::seq::SliceRandom;
@@ -126,10 +126,10 @@ impl QuizState {
.color(iced::Color::from_rgb8(255, 79, 0))
.size(25),
]
.spacing(10),
.spacing(DEFAULT_SPACING),
button("Закончить").on_press(QuizMessage::Back),
]
.spacing(10)
.spacing(DEFAULT_SPACING)
.align_x(alignment::Horizontal::Center),
)
.center_y(Fill)
+2 -2
View File
@@ -1,7 +1,7 @@
use crate::lang::{CardSet, DictionaryElement, WordOpenMode};
use crate::repetitions::CardSetSettings;
use crate::Page::PreviousPage;
use crate::{AppState, KeyPressedPage, NavigatedPage, Page, RootMessage};
use crate::{AppState, KeyPressedPage, NavigatedPage, Page, RootMessage, DEFAULT_SPACING};
use iced::alignment::Horizontal::Center;
use iced::keyboard::key::Physical::Code;
use iced::widget::container::rounded_box;
@@ -139,7 +139,7 @@ impl RepetitionState {
button("Нормально").on_press(RepetitionMessage::Answer(WordOpenMode::Ok)),
button("Легко").on_press(RepetitionMessage::Answer(WordOpenMode::Easy)),
]
.spacing(10)
.spacing(DEFAULT_SPACING)
.into()
}
+6 -6
View File
@@ -2,7 +2,7 @@ use crate::data_provider::card_sets::{delete_set, update_card_set};
use crate::lang::DictionaryElement;
use crate::repetition::RepetitionState;
use crate::Page::{PreviousPage, Repetition};
use crate::{AppState, NavigatedPage, Page, RootMessage};
use crate::{AppState, NavigatedPage, Page, RootMessage, DEFAULT_SPACING};
pub use iced::widget::button::{Catalog, Style};
use iced::widget::{button, column, container, row, scrollable, space, text, text_input, Column};
use iced::Background::Color;
@@ -112,14 +112,14 @@ impl RepetitionsState {
.width(Fill)
.on_press(RepetitionsMessage::CreateSet),
]
.spacing(10)
.spacing(DEFAULT_SPACING)
.width(Length::FillPortion(1)),
self.selected_set_view(),
self.launch_button()
]
.align_y(Center)
.padding(10)
.spacing(10)
.spacing(DEFAULT_SPACING)
.width(Fill)
.height(Fill)
]
@@ -159,7 +159,7 @@ impl RepetitionsState {
button("Проверить фильтр").on_press(RepetitionsMessage::TryFilter),
self.count_view(&sets[index])
]
.spacing(10)
.spacing(DEFAULT_SPACING)
)
.height(Fill),
row![
@@ -174,9 +174,9 @@ impl RepetitionsState {
})
.on_press(RepetitionsMessage::DeleteSet)
]
.spacing(10),
.spacing(DEFAULT_SPACING),
]
.spacing(10)
.spacing(DEFAULT_SPACING)
.width(Length::FillPortion(2))
.into();
}
+5 -5
View File
@@ -6,7 +6,7 @@ use crate::repetitions::RepetitionsState;
use crate::selector::SelectorMessage::ChangeMode;
use crate::writing::WritingState;
use crate::Page::{Quiz, Writing};
use crate::{AppState, NavigatedPage, Page, QuizState, RootMessage};
use crate::{AppState, NavigatedPage, Page, QuizState, RootMessage, DEFAULT_SPACING};
use iced::widget::*;
use iced::{alignment, Element, Task};
@@ -82,14 +82,14 @@ impl SelectorState {
button("Рандомайзер").on_press(SelectorMessage::ToRandomize),
button("Повторение").on_press(SelectorMessage::ToRepetitions)
]
.spacing(10),
.spacing(DEFAULT_SPACING),
self.rows_selector(),
toggler(self.is_writing)
.label("Режим письма")
.on_toggle(ChangeMode),
button("К тесту").on_press(SelectorMessage::Goto),
]
.spacing(10),
.spacing(DEFAULT_SPACING),
)
.padding(10)
.into()
@@ -115,11 +115,11 @@ impl SelectorState {
row = row.push(
chars_column
.spacing(10)
.spacing(DEFAULT_SPACING)
.align_x(alignment::Horizontal::Center),
);
}
row.spacing(10).into()
row.spacing(DEFAULT_SPACING).into()
}
}
+3 -3
View File
@@ -1,6 +1,6 @@
use crate::lang::KanaSet;
use crate::Page::PreviousPage;
use crate::{NavigatedPage, Page, RootMessage};
use crate::{NavigatedPage, Page, RootMessage, DEFAULT_SPACING};
use iced::widget::*;
use iced::{alignment, Element, Fill, Task};
use rand::seq::SliceRandom;
@@ -96,9 +96,9 @@ impl WritingState {
button(text!("{}", self.next_text)).on_press(WritingMessage::Next),
button("Закончить").on_press(WritingMessage::Back),
]
.spacing(10)
.spacing(DEFAULT_SPACING)
]
.spacing(10)
.spacing(DEFAULT_SPACING)
.align_x(alignment::Horizontal::Center),
)
.center_x(Fill)