-
Notifications
You must be signed in to change notification settings - Fork 396
/
oref0-normalize-temps.js
executable file
·70 lines (55 loc) · 1.89 KB
/
oref0-normalize-temps.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
'use strict';
/*
Released under MIT license. See the accompanying LICENSE.txt file for
full terms and conditions
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var find_insulin = require('../lib/temps');
var find_bolus = require('../lib/bolus');
var describe_pump = require('../lib/pump');
var fs = require('fs');
var oref0_normalize_temps = function oref0_normalize_temps(argv_params) {
var argv = require('yargs')(argv_params)
.usage('$0 <pumphistory.json>')
.demand(1)
// error and show help if some other args given
.strict(true)
.help('help');
var params = argv.argv;
var iob_input = params._[0];
if (params._.length > 1) {
argv.showHelp();
return console.error('Too many arguments');
}
var cwd = process.cwd()
try {
var all_data = JSON.parse(fs.readFileSync(cwd + '/' + iob_input));
} catch (e) {
return console.error("Could not parse pumphistory: ", e);
}
var inputs = {
history: all_data
};
var treatments = find_insulin(find_bolus(inputs.history));
treatments = describe_pump(treatments);
// treatments.sort(function (a, b) { return a.date > b.date });
return JSON.stringify(treatments);
}
if (!module.parent) {
// remove the first parameter.
var command = process.argv;
command.shift();
command.shift();
var result = oref0_normalize_temps(command)
if(result !== undefined) {
console.log(result);
}
}
exports = module.exports = oref0_normalize_temps