-
Notifications
You must be signed in to change notification settings - Fork 1
/
avgLogRuntime.js
37 lines (29 loc) · 855 Bytes
/
avgLogRuntime.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
const fs = require('fs');
fs.readFile('./log.txt', (err, data) => {
if (err) throw err;
const logHash = {};
logs = data.toString().split('\n');
logs.pop();
logs.map((log) => {
const logData = log.split(' ');
const timestamp = logData[0];
const operation = logData[1];
const status = logData[2];
if (!logHash.hasOwnProperty(operation)) {
logHash[operation] = {start: null, end: null};
}
if (status === 'start') {
logHash[operation].start = timestamp;
} else {
logHash[operation].end = timestamp;
}
return logHash[operation]
});
var arr = Object.keys(logHash).map(function (key) { return logHash[key]; });
console.log('arr', arr);
const avgTime = arr.reduce((prev, log) => {
console.log('log.end.getTime()', log.end.getSeconds());
return (log.end - log.start)
}, 0);
console.log('avgTime', avgTime);
});