-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.js
65 lines (51 loc) · 1.22 KB
/
stats.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
54
55
56
57
58
59
60
61
62
63
64
65
var csv = require("fast-csv");
var URL = require("url");
if (process.argv.length < 3) {
console.warn("Usage: node stats.js [url|column] ./path/to/file.csv");
return;
}
csv
.fromPath(process.argv[3], { delimiter : "\t"})
.on("data", function(data){
if (process.argv[2] == "url") {
try {
var request = {
url : URL.parse(data[22], true),
domain : data[21]
};
analyseQuery(request);
} catch(e){
console.error(e.message);
console.log(data[21] + data[22]);
}
} else {
var column = process.argv[2];
if (data[column]!= ""){
console.log(data[column]);
}
}
})
.on("end", function(){
console.info("done");
});
var currDomain = null;
var summary = [];
var analyseQuery = function(request){
if (request.domain != currDomain) {
if (currDomain){
renderAnalysis (summary, currDomain);
}
currDomain = request.domain;
summary = [];
}
for (param in request.url.query) {
if (summary.indexOf(param) < 0){
summary.push(param);
}
}
};
var renderAnalysis = function(summary, domain){
for (var i=0; i< summary.length; i++){
console.log(summary[i] + "\t" + domain);
}
}