Skip to content

Commit afd4f12

Browse files
committed
Small tweaks and improvements.
1 parent 2820c7f commit afd4f12

12 files changed

+466
-52
lines changed

listing-2.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
'use strict';
1+
"use strict";
22

33
const openCsvInputStream = require('./toolkit/open-csv-input-stream');
44
const openMongodbOutputStream = require('./toolkit/open-mongodb-output-stream');
55
const MongoClient = require('mongodb').MongoClient;
66

7-
const hostName = 'mongodb://127.0.0.1:6000';
8-
const databaseName = 'weather_stations';
9-
const collectionName = 'daily_readings';
7+
const hostName = "mongodb://127.0.0.1:6000";
8+
const databaseName = "weather_stations";
9+
const collectionName = "daily_readings";
1010

1111
const inputFilePath = "./data/weather-stations.csv";
1212

@@ -31,10 +31,10 @@ function streamData (inputFilePath, dbCollection) {
3131
return new Promise((resolve, reject) => {
3232
openCsvInputStream(inputFilePath)
3333
.pipe(openMongodbOutputStream(dbCollection))
34-
.on('finish', () => {
34+
.on("finish", () => {
3535
resolve();
3636
})
37-
.on('error', err => {
37+
.on("error", err => {
3838
reject(err);
3939
});
4040
});
@@ -46,7 +46,7 @@ openDatabase()
4646
.then(() => client.close());
4747
})
4848
.then(() => {
49-
console.log('Done');
49+
console.log("Done");
5050
})
5151
.catch(err => {
5252
console.error("An error occurred.");

listing-3.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
'use strict';
1+
"use strict";
22

33
const MongoClient = require('mongodb').MongoClient;
44

5-
const hostName = 'mongodb://127.0.0.1:7000';
6-
const databaseName = 'weather_stations';
7-
const collectionName = 'daily_readings';
5+
const hostName = "mongodb://127.0.0.1:7000";
6+
const databaseName = "weather_stations";
7+
const collectionName = "daily_readings";
88

99
//
1010
// Open the connection to the database.

listing-4.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
'use strict';
1+
"use strict";
22

33
const MongoClient = require('mongodb').MongoClient;
44

5-
const hostName = 'mongodb://127.0.0.1:7000';
6-
const databaseName = 'weather_stations';
7-
const collectionName = 'daily_readings';
5+
const hostName = "mongodb://127.0.0.1:7000";
6+
const databaseName = "weather_stations";
7+
const collectionName = "daily_readings";
88

99
//
1010
// Open the connection to the database.

listing-5.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
'use strict';
1+
"use strict";
22

33
const MongoClient = require('mongodb').MongoClient;
44

5-
const hostName = 'mongodb://127.0.0.1:7000';
6-
const databaseName = 'weather_stations';
7-
const collectionName = 'daily_readings';
5+
const hostName = "mongodb://127.0.0.1:7000";
6+
const databaseName = "weather_stations";
7+
const collectionName = "daily_readings";
88

99
//
1010
// Open the connection to the database.

listing-6.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
'use strict';
1+
"use strict";
22

33
const MongoClient = require('mongodb').MongoClient;
44

5-
const hostName = 'mongodb://127.0.0.1:7000';
6-
const databaseName = 'weather_stations';
7-
const collectionName = 'daily_readings';
5+
const hostName = "mongodb://127.0.0.1:7000";
6+
const databaseName = "weather_stations";
7+
const collectionName = "daily_readings";
88

99
//
1010
// Open the connection to the database.
@@ -31,7 +31,6 @@ openDatabase()
3131
_id: 0,
3232
Year: 1,
3333
Month: 1,
34-
Day: 1,
3534
Precipitation: 1
3635
}
3736
};

listing-7.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
'use strict';
1+
"use strict";
22

33
const MongoClient = require('mongodb').MongoClient;
44

5-
const hostName = 'mongodb://127.0.0.1:7000';
6-
const databaseName = 'weather_stations';
7-
const collectionName = 'daily_readings';
5+
const hostName = "mongodb://127.0.0.1:7000";
6+
const databaseName = "weather_stations";
7+
const collectionName = "daily_readings";
88

99
//
1010
// Open the connection to the database.

listing-8.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
'use strict';
1+
"use strict";
22

33
const argv = require('yargs').argv;
44
const MongoClient = require('mongodb').MongoClient;
55

6-
const hostName = 'mongodb://127.0.0.1:7000';
7-
const databaseName = 'weather_stations';
8-
const collectionName = 'daily_readings';
6+
const hostName = "mongodb://127.0.0.1:7000";
7+
const databaseName = "weather_stations";
8+
const collectionName = "daily_readings";
99

1010
if (argv.skip === undefined || argv.limit === undefined) {
1111
throw new Error("Slave process requires command line arguments 'skip' and 'limit' to define the data window.");

listing-9.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
'use strict';
1+
"use strict";
22

33
const argv = require('yargs').argv;
44
const MongoClient = require('mongodb').MongoClient;
55
const spawn = require('child_process').spawn;
66
const parallel = require('async-await-parallel');
77

8-
const hostName = 'mongodb://127.0.0.1:7000';
9-
const databaseName = 'weather_stations';
10-
const collectionName = 'daily_readings';
8+
const hostName = "mongodb://127.0.0.1:7000";
9+
const databaseName = "weather_stations";
10+
const collectionName = "daily_readings";
1111

1212
//
1313
// Open the connection to the database.
@@ -31,18 +31,18 @@ function openDatabase () {
3131
//
3232
function runSlave (skip, limit, slaveIndex) {
3333
return new Promise((resolve, reject) => {
34-
const args = [ 'listing-8.js', '--skip', skip, '--limit', limit ];
34+
const args = [ "listing-8.js", "--skip", skip, "--limit", limit ];
3535

36-
const childProcess = spawn('node', args);
37-
childProcess.stdout.on('data', data => {
36+
const childProcess = spawn("node", args);
37+
childProcess.stdout.on("data", data => {
3838
console.log("[" + slaveIndex + "]: INF: " + data);
3939
});
4040

41-
childProcess.stderr.on('data', data => {
41+
childProcess.stderr.on("data", data => {
4242
console.log("[" + slaveIndex + "]: ERR: " + data);
4343
});
4444

45-
childProcess.on('close', code => {
45+
childProcess.on("close", code => {
4646
if (code === 0) {
4747
resolve();
4848
}
@@ -51,7 +51,7 @@ function runSlave (skip, limit, slaveIndex) {
5151
}
5252
});
5353

54-
childProcess.on('error', err => {
54+
childProcess.on("error", err => {
5555
reject(err);
5656
});
5757
});

0 commit comments

Comments
 (0)