Skip to content

Commit

Permalink
Revert "Tzachi shared node phase2 (openaps#1370)"
Browse files Browse the repository at this point in the history
This reverts commit 912ab07.
  • Loading branch information
bjornoleh committed Feb 22, 2024
1 parent a9bdbb1 commit efdca23
Show file tree
Hide file tree
Showing 31 changed files with 171 additions and 463 deletions.
13 changes: 6 additions & 7 deletions bin/oref0-autosens-history.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
'use strict';

/*
Determine Basal
Expand All @@ -17,10 +16,10 @@
*/

var basal = require('../lib/profile/basal');
var detectSensitivity = require('../lib/determine-basal/autosens');
var detect = require('../lib/determine-basal/autosens');

if (!module.parent) {
//var detectsensitivity = init(); // I don't see where this variable is used, so deleted it.
var detectsensitivity = init();

var argv = require('yargs')
.usage("$0 <glucose.json> <pumphistory.json> <profile.json> <readings_per_run> [outputfile.json]")
Expand Down Expand Up @@ -136,16 +135,16 @@ if (!module.parent) {
var ratioArray = [];
do {
detection_inputs.deviations = 96;
var result = detectSensitivity(detection_inputs);
detect(detection_inputs);
for(i=0; i<readings_per_run; i++) {
detection_inputs.glucose_data.shift();
}
console.error(result.ratio, result.newisf, detection_inputs.glucose_data[0].dateString);
console.error(ratio, newisf, detection_inputs.glucose_data[0].dateString);

var obj = {
"dateString": detection_inputs.glucose_data[0].dateString,
"sensitivityRatio": result.ratio,
"ISF": result.newisf
"sensitivityRatio": ratio,
"ISF": newisf
}
ratioArray.unshift(obj);
if (output_file) {
Expand Down
31 changes: 9 additions & 22 deletions bin/oref0-calculate-iob.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
'use strict';

/*
Insulin On Board (IOB) calculations.
Expand All @@ -19,16 +19,13 @@
*/

var generate = require('../lib/iob');
var fs = require('fs');
function usage ( ) {
console.log('usage: ', process.argv.slice(0, 2), '<pumphistory-zoned.json> <profile.json> <clock-zoned.json> [autosens.json] [pumphistory-24h-zoned.json]');

}



var oref0_calculate_iob = function oref0_calculate_iob(argv_params) {
var argv = require('yargs')(argv_params)
if (!module.parent) {
var argv = require('yargs')
.usage("$0 <pumphistory-zoned.json> <profile.json> <clock-zoned.json> [<autosens.json>] [<pumphistory-24h-zoned.json>]")
.strict(true)
.help('help');
Expand All @@ -49,21 +46,21 @@ var oref0_calculate_iob = function oref0_calculate_iob(argv_params) {
var pumphistory_24_input = inputs[4];

var cwd = process.cwd();
var pumphistory_data = JSON.parse(fs.readFileSync(cwd + '/' + pumphistory_input));
var profile_data = JSON.parse(fs.readFileSync(cwd + '/' + profile_input));
var clock_data = JSON.parse(fs.readFileSync(cwd + '/' + clock_input));
var pumphistory_data = require(cwd + '/' + pumphistory_input);
var profile_data = require(cwd + '/' + profile_input);
var clock_data = require(cwd + '/' + clock_input);

var autosens_data = null;
if (autosens_input) {
try {
autosens_data = JSON.parse(fs.readFileSync(cwd + '/' + autosens_input));
autosens_data = require(cwd + '/' + autosens_input);
} catch (e) {}
//console.error(autosens_input, JSON.stringify(autosens_data));
}
var pumphistory_24_data = null;
if (pumphistory_24_input) {
try {
pumphistory_24_data = JSON.parse(fs.readFileSync(cwd + '/' + pumphistory_24_input));
pumphistory_24_data = require(cwd + '/' + pumphistory_24_input);
} catch (e) {}
}

Expand All @@ -80,16 +77,6 @@ var oref0_calculate_iob = function oref0_calculate_iob(argv_params) {
}

var iob = generate(inputs);
return(JSON.stringify(iob));
}

if (!module.parent) {
// remove the first parameter.
var command = process.argv;
command.shift();
command.shift();
var result = oref0_calculate_iob(command)
console.log(result);
console.log(JSON.stringify(iob));
}

exports = module.exports = oref0_calculate_iob
14 changes: 7 additions & 7 deletions bin/oref0-detect-sensitivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var detectSensitivity = require('../lib/determine-basal/autosens');
var detect = require('../lib/determine-basal/autosens');

if (!module.parent) {
var argv = require('yargs')
Expand Down Expand Up @@ -112,14 +112,14 @@ if (!module.parent) {
};
console.error("Calculating sensitivity using 8h of non-exluded data");
detection_inputs.deviations = 96;
var result = detectSensitivity(detection_inputs);
var ratio8h = result.ratio;
var newisf8h = result.newisf;
detect(detection_inputs);
var ratio8h = ratio;
var newisf8h = newisf;
console.error("Calculating sensitivity using all non-exluded data (up to 24h)");
detection_inputs.deviations = 288;
result = detectSensitivity(detection_inputs);
var ratio24h = result.ratio;
var newisf24h = result.newisf;
detect(detection_inputs);
var ratio24h = ratio;
var newisf24h = newisf;
if ( ratio8h < ratio24h ) {
console.error("Using 8h autosens ratio of",ratio8h,"(ISF",newisf8h+")");
} else {
Expand Down
67 changes: 19 additions & 48 deletions bin/oref0-get-ns-entries.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
'use strict';

/*
oref0 Nightscout treatment fetch tool
Expand All @@ -26,16 +25,13 @@ var request = require('request');
var _ = require('lodash');
var fs = require('fs');
var network = require('network');
var shared_node = require('./oref0-shared-node-utils');
var console_error = shared_node.console_error;
var console_log = shared_node.console_log;
var initFinalResults = shared_node.initFinalResults;

var oref0_get_ns_engtires = function oref0_get_ns_engtires(argv_params, print_callback, final_result) {
var safe_errors = ['ECONNREFUSED', 'ESOCKETTIMEDOUT', 'ETIMEDOUT'];
var log_errors = true;
var safe_errors = ['ECONNREFUSED', 'ESOCKETTIMEDOUT', 'ETIMEDOUT'];
var log_errors = true;

var argv = require('yargs')(argv_params)
if (!module.parent) {

var argv = require('yargs')
.usage("$0 ns-glucose.json NSURL API-SECRET <hours>")
.strict(true)
.help('help');
Expand All @@ -49,7 +45,7 @@ var oref0_get_ns_engtires = function oref0_get_ns_engtires(argv_params, print_ca

if ([null, '--help', '-h', 'help'].indexOf(glucose_input) > 0) {
usage();
process.exit(0); //???????
process.exit(0);
}

var nsurl = params._.slice(1, 2).pop();
Expand Down Expand Up @@ -92,21 +88,21 @@ var oref0_get_ns_engtires = function oref0_get_ns_engtires(argv_params, print_ca
, headers: headers
};

if (log_errors) console_error(final_result, 'Connecting to ' + ip +', testing for xDrip API availability');
if (log_errors) console.error('Connected to ' + ip +', testing for xDrip API availability');

request(options, function(error, res, data) {
var failed = false;
if (res && res.statusCode == 403) {
console_error(final_result, "Load from xDrip failed: API_SECRET didn't match");
console.error("Load from xDrip failed: API_SECRET didn't match");
failed = true;
}

if (error) {
if (safe_errors.includes(error.code)) {
if (log_errors) console_error(final_result, 'Load from local xDrip timed out, likely not connected to xDrip hotspot');
if (log_errors) console.error('Load from local xDrip timed out, likely not connected to xDrip hotspot');
log_errors = false;
} else {
if (log_errors) console_error(final_result, "Load from xDrip failed", error);
if (log_errors) console.error("Load from xDrip failed", error);
log_errors = false;
failed = true;
}
Expand All @@ -115,18 +111,12 @@ var oref0_get_ns_engtires = function oref0_get_ns_engtires(argv_params, print_ca
}

if (!failed && data) {
console_error(final_result, "CGM results loaded from xDrip");
console.error("CGM results loaded from xDrip");
processAndOutput(data);
return true;
}

if (failed && callback) {
// printing will happen in the callback
callback();
} else {
print_callback(final_result);
}

if (failed && callback) callback();
});

return false;
Expand All @@ -141,7 +131,7 @@ var oref0_get_ns_engtires = function oref0_get_ns_engtires(argv_params, print_ca
fs.readFile(outputPath, 'utf8', function(err, fileContent) {

if (err) {
console_error(final_result, err);
console.error(err);
} else {
try {
glucosedata = JSON.parse(fileContent);
Expand All @@ -157,11 +147,10 @@ var oref0_get_ns_engtires = function oref0_get_ns_engtires(argv_params, print_ca
glucosedata = null;
}
} catch (e) {
console_error(final_result, e);
console.error(e);
}
}
loadFromNightscoutWithDate(lastDate, glucosedata);
// callback will happen in loadFromNightscoutWithDate
});
}

Expand Down Expand Up @@ -192,19 +181,18 @@ var oref0_get_ns_engtires = function oref0_get_ns_engtires(argv_params, print_ca
if (res && (res.statusCode == 200 || res.statusCode == 304)) {

if (data) {
console_error(final_result, "Got CGM results from Nightscout");
console.error("Got CGM results from Nightscout");
processAndOutput(data);
} else {
console_error(final_result, "Got Not Changed response from Nightscout, assuming no new data is available");
console.error("Got Not Changed response from Nightscout, assuming no new data is available");
// output old file
if (!_.isNil(glucosedata)) {
console_log(final_result, JSON.stringify(glucosedata));
console.log(JSON.stringify(glucosedata));
}
}
} else {
console_error(final_result, "Loading CGM data from Nightscout failed", error);
console.error("Loading CGM data from Nightscout failed", error);
}
print_callback(final_result);
});

}
Expand All @@ -215,28 +203,11 @@ var oref0_get_ns_engtires = function oref0_get_ns_engtires(argv_params, print_ca
sgvrecord.glucose = sgvrecord.sgv;
});

console_log(final_result, JSON.stringify(glucosedata));
console.log(JSON.stringify(glucosedata));
}

network.get_gateway_ip(function(err, ip) {
loadFromxDrip(nsCallback, ip);
});
}

function print_callback(final_result) {
console.log(final_result.stdout);
console.error(final_result.err);
}


if (!module.parent) {
var final_result = initFinalResults();

// remove the first parameter.
var command = process.argv;
command.shift();
command.shift();
var result = oref0_get_ns_engtires(command, print_callback, final_result)
}

exports = module.exports = oref0_get_ns_engtires
Loading

0 comments on commit efdca23

Please sign in to comment.