diff --git a/FreeAPS/Resources/javascript/bundle/determine-basal.js b/FreeAPS/Resources/javascript/bundle/determine-basal.js index 88cf516e01..0ad056a2fd 100644 --- a/FreeAPS/Resources/javascript/bundle/determine-basal.js +++ b/FreeAPS/Resources/javascript/bundle/determine-basal.js @@ -1,2 +1 @@ - -var freeaps_determineBasal;(()=>{var e={5546:(e,t,a)=>{var r=a(6880);function o(e,t){t||(t=0);var a=Math.pow(10,t);return Math.round(e*a)/a}function n(e,t){return"mmol/L"===t.out_units?o(.0555*e,1):Math.round(e)}e.exports=function(e,t,a,i,s,l,m,u,d,c,g,h,p,f){var v=i.min_bg,B=f.overrideTarget,b=0,M="",_="",y="",x="",D="",S=0,w=0,T=0,C=0,U=0,G=0;const O=f.weightedAverage;var R=1,A=i.sens,I=i.carb_ratio;f.useOverride&&(A/=R=f.overridePercentage/100,I/=R);const j=i.weightPercentage,F=f.average_total_data;function P(e,t){var a=e.getTime();return new Date(a+36e5*t)}function E(e){var t=i.bolus_increment;.025!=t&&(t=.05);var a=e/t;return a>=1?o(Math.floor(a)*t,5):0}function q(e){function t(e){return e<10&&(e="0"+e),e}return t(e.getHours())+":"+t(e.getMinutes())+":00"}function W(e,t){var a=new Date("1/1/1999 "+e),r=new Date("1/1/1999 "+t);return(a.getTime()-r.getTime())/36e5}function k(e,t){var a=0,r=t,o=(e-t)/36e5,n=0,i=o,s=0;do{if(o>0){var l=q(r),m=p[0].rate;for(let e=0;e=(s=W(p[e+1].start,p[e].start))?n=s:o=(s=24-W(p[e].start,t))?n=s:ou)if(e+1=(s=W(d,l))?n=s:o=(s=W("23:59:59",l))?n=s:o0&&o21)U=k(L,(N=24-b,H=L.getTime(),new Date(H-36e5*N))),x="24 hours of data is required for an accurate tdd calculation. Currently only "+b.toPrecision(3)+" hours of pump history data are available. Using your pump scheduled basals to fill in the missing hours. Scheduled basals added: "+U.toPrecision(5)+" U. ";else b<21?(re=!1,enableDynamicCR=!1):x=""}else console.log("Pumphistory is empty!"),re=!1,enableDynamicCR=!1;var N,H;for(let e=0;e0){S=e,G=g[e].rate;var Z=g[e-1]["duration (min)"]/60,$=Z,J=new Date(g[e-1].timestamp),K=J,Q=0;do{if(e--,0==e){K=new Date;break}if("TempBasal"==g[e]._type||"PumpSuspend"==g[e]._type){K=new Date(g[e].timestamp);break}var V=e-2;if(V>=0&&"Rewind"==g[V]._type){let e=g[V].timestamp;for(;V-1>=0&&"Prime"==g[V-=1]._type;)Q=(g[V].timestamp-e)/36e5;Q>=Z&&(K=e,Q=0)}}while(e>0);var X=(K-J)/36e5;X<$&&(Z=X),T+=E(G*(Z-Q)),e=S}for(let e=0;e0&&(--r,"TempBasal"==g[r]._type)){a=new Date(g[r].timestamp);break}}while(r>0);(a-t)/36e5>0&&(U+=k(a,t))}for(let e=g.length-1;e>0;e--)if("TempBasalDuration"==g[e]._type){let t=g[e]["duration (min)"]/60,a=new Date(g[e].timestamp);var Y=a;let r=e;do{if(--r,r>=0&&("TempBasal"==g[r]._type||"PumpSuspend"==g[r]._type)){Y=new Date(g[r].timestamp);break}}while(r>0);if(0==e&&"TempBasalDuration"==g[0]._type&&(Y=new Date,t=g[e]["duration (min)"]/60),(Y-a)/36e5-t>0){U+=k(Y,P(a,t))}}var ee,te={TDD:o(w=C+T+U,5),bolus:o(C,5),temp_basal:o(T,5),scheduled_basal:o(U,5)};b>21?(_=". Bolus insulin: "+C.toPrecision(5)+" U",y=". Temporary basal insulin: "+T.toPrecision(5)+" U",M=". Insulin with scheduled basal rate: "+U.toPrecision(5)+" U",D=x+(" TDD past 24h is: "+w.toPrecision(5)+" U")+_+y+M,tddReason=", Total insulin: "+o(w,2)+" U, "+o(C/w*100,0)+"% Bolus "+o((T+U)/w*100,0)+"% Basal"):tddReason=", TDD: Not enough pumpData (< 21h)";const ae=e.glucose;var re=h.useNewFormula;const oe=h.enableDynamicCR,ne=Math.min(i.autosens_min,i.autosens_max),ie=Math.max(i.autosens_min,i.autosens_max),se=h.adjustmentFactor,le=i.min_bg;var me=!1,ue="",de=1,ce="";F>0&&(de=O/F),ce=de>1?"Basal adjustment with a 24 hour to total average (up to 14 days of data) TDD ratio (limited by Autosens max setting). Basal Ratio: "+(de=o(de=Math.min(de,i.autosens_max),2))+". Upper limit = Autosens max ("+i.autosens_max+")":de<1?"Basal adjustment with a 24 hour to to total average (up to 14 days of data) TDD ratio (limited by Autosens min setting). Basal Ratio: "+(de=o(de=Math.max(de,i.autosens_min),2))+". Lower limit = Autosens min ("+i.autosens_min+")":"Basal adjusted with a 24 hour to total average (up to 14 days of data) TDD ratio: "+de,ce=", Basal ratio: "+de,(i.high_temptarget_raises_sensitivity||i.exercise_mode||f.isEnabled)&&(me=!0),le>=118&&me&&(re=!1,ue="Dynamic ISF temporarily off due to a high temp target/exercising. Current min target: "+le);var ge=", Dynamic ratios log: ",he=", AF: "+se,pe="BG: "+ae+" mg/dl ("+(.0555*ae).toPrecision(2)+" mmol/l)",fe="",ve="";const Be=h.curve,be=h.insulinPeakTime,Me=h.useCustomPeakTime;var _e=55,ye=65;switch(Be){case"rapid-acting":ye=65;break;case"ultra-rapid":ye=50}Me?(_e=120-be,console.log("Custom insulinpeakTime set to :"+be+", insulinFactor: "+_e)):(_e=120-ye,console.log("insulinFactor set to : "+_e)),ee=w,j<1&&O>0&&(w=O,console.log("Using weighted TDD average: "+o(w,2)+" U, instead of past 24 h ("+o(ee,2)+" U), weight: "+j),ve=", Weighted TDD: "+o(w,2)+" U");const xe=h.sigmoid;var De="";if(re){var Se=A*se*w*Math.log(ae/_e+1)/1800;fe=", Logarithmic formula"}if(re&&xe){const e=ne,t=ie-e,a=.0555*(ae-i.min_bg);var we=de;const r=ie-1,o=Math.log10(1/r-e/r)/Math.log10(Math.E),n=a*se*we+o;Se=t/(1+Math.exp(-n))+e,fe=", Sigmoid function"}var Te=I;const Ce=o(I,1);var Ue="",Ge="";if(re&&w>0){if(Ue=", Dynamic ISF/CR: On/",Se>ie?(ue=", Dynamic ISF limited by autosens_max setting: "+ie+" ("+o(Se,2)+"), ",Ge=", Autosens/Dynamic Limit: "+ie+" ("+o(Se,2)+")",Se=ie):Se1&&(Oe=(Se-1)/2+1);var Re=" CR: "+(Te=o(Te/Oe,2))+" g/U";I=Te}else Re=" CR: "+Te+" g/U",Ue+="Off";const e=A/Se;De=". Using Sigmoid function, the autosens ratio has been adjusted with sigmoid factor to: "+o(s.ratio,2)+". New ISF = "+o(e,2)+" mg/dl ("+o(.0555*e,2)+" (mmol/l). CR adjusted from "+o(Ce,2)+" to "+o(Te,2)+" ("+o(.0555*I,2)+" mmol/l).",ue+=xe?De:", Dynamic autosens.ratio set to "+o(Se,2)+" with ISF: "+e.toPrecision(3)+" mg/dl/U ("+(.0555*e).toPrecision(3)+" mmol/l/U)",s.ratio=Se,D+=ge+pe+he+fe+ue+Ue+Re+ve}else D+=ge+"Dynamic Settings disabled";console.log(D),re||oe?re&&i.tddAdjBasal?tddReason+=Ue+fe+Ge+he+ce:re&&!i.tddAdjBasal&&(tddReason+=Ue+fe+Ge+he):tddReason+="";var Ae={},Ie=new Date;if(c&&(Ie=c),void 0===i||void 0===i.current_basal)return Ae.error="Error: could not get current basal rate",Ae;var je=r(i.current_basal,i)*R,Fe=je;f.useOverride&&(0==f.duration?console.log("Profile Override is active. Override "+o(100*R,0)+"%. Override Duration: Enabled indefinitely"):console.log("Profile Override is active. Override "+o(100*R,0)+"%. Override Expires in: "+f.duration+" min."));var Pe=new Date;c&&(Pe=c);var Ee,qe=new Date(e.date),We=o((Pe-qe)/60/1e3,1),ke=e.glucose,Le=e.noise;Ee=e.delta>-.5?"+"+o(e.delta,0):o(e.delta,0);var ze=Math.min(e.delta,e.short_avgdelta),Ne=Math.min(e.short_avgdelta,e.long_avgdelta),He=Math.max(e.delta,e.short_avgdelta,e.long_avgdelta);(ke<=10||38===ke||Le>=3)&&(Ae.reason="CGM is calibrating, in ??? state, or noise is high");if(ke>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 ("+n(ke,i)+"+"+n(e.delta,i)+") for 5m w/ "+n(e.short_avgdelta,i)+" mg/dL ~15m change & "+n(e.long_avgdelta,2)+" mg/dL ~45m change"),console.error("Simulator mode detected ("+e.device+"): continuing anyway")):!0),We>12||We<-5?Ae.reason="If current system time "+Pe+" is correct, then BG data is too old. The last BG data was read "+We+"m ago at "+qe:0===e.short_avgdelta&&0===e.long_avgdelta&&(e.last_cal&&e.last_cal<3?Ae.reason="CGM was just calibrated":Ae.reason="CGM data is unchanged ("+n(ke,i)+"+"+n(e.delta,i)+") for 5m w/ "+n(e.short_avgdelta,i)+" mg/dL ~15m change & "+n(e.long_avgdelta,i)+" mg/dL ~45m change"),ke<=10||38===ke||Le>=3||We>12||We<-5||0===e.short_avgdelta&&0===e.long_avgdelta)return t.rate>=Fe?(Ae.reason+=". Canceling high temp basal of "+t.rate,Ae.deliverAt=Ie,Ae.temp="absolute",Ae.duration=0,Ae.rate=0,Ae):0===t.rate&&t.duration>30?(Ae.reason+=". Shortening "+t.duration+"m long zero temp to 30m. ",Ae.deliverAt=Ie,Ae.temp="absolute",Ae.duration=30,Ae.rate=0,Ae):(Ae.reason+=". Temp "+t.rate+" <= current basal "+Fe+"U/hr; doing nothing. ",Ae);var Ze,$e,Je,Ke,Qe=i.max_iob;if(void 0!==i.min_bg&&($e=i.min_bg),void 0!==i.max_bg&&(Je=i.max_bg),void 0!==i.enableSMB_high_bg_target&&(Ke=i.enableSMB_high_bg_target),void 0===i.min_bg||void 0===i.max_bg)return Ae.error="Error: could not determine target_bg. ",Ae;Ze=(i.min_bg+i.max_bg)/2;var Ve=i.exercise_mode||i.high_temptarget_raises_sensitivity||f.isEnabled,Xe=100,Ye=160;if(Ye=i.half_basal_exercise_target,f.isEnabled){const e=f.hbt;console.log("Half Basal Target used: "+n(e,i)+" "+i.out_units),Ye=e}else console.log("Default Half Basal Target used: "+n(Ye,i)+" "+i.out_units);if(Ve&&i.temptargetSet&&Ze>Xe||i.low_temptarget_lowers_sensitivity&&i.temptargetSet&&Ze=Ze&&sensitivityRatio0&&(process.stderr.write("TDD-adjustment of basals activated, using tdd24h_14d_Ratio "+o(de,2)+", TDD 24h = "+o(ee,2)+"U, Weighted average TDD = "+o(O,2)+"U, (Weight percentage = "+j+"), Total data of TDDs (up to 14 days) average = "+o(F,2)+"U. "),Fe!==je*R?process.stderr.write("Adjusting basal from "+je*R+" U/h to "+Fe+" U/h; "):process.stderr.write("Basal unchanged: "+Fe+" U/h; "))),i.temptargetSet);else if(void 0!==s&&s&&(i.sensitivity_raises_target&&s.ratio<1||i.resistance_lowers_target&&s.ratio>1)){$e=o(($e-60)/s.ratio)+60,Je=o((Je-60)/s.ratio)+60;var tt=o((Ze-60)/s.ratio)+60;Ze===(tt=Math.max(80,tt))?process.stderr.write("target_bg unchanged: "+n(tt,i)+"; "):process.stderr.write("target_bg from "+n(tt,i)+" to "+n(tt,i)+"; "),Ze=tt}var at=n(Ze,i);Ze!=v&&(at=0!==B&&B!==Ze?n(v,i)+"→"+n(B,i)+"→"+n(Ze,i):n(v,i)+"→"+n(Ze,i));var rt=200,ot=200,nt=200;if(e.noise>=2){var it=Math.max(1.1,i.noisyCGMTargetMultiplier);Math.min(250,i.maxRaw);rt=o(Math.min(200,$e*it)),ot=o(Math.min(200,Ze*it)),nt=o(Math.min(200,Je*it)),process.stderr.write("Raising target_bg for noisy / raw CGM data, from "+n(tt,i)+" to "+n(ot,i)+"; "),$e=rt,Ze=ot,Je=nt}var st=$e-.5*($e-40),lt=i.threshold_setting;lt>st&<<=120&<>=65?(console.error("Threshold changed in settings from "+n(st,i)+" to "+n(lt,i)+". "),st=lt):console.error("Current threshold: "+n(st,i));var mt="",ut=(o(A,1),A);if(void 0!==s&&s&&((ut=o(ut=A/sensitivityRatio,1))!==A?process.stderr.write("ISF from "+n(A,i)+" to "+n(ut,i)):process.stderr.write("ISF unchanged: "+n(ut,i)),mt+="Autosens ratio: "+o(sensitivityRatio,2)+", ISF: "+n(A,i)+"→"+n(ut,i)),console.error("CR:"+I),void 0===a)return Ae.error="Error: iob_data undefined. ",Ae;var dt,ct=a;if(a.length,a.length>1&&(a=ct[0]),void 0===a.activity||void 0===a.iob)return Ae.error="Error: iob_data missing some property. ",Ae;var gt=((dt=void 0!==a.lastTemp?o((new Date(Pe).getTime()-a.lastTemp.date)/6e4):0)+t.duration)%30;if(console.error("currenttemp:"+t.rate+" lastTempAge:"+dt+"m, tempModulus:"+gt+"m"),Ae.temp="absolute",Ae.deliverAt=Ie,u&&t&&a.lastTemp&&t.rate!==a.lastTemp.rate&&dt>10&&t.duration)return Ae.reason="Warning: currenttemp rate "+t.rate+" != lastTemp rate "+a.lastTemp.rate+" from pumphistory; canceling temp",m.setTempBasal(0,0,i,Ae,t);if(t&&a.lastTemp&&t.duration>0){var ht=dt-a.lastTemp.duration;if(ht>5&&dt>10)return Ae.reason="Warning: currenttemp running but lastTemp from pumphistory ended "+ht+"m ago; canceling temp",m.setTempBasal(0,0,i,Ae,t)}var pt=o(-a.activity*ut*5,2),ft=o(6*(ze-pt));ft<0&&(ft=o(6*(Ne-pt)))<0&&(ft=o(6*(e.long_avgdelta-pt)));var vt=ke,Bt=(vt=a.iob>0?o(ke-a.iob*ut):o(ke-a.iob*Math.min(ut,A)))+ft;if(void 0===Bt||isNaN(Bt))return Ae.error="Error: could not calculate eventualBG. Sensitivity: "+ut+" Deviation: "+ft,Ae;var bt=function(e,t,a){return o(a+(e-t)/24,1)}(Ze,Bt,pt);Ae={temp:"absolute",bg:ke,tick:Ee,eventualBG:Bt,insulinReq:0,reservoir:d,deliverAt:Ie,sensitivityRatio,TDD:ee,insulin:te,current_target:Ze};var Mt=[],_t=[],yt=[],xt=[];Mt.push(ke),_t.push(ke),xt.push(ke),yt.push(ke);var Dt=function(e,t,a,r,o,i){return t?!e.allowSMB_with_high_temptarget&&e.temptargetSet&&o>100?(console.error("SMB disabled due to high temptarget of "+o),!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&&o<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(o,e)),!0):!0===e.enableSMB_high_bg&&null!==i&&r>=i?(console.error("Checking BG to see if High for SMB enablement."),console.error("Current BG",r," | High BG ",i),a.bwFound?console.error("Warning: High BG SMB enabled within 6h of using Bolus Wizard: be sure to easy bolus 30s before using Bolus Wizard"):console.error("High BG detected. Enabling SMB."),!0):(console.error("SMB disabled (no enableSMB preferences active or no condition satisfied)"),!1):(console.error("SMB disabled (!microBolusAllowed)"),!1)}(i,u,l,ke,Ze,Ke),St=i.enableUAM,wt=0,Tt=0;wt=o(ze-pt,1);var Ct=o(ze-pt,1);csf=ut/I,console.error("profile.sens:"+n(A,i)+", sens:"+n(ut,i)+", CSF:"+o(csf,1));var Ut=o(30*csf*5/60,1);wt>Ut&&(console.error("Limiting carb impact from "+wt+" to "+Ut+"mg/dL/5m (30g/h)"),wt=Ut);var Gt=3;sensitivityRatio&&(Gt/=sensitivityRatio);var Ot=Gt;if(l.carbs){Gt=Math.max(Gt,l.mealCOB/20);var Rt=o((new Date(Pe).getTime()-l.lastCarbTime)/6e4),At=(l.carbs-l.mealCOB)/l.carbs;Ot=o(Ot=Gt+1.5*Rt/60,1),console.error("Last carbs "+Rt+" minutes ago; remainingCATime:"+Ot+"hours; "+o(100*At,1)+"% carbs absorbed")}var It=Math.max(0,wt/5*60*Ot/2)/csf,jt=90,Ft=1;i.remainingCarbsCap&&(jt=Math.min(90,i.remainingCarbsCap)),i.remainingCarbsFraction&&(Ft=Math.min(1,i.remainingCarbsFraction));var Pt=1-Ft,Et=Math.max(0,l.mealCOB-It-l.carbs*Pt),qt=(Et=Math.min(jt,Et))*csf*5/60/(Ot/2),Wt=o(l.slopeFromMaxDeviation,2),kt=o(l.slopeFromMinDeviation,2),Lt=Math.min(Wt,-kt/3);Tt=0===wt?0:Math.min(60*Ot/5/2,Math.max(0,l.mealCOB*csf/wt)),console.error("Carb Impact:"+wt+"mg/dL per 5m; CI Duration:"+o(5*Tt/60*2,1)+"hours; remaining CI ("+Ot/2+"h peak):"+o(qt,1)+"mg/dL per 5m");var zt,Nt,Ht,Zt,$t,Jt=999,Kt=999,Qt=999,Vt=ke,Xt=999,Yt=999,ea=999,ta=999,aa=Bt,ra=ke,oa=ke,na=0,ia=[],sa=[];try{ct.forEach((function(e){var t=o(-e.activity*ut*5,2),a=o(-e.iobWithZeroTemp.activity*ut*5,2),r=vt,n=wt*(1-Math.min(1,_t.length/12));if(!0===(re&&!xe))aa=_t[_t.length-1]+o(-e.activity*(1800/(w*se*Math.log(Math.max(_t[_t.length-1],39)/_e+1)))*5,2)+n,r=xt[xt.length-1]+o(-e.iobWithZeroTemp.activity*(1800/(w*se*Math.log(Math.max(xt[xt.length-1],39)/_e+1)))*5,2),console.log("Dynamic ISF (Logarithmic Formula) )adjusted predictions for IOB and ZT: IOBpredBG: "+o(aa,2)+" , ZTpredBG: "+o(r,2));else aa=_t[_t.length-1]+t+n,r=xt[xt.length-1]+a;var i=Math.max(0,Math.max(0,wt)*(1-Mt.length/Math.max(2*Tt,1))),s=Math.min(Mt.length,12*Ot-Mt.length),l=Math.max(0,s/(Ot/2*12)*qt);i+l,ia.push(o(l,0)),sa.push(o(i,0)),COBpredBG=Mt[Mt.length-1]+t+Math.min(0,n)+i+l;var m=Math.max(0,Ct+yt.length*Lt),u=Math.max(0,Ct*(1-yt.length/Math.max(36,1))),d=Math.min(m,u);if(d>0&&(na=o(5*(yt.length+1)/60,1)),!0===(re&&!xe))UAMpredBG=yt[yt.length-1]+o(-e.activity*(1800/(w*se*Math.log(Math.max(yt[yt.length-1],39)/_e+1)))*5,2)+Math.min(0,n)+d,console.log("Dynamic ISF (Logarithmic Formula) adjusted prediction for UAM: UAMpredBG: "+o(UAMpredBG,2));else UAMpredBG=yt[yt.length-1]+t+Math.min(0,n)+d;_t.length<48&&_t.push(aa),Mt.length<48&&Mt.push(COBpredBG),yt.length<48&&yt.push(UAMpredBG),xt.length<48&&xt.push(r),COBpredBG18&&aara&&(ra=aa),(Tt||qt>0)&&Mt.length>18&&COBpredBG0)&&COBpredBG>ra&&(oa=COBpredBG),St&&yt.length>12&&UAMpredBGra&&UAMpredBG}))}catch(e){console.error("Problem with iobArray. Optional feature Advanced Meal Assist disabled")}l.mealCOB&&(console.error("predCIs (mg/dL/5m):"+sa.join(" ")),console.error("remainingCIs: "+ia.join(" "))),Ae.predBGs={},_t.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))}));for(var la=_t.length-1;la>12&&_t[la-1]===_t[la];la--)_t.pop();for(Ae.predBGs.IOB=_t,Ht=o(_t[_t.length-1]),xt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),la=xt.length-1;la>6&&!(xt[la-1]>=xt[la]||xt[la]<=Ze);la--)xt.pop();if(Ae.predBGs.ZT=xt,o(xt[xt.length-1]),l.mealCOB>0&&(wt>0||qt>0)){for(Mt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),la=Mt.length-1;la>12&&Mt[la-1]===Mt[la];la--)Mt.pop();Ae.predBGs.COB=Mt,Zt=o(Mt[Mt.length-1]),Bt=Math.max(Bt,o(Mt[Mt.length-1]))}if(wt>0||qt>0){if(St){for(yt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),la=yt.length-1;la>12&&yt[la-1]===yt[la];la--)yt.pop();Ae.predBGs.UAM=yt,$t=o(yt[yt.length-1]),yt[yt.length-1]&&(Bt=Math.max(Bt,o(yt[yt.length-1])))}Ae.eventualBG=Bt}console.error("UAM Impact:"+Ct+"mg/dL per 5m; UAM Duration:"+na+"hours"),Jt=Math.max(39,Jt),Kt=Math.max(39,Kt),Qt=Math.max(39,Qt),zt=o(Jt);var ma=l.mealCOB/l.carbs;Nt=o(Qt<999&&Kt<999?(1-ma)*UAMpredBG+ma*COBpredBG:Kt<999?(aa+COBpredBG)/2:Qt<999?(aa+UAMpredBG)/2:aa),ta>Nt&&(Nt=ta),Vt=o(Vt=Tt||qt>0?St?ma*Xt+(1-ma)*Yt:Xt:St?Yt:ea);var ua=Qt;if(taQt&&(ua=(Qt+ta)/2);if(ua=o(ua),l.carbs)if(!St&&Kt<999)zt=o(Math.max(Jt,Kt));else if(Kt<999){var ca=ma*Kt+(1-ma)*ua;zt=o(Math.max(Jt,Kt,ca))}else zt=St?ua:Vt;else St&&(zt=o(Math.max(Jt,ua)));zt=Math.min(zt,Nt),process.stderr.write("minPredBG: "+zt+" minIOBPredBG: "+Jt+" minZTGuardBG: "+ta),Kt<999&&process.stderr.write(" minCOBPredBG: "+Kt),Qt<999&&process.stderr.write(" minUAMPredBG: "+Qt),console.error(" avgPredBG:"+Nt+" COB/Carbs:"+l.mealCOB+"/"+l.carbs),oa>ke&&(zt=Math.min(zt,oa)),Ae.COB=l.mealCOB,Ae.IOB=a.iob,Ae.BGI=n(pt,i),Ae.deviation=n(ft,i),Ae.ISF=n(ut,i),Ae.CR=o(I,1),Ae.target_bg=n(Ze,i),Ae.TDD=o(ee,2),Ae.current_target=o(Ze,0);var ga=Ae.CR;Ce!=Ae.CR&&(ga=Ce+"→"+Ae.CR),Ae.reason=mt+", COB: "+Ae.COB+", Dev: "+Ae.deviation+", BGI: "+Ae.BGI+", CR: "+ga+", Target: "+at+", minPredBG "+n(zt,i)+", minGuardBG "+n(Vt,i)+", IOBpredBG "+n(Ht,i),Zt>0&&(Ae.reason+=", COBpredBG "+n(Zt,i)),$t>0&&(Ae.reason+=", UAMpredBG "+n($t,i)),Ae.reason+=tddReason,Ae.reason+="; ";var ha=vt;ha<40&&(ha=Math.min(Vt,ha));var pa,fa=st-ha,va=240,Ba=240;if(l.mealCOB>0&&(wt>0||qt>0)){for(la=0;lapa*ke&&(console.error("maxDelta "+n(He,i)+" > "+100*pa+"% of BG "+n(ke,i)+" - disabling SMB"),Ae.reason+="maxDelta "+n(He,i)+" > "+100*pa+"% of BG "+n(ke,i)+" - SMB disabled!, ",Dt=!1),console.error("BG projected to remain above "+n($e,i)+" for "+va+"minutes"),(Ba<240||va<60)&&console.error("BG projected to remain above "+n(st,i)+" for "+Ba+"minutes");var ba=Ba,Ma=i.current_basal*R*ut*ba/60,_a=Math.max(0,l.mealCOB-.25*l.carbs),ya=(fa-Ma)/csf-_a;Ma=o(Ma),ya=o(ya),console.error("naive_eventualBG:",vt,"bgUndershoot:",fa,"zeroTempDuration:",ba,"zeroTempEffect:",Ma,"carbsReq:",ya),"Could not parse clock data"==l.reason?console.error("carbsReq unknown: Could not parse clock data"):ya>=i.carbsReqThreshold&&Ba<=45&&(Ae.carbsReq=ya,Ae.reason+=ya+" add'l carbs req w/in "+Ba+"m; ");var xa=0;if(ke0&&ze>bt)Ae.reason+="IOB "+a.iob+" < "+o(-i.current_basal*R*20/60,2),Ae.reason+=" and minDelta "+n(ze,i)+" > expectedDelta "+n(bt,i)+"; ";else if(ke=55)return Ae.reason+="; Canceling temp at "+Ae.deliverAt.getMinutes()+"m past the hour. ",m.setTempBasal(0,0,i,Ae,t);var Da=0,Sa=Fe;if(Bt<$e){if(Ae.reason+="Eventual BG "+n(Bt,i)+" < "+n($e,i),ze>bt&&ze>0&&!ya)return vt<40?(Ae.reason+=", naive_eventualBG < 40. ",m.setTempBasal(0,30,i,Ae,t)):(e.delta>ze?Ae.reason+=", but Delta "+n(Ee,i)+" > expectedDelta "+n(bt,i):Ae.reason+=", but Min. Delta "+ze.toFixed(2)+" > Exp. Delta "+n(bt,i),t.duration>15&&r(Fe,i)===r(t.rate,i)?(Ae.reason+=", temp "+t.rate+" ~ req "+Fe+"U/hr. ",Ae):(Ae.reason+="; setting current basal of "+Fe+" as temp. ",m.setTempBasal(Fe,30,i,Ae,t)));Da=o(Da=2*Math.min(0,(Bt-Ze)/ut),2);var wa=Math.min(0,(vt-Ze)/ut);if(wa=o(wa,2),ze<0&&ze>bt)Da=o(Da*(ze/bt),2);if(Sa=r(Sa=Fe+2*Da,i),t.duration*(t.rate-Fe)/605&&Sa>=.8*t.rate)return Ae.reason+=", temp "+t.rate+" ~< req "+Sa+"U/hr. ",Ae;if(Sa<=0){if((xa=o(60*((fa=Ze-vt)/ut)/i.current_basal*R))<0?xa=0:(xa=30*o(xa/30),xa=Math.min(120,Math.max(0,xa))),xa>0)return Ae.reason+=", setting "+xa+"m zero temp. ",m.setTempBasal(Sa,xa,i,Ae,t)}else Ae.reason+=", setting "+Sa+"U/hr. ";return m.setTempBasal(Sa,30,i,Ae,t)}if(ze "+n($e,i)+" but Delta "+n(Ee,i)+" < Exp. Delta "+n(bt,i):Ae.reason+="Eventual BG "+n(Bt,i)+" > "+n($e,i)+" but Min. Delta "+ze.toFixed(2)+" < Exp. Delta "+n(bt,i),t.duration>15&&r(Fe,i)===r(t.rate,i)?(Ae.reason+=", temp "+t.rate+" ~ req "+Fe+"U/hr. ",Ae):(Ae.reason+="; setting current basal of "+Fe+" as temp. ",m.setTempBasal(Fe,30,i,Ae,t));if(Math.min(Bt,zt)15&&r(Fe,i)===r(t.rate,i)?(Ae.reason+=", temp "+t.rate+" ~ req "+Fe+"U/hr. ",Ae):(Ae.reason+="; setting current basal of "+Fe+" as temp. ",m.setTempBasal(Fe,30,i,Ae,t));if(Bt>=Je&&(Ae.reason+="Eventual BG "+n(Bt,i)+" >= "+n(Je,i)+", "),a.iob>Qe)return Ae.reason+="IOB "+o(a.iob,2)+" > max_iob "+Qe,t.duration>15&&r(Fe,i)===r(t.rate,i)?(Ae.reason+=", temp "+t.rate+" ~ req "+Fe+"U/hr. ",Ae):(Ae.reason+="; setting current basal of "+Fe+" as temp. ",m.setTempBasal(Fe,30,i,Ae,t));(Da=o((Math.min(zt,Bt)-Ze)/ut,2))>Qe-a.iob?(console.error("SMB limited by maxIOB: "+Qe-a.iob+" (. insulinReq: "+Da+" U)"),Ae.reason+="max_iob "+Qe+", ",Da=Qe-a.iob):console.error("SMB not limited by maxIOB ( insulinReq: "+Da+" U)."),Sa=r(Sa=Fe+2*Da,i),Da=o(Da,3),Ae.insulinReq=Da;var Ta=o((new Date(Pe).getTime()-a.lastBolusTime)/6e4,1);if(u&&Dt&&ke>st){var Ca=o(l.mealCOB/I,3),Ua=0;void 0===i.maxSMBBasalMinutes?(Ua=o(i.current_basal*R*30/60,1),console.error("profile.maxSMBBasalMinutes undefined: defaulting to 30m"),Da>Ua&&console.error("SMB limited by maxBolus: "+Ua+" ( "+Da+" U)")):a.iob>Ca&&a.iob>0?(console.error("IOB"+a.iob+"> COB"+l.mealCOB+"; mealInsulinReq ="+Ca),i.maxUAMSMBBasalMinutes?(console.error("profile.maxUAMSMBBasalMinutes: "+i.maxUAMSMBBasalMinutes+", profile.current_basal: "+i.current_basal*R),Ua=o(i.current_basal*R*i.maxUAMSMBBasalMinutes/60,1)):(console.error("profile.maxUAMSMBBasalMinutes undefined: defaulting to 30m"),Ua=o(i.current_basal*R*30/60,1)),Da>Ua?console.error("SMB limited by maxUAMSMBBasalMinutes [ "+i.maxUAMSMBBasalMinutes+"m ]: "+Ua+"U ( "+Da+"U )"):console.error("SMB is not limited by maxUAMSMBBasalMinutes. ( insulinReq: "+Da+"U )")):(console.error("profile.maxSMBBasalMinutes: "+i.maxSMBBasalMinutes+", profile.current_basal: "+i.current_basal*R),Da>(Ua=o(i.current_basal*i.maxSMBBasalMinutes/60,1))?console.error("SMB limited by maxSMBBasalMinutes: "+i.maxSMBBasalMinutes+"m ]: "+Ua+"U ( insulinReq: "+Da+"U )"):console.error("SMB is not limited by maxSMBBasalMinutes. ( insulinReq: "+Da+"U )"));var Ga=i.bolus_increment,Oa=1/Ga,Ra=i.smb_delivery_ratio;Ra>.5&&console.error("SMB Delivery Ratio increased from default 0.5 to "+o(Ra,2));var Aa=Math.min(Da*Ra,Ua);Aa=Math.floor(Aa*Oa)/Oa,xa=o(60*((Ze-(vt+Jt)/2)/ut)/i.current_basal*R),Da>0&&Aa=30?(xa=30*o(xa/30),xa=Math.min(60,Math.max(0,xa))):(Ia=o(Fe*xa/30,2),xa=30),Ae.reason+=" insulinReq "+Da,Aa>=Ua&&(Ae.reason+="; maxBolus "+Ua),xa>0&&(Ae.reason+="; setting "+xa+"m low temp of "+Ia+"U/h"),Ae.reason+=". ";var ja=3;i.SMBInterval&&(ja=Math.min(10,Math.max(1,i.SMBInterval)));var Fa=o(ja-Ta,0),Pa=o(60*(ja-Ta),0)%60;if(console.error("naive_eventualBG "+vt+","+xa+"m "+Ia+"U/h temp needed; last bolus "+Ta+"m ago; maxBolus: "+Ua),Ta>ja?Aa>0&&(Ae.units=Aa,Ae.reason+="Microbolusing "+Aa+"U. "):Ae.reason+="Waiting "+Fa+"m "+Pa+"s to microbolus again. ",xa>0)return Ae.rate=Ia,Ae.duration=xa,Ae}var Ea=m.getMaxSafeBasal(i);return Sa>Ea&&(Ae.reason+="adj. req. rate: "+Sa+" to maxSafeBasal: "+o(Ea,2)+", ",Sa=r(Ea,i)),t.duration*(t.rate-Fe)/60>=2*Da?(Ae.reason+=t.duration+"m@"+t.rate.toFixed(2)+" > 2 * insulinReq. Setting temp basal of "+Sa+"U/hr. ",m.setTempBasal(Sa,30,i,Ae,t)):void 0===t.duration||0===t.duration?(Ae.reason+="no temp, setting "+Sa+"U/hr. ",m.setTempBasal(Sa,30,i,Ae,t)):t.duration>5&&r(Sa,i)<=r(t.rate,i)?(Ae.reason+="temp "+t.rate+" >~ req "+Sa+"U/hr. ",Ae):(Ae.reason+="temp "+t.rate+"<"+Sa+"U/hr. ",m.setTempBasal(Sa,30,i,Ae,t))}},6880:(e,t,a)=>{var r=a(6654);e.exports=function(e,t){var a=20;void 0!==t&&"string"==typeof t.model&&(r(t.model,"54")||r(t.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,t,a)=>{var r=a(5639).Symbol;e.exports=r},9932:e=>{e.exports=function(e,t){for(var a=-1,r=null==e?0:e.length,o=Array(r);++a{e.exports=function(e,t,a){return e==e&&(void 0!==a&&(e=e<=a?e:a),void 0!==t&&(e=e>=t?e:t)),e}},4239:(e,t,a)=>{var r=a(2705),o=a(9607),n=a(2333),i=r?r.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":i&&i in Object(e)?o(e):n(e)}},531:(e,t,a)=>{var r=a(2705),o=a(9932),n=a(1469),i=a(3448),s=r?r.prototype:void 0,l=s?s.toString:void 0;e.exports=function e(t){if("string"==typeof t)return t;if(n(t))return o(t,e)+"";if(i(t))return l?l.call(t):"";var a=t+"";return"0"==a&&1/t==-Infinity?"-0":a}},7561:(e,t,a)=>{var r=a(7990),o=/^\s+/;e.exports=function(e){return e?e.slice(0,r(e)+1).replace(o,""):e}},1957:(e,t,a)=>{var r="object"==typeof a.g&&a.g&&a.g.Object===Object&&a.g;e.exports=r},9607:(e,t,a)=>{var r=a(2705),o=Object.prototype,n=o.hasOwnProperty,i=o.toString,s=r?r.toStringTag:void 0;e.exports=function(e){var t=n.call(e,s),a=e[s];try{e[s]=void 0;var r=!0}catch(e){}var o=i.call(e);return r&&(t?e[s]=a:delete e[s]),o}},2333:e=>{var t=Object.prototype.toString;e.exports=function(e){return t.call(e)}},5639:(e,t,a)=>{var r=a(1957),o="object"==typeof self&&self&&self.Object===Object&&self,n=r||o||Function("return this")();e.exports=n},7990:e=>{var t=/\s/;e.exports=function(e){for(var a=e.length;a--&&t.test(e.charAt(a)););return a}},6654:(e,t,a)=>{var r=a(9750),o=a(531),n=a(554),i=a(9833);e.exports=function(e,t,a){e=i(e),t=o(t);var s=e.length,l=a=void 0===a?s:r(n(a),0,s);return(a-=t.length)>=0&&e.slice(a,l)==t}},1469:e=>{var t=Array.isArray;e.exports=t},3218:e=>{e.exports=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}},7005:e=>{e.exports=function(e){return null!=e&&"object"==typeof e}},3448:(e,t,a)=>{var r=a(4239),o=a(7005);e.exports=function(e){return"symbol"==typeof e||o(e)&&"[object Symbol]"==r(e)}},8601:(e,t,a)=>{var r=a(4841),o=1/0;e.exports=function(e){return e?(e=r(e))===o||e===-1/0?17976931348623157e292*(e<0?-1:1):e==e?e:0:0===e?e:0}},554:(e,t,a)=>{var r=a(8601);e.exports=function(e){var t=r(e),a=t%1;return t==t?a?t-a:t:0}},4841:(e,t,a)=>{var r=a(7561),o=a(3218),n=a(3448),i=/^[-+]0x[0-9a-f]+$/i,s=/^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 t="function"==typeof e.valueOf?e.valueOf():e;e=o(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=r(e);var a=s.test(e);return a||l.test(e)?m(e.slice(2),a?2:8):i.test(e)?NaN:+e}},9833:(e,t,a)=>{var r=a(531);e.exports=function(e){return null==e?"":r(e)}}},t={};function a(r){var o=t[r];if(void 0!==o)return o.exports;var n=t[r]={exports:{}};return e[r](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 r=a(5546);freeaps_determineBasal=r})(); +var freeaps_determineBasal;(()=>{var e={5546:(e,t,a)=>{var r=a(6880);function o(e,t){t||(t=0);var a=Math.pow(10,t);return Math.round(e*a)/a}function n(e,t){return"mmol/L"===t.out_units?o(.0555*e,1):Math.round(e)}e.exports=function(e,t,a,i,s,l,m,u,d,c,g,h,p,f){var v=i.min_bg,B=f.overrideTarget,b=0,M="",_="",y="",x="",D="",S=0,w=0,T=0,C=0,U=0,G=0;const O=f.weightedAverage;var R=1,A=i.sens,I=i.carb_ratio;f.useOverride&&(A/=R=f.overridePercentage/100,I/=R);const j=i.weightPercentage,F=f.average_total_data;function P(e,t){var a=e.getTime();return new Date(a+36e5*t)}function E(e){var t=i.bolus_increment;.025!=t&&(t=.05);var a=e/t;return a>=1?o(Math.floor(a)*t,5):0}function q(e){function t(e){return e<10&&(e="0"+e),e}return t(e.getHours())+":"+t(e.getMinutes())+":00"}function W(e,t){var a=new Date("1/1/1999 "+e),r=new Date("1/1/1999 "+t);return(a.getTime()-r.getTime())/36e5}function k(e,t){var a=0,r=t,o=(e-t)/36e5,n=0,i=o,s=0;do{if(o>0){var l=q(r),m=p[0].rate;for(let e=0;e=(s=W(p[e+1].start,p[e].start))?n=s:o=(s=24-W(p[e].start,t))?n=s:ou)if(e+1=(s=W(d,l))?n=s:o=(s=W("23:59:59",l))?n=s:o0&&o21)U=k(L,(N=24-b,H=L.getTime(),new Date(H-36e5*N))),x="24 hours of data is required for an accurate tdd calculation. Currently only "+b.toPrecision(3)+" hours of pump history data are available. Using your pump scheduled basals to fill in the missing hours. Scheduled basals added: "+U.toPrecision(5)+" U. ";else b<21?(re=!1,enableDynamicCR=!1):x=""}else console.log("Pumphistory is empty!"),re=!1,enableDynamicCR=!1;var N,H;for(let e=0;e0){S=e,G=g[e].rate;var Z=g[e-1]["duration (min)"]/60,$=Z,J=new Date(g[e-1].timestamp),K=J,Q=0;do{if(e--,0==e){K=new Date;break}if("TempBasal"==g[e]._type||"PumpSuspend"==g[e]._type){K=new Date(g[e].timestamp);break}var V=e-2;if(V>=0&&"Rewind"==g[V]._type){let e=g[V].timestamp;for(;V-1>=0&&"Prime"==g[V-=1]._type;)Q=(g[V].timestamp-e)/36e5;Q>=Z&&(K=e,Q=0)}}while(e>0);var X=(K-J)/36e5;X<$&&(Z=X),T+=E(G*(Z-Q)),e=S}for(let e=0;e0&&(--r,"TempBasal"==g[r]._type)){a=new Date(g[r].timestamp);break}}while(r>0);(a-t)/36e5>0&&(U+=k(a,t))}for(let e=g.length-1;e>0;e--)if("TempBasalDuration"==g[e]._type){let t=g[e]["duration (min)"]/60,a=new Date(g[e].timestamp);var Y=a;let r=e;do{if(--r,r>=0&&("TempBasal"==g[r]._type||"PumpSuspend"==g[r]._type)){Y=new Date(g[r].timestamp);break}}while(r>0);if(0==e&&"TempBasalDuration"==g[0]._type&&(Y=new Date,t=g[e]["duration (min)"]/60),(Y-a)/36e5-t>0){U+=k(Y,P(a,t))}}var ee,te={TDD:o(w=C+T+U,5),bolus:o(C,5),temp_basal:o(T,5),scheduled_basal:o(U,5)};b>21?(_=". Bolus insulin: "+C.toPrecision(5)+" U",y=". Temporary basal insulin: "+T.toPrecision(5)+" U",M=". Insulin with scheduled basal rate: "+U.toPrecision(5)+" U",D=x+(" TDD past 24h is: "+w.toPrecision(5)+" U")+_+y+M,tddReason=", Total insulin: "+o(w,2)+" U, "+o(C/w*100,0)+"% Bolus "+o((T+U)/w*100,0)+"% Basal"):tddReason=", TDD: Not enough pumpData (< 21h)";const ae=e.glucose;var re=h.useNewFormula;const oe=h.enableDynamicCR,ne=Math.min(i.autosens_min,i.autosens_max),ie=Math.max(i.autosens_min,i.autosens_max);(ie==ne||ie<1||ne>1)&&(re=!1,console.log("Dynamic ISF disabled due to current autosens settings"));const se=h.adjustmentFactor,le=i.min_bg;var me=!1,ue="",de=1,ce="";F>0&&(de=O/F),ce=de>1?"Basal adjustment with a 24 hour to total average (up to 14 days of data) TDD ratio (limited by Autosens max setting). Basal Ratio: "+(de=o(de=Math.min(de,i.autosens_max),2))+". Upper limit = Autosens max ("+i.autosens_max+")":de<1?"Basal adjustment with a 24 hour to to total average (up to 14 days of data) TDD ratio (limited by Autosens min setting). Basal Ratio: "+(de=o(de=Math.max(de,i.autosens_min),2))+". Lower limit = Autosens min ("+i.autosens_min+")":"Basal adjusted with a 24 hour to total average (up to 14 days of data) TDD ratio: "+de,ce=", Basal ratio: "+de,(i.high_temptarget_raises_sensitivity||i.exercise_mode||f.isEnabled)&&(me=!0),le>=118&&me&&(re=!1,ue="Dynamic ISF temporarily off due to a high temp target/exercising. Current min target: "+le);var ge=", Dynamic ratios log: ",he=", AF: "+se,pe="BG: "+ae+" mg/dl ("+(.0555*ae).toPrecision(2)+" mmol/l)",fe="",ve="";const Be=h.curve,be=h.insulinPeakTime,Me=h.useCustomPeakTime;var _e=55,ye=65;switch(Be){case"rapid-acting":ye=65;break;case"ultra-rapid":ye=50}Me?(_e=120-be,console.log("Custom insulinpeakTime set to :"+be+", insulinFactor: "+_e)):(_e=120-ye,console.log("insulinFactor set to : "+_e)),ee=w,j<1&&O>0&&(w=O,console.log("Using weighted TDD average: "+o(w,2)+" U, instead of past 24 h ("+o(ee,2)+" U), weight: "+j),ve=", Weighted TDD: "+o(w,2)+" U");const xe=h.sigmoid;var De="";if(re){var Se=A*se*w*Math.log(ae/_e+1)/1800;fe=", Logarithmic formula"}if(re&&xe){const e=ne,t=ie-e,a=.0555*(ae-i.min_bg);var we=de,Te=ie-1;1==ie&&(Te=ie+.01-1);const r=Math.log10(1/Te-e/Te)/Math.log10(Math.E),o=a*se*we+r;Se=t/(1+Math.exp(-o))+e,fe=", Sigmoid function"}var Ce=I;const Ue=o(I,1);var Ge="",Oe="";if(re&&w>0){if(Ge=", Dynamic ISF/CR: On/",Se>ie?(ue=", Dynamic ISF limited by autosens_max setting: "+ie+" ("+o(Se,2)+"), ",Oe=", Autosens/Dynamic Limit: "+ie+" ("+o(Se,2)+")",Se=ie):Se1&&(Re=(Se-1)/2+1);var Ae=" CR: "+(Ce=o(Ce/Re,2))+" g/U";I=Ce}else Ae=" CR: "+Ce+" g/U",Ge+="Off";const e=A/Se;s.ratio=Se,De=". Using Sigmoid function, the autosens ratio has been adjusted with sigmoid factor to: "+o(s.ratio,2)+". New ISF = "+o(e,2)+" mg/dl ("+o(.0555*e,2)+" (mmol/l). CR adjusted from "+o(Ue,2)+" to "+o(Ce,2),D+=ge+pe+he+fe+(ue+=xe?De:", Dynamic autosens.ratio set to "+o(Se,2)+" with ISF: "+e.toPrecision(3)+" mg/dl/U ("+(.0555*e).toPrecision(3)+" mmol/l/U)")+Ge+Ae+ve}else D+=ge+"Dynamic Settings disabled";console.log(D),re||oe?re&&i.tddAdjBasal?tddReason+=Ge+fe+Oe+he+ce:re&&!i.tddAdjBasal&&(tddReason+=Ge+fe+Oe+he):tddReason+="";var Ie={},je=new Date;if(c&&(je=c),void 0===i||void 0===i.current_basal)return Ie.error="Error: could not get current basal rate",Ie;var Fe=r(i.current_basal,i)*R,Pe=Fe;f.useOverride&&(0==f.duration?console.log("Profile Override is active. Override "+o(100*R,0)+"%. Override Duration: Enabled indefinitely"):console.log("Profile Override is active. Override "+o(100*R,0)+"%. Override Expires in: "+f.duration+" min."));var Ee=new Date;c&&(Ee=c);var qe,We=new Date(e.date),ke=o((Ee-We)/60/1e3,1),Le=e.glucose,ze=e.noise;qe=e.delta>-.5?"+"+o(e.delta,0):o(e.delta,0);var Ne=Math.min(e.delta,e.short_avgdelta),He=Math.min(e.short_avgdelta,e.long_avgdelta),Ze=Math.max(e.delta,e.short_avgdelta,e.long_avgdelta);(Le<=10||38===Le||ze>=3)&&(Ie.reason="CGM is calibrating, in ??? state, or noise is high");if(Le>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 ("+n(Le,i)+"+"+n(e.delta,i)+") for 5m w/ "+n(e.short_avgdelta,i)+" mg/dL ~15m change & "+n(e.long_avgdelta,2)+" mg/dL ~45m change"),console.error("Simulator mode detected ("+e.device+"): continuing anyway")):!0),ke>12||ke<-5?Ie.reason="If current system time "+Ee+" is correct, then BG data is too old. The last BG data was read "+ke+"m ago at "+We:0===e.short_avgdelta&&0===e.long_avgdelta&&(e.last_cal&&e.last_cal<3?Ie.reason="CGM was just calibrated":Ie.reason="CGM data is unchanged ("+n(Le,i)+"+"+n(e.delta,i)+") for 5m w/ "+n(e.short_avgdelta,i)+" mg/dL ~15m change & "+n(e.long_avgdelta,i)+" mg/dL ~45m change"),Le<=10||38===Le||ze>=3||ke>12||ke<-5||0===e.short_avgdelta&&0===e.long_avgdelta)return t.rate>=Pe?(Ie.reason+=". Canceling high temp basal of "+t.rate,Ie.deliverAt=je,Ie.temp="absolute",Ie.duration=0,Ie.rate=0,Ie):0===t.rate&&t.duration>30?(Ie.reason+=". Shortening "+t.duration+"m long zero temp to 30m. ",Ie.deliverAt=je,Ie.temp="absolute",Ie.duration=30,Ie.rate=0,Ie):(Ie.reason+=". Temp "+t.rate+" <= current basal "+Pe+"U/hr; doing nothing. ",Ie);var $e,Je,Ke,Qe,Ve=i.max_iob;if(void 0!==i.min_bg&&(Je=i.min_bg),void 0!==i.max_bg&&(Ke=i.max_bg),void 0!==i.enableSMB_high_bg_target&&(Qe=i.enableSMB_high_bg_target),void 0===i.min_bg||void 0===i.max_bg)return Ie.error="Error: could not determine target_bg. ",Ie;$e=(i.min_bg+i.max_bg)/2;var Xe=i.exercise_mode||i.high_temptarget_raises_sensitivity||f.isEnabled,Ye=100,et=160;if(et=i.half_basal_exercise_target,f.isEnabled){const e=f.hbt;console.log("Half Basal Target used: "+n(e,i)+" "+i.out_units),et=e}else console.log("Default Half Basal Target used: "+n(et,i)+" "+i.out_units);if(Xe&&i.temptargetSet&&$e>Ye||i.low_temptarget_lowers_sensitivity&&i.temptargetSet&&$e=$e&&sensitivityRatio0&&(process.stderr.write("TDD-adjustment of basals activated, using tdd24h_14d_Ratio "+o(de,2)+", TDD 24h = "+o(ee,2)+"U, Weighted average TDD = "+o(O,2)+"U, (Weight percentage = "+j+"), Total data of TDDs (up to 14 days) average = "+o(F,2)+"U. "),Pe!==Fe*R?process.stderr.write("Adjusting basal from "+Fe*R+" U/h to "+Pe+" U/h; "):process.stderr.write("Basal unchanged: "+Pe+" U/h; "))),i.temptargetSet);else if(void 0!==s&&s&&(i.sensitivity_raises_target&&s.ratio<1||i.resistance_lowers_target&&s.ratio>1)){Je=o((Je-60)/s.ratio)+60,Ke=o((Ke-60)/s.ratio)+60;var at=o(($e-60)/s.ratio)+60;$e===(at=Math.max(80,at))?process.stderr.write("target_bg unchanged: "+n(at,i)+"; "):process.stderr.write("target_bg from "+n(at,i)+" to "+n(at,i)+"; "),$e=at}var rt=n($e,i);$e!=v&&(rt=0!==B&&B!==$e?n(v,i)+"→"+n(B,i)+"→"+n($e,i):n(v,i)+"→"+n($e,i));var ot=200,nt=200,it=200;if(e.noise>=2){var st=Math.max(1.1,i.noisyCGMTargetMultiplier);Math.min(250,i.maxRaw);ot=o(Math.min(200,Je*st)),nt=o(Math.min(200,$e*st)),it=o(Math.min(200,Ke*st)),process.stderr.write("Raising target_bg for noisy / raw CGM data, from "+n(at,i)+" to "+n(nt,i)+"; "),Je=ot,$e=nt,Ke=it}var lt=Je-.5*(Je-40),mt=i.threshold_setting;mt>lt&&mt<=120&&mt>=65?(console.error("Threshold changed in settings from "+n(lt,i)+" to "+n(mt,i)+". "),lt=mt):console.error("Current threshold: "+n(lt,i));var ut="",dt=(o(A,1),A);if(void 0!==s&&s&&((dt=o(dt=A/sensitivityRatio,1))!==A?process.stderr.write("ISF from "+n(A,i)+" to "+n(dt,i)):process.stderr.write("ISF unchanged: "+n(dt,i)),ut+="Autosens ratio: "+o(sensitivityRatio,2)+", ISF: "+n(A,i)+"→"+n(dt,i)),console.error("CR:"+I),void 0===a)return Ie.error="Error: iob_data undefined. ",Ie;var ct,gt=a;if(a.length,a.length>1&&(a=gt[0]),void 0===a.activity||void 0===a.iob)return Ie.error="Error: iob_data missing some property. ",Ie;var ht=((ct=void 0!==a.lastTemp?o((new Date(Ee).getTime()-a.lastTemp.date)/6e4):0)+t.duration)%30;if(console.error("currenttemp:"+t.rate+" lastTempAge:"+ct+"m, tempModulus:"+ht+"m"),Ie.temp="absolute",Ie.deliverAt=je,u&&t&&a.lastTemp&&t.rate!==a.lastTemp.rate&&ct>10&&t.duration)return Ie.reason="Warning: currenttemp rate "+t.rate+" != lastTemp rate "+a.lastTemp.rate+" from pumphistory; canceling temp",m.setTempBasal(0,0,i,Ie,t);if(t&&a.lastTemp&&t.duration>0){var pt=ct-a.lastTemp.duration;if(pt>5&&ct>10)return Ie.reason="Warning: currenttemp running but lastTemp from pumphistory ended "+pt+"m ago; canceling temp",m.setTempBasal(0,0,i,Ie,t)}var ft=o(-a.activity*dt*5,2),vt=o(6*(Ne-ft));vt<0&&(vt=o(6*(He-ft)))<0&&(vt=o(6*(e.long_avgdelta-ft)));var Bt=Le,bt=(Bt=a.iob>0?o(Le-a.iob*dt):o(Le-a.iob*Math.min(dt,A)))+vt;if(void 0===bt||isNaN(bt))return Ie.error="Error: could not calculate eventualBG. Sensitivity: "+dt+" Deviation: "+vt,Ie;var Mt=function(e,t,a){return o(a+(e-t)/24,1)}($e,bt,ft);Ie={temp:"absolute",bg:Le,tick:qe,eventualBG:bt,insulinReq:0,reservoir:d,deliverAt:je,sensitivityRatio,TDD:ee,insulin:te,current_target:$e};var _t=[],yt=[],xt=[],Dt=[];_t.push(Le),yt.push(Le),Dt.push(Le),xt.push(Le);var St=function(e,t,a,r,o,i){return t?!e.allowSMB_with_high_temptarget&&e.temptargetSet&&o>100?(console.error("SMB disabled due to high temptarget of "+o),!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&&o<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(o,e)),!0):!0===e.enableSMB_high_bg&&null!==i&&r>=i?(console.error("Checking BG to see if High for SMB enablement."),console.error("Current BG",r," | High BG ",i),a.bwFound?console.error("Warning: High BG SMB enabled within 6h of using Bolus Wizard: be sure to easy bolus 30s before using Bolus Wizard"):console.error("High BG detected. Enabling SMB."),!0):(console.error("SMB disabled (no enableSMB preferences active or no condition satisfied)"),!1):(console.error("SMB disabled (!microBolusAllowed)"),!1)}(i,u,l,Le,$e,Qe),wt=i.enableUAM,Tt=0,Ct=0;Tt=o(Ne-ft,1);var Ut=o(Ne-ft,1);csf=dt/I,console.error("profile.sens:"+n(A,i)+", sens:"+n(dt,i)+", CSF:"+o(csf,1));var Gt=o(30*csf*5/60,1);Tt>Gt&&(console.error("Limiting carb impact from "+Tt+" to "+Gt+"mg/dL/5m (30g/h)"),Tt=Gt);var Ot=3;sensitivityRatio&&(Ot/=sensitivityRatio);var Rt=Ot;if(l.carbs){Ot=Math.max(Ot,l.mealCOB/20);var At=o((new Date(Ee).getTime()-l.lastCarbTime)/6e4),It=(l.carbs-l.mealCOB)/l.carbs;Rt=o(Rt=Ot+1.5*At/60,1),console.error("Last carbs "+At+" minutes ago; remainingCATime:"+Rt+"hours; "+o(100*It,1)+"% carbs absorbed")}var jt=Math.max(0,Tt/5*60*Rt/2)/csf,Ft=90,Pt=1;i.remainingCarbsCap&&(Ft=Math.min(90,i.remainingCarbsCap)),i.remainingCarbsFraction&&(Pt=Math.min(1,i.remainingCarbsFraction));var Et=1-Pt,qt=Math.max(0,l.mealCOB-jt-l.carbs*Et),Wt=(qt=Math.min(Ft,qt))*csf*5/60/(Rt/2),kt=o(l.slopeFromMaxDeviation,2),Lt=o(l.slopeFromMinDeviation,2),zt=Math.min(kt,-Lt/3);Ct=0===Tt?0:Math.min(60*Rt/5/2,Math.max(0,l.mealCOB*csf/Tt)),console.error("Carb Impact:"+Tt+"mg/dL per 5m; CI Duration:"+o(5*Ct/60*2,1)+"hours; remaining CI ("+Rt/2+"h peak):"+o(Wt,1)+"mg/dL per 5m");var Nt,Ht,Zt,$t,Jt,Kt=999,Qt=999,Vt=999,Xt=Le,Yt=999,ea=999,ta=999,aa=999,ra=bt,oa=Le,na=Le,ia=0,sa=[],la=[];try{gt.forEach((function(e){var t=o(-e.activity*dt*5,2),a=o(-e.iobWithZeroTemp.activity*dt*5,2),r=Bt,n=Tt*(1-Math.min(1,yt.length/12));if(!0===(re&&!xe))ra=yt[yt.length-1]+o(-e.activity*(1800/(w*se*Math.log(Math.max(yt[yt.length-1],39)/_e+1)))*5,2)+n,r=Dt[Dt.length-1]+o(-e.iobWithZeroTemp.activity*(1800/(w*se*Math.log(Math.max(Dt[Dt.length-1],39)/_e+1)))*5,2),console.log("Dynamic ISF (Logarithmic Formula) )adjusted predictions for IOB and ZT: IOBpredBG: "+o(ra,2)+" , ZTpredBG: "+o(r,2));else ra=yt[yt.length-1]+t+n,r=Dt[Dt.length-1]+a;var i=Math.max(0,Math.max(0,Tt)*(1-_t.length/Math.max(2*Ct,1))),s=Math.min(_t.length,12*Rt-_t.length),l=Math.max(0,s/(Rt/2*12)*Wt);i+l,sa.push(o(l,0)),la.push(o(i,0)),COBpredBG=_t[_t.length-1]+t+Math.min(0,n)+i+l;var m=Math.max(0,Ut+xt.length*zt),u=Math.max(0,Ut*(1-xt.length/Math.max(36,1))),d=Math.min(m,u);if(d>0&&(ia=o(5*(xt.length+1)/60,1)),!0===(re&&!xe))UAMpredBG=xt[xt.length-1]+o(-e.activity*(1800/(w*se*Math.log(Math.max(xt[xt.length-1],39)/_e+1)))*5,2)+Math.min(0,n)+d,console.log("Dynamic ISF (Logarithmic Formula) adjusted prediction for UAM: UAMpredBG: "+o(UAMpredBG,2));else UAMpredBG=xt[xt.length-1]+t+Math.min(0,n)+d;yt.length<48&&yt.push(ra),_t.length<48&&_t.push(COBpredBG),xt.length<48&&xt.push(UAMpredBG),Dt.length<48&&Dt.push(r),COBpredBG18&&raoa&&(oa=ra),(Ct||Wt>0)&&_t.length>18&&COBpredBG0)&&COBpredBG>oa&&(na=COBpredBG),wt&&xt.length>12&&UAMpredBGoa&&UAMpredBG}))}catch(e){console.error("Problem with iobArray. Optional feature Advanced Meal Assist disabled")}l.mealCOB&&(console.error("predCIs (mg/dL/5m):"+la.join(" ")),console.error("remainingCIs: "+sa.join(" "))),Ie.predBGs={},yt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))}));for(var ma=yt.length-1;ma>12&&yt[ma-1]===yt[ma];ma--)yt.pop();for(Ie.predBGs.IOB=yt,Zt=o(yt[yt.length-1]),Dt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),ma=Dt.length-1;ma>6&&!(Dt[ma-1]>=Dt[ma]||Dt[ma]<=$e);ma--)Dt.pop();if(Ie.predBGs.ZT=Dt,o(Dt[Dt.length-1]),l.mealCOB>0&&(Tt>0||Wt>0)){for(_t.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),ma=_t.length-1;ma>12&&_t[ma-1]===_t[ma];ma--)_t.pop();Ie.predBGs.COB=_t,$t=o(_t[_t.length-1]),bt=Math.max(bt,o(_t[_t.length-1]))}if(Tt>0||Wt>0){if(wt){for(xt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),ma=xt.length-1;ma>12&&xt[ma-1]===xt[ma];ma--)xt.pop();Ie.predBGs.UAM=xt,Jt=o(xt[xt.length-1]),xt[xt.length-1]&&(bt=Math.max(bt,o(xt[xt.length-1])))}Ie.eventualBG=bt}console.error("UAM Impact:"+Ut+"mg/dL per 5m; UAM Duration:"+ia+"hours"),Kt=Math.max(39,Kt),Qt=Math.max(39,Qt),Vt=Math.max(39,Vt),Nt=o(Kt);var ua=l.mealCOB/l.carbs;Ht=o(Vt<999&&Qt<999?(1-ua)*UAMpredBG+ua*COBpredBG:Qt<999?(ra+COBpredBG)/2:Vt<999?(ra+UAMpredBG)/2:ra),aa>Ht&&(Ht=aa),Xt=o(Xt=Ct||Wt>0?wt?ua*Yt+(1-ua)*ea:Yt:wt?ea:ta);var da=Vt;if(aaVt&&(da=(Vt+aa)/2);if(da=o(da),l.carbs)if(!wt&&Qt<999)Nt=o(Math.max(Kt,Qt));else if(Qt<999){var ga=ua*Qt+(1-ua)*da;Nt=o(Math.max(Kt,Qt,ga))}else Nt=wt?da:Xt;else wt&&(Nt=o(Math.max(Kt,da)));Nt=Math.min(Nt,Ht),process.stderr.write("minPredBG: "+Nt+" minIOBPredBG: "+Kt+" minZTGuardBG: "+aa),Qt<999&&process.stderr.write(" minCOBPredBG: "+Qt),Vt<999&&process.stderr.write(" minUAMPredBG: "+Vt),console.error(" avgPredBG:"+Ht+" COB/Carbs:"+l.mealCOB+"/"+l.carbs),na>Le&&(Nt=Math.min(Nt,na)),Ie.COB=l.mealCOB,Ie.IOB=a.iob,Ie.BGI=n(ft,i),Ie.deviation=n(vt,i),Ie.ISF=n(dt,i),Ie.CR=o(I,1),Ie.target_bg=n($e,i),Ie.TDD=o(ee,2),Ie.current_target=o($e,0);var ha=Ie.CR;Ue!=Ie.CR&&(ha=Ue+"→"+Ie.CR),Ie.reason=ut+", COB: "+Ie.COB+", Dev: "+Ie.deviation+", BGI: "+Ie.BGI+", CR: "+ha+", Target: "+rt+", minPredBG "+n(Nt,i)+", minGuardBG "+n(Xt,i)+", IOBpredBG "+n(Zt,i),$t>0&&(Ie.reason+=", COBpredBG "+n($t,i)),Jt>0&&(Ie.reason+=", UAMpredBG "+n(Jt,i)),Ie.reason+=tddReason,Ie.reason+="; ";var pa=Bt;pa<40&&(pa=Math.min(Xt,pa));var fa,va=lt-pa,Ba=240,ba=240;if(l.mealCOB>0&&(Tt>0||Wt>0)){for(ma=0;ma<_t.length;ma++)if(_t[ma]fa*Le&&(console.error("maxDelta "+n(Ze,i)+" > "+100*fa+"% of BG "+n(Le,i)+" - disabling SMB"),Ie.reason+="maxDelta "+n(Ze,i)+" > "+100*fa+"% of BG "+n(Le,i)+" - SMB disabled!, ",St=!1),console.error("BG projected to remain above "+n(Je,i)+" for "+Ba+"minutes"),(ba<240||Ba<60)&&console.error("BG projected to remain above "+n(lt,i)+" for "+ba+"minutes");var Ma=ba,_a=i.current_basal*R*dt*Ma/60,ya=Math.max(0,l.mealCOB-.25*l.carbs),xa=(va-_a)/csf-ya;_a=o(_a),xa=o(xa),console.error("naive_eventualBG:",Bt,"bgUndershoot:",va,"zeroTempDuration:",Ma,"zeroTempEffect:",_a,"carbsReq:",xa),"Could not parse clock data"==l.reason?console.error("carbsReq unknown: Could not parse clock data"):xa>=i.carbsReqThreshold&&ba<=45&&(Ie.carbsReq=xa,Ie.reason+=xa+" add'l carbs req w/in "+ba+"m; ");var Da=0;if(Le0&&Ne>Mt)Ie.reason+="IOB "+a.iob+" < "+o(-i.current_basal*R*20/60,2),Ie.reason+=" and minDelta "+n(Ne,i)+" > expectedDelta "+n(Mt,i)+"; ";else if(Le=55)return Ie.reason+="; Canceling temp at "+Ie.deliverAt.getMinutes()+"m past the hour. ",m.setTempBasal(0,0,i,Ie,t);var Sa=0,wa=Pe;if(btMt&&Ne>0&&!xa)return Bt<40?(Ie.reason+=", naive_eventualBG < 40. ",m.setTempBasal(0,30,i,Ie,t)):(e.delta>Ne?Ie.reason+=", but Delta "+n(qe,i)+" > expectedDelta "+n(Mt,i):Ie.reason+=", but Min. Delta "+Ne.toFixed(2)+" > Exp. Delta "+n(Mt,i),t.duration>15&&r(Pe,i)===r(t.rate,i)?(Ie.reason+=", temp "+t.rate+" ~ req "+Pe+"U/hr. ",Ie):(Ie.reason+="; setting current basal of "+Pe+" as temp. ",m.setTempBasal(Pe,30,i,Ie,t)));Sa=o(Sa=2*Math.min(0,(bt-$e)/dt),2);var Ta=Math.min(0,(Bt-$e)/dt);if(Ta=o(Ta,2),Ne<0&&Ne>Mt)Sa=o(Sa*(Ne/Mt),2);if(wa=r(wa=Pe+2*Sa,i),t.duration*(t.rate-Pe)/605&&wa>=.8*t.rate)return Ie.reason+=", temp "+t.rate+" ~< req "+wa+"U/hr. ",Ie;if(wa<=0){if((Da=o(60*((va=$e-Bt)/dt)/i.current_basal*R))<0?Da=0:(Da=30*o(Da/30),Da=Math.min(120,Math.max(0,Da))),Da>0)return Ie.reason+=", setting "+Da+"m zero temp. ",m.setTempBasal(wa,Da,i,Ie,t)}else Ie.reason+=", setting "+wa+"U/hr. ";return m.setTempBasal(wa,30,i,Ie,t)}if(Ne "+n(Je,i)+" but Delta "+n(qe,i)+" < Exp. Delta "+n(Mt,i):Ie.reason+="Eventual BG "+n(bt,i)+" > "+n(Je,i)+" but Min. Delta "+Ne.toFixed(2)+" < Exp. Delta "+n(Mt,i),t.duration>15&&r(Pe,i)===r(t.rate,i)?(Ie.reason+=", temp "+t.rate+" ~ req "+Pe+"U/hr. ",Ie):(Ie.reason+="; setting current basal of "+Pe+" as temp. ",m.setTempBasal(Pe,30,i,Ie,t));if(Math.min(bt,Nt)15&&r(Pe,i)===r(t.rate,i)?(Ie.reason+=", temp "+t.rate+" ~ req "+Pe+"U/hr. ",Ie):(Ie.reason+="; setting current basal of "+Pe+" as temp. ",m.setTempBasal(Pe,30,i,Ie,t));if(bt>=Ke&&(Ie.reason+="Eventual BG "+n(bt,i)+" >= "+n(Ke,i)+", "),a.iob>Ve)return Ie.reason+="IOB "+o(a.iob,2)+" > max_iob "+Ve,t.duration>15&&r(Pe,i)===r(t.rate,i)?(Ie.reason+=", temp "+t.rate+" ~ req "+Pe+"U/hr. ",Ie):(Ie.reason+="; setting current basal of "+Pe+" as temp. ",m.setTempBasal(Pe,30,i,Ie,t));(Sa=o((Math.min(Nt,bt)-$e)/dt,2))>Ve-a.iob?(console.error("SMB limited by maxIOB: "+Ve-a.iob+" (. insulinReq: "+Sa+" U)"),Ie.reason+="max_iob "+Ve+", ",Sa=Ve-a.iob):console.error("SMB not limited by maxIOB ( insulinReq: "+Sa+" U)."),wa=r(wa=Pe+2*Sa,i),Sa=o(Sa,3),Ie.insulinReq=Sa;var Ca=o((new Date(Ee).getTime()-a.lastBolusTime)/6e4,1);if(u&&St&&Le>lt){var Ua=o(l.mealCOB/I,3),Ga=0;void 0===i.maxSMBBasalMinutes?(Ga=o(i.current_basal*R*30/60,1),console.error("profile.maxSMBBasalMinutes undefined: defaulting to 30m"),Sa>Ga&&console.error("SMB limited by maxBolus: "+Ga+" ( "+Sa+" U)")):a.iob>Ua&&a.iob>0?(console.error("IOB"+a.iob+"> COB"+l.mealCOB+"; mealInsulinReq ="+Ua),i.maxUAMSMBBasalMinutes?(console.error("profile.maxUAMSMBBasalMinutes: "+i.maxUAMSMBBasalMinutes+", profile.current_basal: "+i.current_basal*R),Ga=o(i.current_basal*R*i.maxUAMSMBBasalMinutes/60,1)):(console.error("profile.maxUAMSMBBasalMinutes undefined: defaulting to 30m"),Ga=o(i.current_basal*R*30/60,1)),Sa>Ga?console.error("SMB limited by maxUAMSMBBasalMinutes [ "+i.maxUAMSMBBasalMinutes+"m ]: "+Ga+"U ( "+Sa+"U )"):console.error("SMB is not limited by maxUAMSMBBasalMinutes. ( insulinReq: "+Sa+"U )")):(console.error("profile.maxSMBBasalMinutes: "+i.maxSMBBasalMinutes+", profile.current_basal: "+i.current_basal*R),Sa>(Ga=o(i.current_basal*i.maxSMBBasalMinutes/60,1))?console.error("SMB limited by maxSMBBasalMinutes: "+i.maxSMBBasalMinutes+"m ]: "+Ga+"U ( insulinReq: "+Sa+"U )"):console.error("SMB is not limited by maxSMBBasalMinutes. ( insulinReq: "+Sa+"U )"));var Oa=i.bolus_increment,Ra=1/Oa,Aa=i.smb_delivery_ratio;Aa>.5&&console.error("SMB Delivery Ratio increased from default 0.5 to "+o(Aa,2));var Ia=Math.min(Sa*Aa,Ga);Ia=Math.floor(Ia*Ra)/Ra,Da=o(60*(($e-(Bt+Kt)/2)/dt)/i.current_basal*R),Sa>0&&Ia=30?(Da=30*o(Da/30),Da=Math.min(60,Math.max(0,Da))):(ja=o(Pe*Da/30,2),Da=30),Ie.reason+=" insulinReq "+Sa,Ia>=Ga&&(Ie.reason+="; maxBolus "+Ga),Da>0&&(Ie.reason+="; setting "+Da+"m low temp of "+ja+"U/h"),Ie.reason+=". ";var Fa=3;i.SMBInterval&&(Fa=Math.min(10,Math.max(1,i.SMBInterval)));var Pa=o(Fa-Ca,0),Ea=o(60*(Fa-Ca),0)%60;if(console.error("naive_eventualBG "+Bt+","+Da+"m "+ja+"U/h temp needed; last bolus "+Ca+"m ago; maxBolus: "+Ga),Ca>Fa?Ia>0&&(Ie.units=Ia,Ie.reason+="Microbolusing "+Ia+"U. "):Ie.reason+="Waiting "+Pa+"m "+Ea+"s to microbolus again. ",Da>0)return Ie.rate=ja,Ie.duration=Da,Ie}var qa=m.getMaxSafeBasal(i);return wa>qa&&(Ie.reason+="adj. req. rate: "+wa+" to maxSafeBasal: "+o(qa,2)+", ",wa=r(qa,i)),t.duration*(t.rate-Pe)/60>=2*Sa?(Ie.reason+=t.duration+"m@"+t.rate.toFixed(2)+" > 2 * insulinReq. Setting temp basal of "+wa+"U/hr. ",m.setTempBasal(wa,30,i,Ie,t)):void 0===t.duration||0===t.duration?(Ie.reason+="no temp, setting "+wa+"U/hr. ",m.setTempBasal(wa,30,i,Ie,t)):t.duration>5&&r(wa,i)<=r(t.rate,i)?(Ie.reason+="temp "+t.rate+" >~ req "+wa+"U/hr. ",Ie):(Ie.reason+="temp "+t.rate+"<"+wa+"U/hr. ",m.setTempBasal(wa,30,i,Ie,t))}},6880:(e,t,a)=>{var r=a(6654);e.exports=function(e,t){var a=20;void 0!==t&&"string"==typeof t.model&&(r(t.model,"54")||r(t.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,t,a)=>{var r=a(5639).Symbol;e.exports=r},9932:e=>{e.exports=function(e,t){for(var a=-1,r=null==e?0:e.length,o=Array(r);++a{e.exports=function(e,t,a){return e==e&&(void 0!==a&&(e=e<=a?e:a),void 0!==t&&(e=e>=t?e:t)),e}},4239:(e,t,a)=>{var r=a(2705),o=a(9607),n=a(2333),i=r?r.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":i&&i in Object(e)?o(e):n(e)}},531:(e,t,a)=>{var r=a(2705),o=a(9932),n=a(1469),i=a(3448),s=r?r.prototype:void 0,l=s?s.toString:void 0;e.exports=function e(t){if("string"==typeof t)return t;if(n(t))return o(t,e)+"";if(i(t))return l?l.call(t):"";var a=t+"";return"0"==a&&1/t==-Infinity?"-0":a}},7561:(e,t,a)=>{var r=a(7990),o=/^\s+/;e.exports=function(e){return e?e.slice(0,r(e)+1).replace(o,""):e}},1957:(e,t,a)=>{var r="object"==typeof a.g&&a.g&&a.g.Object===Object&&a.g;e.exports=r},9607:(e,t,a)=>{var r=a(2705),o=Object.prototype,n=o.hasOwnProperty,i=o.toString,s=r?r.toStringTag:void 0;e.exports=function(e){var t=n.call(e,s),a=e[s];try{e[s]=void 0;var r=!0}catch(e){}var o=i.call(e);return r&&(t?e[s]=a:delete e[s]),o}},2333:e=>{var t=Object.prototype.toString;e.exports=function(e){return t.call(e)}},5639:(e,t,a)=>{var r=a(1957),o="object"==typeof self&&self&&self.Object===Object&&self,n=r||o||Function("return this")();e.exports=n},7990:e=>{var t=/\s/;e.exports=function(e){for(var a=e.length;a--&&t.test(e.charAt(a)););return a}},6654:(e,t,a)=>{var r=a(9750),o=a(531),n=a(554),i=a(9833);e.exports=function(e,t,a){e=i(e),t=o(t);var s=e.length,l=a=void 0===a?s:r(n(a),0,s);return(a-=t.length)>=0&&e.slice(a,l)==t}},1469:e=>{var t=Array.isArray;e.exports=t},3218:e=>{e.exports=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}},7005:e=>{e.exports=function(e){return null!=e&&"object"==typeof e}},3448:(e,t,a)=>{var r=a(4239),o=a(7005);e.exports=function(e){return"symbol"==typeof e||o(e)&&"[object Symbol]"==r(e)}},8601:(e,t,a)=>{var r=a(4841),o=1/0;e.exports=function(e){return e?(e=r(e))===o||e===-1/0?17976931348623157e292*(e<0?-1:1):e==e?e:0:0===e?e:0}},554:(e,t,a)=>{var r=a(8601);e.exports=function(e){var t=r(e),a=t%1;return t==t?a?t-a:t:0}},4841:(e,t,a)=>{var r=a(7561),o=a(3218),n=a(3448),i=/^[-+]0x[0-9a-f]+$/i,s=/^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 t="function"==typeof e.valueOf?e.valueOf():e;e=o(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=r(e);var a=s.test(e);return a||l.test(e)?m(e.slice(2),a?2:8):i.test(e)?NaN:+e}},9833:(e,t,a)=>{var r=a(531);e.exports=function(e){return null==e?"":r(e)}}},t={};function a(r){var o=t[r];if(void 0!==o)return o.exports;var n=t[r]={exports:{}};return e[r](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 r=a(5546);freeaps_determineBasal=r})(); \ No newline at end of file