max-niederman / ttyper

Terminal-based typing test.
MIT License
1.05k stars 76 forks source link

Add "practice missed words" mode #89

Closed glazari closed 11 months ago

glazari commented 1 year ago

Motivation

Monkeytype has the possibility of training just the words that you miss and this seems like a straight forward thing to add.

Implementation

Main change is to add a mssed_words item to the Result struct

pub struct Results {
    pub timing: TimingData,
    pub accuracy: AccuracyData,
    pub missed_words: Vec<String>,
}

And on the Results State, listen for 'p' (practice) to start a new test from missed words.

state = State::Test(Test::from_missed_words(&result.missed_words));

For the Results struct I did a very small refactor in the From<&Test> Trait implementation. I moved the calculation of each result to its own function, to leave the From function easier to follow.

Self {
    timing: Self::calc_timing(&events),
    accuracy: Self::calc_accuracy(&events),
    missed_words: Self::calc_missed_words(&test),
}
glazari commented 1 year ago

This would solve the issue I created: https://github.com/max-niederman/ttyper/issues/88 And it also goes in the direction of ttyperV2: https://github.com/max-niederman/ttyper/issues/83

glazari commented 1 year ago

Thanks for reviewing my PR and suggesting updates. I made the updates you suggested!

thanks again for the nice project