-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.js
53 lines (47 loc) · 1.2 KB
/
dashboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const request = require('superagent');
const blessed = require('blessed');
const contrib = require('blessed-contrib');
const Promise = require('bluebird');
Promise.promisifyAll(request.Request.prototype);
const screen = blessed.screen();
let data = {};
function randomColor() {
return [Math.random() * 255,Math.random()*255, Math.random()*255]
}
const line = contrib.line({
showLegend: true,
style: {
line: 'yellow',
text: 'green',
baseline: 'blue',
label: 'Downloads over time',
},
});
screen.append(line);
screen.render();
const start = new Date().getTime();
function updateDisplay(topPackages) {
const now = new Date().getTime() - start;
topPackages.forEach((p, i) => {
if(!data[p.name]) data[p.name] = {
x: [],
y: [],
title: p.name,
style: {
line: i,
//text: randomColor()
}
};
data[p.name].x.push(now);
data[p.name].y.push(p.downloads);
});
line.setData(Object.keys(data).map(k => data[k]));
screen.render();
}
setInterval(() => {
request.get('http://localhost:9999/').end((err, res) => {
if (err) return console.error(err);
const topPackages = res.body.slice(0, 10);
updateDisplay(topPackages);
});
}, 1000);