| 1 |
- var freeaps_determineBasal;(()=>{var e={5546:(e,r,a)=>{var t=a(6880);function o(e,r){r||(r=0);var a=Math.pow(10,r);return Math.round(e*a)/a}function n(e,r){return"mmol/L"===r.out_units?o(e/18,1):Math.round(e)}var s="";e.exports=function(e,r,a,i,l,u,m,d,c,g){var h={},f=new Date;if(g&&(f=g),void 0===i||void 0===i.current_basal)return h.error="Error: could not get current basal rate",h;var p=t(i.current_basal,i),v=p,b=new Date;g&&(b=g);var B,M=new Date(e.date),_=o((b-M)/60/1e3,1),x=e.glucose,S=e.noise;B=e.delta>-.5?"+"+o(e.delta,0):o(e.delta,0);var y=Math.min(e.delta,e.short_avgdelta),C=Math.min(e.short_avgdelta,e.long_avgdelta),G=Math.max(e.delta,e.short_avgdelta,e.long_avgdelta);(x<=10||38===x||S>=3)&&(h.reason="CGM is calibrating, in ??? state, or noise is high");if(x>60&&0==e.delta&&e.short_avgdelta>-1&&e.short_avgdelta<1&&e.long_avgdelta>-1&&e.long_avgdelta<1&&("fakecgm"==e.device?(console.error("CGM data is unchanged ("+x+"+"+e.delta+") for 5m w/ "+e.short_avgdelta+" mg/dL ~15m change & "+e.long_avgdelta+" mg/dL ~45m change"),console.error("Simulator mode detected (",e.device,"): continuing anyway")):!0),_>12||_<-5?h.reason="If current system time "+b+" is correct, then BG data is too old. The last BG data was read "+_+"m ago at "+M:0===e.short_avgdelta&&0===e.long_avgdelta&&(e.last_cal&&e.last_cal<3?h.reason="CGM was just calibrated":h.reason="CGM data is unchanged ("+x+"+"+e.delta+") for 5m w/ "+e.short_avgdelta+" mg/dL ~15m change & "+e.long_avgdelta+" mg/dL ~45m change"),x<=10||38===x||S>=3||_>12||_<-5||0===e.short_avgdelta&&0===e.long_avgdelta)return r.rate>=v?(h.reason+=". Canceling high temp basal of "+r.rate,h.deliverAt=f,h.temp="absolute",h.duration=0,h.rate=0,h):0===r.rate&&r.duration>30?(h.reason+=". Shortening "+r.duration+"m long zero temp to 30m. ",h.deliverAt=f,h.temp="absolute",h.duration=30,h.rate=0,h):(h.reason+=". Temp "+r.rate+" <= current basal "+v+"U/hr; doing nothing. ",h);var w,O,I,T=i.max_iob;if(void 0!==i.min_bg&&(O=i.min_bg),void 0!==i.max_bg&&(I=i.max_bg),void 0===i.min_bg||void 0===i.max_bg)return h.error="Error: could not determine target_bg. ",h;w=(i.min_bg+i.max_bg)/2;var F=i.exercise_mode||i.high_temptarget_raises_sensitivity,A=100;if(i.half_basal_exercise_target)var U=i.half_basal_exercise_target;else U=160;if(F&&i.temptargetSet&&w>A||i.low_temptarget_lowers_sensitivity&&i.temptargetSet&&w<A){var R=U-A;R+w-A>0?(sensitivityRatio=R/(R+w-A),sensitivityRatio=Math.min(sensitivityRatio,i.autosens_max),sensitivityRatio=o(sensitivityRatio,2)):sensitivityRatio=i.autosens_max,process.stderr.write("Sensitivity ratio set to "+sensitivityRatio+" based on temp target of "+w+"; ")}else void 0!==l&&l&&(sensitivityRatio=l.ratio,process.stderr.write("Autosens ratio: "+sensitivityRatio+"; "));if(sensitivityRatio&&(v=i.current_basal*sensitivityRatio,(v=t(v,i))!==p?process.stderr.write("Adjusting basal from "+p+" to "+v+"; "):process.stderr.write("Basal unchanged: "+v+"; ")),i.temptargetSet);else if(void 0!==l&&l&&(i.sensitivity_raises_target&&l.ratio<1||i.resistance_lowers_target&&l.ratio>1)){O=o((O-60)/l.ratio)+60,I=o((I-60)/l.ratio)+60;var D=o((w-60)/l.ratio)+60;w===(D=Math.max(80,D))?process.stderr.write("target_bg unchanged: "+D+"; "):process.stderr.write("target_bg from "+w+" to "+D+"; "),w=D}if(e.noise>=2){var j=Math.max(1.1,i.noisyCGMTargetMultiplier),E=(Math.min(250,i.maxRaw),o(Math.min(200,O*j))),q=o(Math.min(200,w*j)),W=o(Math.min(200,I*j));process.stderr.write("Raising target_bg for noisy / raw CGM data, from "+w+" to "+q+"; "),O=E,w=q,I=W}var z=O-.5*(O-40),L=o(i.sens,1),P=i.sens;if(void 0!==l&&l&&((P=o(P=i.sens/sensitivityRatio,1))!==L?process.stderr.write("ISF from "+L+" to "+P):process.stderr.write("ISF unchanged: "+P),s+="Autosense: Ratio "+sensitivityRatio+", ISF "+n(L,i)+" -> "+n(P,i)+"; "),console.error("; CR:",i.carb_ratio),P=function(e,r,a,t,i,l,u){if(!1===a.auto_isf)return console.error("autoISF disabled in Preferences"),e;if(void 0===a.autoisf_max)return console.error("autoISF_max not defined"),e;if(a.autoisf_max){console.error("autoISF enabled in Preferences"),console.error("autoISF hourly change: "+a.autoisf_hourlychange),console.error("autoISF max: "+a.autoisf_max),console.error("SMB Range Extension: "+a.smb_max_range_extension),console.error("SMB fraction of InsReq: "+a.smb_delivery_ratio);var m=t.autoISF_duration,d=t.autoISF_average,c=a.autoisf_hourlychange;if(0==i.mealCOB&&m>=10)if(d>r){var g=a.autoisf_max,h=m/60,f=c/r,p=1+h*f*(d-r),v=Math.min(g,p);console.error("ISFreductionLevel = "+v+" ;");var b=o(Math.max(v,u),2);console.error("dura05_weight = "+h+"; avg05_weight = "+f+"; levelISF = "+p+"; liftISF = "+b),console.error("autoISF reports "+n(e,a)+" did not do it for "+m+"min; go more aggressive by "+o(p,2)),g<p&&console.error("autoISF reduction "+o(p,2)+" limited by autoisf_max "+g),e=o(a.sens/b,1),console.error("autoISF reports sens is now "+n(e,a)),s+="autoISF -> "+n(e,a)+", Ratio "+b+"; "}else console.error("autoISF by-passed; avg. glucose "+d+" below target "+r);else i.mealCOB>0?console.error("autoISF by-passed; mealCOB of "+o(i.mealCOB,1)):console.error("autoISF by-passed; BG is only "+m+"min at level "+d);return console.error("autoISF has run. Sens is now "+n(e,a)),e}}(P,w,i,e,u,0,sensitivityRatio),void 0===a)return h.error="Error: iob_data undefined. ",h;var k,N=a;if(a.length,a.length>1&&(a=N[0]),void 0===a.activity||void 0===a.iob)return h.error="Error: iob_data missing some property. ",h;var Z=((k=void 0!==a.lastTemp?o((new Date(b).getTime()-a.lastTemp.date)/6e4):0)+r.duration)%30;if(console.error("currenttemp:",r,"lastTempAge:",k,"m","tempModulus:",Z,"m"),h.temp="absolute",h.deliverAt=f,d&&r&&a.lastTemp&&r.rate!==a.lastTemp.rate&&k>10&&r.duration)return h.reason="Warning: currenttemp rate "+r.rate+" != lastTemp rate "+a.lastTemp.rate+" from pumphistory; canceling temp",m.setTempBasal(0,0,i,h,r);if(r&&a.lastTemp&&r.duration>0){var $=k-a.lastTemp.duration;if($>5&&k>10)return h.reason="Warning: currenttemp running but lastTemp from pumphistory ended "+$+"m ago; canceling temp",m.setTempBasal(0,0,i,h,r)}var H=o(-a.activity*P*5,2),J=o(6*(y-H));if(J<0&&(J=o(6*(C-H)))<0&&(J=o(6*(e.long_avgdelta-H))),a.iob>0)var K=o(x-a.iob*P);else K=o(x-a.iob*Math.min(P,i.sens));var Q=K+J;if(void 0===Q||isNaN(Q))return h.error="Error: could not calculate eventualBG. ",h;var V=function(e,r,a){return o(a+(e-r)/24,1)}(w,Q,H);h={temp:"absolute",bg:x,tick:B,eventualBG:Q,insulinReq:0,reservoir:c,deliverAt:f,sensitivityRatio};var X=[],Y=[],ee=[],re=[];X.push(x),Y.push(x),re.push(x),ee.push(x);var ae=function(e,r,a,t){return r?!e.allowSMB_with_high_temptarget&&e.temptargetSet&&t>100?(console.error("SMB disabled due to high temptarget of",t),!1):!0===a.bwFound&&!1===e.A52_risk_enable?(console.error("SMB disabled due to Bolus Wizard activity in the last 6 hours."),!1):!0===e.enableSMB_always?(a.bwFound?console.error("Warning: SMB enabled within 6h of using Bolus Wizard: be sure to easy bolus 30s before using Bolus Wizard"):console.error("SMB enabled due to enableSMB_always"),!0):!0===e.enableSMB_with_COB&&a.mealCOB?(a.bwCarbs?console.error("Warning: SMB enabled with Bolus Wizard carbs: be sure to easy bolus 30s before using Bolus Wizard"):console.error("SMB enabled for COB of",a.mealCOB),!0):!0===e.enableSMB_after_carbs&&a.carbs?(a.bwCarbs?console.error("Warning: SMB enabled with Bolus Wizard carbs: be sure to easy bolus 30s before using Bolus Wizard"):console.error("SMB enabled for 6h after carb entry"),!0):!0===e.enableSMB_with_temptarget&&e.temptargetSet&&t<100?(a.bwFound?console.error("Warning: SMB enabled within 6h of using Bolus Wizard: be sure to easy bolus 30s before using Bolus Wizard"):console.error("SMB enabled for temptarget of",n(t,e)),!0):(console.error("SMB disabled (no enableSMB preferences active or no condition satisfied)"),!1):(console.error("SMB disabled (!microBolusAllowed)"),!1)}(i,d,u,w),te=i.enableUAM,oe=0,ne=0;oe=o(y-H,1);var se=o(y-H,1);csf=P/i.carb_ratio,console.error("profile.sens:",i.sens,"sens:",P,"CSF:",csf);var ie=o(30*csf*5/60,1);oe>ie&&(console.error("Limiting carb impact from",oe,"to",ie,"mg/dL/5m (",30,"g/h )"),oe=ie);var le=3;sensitivityRatio&&(le/=sensitivityRatio);var ue=le;if(u.carbs){le=Math.max(le,u.mealCOB/20);var me=o((new Date(b).getTime()-u.lastCarbTime)/6e4),de=(u.carbs-u.mealCOB)/u.carbs;ue=o(ue=le+1.5*me/60,1),console.error("Last carbs",me,"minutes ago; remainingCATime:",ue,"hours;",o(100*de)+"% carbs absorbed")}var ce=Math.max(0,oe/5*60*ue/2)/csf,ge=90,he=1;i.remainingCarbsCap&&(ge=Math.min(90,i.remainingCarbsCap)),i.remainingCarbsFraction&&(he=Math.min(1,i.remainingCarbsFraction));var fe=1-he,pe=Math.max(0,u.mealCOB-ce-u.carbs*fe),ve=(pe=Math.min(ge,pe))*csf*5/60/(ue/2),be=o(u.slopeFromMaxDeviation,2),Be=o(u.slopeFromMinDeviation,2),Me=Math.min(be,-Be/3),_e=0;0===oe?ne=0:!0===i.floating_carbs?(ne=Math.min(60*ue/5/2,Math.max(0,u.carbs*csf/oe)),_e=Math.min(60*ue/5/2,Math.max(0,u.mealCOB*csf/oe)),u.carbs>0&&(s+="Floating Carbs CID:"+o(ne,1)+" / MealCarbs:"+o(u.carbs,1)+" vs. Not Floating:"+o(_e,1)+" / MealCOB:"+o(u.mealCOB,1)+"; ",console.error("Floating Carbs CID:"+o(ne,1)+" / MealCarbs:"+o(u.carbs,1)+" vs. Not Floating:"+o(_e,1)+" / MealCOB:"+o(u.mealCOB,1)))):ne=Math.min(60*ue/5/2,Math.max(0,u.mealCOB*csf/oe)),console.error("Carb Impact:",oe,"mg/dL per 5m; CI Duration:",o(5*ne/60*2,1),"hours; remaining CI (",ue/2,"h peak):",o(ve,1),"mg/dL per 5m");var xe,Se,ye,Ce,Ge,we=999,Oe=999,Ie=999,Te=x,Fe=999,Ae=999,Ue=999,Re=999,De=Q,je=x,Ee=x,qe=0,We=[],ze=[];try{N.forEach((function(e){var r=o(-e.activity*P*5,2),a=o(-e.iobWithZeroTemp.activity*P*5,2),t=oe*(1-Math.min(1,Y.length/12));De=Y[Y.length-1]+r+t;var n=re[re.length-1]+a,s=Math.max(0,Math.max(0,oe)*(1-X.length/Math.max(2*ne,1))),i=Math.min(X.length,12*ue-X.length),l=Math.max(0,i/(ue/2*12)*ve);s+l,We.push(o(l,0)),ze.push(o(s,0)),COBpredBG=X[X.length-1]+r+Math.min(0,t)+s+l;var u=Math.max(0,se+ee.length*Me),m=Math.max(0,se*(1-ee.length/Math.max(36,1))),d=Math.min(u,m);d>0&&(qe=o(5*(ee.length+1)/60,1)),UAMpredBG=ee[ee.length-1]+r+Math.min(0,t)+d,Y.length<48&&Y.push(De),X.length<48&&X.push(COBpredBG),ee.length<48&&ee.push(UAMpredBG),re.length<48&&re.push(n),COBpredBG<Fe&&(Fe=o(COBpredBG)),UAMpredBG<Ae&&(Ae=o(UAMpredBG)),De<Ue&&(Ue=o(De)),n<Re&&(Re=o(n));Y.length>18&&De<we&&(we=o(De)),De>je&&(je=De),(ne||ve>0)&&X.length>18&&COBpredBG<Oe&&(Oe=o(COBpredBG)),(ne||ve>0)&&COBpredBG>je&&(Ee=COBpredBG),te&&ee.length>12&&UAMpredBG<Ie&&(Ie=o(UAMpredBG)),te&&UAMpredBG>je&&UAMpredBG}))}catch(e){console.error("Problem with iobArray. Optional feature Advanced Meal Assist disabled")}u.mealCOB&&(console.error("predCIs (mg/dL/5m):",ze.join(" ")),console.error("remainingCIs: ",We.join(" "))),h.predBGs={},Y.forEach((function(e,r,a){a[r]=o(Math.min(401,Math.max(39,e)))}));for(var Le=Y.length-1;Le>12&&Y[Le-1]===Y[Le];Le--)Y.pop();for(h.predBGs.IOB=Y,ye=o(Y[Y.length-1]),re.forEach((function(e,r,a){a[r]=o(Math.min(401,Math.max(39,e)))})),Le=re.length-1;Le>6&&!(re[Le-1]>=re[Le]||re[Le]<=w);Le--)re.pop();if(h.predBGs.ZT=re,o(re[re.length-1]),u.mealCOB>0&&(oe>0||ve>0)){for(X.forEach((function(e,r,a){a[r]=o(Math.min(401,Math.max(39,e)))})),Le=X.length-1;Le>12&&X[Le-1]===X[Le];Le--)X.pop();h.predBGs.COB=X,Ce=o(X[X.length-1]),Q=Math.max(Q,o(X[X.length-1]))}if(oe>0||ve>0){if(te){for(ee.forEach((function(e,r,a){a[r]=o(Math.min(401,Math.max(39,e)))})),Le=ee.length-1;Le>12&&ee[Le-1]===ee[Le];Le--)ee.pop();h.predBGs.UAM=ee,Ge=o(ee[ee.length-1]),ee[ee.length-1]&&(Q=Math.max(Q,o(ee[ee.length-1])))}h.eventualBG=Q}console.error("UAM Impact:",se,"mg/dL per 5m; UAM Duration:",qe,"hours"),we=Math.max(39,we),Oe=Math.max(39,Oe),Ie=Math.max(39,Ie),xe=o(we);var Pe=u.mealCOB/u.carbs;Se=o(Ie<999&&Oe<999?(1-Pe)*UAMpredBG+Pe*COBpredBG:Oe<999?(De+COBpredBG)/2:Ie<999?(De+UAMpredBG)/2:De),Re>Se&&(Se=Re),Te=o(Te=ne||ve>0?te?Pe*Fe+(1-Pe)*Ae:Fe:te?Ae:Ue);var ke=Ie;if(Re<z)ke=(Ie+Re)/2;else if(Re<w){var Ne=(Re-z)/(w-z);ke=(Ie+(Ie*Ne+Re*(1-Ne)))/2}else Re>Ie&&(ke=(Ie+Re)/2);if(ke=o(ke),u.carbs)if(!te&&Oe<999)xe=o(Math.max(we,Oe));else if(Oe<999){var Ze=Pe*Oe+(1-Pe)*ke;xe=o(Math.max(we,Oe,Ze))}else xe=te?ke:Te;else te&&(xe=o(Math.max(we,ke)));xe=Math.min(xe,Se),process.stderr.write("minPredBG: "+xe+" minIOBPredBG: "+we+" minZTGuardBG: "+Re),Oe<999&&process.stderr.write(" minCOBPredBG: "+Oe),Ie<999&&process.stderr.write(" minUAMPredBG: "+Ie),console.error(" avgPredBG:",Se,"COB:",u.mealCOB,"/",u.carbs),Ee>x&&(xe=Math.min(xe,Ee)),h.COB=u.mealCOB,h.IOB=a.iob,h.BGI=H,h.deviation=n(J,i),h.ISF=n(P,i),h.CR=o(i.carb_ratio,2),h.target_bg=n(w,i),h.reason=s+"minPredBG "+n(xe,i)+", minGuardBG "+n(Te,i)+", IOBpredBG "+n(ye,i),Ce>0&&(h.reason+=", COBpredBG "+n(Ce,i)),Ge>0&&(h.reason+=", UAMpredBG "+n(Ge,i)),h.reason+="; ";var $e=K;$e<40&&($e=Math.min(Te,$e));var He,Je=z-$e,Ke=240,Qe=240;if(u.mealCOB>0&&(oe>0||ve>0)){for(Le=0;Le<X.length;Le++)if(X[Le]<O){Ke=5*Le;break}for(Le=0;Le<X.length;Le++)if(X[Le]<z){Qe=5*Le;break}}else{for(Le=0;Le<Y.length;Le++)if(Y[Le]<O){Ke=5*Le;break}for(Le=0;Le<Y.length;Le++)if(Y[Le]<z){Qe=5*Le;break}}ae&&Te<z&&(console.error("minGuardBG",n(Te,i),"projected below",n(z,i),"- disabling SMB"),ae=!1),void 0===i.maxDelta_bg_threshold&&(He=.2),void 0!==i.maxDelta_bg_threshold&&(He=Math.min(i.maxDelta_bg_threshold,.3)),G>He*x&&(console.error("maxDelta "+n(G,i)+" > "+100*He+"% of BG "+n(x,i)+" - disabling SMB"),h.reason+="maxDelta "+n(G,i)+" > "+100*He+"% of BG "+n(x,i)+": SMB disabled; ",ae=!1),console.error("BG projected to remain above",n(O,i),"for",Ke,"minutes"),(Qe<240||Ke<60)&&console.error("BG projected to remain above",n(z,i),"for",Qe,"minutes");var Ve=Qe,Xe=i.current_basal*P*Ve/60,Ye=Math.max(0,u.mealCOB-.25*u.carbs),er=(Je-Xe)/csf-Ye;if(Xe=o(Xe),er=o(er),console.error("naive_eventualBG:",K,"bgUndershoot:",Je,"zeroTempDuration:",Ve,"zeroTempEffect:",Xe,"carbsReq:",er),er>=i.carbsReqThreshold&&Qe<=45&&(h.carbsReq=er,h.reason+=er+" add'l carbs req w/in "+Qe+"m; "),x<z&&a.iob<20*-i.current_basal/60&&y>0&&y>V)h.reason+="IOB "+a.iob+" < "+o(20*-i.current_basal/60,2),h.reason+=" and minDelta "+n(y,i)+" > expectedDelta "+n(V,i)+"; ";else if(x<z||Te<z){h.reason+="minGuardBG "+n(Te,i)+"<"+n(z,i);var rr=(Je=w-Te)/P,ar=o(60*rr/i.current_basal);return ar=30*o(ar/30),ar=Math.min(120,Math.max(30,ar)),m.setTempBasal(0,ar,i,h,r)}if(i.skip_neutral_temps&&h.deliverAt.getMinutes()>=55)return h.reason+="; Canceling temp at "+h.deliverAt.getMinutes()+"m past the hour. ",m.setTempBasal(0,0,i,h,r);if(Q<O){if(h.reason+="Eventual BG "+n(Q,i)+" < "+n(O,i),y>V&&y>0&&!er)return K<40?(h.reason+=", naive_eventualBG < 40. ",m.setTempBasal(0,30,i,h,r)):(e.delta>y?h.reason+=", but Delta "+n(B,i)+" > expectedDelta "+n(V,i):h.reason+=", but Min. Delta "+y.toFixed(2)+" > Exp. Delta "+n(V,i),r.duration>15&&t(v,i)===t(r.rate,i)?(h.reason+=", temp "+r.rate+" ~ req "+v+"U/hr. ",h):(h.reason+="; setting current basal of "+v+" as temp. ",m.setTempBasal(v,30,i,h,r)));var tr=2*Math.min(0,(Q-w)/P);tr=o(tr,2);var or=Math.min(0,(K-w)/P);if(or=o(or,2),y<0&&y>V)tr=o(tr*(y/V),2);var nr=v+2*tr;nr=t(nr,i);var sr=r.duration*(r.rate-v)/60;if(sr<Math.min(tr,or)-.3*v)return h.reason+=", "+r.duration+"m@"+r.rate.toFixed(2)+" is a lot less than needed. ",m.setTempBasal(nr,30,i,h,r);if(void 0!==r.rate&&r.duration>5&&nr>=.8*r.rate)return h.reason+=", temp "+r.rate+" ~< req "+nr+"U/hr. ",h;if(nr<=0){if((ar=o(60*(rr=(Je=w-K)/P)/i.current_basal))<0?ar=0:(ar=30*o(ar/30),ar=Math.min(120,Math.max(0,ar))),ar>0)return h.reason+=", setting "+ar+"m zero temp. ",m.setTempBasal(nr,ar,i,h,r)}else h.reason+=", setting "+nr+"U/hr. ";return m.setTempBasal(nr,30,i,h,r)}if(y<V&&(!d||!ae))return e.delta<y?h.reason+="Eventual BG "+n(Q,i)+" > "+n(O,i)+" but Delta "+n(B,i)+" < Exp. Delta "+n(V,i):h.reason+="Eventual BG "+n(Q,i)+" > "+n(O,i)+" but Min. Delta "+y.toFixed(2)+" < Exp. Delta "+n(V,i),r.duration>15&&t(v,i)===t(r.rate,i)?(h.reason+=", temp "+r.rate+" ~ req "+v+"U/hr. ",h):(h.reason+="; setting current basal of "+v+" as temp. ",m.setTempBasal(v,30,i,h,r));if(Math.min(Q,xe)<I&&(!d||!ae))return h.reason+=n(Q,i)+"-"+n(xe,i)+" in range: no temp required",r.duration>15&&t(v,i)===t(r.rate,i)?(h.reason+=", temp "+r.rate+" ~ req "+v+"U/hr. ",h):(h.reason+="; setting current basal of "+v+" as temp. ",m.setTempBasal(v,30,i,h,r));if(Q>=I&&(h.reason+="Eventual BG "+n(Q,i)+" >= "+n(I,i)+", "),a.iob>T)return h.reason+="IOB "+o(a.iob,2)+" > max_iob "+T,r.duration>15&&t(v,i)===t(r.rate,i)?(h.reason+=", temp "+r.rate+" ~ req "+v+"U/hr. ",h):(h.reason+="; setting current basal of "+v+" as temp. ",m.setTempBasal(v,30,i,h,r));(tr=o((Math.min(xe,Q)-w)/P,2))>T-a.iob&&(h.reason+="max_iob "+T+", ",tr=T-a.iob),nr=t(nr=v+2*tr,i),tr=o(tr,3),h.insulinReq=tr;var ir=o((new Date(b).getTime()-a.lastBolusTime)/6e4,1);if(d&&ae&&x>z){var lr=o(u.mealCOB/i.carb_ratio,3);if(!1===i.auto_isf){console.error("autoISF disabled, SMB range is 1");var ur=1}else ur=i.smb_max_range_extension;if(ur>1&&console.error("SMB max range extended from default by factor "+ur),void 0===i.maxSMBBasalMinutes){var mr=o(ur*i.current_basal*30/60,1);console.error("profile.maxSMBBasalMinutes undefined: defaulting to 30m")}else a.iob>lr&&a.iob>0?(console.error("IOB",a.iob,"> COB",u.mealCOB+"; mealInsulinReq =",lr),i.maxUAMSMBBasalMinutes?(console.error("profile.maxUAMSMBBasalMinutes:",i.maxUAMSMBBasalMinutes,"profile.current_basal:",i.current_basal),mr=o(ur*i.current_basal*i.maxUAMSMBBasalMinutes/60,1)):(console.error("profile.maxUAMSMBBasalMinutes undefined: defaulting to 30m"),mr=o(30*i.current_basal/60,1))):(console.error("profile.maxSMBBasalMinutes:",i.maxSMBBasalMinutes,"profile.current_basal:",i.current_basal),mr=o(ur*i.current_basal*i.maxSMBBasalMinutes/60,1));var dr=i.bolus_increment,cr=1/dr;if(!1===i.auto_isf)console.error("autoISF disabled, don't adjust SMB ratio"),gr=.5;else var gr=i.smb_delivery_ratio;gr>.5&&console.error("SMB ratio increased from default 0.5 to "+gr);var hr=Math.floor(Math.min(tr*gr,mr)*cr)/cr;ar=o(60*(rr=(w-(K+we)/2)/P)/i.current_basal),tr>0&&hr<dr&&(ar=0);var fr=0;ar<=0?ar=0:ar>=30?(ar=30*o(ar/30),ar=Math.min(60,Math.max(0,ar))):(fr=o(v*ar/30,2),ar=30),h.reason+=" insulinReq "+tr,hr>=mr&&(h.reason+="; maxBolus "+mr),ar>0&&(h.reason+="; setting "+ar+"m low temp of "+fr+"U/h"),h.reason+=". ";var pr=3;i.SMBInterval&&(pr=Math.min(10,Math.max(1,i.SMBInterval)));var vr=o(pr-ir,0),br=o(60*(pr-ir),0)%60;if(console.error("naive_eventualBG",K+",",ar+"m "+fr+"U/h temp needed; last bolus",ir+"m ago; maxBolus: "+mr),ir>pr?hr>0&&(h.units=hr,h.reason+="Microbolusing "+hr+"U. "):h.reason+="Waiting "+vr+"m "+br+"s to microbolus again. ",ar>0)return h.rate=fr,h.duration=ar,h}var Br=m.getMaxSafeBasal(i);return nr>Br&&(h.reason+="adj. req. rate: "+nr+" to maxSafeBasal: "+Br+", ",nr=t(Br,i)),(sr=r.duration*(r.rate-v)/60)>=2*tr?(h.reason+=r.duration+"m@"+r.rate.toFixed(2)+" > 2 * insulinReq. Setting temp basal of "+nr+"U/hr. ",m.setTempBasal(nr,30,i,h,r)):void 0===r.duration||0===r.duration?(h.reason+="no temp, setting "+nr+"U/hr. ",m.setTempBasal(nr,30,i,h,r)):r.duration>5&&t(nr,i)<=t(r.rate,i)?(h.reason+="temp "+r.rate+" >~ req "+nr+"U/hr. ",h):(h.reason+="temp "+r.rate+"<"+nr+"U/hr. ",m.setTempBasal(nr,30,i,h,r))}},6880:(e,r,a)=>{var t=a(6654);e.exports=function(e,r){var a=20;void 0!==r&&"string"==typeof r.model&&(t(r.model,"54")||t(r.model,"23"))&&(a=40);return e<1?Math.round(e*a)/a:e<10?Math.round(20*e)/20:Math.round(10*e)/10}},2705:(e,r,a)=>{var t=a(5639).Symbol;e.exports=t},9932:e=>{e.exports=function(e,r){for(var a=-1,t=null==e?0:e.length,o=Array(t);++a<t;)o[a]=r(e[a],a,e);return o}},9750:e=>{e.exports=function(e,r,a){return e==e&&(void 0!==a&&(e=e<=a?e:a),void 0!==r&&(e=e>=r?e:r)),e}},4239:(e,r,a)=>{var t=a(2705),o=a(9607),n=a(2333),s=t?t.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":s&&s in Object(e)?o(e):n(e)}},531:(e,r,a)=>{var t=a(2705),o=a(9932),n=a(1469),s=a(3448),i=t?t.prototype:void 0,l=i?i.toString:void 0;e.exports=function e(r){if("string"==typeof r)return r;if(n(r))return o(r,e)+"";if(s(r))return l?l.call(r):"";var a=r+"";return"0"==a&&1/r==-Infinity?"-0":a}},7561:(e,r,a)=>{var t=a(7990),o=/^\s+/;e.exports=function(e){return e?e.slice(0,t(e)+1).replace(o,""):e}},1957:(e,r,a)=>{var t="object"==typeof a.g&&a.g&&a.g.Object===Object&&a.g;e.exports=t},9607:(e,r,a)=>{var t=a(2705),o=Object.prototype,n=o.hasOwnProperty,s=o.toString,i=t?t.toStringTag:void 0;e.exports=function(e){var r=n.call(e,i),a=e[i];try{e[i]=void 0;var t=!0}catch(e){}var o=s.call(e);return t&&(r?e[i]=a:delete e[i]),o}},2333:e=>{var r=Object.prototype.toString;e.exports=function(e){return r.call(e)}},5639:(e,r,a)=>{var t=a(1957),o="object"==typeof self&&self&&self.Object===Object&&self,n=t||o||Function("return this")();e.exports=n},7990:e=>{var r=/\s/;e.exports=function(e){for(var a=e.length;a--&&r.test(e.charAt(a)););return a}},6654:(e,r,a)=>{var t=a(9750),o=a(531),n=a(554),s=a(9833);e.exports=function(e,r,a){e=s(e),r=o(r);var i=e.length,l=a=void 0===a?i:t(n(a),0,i);return(a-=r.length)>=0&&e.slice(a,l)==r}},1469:e=>{var r=Array.isArray;e.exports=r},3218:e=>{e.exports=function(e){var r=typeof e;return null!=e&&("object"==r||"function"==r)}},7005:e=>{e.exports=function(e){return null!=e&&"object"==typeof e}},3448:(e,r,a)=>{var t=a(4239),o=a(7005);e.exports=function(e){return"symbol"==typeof e||o(e)&&"[object Symbol]"==t(e)}},8601:(e,r,a)=>{var t=a(4841),o=1/0;e.exports=function(e){return e?(e=t(e))===o||e===-1/0?17976931348623157e292*(e<0?-1:1):e==e?e:0:0===e?e:0}},554:(e,r,a)=>{var t=a(8601);e.exports=function(e){var r=t(e),a=r%1;return r==r?a?r-a:r:0}},4841:(e,r,a)=>{var t=a(7561),o=a(3218),n=a(3448),s=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,l=/^0o[0-7]+$/i,u=parseInt;e.exports=function(e){if("number"==typeof e)return e;if(n(e))return NaN;if(o(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=o(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=t(e);var a=i.test(e);return a||l.test(e)?u(e.slice(2),a?2:8):s.test(e)?NaN:+e}},9833:(e,r,a)=>{var t=a(531);e.exports=function(e){return null==e?"":t(e)}}},r={};function a(t){var o=r[t];if(void 0!==o)return o.exports;var n=r[t]={exports:{}};return e[t](n,n.exports,a),n.exports}a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}();var t=a(5546);freeaps_determineBasal=t})();
|