Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
db6658c
Use endsWith from Lodash
edwingustafson Aug 10, 2018
56d122d
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Aug 16, 2018
0425235
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Aug 21, 2018
7dff7a2
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Aug 22, 2018
f8fd86e
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Aug 24, 2018
d17ca20
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Aug 27, 2018
94b024f
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Aug 30, 2018
5268a1b
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Aug 31, 2018
e0a228c
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Sep 2, 2018
72549f0
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Sep 5, 2018
eb6b49b
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Sep 6, 2018
a7bc42e
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Sep 14, 2018
8492a69
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Sep 15, 2018
a1e0078
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Sep 29, 2018
a7a8e76
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Oct 7, 2018
aa1c3d4
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Oct 12, 2018
de43b76
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Oct 15, 2018
868cb4d
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Oct 21, 2018
a02c9f0
Return function results directly (without trivial local variable)
edwingustafson Oct 27, 2018
599c0bc
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Oct 27, 2018
b7d1a3b
Eliminate another case of function returning trivial local variable
edwingustafson Oct 29, 2018
07967f3
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Oct 30, 2018
d9b616d
Another opportunity to directly return function result without a triv…
edwingustafson Oct 30, 2018
46e97ad
Consolidate redundant functions "percentile"; remove unused function …
edwingustafson Nov 15, 2018
d154a1f
Merge remote-tracking branch 'upstream/dev' into dev
edwingustafson Nov 18, 2018
77386d5
Import percentile with var not const
edwingustafson Nov 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions bin/oref0-autosens-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,39 +179,4 @@ function convertBasal(item)
//"minutes": Math.round(item.timeAsSeconds / 60),
"rate": item.value
};
}

// From https://gist.github.com/IceCreamYou/6ffa1b18c4c8f6aeaad2
// Returns the value at a given percentile in a sorted numeric array.
// "Linear interpolation between closest ranks" method
function percentile(arr, p) {
if (arr.length === 0) return 0;
if (typeof p !== 'number') throw new TypeError('p must be a number');
if (p <= 0) return arr[0];
if (p >= 1) return arr[arr.length - 1];

var index = arr.length * p,
lower = Math.floor(index),
upper = lower + 1,
weight = index % 1;

if (upper >= arr.length) return arr[lower];
return arr[lower] * (1 - weight) + arr[upper] * weight;
}

// Returns the percentile of the given value in a sorted numeric array.
function percentRank(arr, v) {
if (typeof v !== 'number') throw new TypeError('v must be a number');
for (var i = 0, l = arr.length; i < l; i++) {
if (v <= arr[i]) {
while (i < l && v === arr[i]) i++;
if (i === 0) return 0;
if (v !== arr[i-1]) {
i += (v - arr[i-1]) / (arr[i] - arr[i-1]);
}
return i / l;
}
}
return 1;
}

}
21 changes: 2 additions & 19 deletions lib/autotune/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var percentile = require('../percentile')

// does three things - tunes basals, ISF, and CSF

function tuneAllTheThings (inputs) {
Expand Down Expand Up @@ -538,22 +540,3 @@ function tuneAllTheThings (inputs) {
}

exports = module.exports = tuneAllTheThings;

// From https://gist.github.com/IceCreamYou/6ffa1b18c4c8f6aeaad2
// Returns the value at a given percentile in a sorted numeric array.
// "Linear interpolation between closest ranks" method
function percentile(arr, p) {
if (arr.length === 0) return 0;
if (typeof p !== 'number') throw new TypeError('p must be a number');
if (p <= 0) return arr[0];
if (p >= 1) return arr[arr.length - 1];

var index = arr.length * p,
lower = Math.floor(index),
upper = lower + 1,
weight = index % 1;

if (upper >= arr.length) return arr[lower];
return arr[lower] * (1 - weight) + arr[upper] * weight;
}

19 changes: 1 addition & 18 deletions lib/determine-basal/autosens.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var find_insulin = require('../iob/history');
var isf = require('../profile/isf');
var find_meals = require('../meal/history');
var tz = require('moment-timezone');
var percentile = require('../percentile');

function detectSensitivity(inputs) {

Expand Down Expand Up @@ -422,24 +423,6 @@ function detectSensitivity(inputs) {
}
module.exports = detectSensitivity;

// From https://gist.github.com/IceCreamYou/6ffa1b18c4c8f6aeaad2
// Returns the value at a given percentile in a sorted numeric array.
// "Linear interpolation between closest ranks" method
function percentile(arr, p) {
if (arr.length === 0) return 0;
if (typeof p !== 'number') throw new TypeError('p must be a number');
if (p <= 0) return arr[0];
if (p >= 1) return arr[arr.length - 1];

var index = arr.length * p,
lower = Math.floor(index),
upper = lower + 1,
weight = index % 1;

if (upper >= arr.length) return arr[lower];
return arr[lower] * (1 - weight) + arr[upper] * weight;
}

function tempTargetRunning(temptargets_data, time) {
// sort tempTargets by date so we can process most recent first
try {
Expand Down
4 changes: 1 addition & 3 deletions lib/iob/calculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,10 @@ function iobCalcExponential(treatment, minsAgo, dia, peak, profile) {
//console.error('DIA: ' + dia + ' minsAgo: ' + minsAgo + ' end: ' + end + ' peak: ' + peak + ' tau: ' + tau + ' a: ' + a + ' S: ' + S + ' activityContrib: ' + activityContrib + ' iobContrib: ' + iobContrib);
}

var results = {
return {
activityContrib: activityContrib,
iobContrib: iobContrib
};

return results;
}


Expand Down
17 changes: 17 additions & 0 deletions lib/percentile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// From https://gist.github.com/IceCreamYou/6ffa1b18c4c8f6aeaad2
// Returns the value at a given percentile in a sorted numeric array.
// "Linear interpolation between closest ranks" method
module.exports = function percentile(arr, p) {
if (arr.length === 0) return 0;
if (typeof p !== 'number') throw new TypeError('p must be a number');
if (p <= 0) return arr[0];
if (p >= 1) return arr[arr.length - 1];

var index = arr.length * p,
lower = Math.floor(index),
upper = lower + 1,
weight = index % 1;

if (upper >= arr.length) return arr[lower];
return arr[lower] * (1 - weight) + arr[upper] * weight;
}