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,b){var v=0,B="",M="",_="",y="",x="",D=0,w=(f=0,0),S=0,T=0,U=0;const C=b.weightedAverage,G=i.weightPercentage,O=b.average_total_data;function A(e,t){var a=e.getTime();return new Date(a+36e5*t)}function R(e){var t=i.bolus_increment;.05!=t&&(t=.1);var a=e/t;return a>=1?o(Math.floor(a)*t,5):0}function I(e){function t(e){return e<10&&(e="0"+e),e}return t(e.getHours())+":"+t(e.getMinutes())+":00"}function j(e,t){var a=new Date("1/1/1999 "+e),r=new Date("1/1/1999 "+t);return(a.getTime()-r.getTime())/36e5}function F(e,t){var a=0,r=t,o=(e-t)/36e5,n=0,i=o,s=0;do{if(o>0){var l=I(r),m=p[0].rate;for(let e=0;e=(s=j(p[e+1].start,p[e].start))?n=s:o=(s=24-j(p[e].start,t))?n=s:ou)if(e+1=(s=j(d,l))?n=s:o=(s=j("23:59:59",l))?n=s:o0&&o21)T=F(P,(q=24-v,k=P.getTime(),new Date(k-36e5*q))),y="24 hours of data is required for an accurate tdd calculation. Currently only "+v.toPrecision(3)+" hours of pump history data are available. Using your pump scheduled basals to fill in the missing hours. Scheduled basals added: "+T.toPrecision(5)+" U. ";else v<21?(Q=!1,enableDynamicCR=!1):y=""}else console.log("Pumphistory is empty!"),Q=!1,enableDynamicCR=!1;var q,k;for(let e=0;e0){D=e,U=g[e].rate;var E=g[e-1]["duration (min)"]/60,L=E,z=new Date(g[e-1].timestamp),N=z;do{if(e--,0==e){N=new Date;break}if("TempBasal"==g[e]._type||"PumpSuspend"==g[e]._type){N=new Date(g[e].timestamp);break}}while(e>0);var Z=(N-z)/36e5;Z0&&(--r,"TempBasal"==g[r]._type)){a=new Date(g[r].timestamp);break}}while(r>0);(a-t)/36e5>0&&(T+=F(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 H=a;let r=e;do{if(--r,r>=0&&("TempBasal"==g[r]._type||"PumpSuspend"==g[r]._type)){H=new Date(g[r].timestamp);break}}while(r>0);if(0==e&&"TempBasalDuration"==g[0]._type&&(H=new Date,t=g[e]["duration (min)"]/60),(H-a)/36e5-t>0){T+=F(H,A(a,t))}}var $,J={TDD:o(f=S+w+T,1),bolus:o(S,5),temp_basal:o(w,5),scheduled_basal:o(T,5)};v>21?(M=". Bolus insulin: "+S.toPrecision(5)+" U",_=". Temporary basal insulin: "+w.toPrecision(5)+" U",B=". Insulin with scheduled basal rate: "+T.toPrecision(5)+" U",x=y+(" TDD past 24h is: "+f.toPrecision(5)+" U")+M+_+B,tddReason=C>0&&O>0?", TDD: "+o(f,1)+" U, Weighted avg: "+o(C,1)+" U, Total data avg: "+o(O,1)+" U, distribution(bolus: "+S.toPrecision(5)+", temp_basal: "+w.toPrecision(5)+", insulin: "+J:", TDD: "+o(f,2)+", insulin: "+J):tddReason=", TDD: Not enough pumpData (< 21h)";const K=e.glucose;var Q=h.useNewFormula;const V=h.enableDynamicCR,X=Math.min(i.autosens_min,i.autosens_max),Y=Math.max(i.autosens_min,i.autosens_max),ee=h.adjustmentFactor,te=i.min_bg;var ae=!1,re="",oe=1,ne="";O>0&&(oe=C/O),ne=oe>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: "+(oe=o(oe=Math.min(oe,i.autosens_max),2))+". Upper limit = Autosens max ("+i.autosens_max+")":oe<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: "+(oe=o(oe=Math.max(oe,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: "+oe,ne=", Basal ratio: "+oe,(i.high_temptarget_raises_sensitivity||i.exercise_mode)&&(ae=!0),te>=118&&ae&&(Q=!1,re="Dynamic ISF temporarily off due to a high temp target/exercising. Current min target: "+te);var ie=", Dynamic ratios log: ",se=", AF: "+ee,le="BG: "+K+" mg/dl ("+(.0555*K).toPrecision(2)+" mmol/l)",me="",ue="";const de=h.curve,ce=h.insulinPeakTime,ge=h.useCustomPeakTime;var he=55,pe=65;switch(de){case"rapid-acting":pe=65;break;case"ultra-rapid":pe=50}ge?(he=120-ce,console.log("Custom insulinpeakTime set to :"+ce+", insulinFactor: "+he)):(he=120-pe,console.log("insulinFactor set to : "+he)),$=f,G<1&&C>0&&(f=C,console.log("Using weighted TDD average: "+o(f,2)+" U, instead of past 24 h ("+o($,2)+" U), weight: "+G),ue=", Weighted TDD: "+o(f,2)+" U");const fe=h.sigmoid;var be="";if(Q){var ve=i.sens*ee*f*Math.log(K/he+1)/1800;me=", Logarithmic formula"}var Be="";if(Q&&fe){const e=X,t=Y-e,a=.0555*(K-i.min_bg);var Me=oe;Be=", tdd_factor: "+o(Me,1);const r=Y-1,n=Math.log10(1/r-e/r)/Math.log10(Math.E),s=a*ee*Me+n;ve=t/(1+Math.exp(-s))+e,me=", Sigmoid function"}var _e=i.carb_ratio,ye="",xe="";if(Q&&f>0){if(ye=", Dynamic ISF/CR: On/",ve>Y?(re=", Dynamic ISF limited by autosens_max setting: "+Y+" ("+o(ve,2)+"), ",xe=", Autosens/Dynamic Limit: "+Y+" ("+o(ve,2)+")",ve=Y):ve1&&(De=(ve-1)/2+1);var we=" CR: "+(_e=o(_e/De,2))+" g/U";i.carb_ratio=_e}else we=" CR: "+_e+" g/U",ye+="Off";const e=i.sens/ve;be=". 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(_e,2)+" to "+o(i.carb_ratio,2)+" ("+o(.0555*i.carb_ratio,2)+" mmol/l).",re+=fe?be:", Dynamic autosens.ratio set to "+o(ve,2)+" with ISF: "+e.toPrecision(3)+" mg/dl/U ("+(.0555*e).toPrecision(3)+" mmol/l/U)",s.ratio=ve,x+=ie+le+se+me+re+ye+we+ue}else x+=ie+"Dynamic Settings disabled";console.log(x),Q||V?Q&&i.tddAdjBasal?tddReason+=ye+me+xe+se+ne:Q&&!i.tddAdjBasal&&(tddReason+=ye+me+xe+se):tddReason+="";var Se={},Te=new Date;if(c&&(Te=c),void 0===i||void 0===i.current_basal)return Se.error="Error: could not get current basal rate",Se;var Ue=r(i.current_basal,i),Ce=Ue,Ge=new Date;c&&(Ge=c);var Oe,Ae=new Date(e.date),Re=o((Ge-Ae)/60/1e3,1),Ie=e.glucose,je=e.noise;Oe=e.delta>-.5?"+"+o(e.delta,0):o(e.delta,0);var Fe=Math.min(e.delta,e.short_avgdelta),Pe=Math.min(e.short_avgdelta,e.long_avgdelta),We=Math.max(e.delta,e.short_avgdelta,e.long_avgdelta);(Ie<=10||38===Ie||je>=3)&&(Se.reason="CGM is calibrating, in ??? state, or noise is high");if(Ie>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(Ie,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),Re>12||Re<-5?Se.reason="If current system time "+Ge+" is correct, then BG data is too old. The last BG data was read "+Re+"m ago at "+Ae:0===e.short_avgdelta&&0===e.long_avgdelta&&(e.last_cal&&e.last_cal<3?Se.reason="CGM was just calibrated":Se.reason="CGM data is unchanged ("+n(Ie,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"),Ie<=10||38===Ie||je>=3||Re>12||Re<-5||0===e.short_avgdelta&&0===e.long_avgdelta)return t.rate>=Ce?(Se.reason+=". Canceling high temp basal of "+t.rate,Se.deliverAt=Te,Se.temp="absolute",Se.duration=0,Se.rate=0,Se):0===t.rate&&t.duration>30?(Se.reason+=". Shortening "+t.duration+"m long zero temp to 30m. ",Se.deliverAt=Te,Se.temp="absolute",Se.duration=30,Se.rate=0,Se):(Se.reason+=". Temp "+t.rate+" <= current basal "+Ce+"U/hr; doing nothing. ",Se);var qe,ke,Ee,Le,ze=i.max_iob;if(void 0!==i.min_bg&&(ke=i.min_bg),void 0!==i.max_bg&&(Ee=i.max_bg),void 0!==i.enableSMB_high_bg_target&&(Le=i.enableSMB_high_bg_target),void 0===i.min_bg||void 0===i.max_bg)return Se.error="Error: could not determine target_bg. ",Se;qe=(i.min_bg+i.max_bg)/2;var Ne=i.exercise_mode||i.high_temptarget_raises_sensitivity,Ze=100,He=160;if(i.half_basal_exercise_target&&(He=i.half_basal_exercise_target),Ne&&i.temptargetSet&&qe>Ze||i.low_temptarget_lowers_sensitivity&&i.temptargetSet&&qe=qe&&sensitivityRatio1)){ke=o((ke-60)/s.ratio)+60,Ee=o((Ee-60)/s.ratio)+60;var Je=o((qe-60)/s.ratio)+60;qe===(Je=Math.max(80,Je))?process.stderr.write("target_bg unchanged: "+Je+"; "):process.stderr.write("target_bg from "+qe+" to "+Je+"; "),qe=Je}var Ke=200,Qe=200,Ve=200;if(e.noise>=2){var Xe=Math.max(1.1,i.noisyCGMTargetMultiplier);Math.min(250,i.maxRaw);Ke=o(Math.min(200,ke*Xe)),Qe=o(Math.min(200,qe*Xe)),Ve=o(Math.min(200,Ee*Xe)),process.stderr.write("Raising target_bg for noisy / raw CGM data, from "+qe+" to "+Qe+"; "),ke=Ke,qe=Qe,Ee=Ve}var Ye=ke-.5*(ke-40),et=i.threshold_setting;et>Ye&&et<=120&&et>=65?(console.error("Threshold changed in settings from "+n(Ye,i)+" to "+n(et,i)+". "),Ye=et):console.error("Current threshold: "+n(Ye,i));var tt="",at=o(i.sens,1),rt=i.sens;if(void 0!==s&&s&&((rt=o(rt=i.sens/sensitivityRatio,1))!==at?process.stderr.write("ISF from "+n(at,i)+" to "+n(rt,i)):process.stderr.write("ISF unchanged: "+n(rt,i)),tt+="Autosens ratio: "+o(sensitivityRatio,2)+", ISF: "+n(at,i)+"→"+n(rt,i)),console.error("CR:"+i.carb_ratio),void 0===a)return Se.error="Error: iob_data undefined. ",Se;var ot,nt=a;if(a.length,a.length>1&&$>0&&(a=nt[0]),void 0===a.activity||void 0===a.iob)return Se.error="Error: iob_data missing some property. ",Se;var it=((ot=void 0!==a.lastTemp?o((new Date(Ge).getTime()-a.lastTemp.date)/6e4):0)+t.duration)%30;if(console.error("currenttemp:"+t.rate+" lastTempAge:"+ot+"m, tempModulus:"+it+"m"),Se.temp="absolute",Se.deliverAt=Te,u&&t&&a.lastTemp&&t.rate!==a.lastTemp.rate&&ot>10&&t.duration)return Se.reason="Warning: currenttemp rate "+t.rate+" != lastTemp rate "+a.lastTemp.rate+" from pumphistory; canceling temp",m.setTempBasal(0,0,i,Se,t);if(t&&a.lastTemp&&t.duration>0){var st=ot-a.lastTemp.duration;if(st>5&&ot>10)return Se.reason="Warning: currenttemp running but lastTemp from pumphistory ended "+st+"m ago; canceling temp",m.setTempBasal(0,0,i,Se,t)}var lt=o(-a.activity*rt*5,2),mt=o(6*(Fe-lt));mt<0&&(mt=o(6*(Pe-lt)))<0&&(mt=o(6*(e.long_avgdelta-lt)));var ut=Ie,dt=(ut=a.iob>0?o(Ie-a.iob*rt):o(Ie-a.iob*Math.min(rt,i.sens)))+mt;if(void 0===dt||isNaN(dt))return Se.error="Error: could not calculate eventualBG. Sensitivity: "+rt+" Deviation: "+mt,Se;var ct=function(e,t,a){return o(a+(e-t)/24,1)}(qe,dt,lt);Se={temp:"absolute",bg:Ie,tick:Oe,eventualBG:dt,insulinReq:0,reservoir:d,deliverAt:Te,sensitivityRatio,TDD:$,insulin:{TDD:o($,5),bolus:o(S,5),temp_basal:o(w,5),scheduled_basal:o(T,5)}};var gt=[],ht=[],pt=[],ft=[];gt.push(Ie),ht.push(Ie),ft.push(Ie),pt.push(Ie);var bt=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,Ie,qe,Le),vt=i.enableUAM,Bt=0,Mt=0;Bt=o(Fe-lt,1);var _t=o(Fe-lt,1);csf=rt/i.carb_ratio,console.error("profile.sens:"+n(i.sens,i)+", sens:"+n(rt,i)+", CSF:"+o(csf,1));var yt=o(30*csf*5/60,1);Bt>yt&&(console.error("Limiting carb impact from "+Bt+" to "+yt+"mg/dL/5m (30g/h)"),Bt=yt);var xt=3;sensitivityRatio&&(xt/=sensitivityRatio);var Dt=xt;if(l.carbs){xt=Math.max(xt,l.mealCOB/20);var wt=o((new Date(Ge).getTime()-l.lastCarbTime)/6e4),St=(l.carbs-l.mealCOB)/l.carbs;Dt=o(Dt=xt+1.5*wt/60,1),console.error("Last carbs "+wt+" minutes ago; remainingCATime:"+Dt+"hours; "+o(100*St,1)+"% carbs absorbed")}var Tt=Math.max(0,Bt/5*60*Dt/2)/csf,Ut=90,Ct=1;i.remainingCarbsCap&&(Ut=Math.min(90,i.remainingCarbsCap)),i.remainingCarbsFraction&&(Ct=Math.min(1,i.remainingCarbsFraction));var Gt=1-Ct,Ot=Math.max(0,l.mealCOB-Tt-l.carbs*Gt),At=(Ot=Math.min(Ut,Ot))*csf*5/60/(Dt/2),Rt=o(l.slopeFromMaxDeviation,2),It=o(l.slopeFromMinDeviation,2),jt=Math.min(Rt,-It/3);Mt=0===Bt?0:Math.min(60*Dt/5/2,Math.max(0,l.mealCOB*csf/Bt)),console.error("Carb Impact:"+Bt+"mg/dL per 5m; CI Duration:"+o(5*Mt/60*2,1)+"hours; remaining CI ("+Dt/2+"h peak):"+o(At,1)+"mg/dL per 5m");var Ft,Pt,Wt,qt,kt,Et=999,Lt=999,zt=999,Nt=Ie,Zt=999,Ht=999,$t=999,Jt=999,Kt=dt,Qt=Ie,Vt=Ie,Xt=0,Yt=[],ea=[];try{nt.forEach((function(e){var t=o(-e.activity*rt*5,2),a=o(-e.iobWithZeroTemp.activity*rt*5,2),r=ut,n=Bt*(1-Math.min(1,ht.length/12));if(!0===(Q&&!fe))Kt=ht[ht.length-1]+o(-e.activity*(1800/(f*ee*Math.log(Math.max(ht[ht.length-1],39)/he+1)))*5,2)+n,r=ft[ft.length-1]+o(-e.iobWithZeroTemp.activity*(1800/(f*ee*Math.log(Math.max(ft[ft.length-1],39)/he+1)))*5,2),console.log("Dynamic ISF (Logarithmic Formula) )adjusted predictions for IOB and ZT: IOBpredBG: "+o(Kt,2)+" , ZTpredBG: "+o(r,2));else Kt=ht[ht.length-1]+t+n,r=ft[ft.length-1]+a;var i=Math.max(0,Math.max(0,Bt)*(1-gt.length/Math.max(2*Mt,1))),s=Math.min(gt.length,12*Dt-gt.length),l=Math.max(0,s/(Dt/2*12)*At);i+l,Yt.push(o(l,0)),ea.push(o(i,0)),COBpredBG=gt[gt.length-1]+t+Math.min(0,n)+i+l;var m=Math.max(0,_t+pt.length*jt),u=Math.max(0,_t*(1-pt.length/Math.max(36,1))),d=Math.min(m,u);if(d>0&&(Xt=o(5*(pt.length+1)/60,1)),!0===(Q&&!fe))UAMpredBG=pt[pt.length-1]+o(-e.activity*(1800/(f*ee*Math.log(Math.max(pt[pt.length-1],39)/he+1)))*5,2)+Math.min(0,n)+d,console.log("Dynamic ISF (Logarithmic Formula) adjusted prediction for UAM: UAMpredBG: "+o(UAMpredBG,2));else UAMpredBG=pt[pt.length-1]+t+Math.min(0,n)+d;ht.length<48&&ht.push(Kt),gt.length<48&>.push(COBpredBG),pt.length<48&&pt.push(UAMpredBG),ft.length<48&&ft.push(r),COBpredBG18&&KtQt&&(Qt=Kt),(Mt||At>0)&>.length>18&&COBpredBG0)&&COBpredBG>Qt&&(Vt=COBpredBG),vt&&pt.length>12&&UAMpredBGQt&&UAMpredBG}))}catch(e){console.error("Problem with iobArray. Optional feature Advanced Meal Assist disabled")}l.mealCOB&&(console.error("predCIs (mg/dL/5m):"+ea.join(" ")),console.error("remainingCIs: "+Yt.join(" "))),Se.predBGs={},ht.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))}));for(var ta=ht.length-1;ta>12&&ht[ta-1]===ht[ta];ta--)ht.pop();for(Se.predBGs.IOB=ht,Wt=o(ht[ht.length-1]),ft.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),ta=ft.length-1;ta>6&&!(ft[ta-1]>=ft[ta]||ft[ta]<=qe);ta--)ft.pop();if(Se.predBGs.ZT=ft,o(ft[ft.length-1]),l.mealCOB>0&&(Bt>0||At>0)){for(gt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),ta=gt.length-1;ta>12&>[ta-1]===gt[ta];ta--)gt.pop();Se.predBGs.COB=gt,qt=o(gt[gt.length-1]),dt=Math.max(dt,o(gt[gt.length-1]))}if(Bt>0||At>0){if(vt){for(pt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),ta=pt.length-1;ta>12&&pt[ta-1]===pt[ta];ta--)pt.pop();Se.predBGs.UAM=pt,kt=o(pt[pt.length-1]),pt[pt.length-1]&&(dt=Math.max(dt,o(pt[pt.length-1])))}Se.eventualBG=dt}console.error("UAM Impact:"+_t+"mg/dL per 5m; UAM Duration:"+Xt+"hours"),Et=Math.max(39,Et),Lt=Math.max(39,Lt),zt=Math.max(39,zt),Ft=o(Et);var aa=l.mealCOB/l.carbs;Pt=o(zt<999&&Lt<999?(1-aa)*UAMpredBG+aa*COBpredBG:Lt<999?(Kt+COBpredBG)/2:zt<999?(Kt+UAMpredBG)/2:Kt),Jt>Pt&&(Pt=Jt),Nt=o(Nt=Mt||At>0?vt?aa*Zt+(1-aa)*Ht:Zt:vt?Ht:$t);var ra=zt;if(Jtzt&&(ra=(zt+Jt)/2);if(ra=o(ra),l.carbs)if(!vt&&Lt<999)Ft=o(Math.max(Et,Lt));else if(Lt<999){var na=aa*Lt+(1-aa)*ra;Ft=o(Math.max(Et,Lt,na))}else Ft=vt?ra:Nt;else vt&&(Ft=o(Math.max(Et,ra)));Ft=Math.min(Ft,Pt),process.stderr.write("minPredBG: "+Ft+" minIOBPredBG: "+Et+" minZTGuardBG: "+Jt),Lt<999&&process.stderr.write(" minCOBPredBG: "+Lt),zt<999&&process.stderr.write(" minUAMPredBG: "+zt),console.error(" avgPredBG:"+Pt+" COB/Carbs:"+l.mealCOB+"/"+l.carbs),Vt>Ie&&(Ft=Math.min(Ft,Vt)),Se.COB=l.mealCOB,Se.IOB=a.iob,Se.BGI=n(lt,i),Se.deviation=n(mt,i),Se.ISF=n(rt,i),Se.CR=o(i.carb_ratio,2),Se.target_bg=n(qe,i),Se.TDD=o($,2),Se.reason=tt+", COB: "+Se.COB+", Dev: "+Se.deviation+", BGI: "+Se.BGI+", CR: "+Se.CR+", Target: "+Se.target_bg+", minPredBG "+n(Ft,i)+", minGuardBG "+n(Nt,i)+", IOBpredBG "+n(Wt,i),qt>0&&(Se.reason+=", COBpredBG "+n(qt,i)),kt>0&&(Se.reason+=", UAMpredBG "+n(kt,i)),Se.reason+=tddReason+Be,Se.reason+="; ";var ia=ut;ia<40&&(ia=Math.min(Nt,ia));var sa,la=Ye-ia,ma=240,ua=240;if(l.mealCOB>0&&(Bt>0||At>0)){for(ta=0;tasa*Ie&&(console.error("maxDelta "+n(We,i)+" > "+100*sa+"% of BG "+n(Ie,i)+" - disabling SMB"),Se.reason+="maxDelta "+n(We,i)+" > "+100*sa+"% of BG "+n(Ie,i)+" - SMB disabled!, ",bt=!1),console.error("BG projected to remain above "+n(ke,i)+" for "+ma+"minutes"),(ua<240||ma<60)&&console.error("BG projected to remain above "+n(Ye,i)+" for "+ua+"minutes");var da=ua,ca=i.current_basal*rt*da/60,ga=Math.max(0,l.mealCOB-.25*l.carbs),ha=(la-ca)/csf-ga;ca=o(ca),ha=o(ha),console.error("naive_eventualBG:",ut,"bgUndershoot:",la,"zeroTempDuration:",da,"zeroTempEffect:",ca,"carbsReq:",ha),"Could not parse clock data"==l.reason?console.error("carbsReq unknown: Could not parse clock data"):ha>=i.carbsReqThreshold&&ua<=45&&(Se.carbsReq=ha,Se.reason+=ha+" add'l carbs req w/in "+ua+"m; ");var pa=0;if(Ie0&&Fe>ct)Se.reason+="IOB "+a.iob+" < "+o(20*-i.current_basal/60,2),Se.reason+=" and minDelta "+n(Fe,i)+" > expectedDelta "+n(ct,i)+"; ";else if(Ie=55)return Se.reason+="; Canceling temp at "+Se.deliverAt.getMinutes()+"m past the hour. ",m.setTempBasal(0,0,i,Se,t);var fa=0,ba=Ce;if(dtct&&Fe>0&&!ha)return ut<40?(Se.reason+=", naive_eventualBG < 40. ",m.setTempBasal(0,30,i,Se,t)):(e.delta>Fe?Se.reason+=", but Delta "+n(Oe,i)+" > expectedDelta "+n(ct,i):Se.reason+=", but Min. Delta "+Fe.toFixed(2)+" > Exp. Delta "+n(ct,i),t.duration>15&&r(Ce,i)===r(t.rate,i)?(Se.reason+=", temp "+t.rate+" ~ req "+Ce+"U/hr. ",Se):(Se.reason+="; setting current basal of "+Ce+" as temp. ",m.setTempBasal(Ce,30,i,Se,t)));fa=o(fa=2*Math.min(0,(dt-qe)/rt),2);var va=Math.min(0,(ut-qe)/rt);if(va=o(va,2),Fe<0&&Fe>ct)fa=o(fa*(Fe/ct),2);if(ba=r(ba=Ce+2*fa,i),t.duration*(t.rate-Ce)/605&&ba>=.8*t.rate)return Se.reason+=", temp "+t.rate+" ~< req "+ba+"U/hr. ",Se;if(ba<=0){if((pa=o(60*((la=qe-ut)/rt)/i.current_basal))<0?pa=0:(pa=30*o(pa/30),pa=Math.min(120,Math.max(0,pa))),pa>0)return Se.reason+=", setting "+pa+"m zero temp. ",m.setTempBasal(ba,pa,i,Se,t)}else Se.reason+=", setting "+ba+"U/hr. ";return m.setTempBasal(ba,30,i,Se,t)}if(Fe "+n(ke,i)+" but Delta "+n(Oe,i)+" < Exp. Delta "+n(ct,i):Se.reason+="Eventual BG "+n(dt,i)+" > "+n(ke,i)+" but Min. Delta "+Fe.toFixed(2)+" < Exp. Delta "+n(ct,i),t.duration>15&&r(Ce,i)===r(t.rate,i)?(Se.reason+=", temp "+t.rate+" ~ req "+Ce+"U/hr. ",Se):(Se.reason+="; setting current basal of "+Ce+" as temp. ",m.setTempBasal(Ce,30,i,Se,t));if(Math.min(dt,Ft)15&&r(Ce,i)===r(t.rate,i)?(Se.reason+=", temp "+t.rate+" ~ req "+Ce+"U/hr. ",Se):(Se.reason+="; setting current basal of "+Ce+" as temp. ",m.setTempBasal(Ce,30,i,Se,t));if(dt>=Ee&&(Se.reason+="Eventual BG "+n(dt,i)+" >= "+n(Ee,i)+", "),a.iob>ze)return Se.reason+="IOB "+o(a.iob,2)+" > max_iob "+ze,t.duration>15&&r(Ce,i)===r(t.rate,i)?(Se.reason+=", temp "+t.rate+" ~ req "+Ce+"U/hr. ",Se):(Se.reason+="; setting current basal of "+Ce+" as temp. ",m.setTempBasal(Ce,30,i,Se,t));(fa=o((Math.min(Ft,dt)-qe)/rt,2))>ze-a.iob?(console.error("SMB limited by maxIOB: "+ze-a.iob+" (. insulinReq: "+fa+" U)"),Se.reason+="max_iob "+ze+", ",fa=ze-a.iob):console.error("SMB not limited by maxIOB ( insulinReq: "+fa+" U)."),ba=r(ba=Ce+2*fa,i),fa=o(fa,3),Se.insulinReq=fa;var Ba=o((new Date(Ge).getTime()-a.lastBolusTime)/6e4,1);if(u&&bt&&Ie>Ye){var Ma=o(l.mealCOB/i.carb_ratio,3),_a=0;void 0===i.maxSMBBasalMinutes?(_a=o(30*i.current_basal/60,1),console.error("profile.maxSMBBasalMinutes undefined: defaulting to 30m"),fa>_a&&console.error("SMB limited by maxBolus: "+_a+" ( "+fa+" U)")):a.iob>Ma&&a.iob>0?(console.error("IOB"+a.iob+"> COB"+l.mealCOB+"; mealInsulinReq ="+Ma),i.maxUAMSMBBasalMinutes?(console.error("profile.maxUAMSMBBasalMinutes: "+i.maxUAMSMBBasalMinutes+", profile.current_basal: "+i.current_basal),_a=o(i.current_basal*i.maxUAMSMBBasalMinutes/60,1)):(console.error("profile.maxUAMSMBBasalMinutes undefined: defaulting to 30m"),_a=o(30*i.current_basal/60,1)),fa>_a?console.error("SMB limited by maxUAMSMBBasalMinutes [ "+i.maxUAMSMBBasalMinutes+"m ]: "+_a+"U ( "+fa+"U )"):console.error("SMB is not limited by maxUAMSMBBasalMinutes. ( insulinReq: "+fa+"U )")):(console.error("profile.maxSMBBasalMinutes: "+i.maxSMBBasalMinutes+", profile.current_basal: "+i.current_basal),fa>(_a=o(i.current_basal*i.maxSMBBasalMinutes/60,1))?console.error("SMB limited by maxSMBBasalMinutes: "+i.maxSMBBasalMinutes+"m ]: "+_a+"U ( insulinReq: "+fa+"U )"):console.error("SMB is not limited by maxSMBBasalMinutes. ( insulinReq: "+fa+"U )"));var ya=i.bolus_increment,xa=1/ya,Da=i.smb_delivery_ratio;Da>.5&&console.error("SMB Delivery Ratio increased from default 0.5 to "+o(Da,2));var wa=Math.min(fa*Da,_a);wa=Math.floor(wa*xa)/xa,pa=o(60*((qe-(ut+Et)/2)/rt)/i.current_basal),fa>0&&wa=30?(pa=30*o(pa/30),pa=Math.min(60,Math.max(0,pa))):(Sa=o(Ce*pa/30,2),pa=30),Se.reason+=" insulinReq "+fa,wa>=_a&&(Se.reason+="; maxBolus "+_a),pa>0&&(Se.reason+="; setting "+pa+"m low temp of "+Sa+"U/h"),Se.reason+=". ";var Ta=3;i.SMBInterval&&(Ta=Math.min(10,Math.max(1,i.SMBInterval)));var Ua=o(Ta-Ba,0),Ca=o(60*(Ta-Ba),0)%60;if(console.error("naive_eventualBG "+ut+","+pa+"m "+Sa+"U/h temp needed; last bolus "+Ba+"m ago; maxBolus: "+_a),Ba>Ta?wa>0&&(Se.units=wa,Se.reason+="Microbolusing "+wa+"U. "):Se.reason+="Waiting "+Ua+"m "+Ca+"s to microbolus again. ",pa>0)return Se.rate=Sa,Se.duration=pa,Se}var Ga=m.getMaxSafeBasal(i);return ba>Ga&&(Se.reason+="adj. req. rate: "+ba+" to maxSafeBasal: "+o(Ga,2)+", ",ba=r(Ga,i)),t.duration*(t.rate-Ce)/60>=2*fa?(Se.reason+=t.duration+"m@"+t.rate.toFixed(2)+" > 2 * insulinReq. Setting temp basal of "+ba+"U/hr. ",m.setTempBasal(ba,30,i,Se,t)):void 0===t.duration||0===t.duration?(Se.reason+="no temp, setting "+ba+"U/hr. ",m.setTempBasal(ba,30,i,Se,t)):t.duration>5&&r(ba,i)<=r(t.rate,i)?(Se.reason+="temp "+t.rate+" >~ req "+ba+"U/hr. ",Se):(Se.reason+="temp "+t.rate+"<"+ba+"U/hr. ",m.setTempBasal(ba,30,i,Se,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})();