added account page graphs

This commit is contained in:
Jack 2020-05-10 02:04:05 +01:00
parent 99ce95dfac
commit 09c75fbec4
7 changed files with 528 additions and 71 deletions

View file

@ -84,7 +84,7 @@
</div>
</div>
<div class="config">
<div class="group punctuationMode">
<!-- <div class="title">time</div> -->
@ -130,7 +130,7 @@
</div>
<div id="middle">
<div class="page pageTest">
<div id="caret" class="hidden"></div>
<div id="words" class=""></div>
@ -183,15 +183,54 @@
</div>
<div class="page pageAccount hidden">
account page
<div class="signOut">sign out</div>
<div class="group">
<div class="title"></div>
<div class="chart">
<canvas id="resultHistoryChart"></canvas>
</div>
</div>
<div class="triplegroup">
<div class="group highestWpm">
<div class="title">highest wpm</div>
<div class="val">1</div>
<div class="mode"></div>
</div>
<div class="group testsTaken">
<div class="title">tests taken</div>
<div class="val">1</div>
</div>
<div class="group favouriteTest">
<div class="title">favourite test</div>
<div class="val">words 10</div>
</div>
</div>
<div class="group history">
<!-- <div class="title">result history</div> -->
<table width="100%">
<thead>
<tr>
<td>wpm</td>
<td>accuracy</td>
<td>correct chars</td>
<td>incorrect chars</td>
<td>mode</td>
<td>date</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<div id="bottom">
<key>tab</key> and <key>enter</key> / <key>space</key> - restart test<br>
<key>esc</key> - command line
<br><br>
<div class="keyTips">
<key>tab</key> and <key>enter</key> / <key>space</key> - restart test<br>
<key>esc</key> - command line
</div>
Created by <a href="https://www.reddit.com/message/compose?to=Miodec">Miodec</a>
</div>
@ -211,7 +250,9 @@
<script src="/__/firebase/init.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline@0.1.3/src/chartjs-plugin-trendline.min.js"></script>
<script src="js/db.js"></script>
<script src="js/commandline.js"></script>
<script src="js/words.js"></script>

View file

@ -17,13 +17,17 @@
} */
body {
margin: 0;
padding: 2rem;
padding: 2rem 2rem 0 2rem;
height: 100vh;
background: var(--bg-color);
font-family: "Roboto Mono";
color: var(--main-color);
}
html {
overflow-y: scroll;
}
a {
color: var(--sub-color);
-webkit-transition: 0.25s;
@ -484,6 +488,11 @@ key {
color: var(--sub-color);
-webkit-transition: 0.5s;
transition: 0.5s;
margin-bottom: 2rem;
}
#bottom .keyTips {
margin-bottom: 1rem;
}
#top.focus {
@ -715,6 +724,66 @@ key {
opacity: 0.5;
}
.pageAccount {
display: -ms-grid;
display: grid;
gap: 1rem;
}
.pageAccount .signOut {
-ms-grid-column-align: end;
justify-self: end;
background: var(--sub-color);
color: var(--bg-color);
width: -webkit-fit-content;
width: -moz-fit-content;
width: fit-content;
padding: .5rem;
border-radius: var(--roundness);
cursor: pointer;
-webkit-transition: .25s;
transition: .25s;
float: right;
}
.pageAccount .signOut:hover {
color: var(--main-color);
}
.pageAccount .triplegroup {
display: -ms-grid;
display: grid;
grid-auto-flow: column;
gap: 1rem;
}
.pageAccount .group .title {
color: var(--sub-color);
}
.pageAccount .group .val {
font-size: 3rem;
line-height: 3rem;
}
.pageAccount table {
border-spacing: 0;
border-collapse: collapse;
}
.pageAccount table td {
padding: .5rem .25rem;
}
.pageAccount table thead {
color: var(--sub-color);
font-size: .75rem;
}
.pageAccount table tbody tr:nth-child(odd) td {
background: rgba(0, 0, 0, 0.5);
}
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;

File diff suppressed because one or more lines are too long

View file

