Calculate searching saved time

This commit is contained in:
shwin0901 2020-05-17 18:39:34 +08:00
parent c18ff5a691
commit 57137366ed
2 changed files with 16 additions and 3 deletions

View file

@ -28,8 +28,8 @@
<div style="flex-direction: column;" class="flex-layout">
<div class="chart-heatmap"></div>
</div>
<div style="text-align: center;font-size: 20px;">
<b>1000</b> searchings in total since the first day, approximately saved <b></b>2 hours.
<div class="searching-time" style="text-align: center;font-size: 20px;">
<b>0</b> searchings in total since the first day, approximately saved <b>0 seconds.</b>
<a href="#appendix1"><small>[1]</small></a>
</div>
<div id="chart">

View file

@ -102,6 +102,20 @@ histogram({
...histogramConfig,
});
let searchingTimes = document.querySelector(".searching-time");
let frequency = searchingTimes.querySelectorAll("b");
frequency[0].textContent = `${history.length}`;
frequency[1].textContent = calculateSavedTime(history.length);
function calculateSavedTime(times) {
if(times * 5 >3600){
return `${Math.round(times * 5 /3600)} hours.`;
} else if(times * 5 > 60) {
return `${Math.round(times * 5 /60)} minutes.`;
} else {
return `${Math.round(times * 5)} seconds.`;
}
}
let searchingStatsGraph = document.querySelector(".searching-stats-graph");
let searchingStatsText = document.querySelector(".searching-stats-text");
let ol = searchingStatsText.querySelector("ol");
@ -117,7 +131,6 @@ function byField(key) {
let sum = stats.sort(byField("value")).reduce((item, { value }) => {
return item + value
}, 0);
stats.forEach(({ name, color, value }) => {
let li = document.createElement("li");
li.innerHTML = `<span class="color-block" style="background-color:${color}"></span>