oref0
oref0 copied to clipboard
Determine_basal behavior changes based on how iob_data is provided
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.
See https://github.com/sulkaharo/oref0/commit/d7745eea780dfdedad56e63d8aa8967f705e26d5 for the change that breaks the tests
Any suggestions for how to fix?
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