💝🖐 Checkpoint
./public/index.js:1954897/86229
This commit is contained in:
1 parent
49f3f77e36
commit
94fc5d39b6
2 files changed
+51
-4
No files matched your search
+16
-4
@@ -133,18 +133,30 @@ async function displayCard(id) {
|
||||
|
||||
|
||||
function updateChart(data) {
|
||||
// { loc, time: new Date(+time), count: parseInt(count) }
|
||||
const parsed = data.map(d => {
|
||||
const TEN_MINUTES = 2 * 60 * 1000
|
||||
// this is 0-5
|
||||
let ago = Math.floor((Date.now() - d.time) / TEN_MINUTES)
|
||||
// if (20 < ago) ago = 20
|
||||
return {time: d.time, ago, count: d.count}
|
||||
}).reduce((acc, v) => {
|
||||
if (!acc[v.ago]) {
|
||||
acc[v.ago] = []
|
||||
}
|
||||
acc[v.ago].push(v.count)
|
||||
return acc
|
||||
}, []).map(v => v.reduce((acc, v) => acc + v, 0) / v.length)
|
||||
|
||||
const parsed = data.map(d => ({ x: d.time, y: d.count }))
|
||||
console.log(parsed)
|
||||
|
||||
const ctx = document.getElementById('myChart').getContext('2d')
|
||||
new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
// labels: ['Now', '1h ago', '2h ago', '3h ago', '4h ago', '5h ago'].reverse(),
|
||||
labels: ['Now', '10m ago', '20m ago', '30m ago', '40m ago', '50m ago'].reverse(),
|
||||
datasets: [{
|
||||
label: 'Density',
|
||||
data: parsed,
|
||||
data: parsed.reverse(),
|
||||
borderColor: '#55aadd',
|
||||
backgroundColor: '#55aadd',
|
||||
// borderWidth: 2
|
||||
|
||||
Reference in new issue
Block a user