-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (39 loc) · 1.57 KB
/
index.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
// We can read file using inbuilt node file system module.we use fs module
const fs = require('fs')
//but this file system module has no idea of csv file.
//when we use text file as input they red as string file.
//here we using csv-parse module.
const { parse } = require('csv-parse')
const resault = [];
//Here making function that checking that planet is habitable or not ?
function isHabitablePlanets(planet) {
t1 = Date.now()
return planet['koi_disposition'] === 'CONFIRMED' && planet['koi_insol'] > 0.36 && planet['koi_insol'] < 1.11 && planet['koi_prad'] < 1.6;
}
//This method return bit of stream as buffer object.
const file = fs.createReadStream('Data.csv')
//here pipe function is used to connect two stream like readbale and writeable text.
//Link : https://www.educative.io/answers/what-is-stream-module-pipe-in-nodejs
.pipe(parse({
comment: '#',
columns: true,
}))
.on('data', (data) => {
if (isHabitablePlanets(data)) {
resault.push(data)
}
})
.on('error', (err) => {
console.log(`There is error : ${err.message}`)
})
.on('end', () => {
console.log(`Total habitable planet is ${resault.length} and resault are : `)
// for (i = 0; i < resault.length; i++) {
// console.log(resault[i].kepoi_name);
// }
//map through array
resault.map((planet)=>{console.log(planet.kepoi_name)})
t2 = Date.now();
console.log(`Your Date Done processing data in ${Math.floor((t2-t1))}ms`)
console.log("Done processing data.")
});