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

Added average speed and time in history section. #48

Merged
merged 5 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ const saveHistory = () => {

// History Viewer
const historyBody = document.getElementById("historyTableBody");
const avgHistoryBody = document.getElementById("avgTableBody");

const showHistory = () => {
history = localStorage.getItem("typerHistory");
Expand All @@ -202,11 +203,23 @@ const showHistory = () => {
document.getElementsByClassName("history")[0].style.display = "block";
historyArray = JSON.parse(history);
historyBody.innerHTML = "";
avgHistoryBody.innerHTML="";
const avgRow = document.createElement("tr");
let avgSpeed = 0;
let avgTime = 0;
historyArray.forEach((item) => {
const row = document.createElement("tr");
row.innerHTML = `<td>${htmlEncode(userName)}</td><td>${Math.ceil(item.extracted_words_length / (item.timeTaken / 60))}</td><td>${item.timeTaken}</td><td>${item.difficultyLevel}</td>`;
let speed = Math.ceil(item.extracted_words_length / (item.timeTaken / 60));
let time = item.timeTaken;
avgSpeed += speed;
avgTime += time;
row.innerHTML = `<td>${htmlEncode(userName)}</td><td>${speed}</td><td>${time}</td><td>${item.difficultyLevel}</td>`;
historyBody.appendChild(row);
});
avgSpeed = (avgSpeed / historyArray.length).toFixed(1);
avgTime = (avgTime / historyArray.length).toFixed(3);;
alexsam29 marked this conversation as resolved.
Show resolved Hide resolved
avgRow.innerHTML = `<td>${avgSpeed}</td><td>${avgTime}</td>`;
avgHistoryBody.appendChild(avgRow);
}
else {
document.getElementsByClassName("history")[0].style.display = "none";
Expand Down
10 changes: 10 additions & 0 deletions practice.css
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ h2.subtitle {
margin: 0 auto;
}

.history-avg{
/* width: max-content; */
margin: 5px auto;
border-collapse: collapse;
overflow-x: auto;
}
.history-avg table{
margin: 0 auto;
}

.button-group{
display: inline-block;
margin: 25px 20px 25px;
Expand Down
12 changes: 12 additions & 0 deletions practice.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ <h2>History</h2>
</tbody>
</table>
</div>
<div class="history-avg">
<table>
<thead>
<tr>
<th>Average Speed (wpm)</th>
<th>Average Time Taken (sec)</th>
</tr>
</thead>
<tbody id="avgTableBody">
</tbody>
</table>
</div>
<button id="historyResetBtn">Reset Data</button>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ <h2 class="history-heading">History</h2>
</tbody>
</table>
</div>
<div class="history-avg">
<table>
<thead>
<tr>
<th>Average Speed (wpm)</th>
<th>Average Time Taken (sec)</th>
</tr>
</thead>
<tbody id="avgTableBody">
</tbody>
</table>
</div>
<button id="historyResetBtn">Reset Data</button>
</div>
</section>
Expand Down
16 changes: 14 additions & 2 deletions profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const saveHistory = () => {

// History Viewer
const historyBody = document.getElementById("historyTableBody");
const avgHistoryBody = document.getElementById("avgTableBody");

const showHistory = () => {
history = localStorage.getItem("typerHistory");
Expand All @@ -58,12 +59,23 @@ const showHistory = () => {
document.getElementsByClassName("history")[0].style.display = "block";
historyArray = JSON.parse(history);
historyBody.innerHTML = "";
avgHistoryBody.innerHTML="";
const avgRow = document.createElement("tr");
let avgSpeed = 0;
let avgTime = 0;
historyArray.forEach((item) => {
const row = document.createElement("tr");
row.innerHTML = `<td>${htmlEncode(userName)}</td><td>${Math.ceil(item.extracted_words_length / (item.timeTaken / 60))}</td><td>${item.timeTaken}</td><td>${item.difficultyLevel}</td>`;
let speed = Math.ceil(item.extracted_words_length / (item.timeTaken / 60));
let time = item.timeTaken;
avgSpeed += speed;
avgTime += time;
row.innerHTML = `<td>${htmlEncode(userName)}</td><td>${speed}</td><td>${time}</td><td>${item.difficultyLevel}</td>`;
historyBody.appendChild(row);
});
console.log("I am from show History");
avgSpeed = (avgSpeed / historyArray.length).toFixed(1);
avgTime = (avgTime / historyArray.length).toFixed(3);;
alexsam29 marked this conversation as resolved.
Show resolved Hide resolved
avgRow.innerHTML = `<td>${avgSpeed}</td><td>${avgTime}</td>`;
avgHistoryBody.appendChild(avgRow);
}
else {
document.getElementsByClassName("history")[0].style.display = "none";
Expand Down