autosens-prepare.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. // для settings/autosens.json параметры: monitor/glucose.json monitor/pumphistory-24h-zoned.json settings/basal_profile.json settings/profile.json monitor/carbhistory.json settings/temptargets.json
  2. function generate(glucose_data, pumphistory_data, basalprofile, profile_data, carb_data = {}, temptarget_data = {}, now = null) {
  3. if (glucose_data.length < 72) {
  4. return { "ratio": 1, "error": "not enough glucose data to calculate autosens" };
  5. };
  6. if (now) {
  7. now = new Date(now);
  8. } else {
  9. now = new Date();
  10. }
  11. var iob_inputs = {
  12. history: pumphistory_data,
  13. profile: profile_data,
  14. clock: now
  15. };
  16. var detection_inputs = {
  17. iob_inputs: iob_inputs,
  18. carbs: carb_data,
  19. glucose_data: glucose_data,
  20. basalprofile: basalprofile,
  21. temptargets: temptarget_data
  22. };
  23. detection_inputs.deviations = 96;
  24. var ratio8h = trio_autosens(detection_inputs, now);
  25. detection_inputs.deviations = 288;
  26. var ratio24h = trio_autosens(detection_inputs, now);
  27. var lowestRatio = ratio8h.ratio < ratio24h.ratio ? ratio8h : ratio24h;
  28. return lowestRatio;
  29. }