-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add the state machine for our FlashCard
- Loading branch information
Showing
22 changed files
with
2,443 additions
and
194 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::{repositories::flash_card::CardQueue, FlashCard}; | ||
|
||
use super::states::{ | ||
card_state::CardState, learning_state::LearningState, new_state::NewState, | ||
review_state::ReviewState, | ||
}; | ||
|
||
pub fn get_current_card_state(card: &FlashCard) -> CardState { | ||
// get due from the card | ||
let due = card.due; | ||
let interval = card.interval; | ||
let ef = card.ease_factor(); | ||
|
||
match *card.get_queue() { | ||
CardQueue::New => NewState {}.into(), | ||
CardQueue::Learning => LearningState { | ||
remaining_steps: 0, | ||
scheduled_secs: 0, | ||
elapsed_secs: 0, | ||
memory_state: None, | ||
} | ||
.into(), | ||
CardQueue::Review => ReviewState {}.into(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
pub mod deck; | ||
pub mod builder; | ||
pub mod card; | ||
pub mod collection; | ||
pub mod deck; | ||
pub mod queue; | ||
pub mod builder; | ||
pub mod states; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::models::queue::SchedulingStates; | ||
|
||
use super::{ | ||
learning_state::LearningState, new_state::NewState, relearning_state::ReLearningState, | ||
review_state::ReviewState, | ||
}; | ||
|
||
#[derive(Clone)] | ||
pub enum CardState { | ||
New(NewState), | ||
Learning(LearningState), | ||
Review(ReviewState), | ||
ReLearning(ReLearningState), | ||
} | ||
|
||
pub trait CardStateTrait { | ||
fn next_states(self) -> SchedulingStates; | ||
} | ||
|
||
impl CardState { | ||
pub fn next_states(self) -> SchedulingStates { | ||
match self { | ||
CardState::New(state) => state.next_states(), | ||
CardState::Learning(state) => state.next_states(), | ||
CardState::Review(state) => state.next_states(), | ||
CardState::ReLearning(state) => state.next_states(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use fsrs::MemoryState; | ||
|
||
use super::card_state::{CardState, CardStateTrait}; | ||
use crate::models::queue::SchedulingStates; | ||
|
||
#[derive(Clone)] | ||
pub struct LearningState { | ||
pub remaining_steps: u32, | ||
pub scheduled_secs: u32, | ||
pub elapsed_secs: u32, | ||
pub memory_state: Option<MemoryState>, | ||
} | ||
|
||
impl CardStateTrait for LearningState { | ||
fn next_states(self) -> SchedulingStates { | ||
SchedulingStates { | ||
again: self.answer_again().into(), | ||
hard: self.answer_hard().into(), | ||
good: self.answer_good().into(), | ||
easy: self.answer_easy().into(), | ||
current: self.into(), | ||
} | ||
} | ||
} | ||
|
||
impl LearningState { | ||
fn answer_again(&self) -> LearningState { | ||
LearningState { | ||
remaining_steps: 0, | ||
scheduled_secs: 0, | ||
elapsed_secs: 0, | ||
memory_state: None, | ||
} | ||
} | ||
fn answer_hard(&self) -> LearningState { | ||
LearningState { | ||
remaining_steps: 0, | ||
scheduled_secs: 0, | ||
elapsed_secs: 0, | ||
memory_state: None, | ||
} | ||
} | ||
fn answer_good(&self) -> LearningState { | ||
LearningState { | ||
remaining_steps: 0, | ||
scheduled_secs: 0, | ||
elapsed_secs: 0, | ||
memory_state: None, | ||
} | ||
} | ||
fn answer_easy(&self) -> LearningState { | ||
LearningState { | ||
remaining_steps: 0, | ||
scheduled_secs: 0, | ||
elapsed_secs: 0, | ||
memory_state: None, | ||
} | ||
} | ||
} | ||
|
||
impl Into<CardState> for LearningState { | ||
fn into(self) -> CardState { | ||
CardState::Learning(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod card_state; | ||
pub mod learning_state; | ||
pub mod new_state; | ||
pub mod relearning_state; | ||
pub mod review_state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use crate::models::queue::SchedulingStates; | ||
|
||
use super::{ | ||
card_state::{CardState, CardStateTrait}, | ||
learning_state::LearningState, | ||
}; | ||
|
||
#[derive(Clone)] | ||
pub struct NewState {} | ||
|
||
impl CardStateTrait for NewState { | ||
fn next_states(self) -> SchedulingStates { | ||
let next_state = LearningState { | ||
remaining_steps: 0, | ||
scheduled_secs: 0, | ||
elapsed_secs: 0, | ||
memory_state: None, | ||
} | ||
.next_states(); | ||
|
||
SchedulingStates { | ||
current: self.into(), | ||
..next_state | ||
} | ||
} | ||
} | ||
|
||
impl Into<CardState> for NewState { | ||
fn into(self) -> CardState { | ||
CardState::New(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use crate::models::queue::SchedulingStates; | ||
|
||
use super::card_state::CardStateTrait; | ||
|
||
#[derive(Clone)] | ||
pub struct ReLearningState {} | ||
|
||
impl CardStateTrait for ReLearningState { | ||
fn next_states(self) -> SchedulingStates { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use crate::models::queue::SchedulingStates; | ||
|
||
use super::card_state::{CardState, CardStateTrait}; | ||
|
||
#[derive(Clone)] | ||
pub struct ReviewState {} | ||
|
||
impl CardStateTrait for ReviewState { | ||
fn next_states(self) -> SchedulingStates { | ||
todo!() | ||
} | ||
} | ||
|
||
impl Into<CardState> for ReviewState { | ||
fn into(self) -> CardState { | ||
CardState::Review(self) | ||
} | ||
} |
Oops, something went wrong.