-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodefileread.js
55 lines (50 loc) · 1.62 KB
/
nodefileread.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
var fs = require('fs');
var jf = require('jsonfile')
var val = require('validator')
var jsonObject=[];
var lineNumber=0;
var columns=[];
// object for creating HighChart bar graph
var chartObject = {
chart: {
type: "column"
},
title: {
text: "CPU Utilization"
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: "Percentage"
}
},
series: [{
name: "CPU Percentage",
data: []
}] };
var Lazy = require('lazy'),
lazy = new Lazy(fs.createReadStream('/Users/pdonni/Documents/Github/learnNode/Book2.csv'))
.lines
.map(String)
.map(function(lineData){
var fields = lineData.trim().split(',', 11);
if(lineNumber == 0)
{
columns.push(fields[3]);
columns.push(fields[10]);
} else {
// var jsoninput = {
// MEM : fields[3],
// CPU : fields[10]
// };
// jsonObject.push(jsoninput);
//
chartObject.xAxis.categories.push(fields[10]);
chartObject.series[0].data.push(val.toFloat(fields[3]));
var file = '/Users/pdonni/Documents/Github/learnNode/data.json';
jf.writeFile(file, chartObject);
}
lineNumber = lineNumber + 1;
});