@ -18,13 +18,15 @@
body {
margin: 0;
padding: 2rem;
padding: 2rem 2rem 0 2rem;
height: 100vh;
background: var(--bg-color);
font-family: "Roboto Mono";
color: var(--main-color);
}
html { overflow-y: scroll; }
a {
color: var(--sub-color);
transition: 0.25s;
@ -414,6 +416,10 @@ key {
font-size: 0.75rem;
color: var(--sub-color);
transition: 0.5s;
margin-bottom: 2rem;
.keyTips{
margin-bottom: 1rem;
}
}
#top.focus {
@ -598,6 +604,55 @@ key {
opacity: 0.5;
}
.pageAccount{
display: grid;
gap: 1rem;
.signOut{
justify-self: end;
background: var(--sub-color);
color: var(--bg-color);
width: fit-content;
padding: .5rem;
border-radius: var(--roundness);
cursor: pointer;
transition: .25s;
float: right;
&:hover{
color: var(--main-color);
}
}
.triplegroup{
display: grid;
grid-auto-flow: column;
gap: 1rem;
}
.group{
.title{
color: var(--sub-color);
}
.val{
font-size: 3rem;
line-height: 3rem;
}
}
table{
border-spacing:0;
border-collapse: collapse;
td{
padding: .5rem .25rem;
}
thead{
color: var(--sub-color);
font-size: .75rem;
}
tbody tr:nth-child(odd) td{
background: rgba(0, 0, 0, 0.5);
}
}
}
* {
box-sizing: border-box;
}
@ -605,3 +660,4 @@ key {
.hidden {
display: none !important;
}

View file

@ -1,50 +1,50 @@
$(".pageAccount .register input").keyup(e => {
if (e.key == "Enter") {
if (e.key == "Enter") {
let name = $(".pageAccount .register input")[0].value;
let email = $(".pageAccount .register input")[1].value;
let password = $(".pageAccount .register input")[2].value;
let name = $(".pageAccount .register input")[0].value;
let email = $(".pageAccount .register input")[1].value;
let password = $(".pageAccount .register input")[2].value;
firebase.auth().createUserWithEmailAndPassword(email, password).then(user => {
// Account has been created here.
let usr = user.user;
usr.updateProfile({
displayName: name
}).then(function() {
// Update successful.
alert('user created');
}).catch(function(error) {
// An error happened.
usr.delete().then(function() {
// User deleted.
alert('cant have this display name');
}).catch(function(error) {
// An error happened.
});
});
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
alert(errorMessage);
});
firebase.auth().createUserWithEmailAndPassword(email, password).then(user => {
// Account has been created here.
let usr = user.user;
usr.updateProfile({
displayName: name
}).then(function() {
// Update successful.
alert('user created');
}).catch(function(error) {
// An error happened.
usr.delete().then(function() {
// User deleted.
alert('cant have this display name');
}).catch(function(error) {
// An error happened.
}
});
});
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
alert(errorMessage);
});
}
})
$(".pageLogin .login input").keyup(e => {
if (e.key == "Enter") {
let email = $(".pageLogin .login input")[0].value;
let password = $(".pageLogin .login input")[1].value;
let email = $(".pageLogin .login input")[0].value;
let password = $(".pageLogin .login input")[1].value;
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
alert(error.message);
});
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
alert(error.message);
});
}
})
@ -59,21 +59,290 @@ function signOut() {
}
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var displayName = user.displayName;
var email = user.email;
var emailVerified = user.emailVerified;
var photoURL = user.photoURL;
var isAnonymous = user.isAnonymous;
var uid = user.uid;
var providerData = user.providerData;
console.log('user signed in');
// ...
} else {
// User is signed out.
// ...
if (user) {
// User is signed in.
var displayName = user.displayName;
var email = user.email;
var emailVerified = user.emailVerified;
var photoURL = user.photoURL;
var isAnonymous = user.isAnonymous;
var uid = user.uid;
var providerData = user.providerData;
console.log('user signed in');
// ...
} else {
// User is signed out.
// ...
}
});
var resultHistoryChart = new Chart($(".pageAccount #resultHistoryChart"), {
type: 'line',
data: {
datasets: [
{
label: "words 10",
fill: false,
data: [],
borderColor: '#f44336',
borderWidth: 2,
// trendlineLinear: {
// style: "rgba(244,67,54,.25)",
// lineStyle: "solid",
// width: 1
// }
},
{
label: "words 25",
fill: false,
data: [],
borderColor: '#FF5722',
borderWidth: 2,
// trendlineLinear: {
// style: "rgba(255,87,34,.25)",
// lineStyle: "solid",
// width: 1
// }
},
{
label: "words 50",
fill: false,
data: [],
borderColor: '#FF9800',
borderWidth: 2,
// trendlineLinear: {
// style: "rgba(255,152,0,.25)",
// lineStyle: "solid",
// width: 1
// }
},
{
label: "words 100",
fill: false,
data: [],
borderColor: '#FFC107',
borderWidth: 2,
// trendlineLinear: {
// style: "rgba(255,193,7,.25)",
// lineStyle: "solid",
// width: 1
// }
},
{
label: "words 200",
fill: false,
data: [],
borderColor: '#FFEB3B',
borderWidth: 2,
// trendlineLinear: {
// style: "rgba(255,235,59,.25)",
// lineStyle: "solid",
// width: 1
// }
},
{
label: "time 15",
fill: false,
data: [],
borderColor: '#3F51B5',
borderWidth: 2,
// trendlineLinear: {
// style: "rgba(63,81,181,.25)",
// lineStyle: "solid",
// width: 1
// }
},
{
label: "time 30",
fill: false,
data: [],
borderColor: '#2196F3',
borderWidth: 2,
// trendlineLinear: {
// style: "rgba(33,150,243,.25)",
// lineStyle: "solid",
// width: 1
// }
},
{
label: "time 60",
fill: false,
data: [],
borderColor: '#03A9F4',
borderWidth: 2,
// trendlineLinear: {
// style: "rgba(3,169,244,.25)",
// lineStyle: "solid",
// width: 1
// }
},
{
label: "time 120",
fill: false,
data: [],
borderColor: '#00BCD4',
borderWidth: 2,
// trendlineLinear: {
// style: "rgba(0,188,212,.25)",
// lineStyle: "solid",
// width: 1
// }
},
{
label: "custom",
fill: false,
data: [],
borderColor: '#4CAF50',
borderWidth: 2,
// trendlineLinear: {
// style: "rgba(76,175,80,.25)",
// lineStyle: "solid",
// width: 1
// }
}
],
},
options: {
legend: {
display: true,
labels: {
defaultFontFamily: "Roboto Mono"
}
},
responsive: true,
// maintainAspectRatio: false,
// tooltips: {
// mode: 'index',
// intersect: false,
// },
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
type: 'time',
bounds: 'ticks',
distribution: 'series',
display: false,
scaleLabel: {
display: true,
labelString: 'Date'
},
}],
yAxes: [{
display: true,
scaleLabel: {
display: false,
labelString: 'Words per Minute'
}
}]
}
});
}
});
function refreshAccountPage() {
db_getUserResults().then(data => {
let testModes = {
words10: [],
words25: [],
words50: [],
words100: [],
words200: [],
time15: [],
time30: [],
time60: [],
time120: [],
custom: []
}
let topWpm = 0;
let topMode = '';
let testCount = data.length;
data.forEach(result => {
$(".pageAccount .history table tbody").prepend(`
<tr>
<td>${result.wpm}</td>
<td>${result.acc}%</td>
<td>${result.correctChars}</td>
<td>${result.incorrectChars}</td>
<td>${result.mode} ${result.mode2}</td>
<td>${moment(result.timestamp).format('DD MMM YYYY HH:mm')}</td>
</tr>`)
if (result.mode == "words" && result.mode2 == 10) {
testModes.words10.push({ x: result.timestamp, y: result.wpm });
}
if (result.mode == "words" && result.mode2 == 25) {
testModes.words25.push({ x: result.timestamp, y: result.wpm });
}
if (result.mode == "words" && result.mode2 == 50) {
testModes.words50.push({ x: result.timestamp, y: result.wpm });
}
if (result.mode == "words" && result.mode2 == 100) {
testModes.words100.push({ x: result.timestamp, y: result.wpm });
}
if (result.mode == "words" && result.mode2 == 200) {
testModes.words200.push({ x: result.timestamp, y: result.wpm });
}
if (result.mode == "time" && result.mode2 == 15) {
testModes.time15.push({ x: result.timestamp, y: result.wpm });
}
if (result.mode == "time" && result.mode2 == 30) {
testModes.time30.push({ x: result.timestamp, y: result.wpm });
}
if (result.mode == "time" && result.mode2 == 60) {
testModes.time60.push({ x: result.timestamp, y: result.wpm });
}
if (result.mode == "time" && result.mode2 == 120) {
testModes.time120.push({ x: result.timestamp, y: result.wpm });
}
if (result.mode == "custom") {
testModes.custom.push({ x: result.timestamp, y: result.wpm });
}
if (result.wpm > topWpm) {
topWpm = result.wpm;
topMode = result.mode + " " + result.mode2;
}
})
resultHistoryChart.data.datasets[0].data = testModes.words10;
resultHistoryChart.data.datasets[1].data = testModes.words25;
resultHistoryChart.data.datasets[2].data = testModes.words50;
resultHistoryChart.data.datasets[3].data = testModes.words100;
resultHistoryChart.data.datasets[4].data = testModes.words200;
resultHistoryChart.data.datasets[5].data = testModes.time15;
resultHistoryChart.data.datasets[6].data = testModes.time30;
resultHistoryChart.data.datasets[7].data = testModes.time60;
resultHistoryChart.data.datasets[8].data = testModes.time120;
resultHistoryChart.data.datasets[9].data = testModes.custom;
resultHistoryChart.update({ duration: 0 });
$(".pageAccount .highestWpm .val").text(topWpm);
$(".pageAccount .highestWpm .mode").text(topMode);
$(".pageAccount .testsTaken .val").text(testCount);
let favMode = testModes.words10;
let favModeName = 'words10';
$.each(testModes, (key, mode) => {
if (mode.length > favMode.length) {
favMode = mode;
favModeName = key;
}
})
$(".pageAccount .favouriteTest .val").text(`${favModeName} (${Math.floor((favMode.length/testCount) * 100)}%)`);
$(".page.pageAccount").removeClass('hidden');
})
}

