-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting-6.12.js
54 lines (46 loc) · 1.36 KB
/
listing-6.12.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
//
// Example Data-Forge data pipeline.
//
"use strict";
const dataForge = require('data-forge');
const moment = require('moment');
const importDateFormat = "YYYY-MM-DD HH:mm:ss";
const inputFileName = "./data/surveys.csv";
const outputFileName = "./output/data-pipeline-output.csv";
dataForge.readFile(inputFileName)
.parseCSV()
.then(dataFrame => {
return dataFrame.dropSeries([
"exp_id",
"dive_observations",
"obs_topography"
])
.parseDates([
"start_datetime",
"end_datetime"
],
importDateFormat
)
.where(row =>
moment(row.start_datetime).year() === 2014
)
.parseFloats("dive_temperature")
.where(row => row.dive_temperature !== 0)
.groupBy(row => row.country)
.select(group => ({
country: group.first().country,
dive_temperature: group
.deflate(row => row.dive_temperature)
.average()
}))
.inflate()
.asCSV()
.writeFile(outputFileName);
})
.then(() => {
console.log("Done!");
})
.catch(err => {
console.error("An error occured");
console.error(err);
});