| 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).toFixed(1):Math.round(e)}var s=1;e.exports=function(e,r,a,i,l,m,u,d,c,p){var h={},g=new Date;if(p&&(g=p),void 0===i||void 0===i.current_basal)return h.error="Error: could not get current basal rate",h;var f=t(i.current_basal,i),b=f,v=new Date;p&&(v=p);var B,M=new Date(e.date),_=o((v-M)/60/1e3,1),x=e.glucose,S=e.noise;B=e.delta>-.5?"+"+o(e.delta,0):o(e.delta,0);var G=Math.min(e.delta,e.short_avgdelta),C=Math.min(e.short_avgdelta,e.long_avgdelta),w=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");var y=!1;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")):y=!0),_>12||_<-5?h.reason="If current system time "+v+" is correct, then BG data is too old. The last BG data was read "+_+"m ago at "+M:y&&(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||y)return r.rate>b?(h.reason+=". Replacing high temp basal of "+r.rate+" with neutral temp of "+b,h.deliverAt=g,h.temp="absolute",h.duration=30,h.rate=b,h):0===r.rate&&r.duration>30?(h.reason+=". Shortening "+r.duration+"m long zero temp to 30m. ",h.deliverAt=g,h.temp="absolute",h.duration=30,h.rate=0,h):(h.reason+=". Temp "+r.rate+" <= current basal "+b+"U/hr; doing nothing. ",h);var O,T,A,U=i.max_iob;if(void 0!==i.min_bg&&(T=i.min_bg),void 0!==i.max_bg&&(A=i.max_bg),void 0===i.min_bg||void 0===i.max_bg)return h.error="Error: could not determine target_bg. ",h;O=(i.min_bg+i.max_bg)/2;var I=i.exercise_mode||i.high_temptarget_raises_sensitivity,F=100;if(i.half_basal_exercise_target)var D=i.half_basal_exercise_target;else D=160;if(I&&i.temptargetSet&&O>F||i.low_temptarget_lowers_sensitivity&&i.temptargetSet&&O<F){var j=D-F;s=j/(j+O-F),s=o(s=Math.min(s,i.autosens_max),2),process.stderr.write("Sensitivity ratio set to "+s+" based on temp target of "+O+"; ")}else void 0!==l&&l&&(s=l.ratio,process.stderr.write("Autosens ratio: "+s+"; "));if(s&&(b=i.current_basal*s,(b=t(b,i))!==f?process.stderr.write("Adjusting basal from "+f+" to "+b+"; "):process.stderr.write("Basal unchanged: "+b+"; ")),i.temptargetSet);else if(void 0!==l&&l&&(i.sensitivity_raises_target&&l.ratio<1||i.resistance_lowers_target&&l.ratio>1)){T=o((T-60)/l.ratio)+60,A=o((A-60)/l.ratio)+60;var E=o((O-60)/l.ratio)+60;O===(E=Math.max(80,E))?process.stderr.write("target_bg unchanged: "+E+"; "):process.stderr.write("target_bg from "+O+" to "+E+"; "),O=E}if(e.noise>=2){var q=Math.max(1.1,i.noisyCGMTargetMultiplier),W=(Math.min(250,i.maxRaw),o(Math.min(200,T*q))),R=o(Math.min(200,O*q)),z=o(Math.min(200,A*q));process.stderr.write("Raising target_bg for noisy / raw CGM data, from "+O+" to "+R+"; "),T=W,O=R,A=z}var L=T-.5*(T-40),k=o(i.sens,1),P=i.sens;if(void 0!==l&&l&&((P=o(P=i.sens/s,1))!==k?process.stderr.write("ISF from "+k+" to "+P):process.stderr.write("ISF unchanged: "+P)),console.error("; CR:",i.carb_ratio),P=function(e,r,a,t,n,s,i){if(void 0===a.autoisf_max)return console.error("AutoISF not enabled in preferences"),e;if(a.autoisf_max){var l=t.autoISF_duration,m=t.autoISF_average,u=a.autoisf_hourlychange;if(0==n.mealCOB&&l>=10)if(m>r){var d=a.autoisf_max,c=l/60,p=u/r,h=1+c*p*(m-r),g=Math.min(d,h);console.error("ISFreductionLevel = "+g+" ;");var f=Math.max(g,i);console.error("dura05_weight = "+c+"; avg05_weight = "+p+"; levelISF = "+h+"; liftISF = "+f),console.error("autoISF reports "+e+" did not do it for "+l+"min; go more aggressive by "+o(h,2)),d<h&&console.error("autoISF reduction "+o(h,2)+" limited by autoisf_max "+d),e=o(a.sens/f,1),console.error("sens is now "+e+"; ")}else console.error("autoISF by-passed; avg. glucose "+m+" below target "+r);else n.mealCOB>0?console.error("autoISF by-passed; mealCOB of "+o(n.mealCOB,1)):console.error("autoISF by-passed; BG is only "+l+"min at level "+m);return console.error("AutoISF has run. Sens is now "+e),e}}(P,O,i,e,m,0,s),void 0===a)return h.error="Error: iob_data undefined. ",h;var N,Z=a;if(a.length,a.length>1&&(a=Z[0]),void 0===a.activity||void 0===a.iob)return h.error="Error: iob_data missing some property. ",h;var $=((N=void 0!==a.lastTemp?o((new Date(v).getTime()-a.lastTemp.date)/6e4):0)+r.duration)%30;if(console.error("currenttemp:",r,"lastTempAge:",N,"m","tempModulus:",$,"m"),h.temp="absolute",h.deliverAt=g,d&&r&&a.lastTemp&&r.rate!==a.lastTemp.rate&&N>10&&r.duration)return h.reason="Warning: currenttemp rate "+r.rate+" != lastTemp rate "+a.lastTemp.rate+" from pumphistory; canceling temp",u.setTempBasal(0,0,i,h,r);if(r&&a.lastTemp&&r.duration>0){var H=N-a.lastTemp.duration;if(H>5&&N>10)return h.reason="Warning: currenttemp running but lastTemp from pumphistory ended "+H+"m ago; canceling temp",u.setTempBasal(0,0,i,h,r)}var J=o(-a.activity*P*5,2),K=o(6*(G-J));if(K<0&&(K=o(6*(C-J)))<0&&(K=o(6*(e.long_avgdelta-J))),a.iob>0)var Q=o(x-a.iob*P);else Q=o(x-a.iob*Math.min(P,i.sens));var V=Q+K;if(void 0===V||isNaN(V))return h.error="Error: could not calculate eventualBG. ",h;var X=function(e,r,a){return o(a+(e-r)/24,1)}(O,V,J);h={temp:"absolute",bg:x,tick:B,eventualBG:V,insulinReq:0,reservoir:c,deliverAt:g,sensitivityRatio:s};var Y=[],ee=[],re=[],ae=[];Y.push(x),ee.push(x),ae.push(x),re.push(x);var te=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,m,O),oe=i.enableUAM,ne=0,se=0;ne=o(G-J,1);var ie=o(G-J,1);csf=P/i.carb_ratio,console.error("profile.sens:",i.sens,"sens:",P,"CSF:",csf);var le=o(30*csf*5/60,1);ne>le&&(console.error("Limiting carb impact from",ne,"to",le,"mg/dL/5m (",30,"g/h )"),ne=le);var me=3;s&&(me/=s);var ue=me;if(m.carbs){me=Math.max(me,m.mealCOB/20);var de=o((new Date(v).getTime()-m.lastCarbTime)/6e4),ce=(m.carbs-m.mealCOB)/m.carbs;ue=o(ue=me+1.5*de/60,1),console.error("Last carbs",de,"minutes ago; remainingCATime:",ue,"hours;",o(100*ce)+"% carbs absorbed")}var pe=Math.max(0,ne/5*60*ue/2)/csf,he=90,ge=1;i.remainingCarbsCap&&(he=Math.min(90,i.remainingCarbsCap)),i.remainingCarbsFraction&&(ge=Math.min(1,i.remainingCarbsFraction));var fe=1-ge,be=Math.max(0,m.mealCOB-pe-m.carbs*fe),ve=(be=Math.min(he,be))*csf*5/60/(ue/2),Be=o(m.slopeFromMaxDeviation,2),Me=o(m.slopeFromMinDeviation,2),_e=Math.min(Be,-Me/3);se=0===ne?0:Math.min(60*ue/5/2,Math.max(0,m.mealCOB*csf/ne)),console.error("Carb Impact:",ne,"mg/dL per 5m; CI Duration:",o(5*se/60*2,1),"hours; remaining CI (",ue," peak):",o(ve,1),"mg/dL per 5m");var xe,Se,Ge,Ce,we,ye=999,Oe=999,Te=999,Ae=x,Ue=999,Ie=999,Fe=999,De=999,je=V,Ee=x,qe=x,We=0,Re=[],ze=[];try{Z.forEach((function(e){var r=o(-e.activity*P*5,2),a=o(-e.iobWithZeroTemp.activity*P*5,2),t=ne*(1-Math.min(1,ee.length/12));je=ee[ee.length-1]+r+t;var n=ae[ae.length-1]+a,s=Math.max(0,Math.max(0,ne)*(1-Y.length/Math.max(2*se,1))),i=Math.min(Y.length,12*ue-Y.length),l=Math.max(0,i/(ue/2*12)*ve);s+l,Re.push(o(l,0)),ze.push(o(s,0)),COBpredBG=Y[Y.length-1]+r+Math.min(0,t)+s+l;var m=Math.max(0,ie+re.length*_e),u=Math.max(0,ie*(1-re.length/Math.max(36,1))),d=Math.min(m,u);d>0&&(We=o(5*(re.length+1)/60,1)),UAMpredBG=re[re.length-1]+r+Math.min(0,t)+d,ee.length<48&&ee.push(je),Y.length<48&&Y.push(COBpredBG),re.length<48&&re.push(UAMpredBG),ae.length<48&&ae.push(n),COBpredBG<Ue&&(Ue=o(COBpredBG)),UAMpredBG<Ie&&(Ie=o(UAMpredBG)),je<Fe&&(Fe=o(je)),n<De&&(De=o(n));ee.length>18&&je<ye&&(ye=o(je)),je>Ee&&(Ee=je),(se||ve>0)&&Y.length>18&&COBpredBG<Oe&&(Oe=o(COBpredBG)),(se||ve>0)&&COBpredBG>Ee&&(qe=COBpredBG),oe&&re.length>12&&UAMpredBG<Te&&(Te=o(UAMpredBG)),oe&&UAMpredBG>Ee&&UAMpredBG}))}catch(e){console.error("Problem with iobArray. Optional feature Advanced Meal Assist disabled")}m.mealCOB&&(console.error("predCIs (mg/dL/5m):",ze.join(" ")),console.error("remainingCIs: ",Re.join(" "))),h.predBGs={},ee.forEach((function(e,r,a){a[r]=o(Math.min(401,Math.max(39,e)))}));for(var Le=ee.length-1;Le>12&&ee[Le-1]===ee[Le];Le--)ee.pop();for(h.predBGs.IOB=ee,Ge=o(ee[ee.length-1]),ae.forEach((function(e,r,a){a[r]=o(Math.min(401,Math.max(39,e)))})),Le=ae.length-1;Le>6&&!(ae[Le-1]>=ae[Le]||ae[Le]<=O);Le--)ae.pop();if(h.predBGs.ZT=ae,o(ae[ae.length-1]),m.mealCOB>0&&(ne>0||ve>0)){for(Y.forEach((function(e,r,a){a[r]=o(Math.min(401,Math.max(39,e)))})),Le=Y.length-1;Le>12&&Y[Le-1]===Y[Le];Le--)Y.pop();h.predBGs.COB=Y,Ce=o(Y[Y.length-1]),V=Math.max(V,o(Y[Y.length-1]))}if(ne>0||ve>0){if(oe){for(re.forEach((function(e,r,a){a[r]=o(Math.min(401,Math.max(39,e)))})),Le=re.length-1;Le>12&&re[Le-1]===re[Le];Le--)re.pop();h.predBGs.UAM=re,we=o(re[re.length-1]),re[re.length-1]&&(V=Math.max(V,o(re[re.length-1])))}h.eventualBG=V}console.error("UAM Impact:",ie,"mg/dL per 5m; UAM Duration:",We,"hours"),ye=Math.max(39,ye),Oe=Math.max(39,Oe),Te=Math.max(39,Te),xe=o(ye);var ke=m.mealCOB/m.carbs;Se=o(Te<999&&Oe<999?(1-ke)*UAMpredBG+ke*COBpredBG:Oe<999?(je+COBpredBG)/2:Te<999?(je+UAMpredBG)/2:je),De>Se&&(Se=De),Ae=o(Ae=se||ve>0?oe?ke*Ue+(1-ke)*Ie:Ue:oe?Ie:Fe);var Pe=Te;if(De<L)Pe=(Te+De)/2;else if(De<O){var Ne=(De-L)/(O-L);Pe=(Te+(Te*Ne+De*(1-Ne)))/2}else De>Te&&(Pe=(Te+De)/2);if(Pe=o(Pe),m.carbs)if(!oe&&Oe<999)xe=o(Math.max(ye,Oe));else if(Oe<999){var Ze=ke*Oe+(1-ke)*Pe;xe=o(Math.max(ye,Oe,Ze))}else xe=oe?Pe:Ae;else oe&&(xe=o(Math.max(ye,Pe)));xe=Math.min(xe,Se),process.stderr.write("minPredBG: "+xe+" minIOBPredBG: "+ye+" minZTGuardBG: "+De),Oe<999&&process.stderr.write(" minCOBPredBG: "+Oe),Te<999&&process.stderr.write(" minUAMPredBG: "+Te),console.error(" avgPredBG:",Se,"COB:",m.mealCOB,"/",m.carbs),qe>x&&(xe=Math.min(xe,qe)),h.COB=m.mealCOB,h.IOB=a.iob,h.BGI=J,h.deviation=n(K,i),h.ISF=n(P,i),h.CR=o(i.carb_ratio,2),h.target_bg=n(O,i),h.reason="minPredBG "+n(xe,i)+", minGuardBG "+n(Ae,i)+", IOBpredBG "+n(Ge,i),Ce>0&&(h.reason+=", COBpredBG "+n(Ce,i)),we>0&&(h.reason+=", UAMpredBG "+n(we,i)),h.reason+="; ";var $e=Q;$e<40&&($e=Math.min(Ae,$e));var He,Je=L-$e,Ke=240,Qe=240;if(m.mealCOB>0&&(ne>0||ve>0)){for(Le=0;Le<Y.length;Le++)if(Y[Le]<T){Ke=5*Le;break}for(Le=0;Le<Y.length;Le++)if(Y[Le]<L){Qe=5*Le;break}}else{for(Le=0;Le<ee.length;Le++)if(ee[Le]<T){Ke=5*Le;break}for(Le=0;Le<ee.length;Le++)if(ee[Le]<L){Qe=5*Le;break}}te&&Ae<L&&(console.error("minGuardBG",n(Ae,i),"projected below",n(L,i),"- disabling SMB"),te=!1),void 0===i.maxDelta_bg_threshold&&(He=.2),void 0!==i.maxDelta_bg_threshold&&(He=Math.min(i.maxDelta_bg_threshold,.3)),w>He*x&&(console.error("maxDelta "+n(w,i)+" > "+100*He+"% of BG "+n(x,i)+" - disabling SMB"),h.reason+="maxDelta "+n(w,i)+" > "+100*He+"% of BG "+n(x,i)+": SMB disabled; ",te=!1),console.error("BG projected to remain above",n(T,i),"for",Ke,"minutes"),(Qe<240||Ke<60)&&console.error("BG projected to remain above",n(L,i),"for",Qe,"minutes");var Ve=Qe,Xe=i.current_basal*P*Ve/60,Ye=Math.max(0,m.mealCOB-.25*m.carbs),er=(Je-Xe)/csf-Ye;if(Xe=o(Xe),er=o(er),console.error("naive_eventualBG:",Q,"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<L&&a.iob<20*-i.current_basal/60&&G>0&&G>X)h.reason+="IOB "+a.iob+" < "+o(20*-i.current_basal/60,2),h.reason+=" and minDelta "+n(G,i)+" > expectedDelta "+n(X,i)+"; ";else if(x<L||Ae<L){h.reason+="minGuardBG "+n(Ae,i)+"<"+n(L,i);var rr=(Je=O-Ae)/P,ar=o(60*rr/i.current_basal);return ar=30*o(ar/30),ar=Math.min(120,Math.max(30,ar)),u.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. ",u.setTempBasal(0,0,i,h,r);if(V<T){if(h.reason+="Eventual BG "+n(V,i)+" < "+n(T,i),G>X&&G>0&&!er)return Q<40?(h.reason+=", naive_eventualBG < 40. ",u.setTempBasal(0,30,i,h,r)):(e.delta>G?h.reason+=", but Delta "+n(B,i)+" > expectedDelta "+n(X,i):h.reason+=", but Min. Delta "+G.toFixed(2)+" > Exp. Delta "+n(X,i),r.duration>15&&t(b,i)===t(r.rate,i)?(h.reason+=", temp "+r.rate+" ~ req "+b+"U/hr. ",h):(h.reason+="; setting current basal of "+b+" as temp. ",u.setTempBasal(b,30,i,h,r)));var tr=2*Math.min(0,(V-O)/P);tr=o(tr,2);var or=Math.min(0,(Q-O)/P);if(or=o(or,2),G<0&&G>X)tr=o(tr*(G/X),2);var nr=b+2*tr;nr=t(nr,i);var sr=r.duration*(r.rate-b)/60;if(sr<Math.min(tr,or)-.3*b)return h.reason+=", "+r.duration+"m@"+r.rate.toFixed(2)+" is a lot less than needed. ",u.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=O-Q)/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. ",u.setTempBasal(nr,ar,i,h,r)}else h.reason+=", setting "+nr+"U/hr. ";return u.setTempBasal(nr,30,i,h,r)}if(G<X&&(!d||!te))return e.delta<G?h.reason+="Eventual BG "+n(V,i)+" > "+n(T,i)+" but Delta "+n(B,i)+" < Exp. Delta "+n(X,i):h.reason+="Eventual BG "+n(V,i)+" > "+n(T,i)+" but Min. Delta "+G.toFixed(2)+" < Exp. Delta "+n(X,i),r.duration>15&&t(b,i)===t(r.rate,i)?(h.reason+=", temp "+r.rate+" ~ req "+b+"U/hr. ",h):(h.reason+="; setting current basal of "+b+" as temp. ",u.setTempBasal(b,30,i,h,r));if(Math.min(V,xe)<A&&(!d||!te))return h.reason+=n(V,i)+"-"+n(xe,i)+" in range: no temp required",r.duration>15&&t(b,i)===t(r.rate,i)?(h.reason+=", temp "+r.rate+" ~ req "+b+"U/hr. ",h):(h.reason+="; setting current basal of "+b+" as temp. ",u.setTempBasal(b,30,i,h,r));if(V>=A&&(h.reason+="Eventual BG "+n(V,i)+" >= "+n(A,i)+", "),a.iob>U)return h.reason+="IOB "+o(a.iob,2)+" > max_iob "+U,r.duration>15&&t(b,i)===t(r.rate,i)?(h.reason+=", temp "+r.rate+" ~ req "+b+"U/hr. ",h):(h.reason+="; setting current basal of "+b+" as temp. ",u.setTempBasal(b,30,i,h,r));(tr=o((Math.min(xe,V)-O)/P,2))>U-a.iob&&(h.reason+="max_iob "+U+", ",tr=U-a.iob),nr=t(nr=b+2*tr,i),tr=o(tr,3),h.insulinReq=tr;var ir=o((new Date(v).getTime()-a.lastBolusTime)/6e4,1);if(d&&te&&x>L){var lr=o(m.mealCOB/i.carb_ratio,3),mr=i.smb_max_range_extension;if(mr>1&&console.error("SMB max range extended from default by factor "+mr),void 0===i.maxSMBBasalMinutes){var ur=o(mr*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",m.mealCOB+"; mealInsulinReq =",lr),i.maxUAMSMBBasalMinutes?(console.error("profile.maxUAMSMBBasalMinutes:",i.maxUAMSMBBasalMinutes,"profile.current_basal:",i.current_basal),ur=o(i.current_basal*i.maxUAMSMBBasalMinutes/60,1)):(console.error("profile.maxUAMSMBBasalMinutes undefined: defaulting to 30m"),ur=o(30*i.current_basal/60,1))):(console.error("profile.maxSMBBasalMinutes:",i.maxSMBBasalMinutes,"profile.current_basal:",i.current_basal),ur=o(i.current_basal*i.maxSMBBasalMinutes/60,1));var dr=i.bolus_increment,cr=1/dr,pr=i.smb_delivery_ratio;pr>.5&&console.error("SMB ratio increased from default 0.5 to "+pr);var hr=Math.floor(Math.min(tr*pr,ur)*cr)/cr;ar=o(60*(rr=(O-(Q+ye)/2)/P)/i.current_basal),tr>0&&hr<dr&&(ar=0);var gr=0;ar<=0?ar=0:ar>=30?(ar=30*o(ar/30),ar=Math.min(60,Math.max(0,ar))):(gr=o(b*ar/30,2),ar=30),h.reason+=" insulinReq "+tr,hr>=ur&&(h.reason+="; maxBolus "+ur),ar>0&&(h.reason+="; setting "+ar+"m low temp of "+gr+"U/h"),h.reason+=". ";var fr=3;i.SMBInterval&&(fr=Math.min(10,Math.max(1,i.SMBInterval)));var br=o(fr-ir,0),vr=o(60*(fr-ir),0)%60;if(console.error("naive_eventualBG",Q+",",ar+"m "+gr+"U/h temp needed; last bolus",ir+"m ago; maxBolus: "+ur),ir>fr?hr>0&&(h.units=hr,h.reason+="Microbolusing "+hr+"U. "):h.reason+="Waiting "+br+"m "+vr+"s to microbolus again. ",ar>0)return h.rate=gr,h.duration=ar,h}var Br=u.getMaxSafeBasal(i);return nr>Br&&(h.reason+="adj. req. rate: "+nr+" to maxSafeBasal: "+Br+", ",nr=t(Br,i)),(sr=r.duration*(r.rate-b)/60)>=2*tr?(h.reason+=r.duration+"m@"+r.rate.toFixed(2)+" > 2 * insulinReq. Setting temp basal of "+nr+"U/hr. ",u.setTempBasal(nr,30,i,h,r)):void 0===r.duration||0===r.duration?(h.reason+="no temp, setting "+nr+"U/hr. ",u.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. ",u.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,m=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)?m(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})();
|