View file

@ -25,7 +25,7 @@ async function db_getUserResults() {
let user = firebase.auth().currentUser;
if (user == null) return false;
let ret = [];
await db.collection('results').where('uid', '==', user.uid).get().then(data => {
await db.collection('results').orderBy('timestamp').where('uid', '==', user.uid).get().then(data => {
data.docs.forEach(doc => {
ret.push(doc.data());

View file

@ -329,7 +329,8 @@ function loadConfigFromCookie() {
if (newConfig) {
newConfig = JSON.parse(newConfig);
config = newConfig;
setPunctuation(config.punctuation)
setQuickTabMode(config.quickTab);
setPunctuation(config.punctuation);
changeTimeConfig(config.time);
changeWordCount(config.words);
changeMode(config.mode);
@ -464,7 +465,7 @@ function showResult() {
}
var ctx = $("#wpmChart");
var wpmHistoryChart = new Chart(ctx, {
var wpmOverTimeChart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
@ -568,9 +569,9 @@ function showResult2() {
labels.push(i.toString());
}
wpmHistoryChart.data.labels = labels;
wpmHistoryChart.data.datasets[0].data = wpmHistory;
wpmHistoryChart.update({ duration: 0 });
wpmOverTimeChart.data.labels = labels;
wpmOverTimeChart.data.datasets[0].data = wpmHistory;
wpmOverTimeChart.update({ duration: 0 });
$("#words").animate({
opacity: 0
}, 125, () => {
@ -792,13 +793,34 @@ function toggleSmoothCaret() {
saveConfigToCookie();
}
function setQuickTabMode(mode) {
config.quickTab = mode;
if (!config.quickTab) {
$(".pageTest").append('<div id="restartTestButton" class="" tabindex="0"><i class="fas fa-redo-alt"></i></div>');
$("#restartTestButton").css("opacity", 1);
$("#bottom .keyTips").html(`<key>tab</key> and <key>enter</key> / <key>space</key> - restart test<br>
<key>esc</key> - command line`);
} else {
$("#restartTestButton").remove();
$("#bottom .keyTips").html(`<key>tab</key> - restart test<br>
<key>esc</key> - command line`);
}
saveConfigToCookie();
}
function toggleQuickTabMode() {
config.quickTab = !config.quickTab;
if (!config.quickTab) {
$(".pageTest").append('<div id="restartTestButton" class="" tabindex="0"><i class="fas fa-redo-alt"></i></div>');
$("#restartTestButton").css("opacity",1);
$("#restartTestButton").css("opacity", 1);
$("#bottom .keyTips").html(`<key>tab</key> and <key>enter</key> / <key>space</key> - restart test<br>
<key>esc</key> - command line`);
} else {
$("#restartTestButton").remove();
$("#bottom .keyTips").html(`<key>tab</key> - restart test<br>
<key>esc</key> - command line`);
}
saveConfigToCookie();
}
@ -866,7 +888,7 @@ function changePage(page) {
if (!firebase.auth().currentUser) {
changePage("login");
} else {
$(".page.pageAccount").removeClass('hidden');
refreshAccountPage();
}
} else if (page == "login") {
$(".page.pageLogin").removeClass('hidden');