Skip to content

Commit

Permalink
fix: error counted when restart at start - cleanup interval error
Browse files Browse the repository at this point in the history
  • Loading branch information
k11q committed Apr 24, 2023
1 parent ff4d4cf commit ca360a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
37 changes: 21 additions & 16 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ import {
TotalCharactersCounter,
TotalCorrectsCounter,
TotalErrorsCounter,
IntervalErrorCounter,
} from '~/src/counters';
definePageMeta({
Expand Down Expand Up @@ -212,7 +213,7 @@ const intervalCount = new IntervalCounter();
const liveWpm = ref(0);
const liveRawWpm = ref(0);
const liveTimer = ref(0);
let intervalError = 0;
const intervalError = new IntervalErrorCounter();
const intervalCharacterCount = new IntervalCharactersCounter();
let characterCountPerFiveSeconds: number[] = [];
const totalCharactersCount = new TotalCharactersCounter();
Expand Down Expand Up @@ -540,16 +541,12 @@ function handleIncorrectInput(key: string): void {
if (!currentIncorrect) {
totalErrorsCount.increment();
}
incrementIntervalError();
intervalError.increment();
insertExtraChar(key);
currentIncorrect = true;
correctCharIndex.value++;
}
function incrementIntervalError(): void {
intervalError++;
}
// function to delete extra values
function deleteExtras(): void {
const totalExtras = getExtrasCount();
Expand Down Expand Up @@ -740,17 +737,28 @@ function fillFinalIntervalValues(time: number) {
durationRaw
);
if (selectedMode.value === 'word') {
insertChartDataLog(wpm, intervalError, durationSeconds, rawWpm);
insertChartDataLog(
wpm,
intervalError.getValue(),
durationSeconds,
rawWpm
);
} else if (selectedMode.value === 'time') {
insertChartDataLog(
wpm,
intervalError,
intervalError.getValue(),
selectedDuration.value,
rawWpm
);
}
pushIntervalLogs(wpm, intervalError, durationSeconds, rawWpm, time);
pushIntervalLogs(
wpm,
intervalError.getValue(),
durationSeconds,
rawWpm,
time
);
}
function setShowResults() {
Expand Down Expand Up @@ -911,6 +919,7 @@ function resetCounters() {
characterLogs = [];
wordLogs = [];
intervalLogs = [];
intervalError.reset();
totalCorrectsCount.reset();
totalErrorsCount.reset();
totalCharactersCount.reset();
Expand Down Expand Up @@ -1134,20 +1143,20 @@ function updateWPM() {
setIntervalValues(wpm, intervalCount.getValue(), rawWpm);
insertChartDataLog(
wpm,
intervalError,
intervalError.getValue(),
intervalCount.getValue(),
rawWpm
);
pushIntervalLogs(
wpm,
intervalError,
intervalError.getValue(),
intervalCount.getValue(),
rawWpm,
logTime
);
intervalCount.increment();
intervalCharacterCount.reset();
resetIntervalError();
intervalError.reset();
timeoutId = setTimeout(updateWPM, 1000); // Log the values every second
}
Expand Down Expand Up @@ -1217,10 +1226,6 @@ function pushIntervalLogs(
intervalLogs.push(updatedIntervalLogObject);
}
function resetIntervalError(): void {
intervalError = 0;
}
//watch if input out of focus
watch(currentActive, () => {
if (currentActive.value.id !== 'MasterInput') {
Expand Down
3 changes: 2 additions & 1 deletion src/counters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export { IntervalCounter } from './interval-counter';
export { IntervalCharactersCounter } from './interval-characters-counter';
export { TotalCharactersCounter } from './total-characters-counter';
export { TotalErrorsCounter } from './total-errors-counter';
export { ErrorsCounter } from './errors-counter';
export { ErrorsCounter } from './errors-counter';
export { IntervalErrorCounter } from './interval-error-counter';
6 changes: 6 additions & 0 deletions src/counters/interval-error-counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import BaseCounter from './base-counter';

class IntervalErrorCounter extends BaseCounter{
}

export {IntervalErrorCounter};

0 comments on commit ca360a4

Please sign in to comment.