oref0 icon indicating copy to clipboard operation
oref0 copied to clipboard

Determine_basal behavior changes based on how iob_data is provided

Open sulkaharo opened this issue 7 years ago • 3 comments

In production rigs, determine_basal is given an array with multiple IOB datapoints. In development, the unit tests for determine_basal call the logic with one IOB datapoint without wrapping the data into an array. The code contains logic for checking if the input is an array or not, but skips some of the logic if the array only contains one element, causing the execution to fail. OTOH invoking determine_basal without the array also causes some parts of the logic to be skipped, with an error message stating AMA could not run due to IOB data issues. Upon fixing the code to work with a single-element array, I noticed the output of the logic changes depending on whether the same IOB data is wrapped into an array or not, which is a bit worrying.

The line that causes arrays with just one element to not works is at https://github.com/openaps/oref0/blob/master/lib/determine-basal/determine-basal.js#L129 and the line that fails to execute with the unit tests is https://github.com/openaps/oref0/blob/master/lib/determine-basal/determine-basal.js#L340

One of the tests that fails checks the loop zero temps in certain circumstances, which probably never happens in production due to the said execution path differences.

sulkaharo avatar Jul 17 '17 21:07 sulkaharo

See https://github.com/sulkaharo/oref0/commit/d7745eea780dfdedad56e63d8aa8967f705e26d5 for the change that breaks the tests

sulkaharo avatar Jul 17 '17 21:07 sulkaharo

Any suggestions for how to fix?

scottleibrand avatar Oct 09 '17 02:10 scottleibrand

Pushed a changed version of the test to https://github.com/openaps/oref0/commit/07ed4ca72672ebf1a53c87780eabbc7c52924556 which changes the data being passed to determine-basal to match the production rigs. Next up - figure out why it fails

sulkaharo avatar Nov 15 '17 15:11 sulkaharo