-
Notifications
You must be signed in to change notification settings - Fork 0
/
tomato.js
29 lines (26 loc) · 893 Bytes
/
tomato.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
var mongoose = require('mongoose');
var timeModel = require('./schemas/time.js').getModel();
var url = require('url');
const dbUri = 'mongodb://heroku_qjgzdh28:[email protected]:61285/heroku_qjgzdh28';
mongoose.connect(dbUri, createKeywordPareto);
function createKeywordPareto() {
timeModel.find({}).select('secs website').exec((err, data) => {
var timeWebsites = {};
data.forEach(item => {
const seconds = item.secs;
const domain = url.parse(item.website).host;
console.log(domain, seconds);
if (!timeWebsites[domain]) {
timeWebsites[domain] = seconds;
}
else {
timeWebsites[domain] += seconds;
}
});
console.log(timeWebsites);
var sortedKeys = Object.keys(timeWebsites).sort((a,b) => {
return timeWebsites[a] = timeWebsites[b]?-1:1
})
console.log(sortedKeys);
})
}