-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsizing.js
43 lines (41 loc) · 1.02 KB
/
sizing.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
const nlp = require("compromise")
const keys = require('./private/keys')
const fs = require("fs")
const docs = require("./private/documents.json")
const fetchMode = false
const MongoClient = require('mongodb').MongoClient;
var ProgressBar = require('progress');
var async = require("async");
var franc = require('franc')
let masterTopics = {}
let analytics = {
largest: 0,
average: 0,
computed: 0
}
let done = 0
var bar = new ProgressBar(':percent :eta :bar :current/:total :elapsed ', {total: docs.length});
function bytes(s) {
return ~-encodeURI(s).split(/%..|./).length
}
function jsonSize(s) {
return bytes(JSON.stringify(s))
}
async.each(docs, (doc) => {
// console.log(doc.title)
let title = doc.title
try {
let data = JSON.parse(doc.data)
let size = jsonSize(data)
if (size > analytics.largest) {
analytics.largest = size
}
analytics.average += size
analytics.computed++
} catch {
}
done++
bar.tick()
})
analytics.average = analytics.average/analytics.computed
console.log(analytics)