Rebalance
This commit is contained in:
+3
-3
@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
const MAX_HISTORY_LEN: usize = 50;
|
||||
const MAX_HISTORY_LEN: usize = 20;
|
||||
const MAX_HISTORY_LEN_PART: f32 = 0.33;
|
||||
const MAX_SCORE: i32 = 25;
|
||||
const FADE_PER_DAY: f32 = 0.95;
|
||||
@@ -345,7 +345,7 @@ impl CardSet {
|
||||
index += 1;
|
||||
}
|
||||
|
||||
let weights = current_set.iter().map(|s| (100.0 / s.calculated_score()).powf(1.5)).collect::<Vec<f32>>();
|
||||
let weights = current_set.iter().map(|s| (100.0 / s.calculated_score()).powf(2.0)).collect::<Vec<f32>>();
|
||||
let indexes = WeightedIndex::new(weights).unwrap();
|
||||
|
||||
Self {
|
||||
@@ -382,7 +382,7 @@ impl CardSet {
|
||||
|
||||
let word = &mut self.set[self.current_word_index.unwrap()];
|
||||
word.update(status);
|
||||
let new_weight = (100.0 / word.calculated_score()).powf(1.5);
|
||||
let new_weight = (100.0 / word.calculated_score()).powf(2.0);
|
||||
self.last_weights.update_weights(&[(self.current_word_index.unwrap(), &new_weight)]).unwrap();
|
||||
{
|
||||
update_stat_score(word, &self.state.lock().unwrap().connection)
|
||||
|
||||
+3
-4
@@ -144,11 +144,10 @@ impl ScreenState {
|
||||
|
||||
fn handle_keyboard(&mut self, message: Event) -> Task<RootMessage> {
|
||||
let page = self.stack.last_mut().unwrap();
|
||||
match page {
|
||||
return match page {
|
||||
Repetition(page) => page.press(&message),
|
||||
_ => {}
|
||||
_ => Task::none(),
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +201,7 @@ trait NavigatedPage<T> {
|
||||
}
|
||||
|
||||
pub trait KeyPressedPage {
|
||||
fn press(&mut self, message: &keyboard::Event);
|
||||
fn press(&mut self, message: &keyboard::Event) -> Task<RootMessage>;
|
||||
}
|
||||
|
||||
/*pub fn danger_button(x: &Theme, status: Status) -> Style{
|
||||
|
||||
+20
-13
@@ -53,8 +53,8 @@ impl RepetitionState {
|
||||
pub fn update(&mut self, message: RepetitionMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
RepetitionMessage::Back => {}
|
||||
RepetitionMessage::Next => self.next(),
|
||||
RepetitionMessage::Answer(m) => self.answer(m),
|
||||
RepetitionMessage::Next => return self.next(),
|
||||
RepetitionMessage::Answer(m) => return self.answer(m),
|
||||
RepetitionMessage::Play => {
|
||||
if !self.can_play {
|
||||
return Task::none()
|
||||
@@ -75,25 +75,29 @@ impl RepetitionState {
|
||||
|
||||
|
||||
|
||||
fn next(&mut self) {
|
||||
fn next(&mut self) -> Task<RootMessage> {
|
||||
if self.open {
|
||||
self.set.open(WordOpenMode::None);
|
||||
self.current_word = self.set.next();
|
||||
self.open = false;
|
||||
return;
|
||||
|
||||
return Task::perform(play_sound(self.sink.clone(), self.current_word.key.clone()), |_| RootMessage::Repetition(RepetitionMessage::PlayFinished));
|
||||
} else {
|
||||
self.open = true;
|
||||
return Task::none();
|
||||
}
|
||||
}
|
||||
|
||||
fn answer(&mut self, mode: WordOpenMode) {
|
||||
fn answer(&mut self, mode: WordOpenMode) -> Task<RootMessage> {
|
||||
if !self.open {
|
||||
return;
|
||||
return Task::none();
|
||||
}
|
||||
|
||||
self.set.open(mode);
|
||||
self.open = false;
|
||||
self.current_word = self.set.next();
|
||||
return Task::perform(play_sound(self.sink.clone(), self.current_word.key.clone()), |_| RootMessage::Repetition(RepetitionMessage::PlayFinished));
|
||||
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, RepetitionMessage> {
|
||||
@@ -133,7 +137,7 @@ impl RepetitionState {
|
||||
match self.settings.forward.as_str() {
|
||||
"key" => self.draw_key(word),
|
||||
"value" => self.draw_value(word),
|
||||
"speech" => self.draw_voice(word),
|
||||
"speech" => self.draw_voice(),
|
||||
_ => space().into(),
|
||||
}
|
||||
}
|
||||
@@ -147,7 +151,7 @@ impl RepetitionState {
|
||||
match self.settings.backward.as_str() {
|
||||
"key" => self.draw_key(word),
|
||||
"value" => self.draw_value(word),
|
||||
"speech" => self.draw_voice(word),
|
||||
"speech" => self.draw_voice(),
|
||||
_ => space().into(),
|
||||
}
|
||||
}
|
||||
@@ -174,7 +178,8 @@ impl RepetitionState {
|
||||
text!("{}", word.value).size(24).into()
|
||||
}
|
||||
|
||||
fn draw_voice(&self, word: &DictionaryElement) -> Element<'_, RepetitionMessage> {
|
||||
fn draw_voice(&self) -> Element<'_, RepetitionMessage> {
|
||||
|
||||
button("Воспроизвести")
|
||||
.on_press(RepetitionMessage::Play)
|
||||
.into()
|
||||
@@ -182,7 +187,7 @@ impl RepetitionState {
|
||||
}
|
||||
|
||||
impl KeyPressedPage for RepetitionState {
|
||||
fn press(&mut self, message: &keyboard::Event) {
|
||||
fn press(&mut self, message: &keyboard::Event) -> iced::Task<RootMessage> {
|
||||
if let keyboard::Event::KeyPressed {
|
||||
key: _,
|
||||
modified_key: _,
|
||||
@@ -194,16 +199,19 @@ impl KeyPressedPage for RepetitionState {
|
||||
} = message
|
||||
{
|
||||
if let Code(code) = pk {
|
||||
match code {
|
||||
return match code {
|
||||
keyboard::key::Code::Space => self.next(),
|
||||
keyboard::key::Code::Digit1 => self.answer(WordOpenMode::None),
|
||||
keyboard::key::Code::Digit2 => self.answer(WordOpenMode::Hard),
|
||||
keyboard::key::Code::Digit3 => self.answer(WordOpenMode::Ok),
|
||||
keyboard::key::Code::Digit4 => self.answer(WordOpenMode::Easy),
|
||||
_ => {}
|
||||
_ => Task::none(),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Task::none()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,6 +228,5 @@ async fn play_sound(sink: Arc<MixerDeviceSink>, text: String) {
|
||||
let data = get_voice(text.as_str()).await;
|
||||
spawn_blocking(move || {
|
||||
rodio::play(&sink.mixer(), data).unwrap().sleep_until_end();
|
||||
|
||||
}).await.unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user