autosens-prepare.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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. };
  15. var detection_inputs = {
  16. iob_inputs: iob_inputs,
  17. carbs: carb_data,
  18. glucose_data: glucose_data,
  19. basalprofile: basalprofile,
  20. temptargets: temptarget_data
  21. };
  22. detection_inputs.deviations = 96;
  23. var ratio8h = trio_autosens(detection_inputs, now);
  24. detection_inputs.deviations = 288;
  25. var ratio24h = trio_autosens(detection_inputs, now);
  26. var lowestRatio = ratio8h.ratio < ratio24h.ratio ? ratio8h : ratio24h;
  27. return lowestRatio;
  28. }