Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add average performance #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ <h2 id="header">typings</h2>
<div id="left-wing" onClick="hideThemeCenter();">< back</div>
<div id="theme-area"></div>
</div>
<div id="bottom-left-wing">N: XX / WPM AVG: XX / ACC AVG: XX</div>
<div id="footer">
<a href="https://github.com/briano1905/typings#typings" target="_blank" tabindex="3">user guide</a>/
<div id="show-themes"class="button" onClick="showThemeCenter();" tabindex="4">themes</div>
40 changes: 40 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ let startDate = 0;
let timer;
let timerActive = false;
let punctuation = false;
let acc_global = 0;
let wpm_global = 0;

// Get cookies
getCookie('theme') === '' ? setTheme('light') : setTheme(getCookie('theme'));
@@ -24,6 +26,9 @@ getCookie('wordCount') === '' ? setWordCount(50) : setWordCount(getCookie('wordC
getCookie('timeCount') === '' ? setTimeCount(60) : setTimeCount(getCookie('timeCount'));
getCookie('typingMode') === '' ? setTypingMode('wordcount') : setTypingMode(getCookie('typingMode'));
getCookie('punctuation') === '' ? setPunctuation('false') : setPunctuation(getCookie('punctuation'));
getCookie('n_tries') === '' ? setN_tries(0) : setN_tries(getCookie('n_tries'));
getCookie('sumacc') === '' ? setSumAcc(0) : setSumAcc(getCookie('sumacc'));
getCookie('sumwpm') === '' ? setSumWpm(0) : setSumWpm(getCookie('sumwpm'));

// Find a list of words and display it to textDisplay
function setText(e) {
@@ -164,6 +169,10 @@ inputField.addEventListener('keydown', e => {
inputField.className = '';
document.querySelector(`#tc-${timeCount}`).innerHTML = timeCount;
showResult();
setN_tries(parseFloat(getCookie('n_tries'))+1);
setSumAcc(parseFloat(getCookie('sumacc'))+acc_global);
setSumWpm(parseFloat(getCookie('sumwpm'))+wpm_global);
showResultAvg();
}
}
}
@@ -195,6 +204,10 @@ inputField.addEventListener('keydown', e => {
} else if (currentWord === wordList.length - 1) {
textDisplay.childNodes[currentWord].classList.add('wrong');
showResult();
setN_tries(parseFloat(getCookie('n_tries'))+1);
setSumAcc(parseFloat(getCookie('sumacc'))+acc_global);
setSumWpm(parseFloat(getCookie('sumwpm'))+wpm_global);
showResultAvg();
}

inputField.value = '';
@@ -208,11 +221,16 @@ inputField.addEventListener('keydown', e => {
correctKeys += wordList[currentWord].length;
currentWord++;
showResult();
setN_tries(parseFloat(getCookie('n_tries'))+1);
setSumAcc(parseFloat(getCookie('sumacc'))+acc_global);
setSumWpm(parseFloat(getCookie('sumwpm'))+wpm_global);
showResultAvg();
}
}
});

// Calculate and display result

function showResult() {
let words, minute, acc;
switch (typingMode) {
@@ -234,9 +252,18 @@ function showResult() {
acc = acc = Math.min(Math.floor((correctKeys / sumKeys) * 100), 100);
}
let wpm = Math.floor(words / minute);
acc_global = acc
wpm_global = wpm
document.querySelector('#right-wing').innerHTML = `WPM: ${wpm} / ACC: ${acc}`;
}

function showResultAvg() {
let acc_avg = Math.floor(parseFloat(getCookie('sumacc'))/parseFloat(getCookie('n_tries')));
let wpm_avg = Math.floor(parseFloat(getCookie('sumwpm'))/parseFloat(getCookie('n_tries')));
let ntries = Math.floor(parseInt(getCookie('n_tries')));
document.querySelector('#bottom-left-wing').innerHTML = `N: ${ntries} / WPM AVG: ${wpm_avg} / ACC AVG: ${acc_avg}`;
}

// Command actions
document.addEventListener('keydown', e => {
// Modifiers Windows: [Alt], Mac: [Cmd + Ctrl]
@@ -349,6 +376,19 @@ function setPunctuation(_punc) {
}
}

function setN_tries(_nt) {
if (_nt != 0){
showResultAvg();
}
setCookie('n_tries', parseInt(_nt), 90);
}
function setSumAcc(_sumacc) {
setCookie('sumacc', parseInt(_sumacc), 90);
}
function setSumWpm(_sumwpm) {
setCookie('sumwpm', parseInt(_sumwpm), 90);
}

function setWordCount(wc) {
setCookie('wordCount', wc, 90);
wordCount = wc;
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@ body {
display: none !important;
}

body, #header, #left-wing, #right-wing, #typing-area, #theme-area, #theme-center,
body, #header, #left-wing, #bottom-left-wing, #right-wing, #typing-area, #theme-area, #theme-center,
#text-display, #redo-button, #footer, #highlight {
transition: all .4s ease-in-out 0s;