-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
53 lines (48 loc) · 1.36 KB
/
cli.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
#!/usr/bin/env node
//Import classes and utils
var readCsvFile = require('./modules/utils').readCsvFile;
var ampm = require('./modules/utils').ampm;
var Alarms = require('./classes/alarm'); //Import the Alarms class
//Read the command line arguments
const [,, ...args] = process.argv;
/**
*Executes at startup
*
*/
function main(){
//Checks if arguments have been supplied
if(!args[0]){
console.log('Please specify a .csv file');
} else {
//Reads the csv file
readCsvFile(args[0], function(err, parsedArray){
if(err){
console.error(err);
return err;
} else {
//Instantiate the Alarms class
var alarms = new Alarms(parsedArray);
//Scans all the 24 hours for alarms
for (let i = 0; i < 24; i++) {
if(alarms.ringsLowPh(i)){
console.log(ampm(i) + ': ALERT low-pH');
}
if(alarms.ringsHighPh(i)){
console.log(ampm(i) + ': ALERT high-pH');
}
if(alarms.ringsLowDo(i)){
console.log(ampm(i) + ': ALERT low-DO');
}
if(alarms.ringsChangingPh(i)){
console.log(ampm(i) + ': ALERT changing-pH');
}
if(alarms.ringsBorderlineDo(i)){
console.log(ampm(i) + ': ALERT borderline-DO');
}
}
}
});
}
}
//Begins execution
main();