var trio_determineBasal;(()=>{var e={2982:(e,r,t)=>{var a=t(3531);function o(e,r){r||(r=0);var t=Math.pow(10,r);return Math.round(Math.round(e*t*1e7)/1e7)/t}function n(e,r){return"mmol/L"===r.out_units?o(.0555*e,1):Math.round(e)}e.exports=function(e,r,t,i,s,l,u,d,m,c,g,h,v,B,p){var b=i.min_bg,M=B.overrideTarget;0!=M&&6!=M&&B.useOverride&&!i.temptargetSet&&(b=M);const f=B.smbIsOff,_=B.advancedSettings,x=B.isfAndCr,S=B.isf,y=B.cr,G=B.smbMinutes,w=B.uamMinutes;let O=B.currentTDD;var C="",U="",D=h.useNewFormula,T=0,A=b,F=new Date;c&&(F=new Date(c));const R=B.weightedAverage;var I=1,j=i.sens,E=i.carb_ratio;B.useOverride&&(I=B.overridePercentage/100,x?(j/=I,E/=I):(y&&(E/=I),S&&(j/=I)));const q=i.weightPercentage,W=B.average_total_data,P=Math.min(i.autosens_min,i.autosens_max),k=Math.max(i.autosens_min,i.autosens_max);(k==P||k<1||P>1)&&(D=!1,console.log("Dynamic ISF disabled due to current autosens settings"));const L=e.glucose,z=h.adjustmentFactor,N=h.adjustmentFactorSigmoid,Z=h.sigmoid,H=b;var $,J=!1,K="",Q=1;W>0&&(Q=R/W),Q>1?(Q=o(Q=Math.min(Q,i.autosens_max),2),i.autosens_max):Q<1&&(Q=o(Q=Math.max(Q,i.autosens_min),2),i.autosens_min),$=", Basal ratio: "+Q,(i.high_temptarget_raises_sensitivity||i.exercise_mode)&&(J=!0),H>=118&&J&&(D=!1,K="Dynamic ISF temporarily off due to a high temp target/exercising. Current min target: "+H);var V=", Dynamic ratios log: ",X=", AF: "+(Z?N:z),Y="BG: "+L+" mg/dl ("+(.0555*L).toPrecision(2)+" mmol/l)",ee="",re="";const te=h.curve,ae=i.insulinPeakTime,oe=h.useCustomPeakTime;var ne=55,ie=65;switch(te){case"rapid-acting":ie=65;break;case"ultra-rapid":ie=50}oe?(ne=120-ae,console.log("Custom insulinpeakTime set to :"+ae+", insulinFactor: "+ne)):(ne=120-ie,console.log("insulinFactor set to : "+ne)),tdd_before=O,q<1&&R>1&&(O=R,console.log("Using weighted TDD average: "+o(O,2)+" U, instead of past 24 h ("+o(tdd_before,2)+" U), weight: "+q),re=", Weighted TDD: "+o(O,2)+" U");var se="";if(D)if(Z){const e=P,r=k-e;var le=k-1;1==k&&(le=k+.01-1);const t=.0555*(L-b)*N*Q+Math.log10(1/le-e/le)/Math.log10(Math.E);ue=r/(1+Math.exp(-t))+e,ee=", Sigmoid function"}else{var ue=j*z*O*Math.log(L/ne+1)/1800;ee=", Logarithmic formula"}var de="",me="";if(D&&O>0){de=", Dynamic ISF: On",ue>k?(K=", Dynamic ISF limited by autosens_max setting: "+k+" ("+o(ue,2)+"), ",me=", Autosens/Dynamic Limit: "+k+" ("+o(ue,2)+")",ue=k):ue
-.5?"+"+o(e.delta,0):o(e.delta,0);var _e=Math.min(e.delta,e.short_avgdelta),xe=Math.min(e.short_avgdelta,e.long_avgdelta),Se=Math.max(e.delta,e.short_avgdelta,e.long_avgdelta);if((Me<=10||38===Me||fe>=3)&&(ce.reason="CGM is calibrating, in ??? state, or noise is high"),Me>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(Me,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")),be>12||be<-5?ce.reason="If current system time "+F+" is correct, then BG data is too old. The last BG data was read "+be+"m ago at "+pe:0===e.short_avgdelta&&0===e.long_avgdelta&&(e.last_cal&&e.last_cal<3?ce.reason="CGM was just calibrated":ce.reason="CGM data is unchanged ("+n(Me,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"),Me<=10||38===Me||fe>=3||be>12||be<-5)return r.rate>=ve?(ce.reason+=". Replacing high temp basal of "+r.rate+" with neutral temp of "+ve,ce.deliverAt=ge,ce.temp="absolute",ce.duration=30,ce.rate=ve,ce):0===r.rate&&r.duration>30?(ce.reason+=". Shortening "+r.duration+"m long zero temp to 30m. ",ce.deliverAt=ge,ce.temp="absolute",ce.duration=30,ce.rate=0,ce):(ce.reason+=". Temp "+r.rate+" <= current basal "+ve+"U/hr; doing nothing. ",ce);var ye,Ge,we,Oe,Ce=i.max_iob;if(void 0!==b&&(Ge=b),void 0!==i.max_bg&&(we=b),void 0!==i.enableSMB_high_bg_target&&(Oe=i.enableSMB_high_bg_target),void 0===b)return ce.error="Error: could not determine target_bg. ",ce;ye=b;var Ue,De=i.exercise_mode||i.high_temptarget_raises_sensitivity,Te=100;if(Ue=i.half_basal_exercise_target,De&&i.temptargetSet&&ye>Te||i.low_temptarget_lowers_sensitivity&&i.temptargetSet&&ye=ye&&sensitivityRatio0&&(process.stderr.write("TDD-adjustment of basals activated, using tdd24h_14d_Ratio "+o(Q,2)+", TDD 24h = "+o(tdd_before,2)+"U, Weighted average TDD = "+o(R,2)+"U, (Weight percentage = "+q+"), Total data of TDDs (up to 14 days) average = "+o(W,2)+"U. "),ve!==he*I?process.stderr.write("Adjusting basal from "+he*I+" U/h to "+ve+" U/h; "):process.stderr.write("Basal unchanged: "+ve+" U/h; "))),i.temptargetSet);else if(void 0!==s&&s&&(i.sensitivity_raises_target&&s.ratio<1||i.resistance_lowers_target&&s.ratio>1)){Ge=o((Ge-60)/s.ratio)+60,we=o((we-60)/s.ratio)+60;var Fe=o((ye-60)/s.ratio)+60;ye===(Fe=Math.max(80,Fe))?process.stderr.write("target_bg unchanged: "+n(Fe,i)+"; "):process.stderr.write("target_bg from "+n(Fe,i)+" to "+n(Fe,i)+"; "),ye=Fe}var Re=n(ye,i);ye!=b&&(Re=0!==M&&6!==M&&M!==ye?n(b,i)+"→"+n(M,i)+"→"+n(ye,i):n(b,i)+"→"+n(ye,i));var Ie=200,je=200,Ee=200;if(e.noise>=2){var qe=Math.max(1.1,i.noisyCGMTargetMultiplier);Math.min(250,i.maxRaw),Ie=o(Math.min(200,Ge*qe)),je=o(Math.min(200,ye*qe)),Ee=o(Math.min(200,we*qe)),process.stderr.write("Raising target_bg for noisy / raw CGM data, from "+n(Fe,i)+" to "+n(je,i)+"; "),Ge=Ie,ye=je,we=Ee}A=Ge-.5*(Ge-40),A=Math.min(Math.max(i.threshold_setting,A,60),120),console.error(`Threshold set to ${n(A,i)}`);var We="",Pe=(o(j,1),j);if(void 0!==s&&s&&((Pe=o(Pe=j/sensitivityRatio,1))!==j?process.stderr.write("ISF from "+n(j,i)+" to "+n(Pe,i)):process.stderr.write("ISF unchanged: "+n(Pe,i)),We+="Autosens ratio: "+o(sensitivityRatio,2)+", ISF: "+n(j,i)+"→"+n(Pe,i)),console.error("CR:"+E),void 0===t)return ce.error="Error: iob_data undefined. ",ce;var ke,Le=t;if(t.length,t.length>1&&(t=Le[0]),void 0===t.activity||void 0===t.iob)return ce.error="Error: iob_data missing some property. ",ce;var ze=((ke=void 0!==t.lastTemp?o((new Date(F).getTime()-t.lastTemp.date)/6e4):0)+r.duration)%30;if(console.error("currenttemp:"+r.rate+" lastTempAge:"+ke+"m, tempModulus:"+ze+"m"),ce.temp="absolute",ce.deliverAt=ge,d&&r&&t.lastTemp&&r.rate!==t.lastTemp.rate&&ke>10&&r.duration)return ce.reason="Warning: currenttemp rate "+r.rate+" != lastTemp rate "+t.lastTemp.rate+" from pumphistory; canceling temp",u.setTempBasal(0,0,i,ce,r);if(r&&t.lastTemp&&r.duration>0){var Ne=ke-t.lastTemp.duration;if(Ne>5&&ke>10)return ce.reason="Warning: currenttemp running but lastTemp from pumphistory ended "+Ne+"m ago; canceling temp",u.setTempBasal(0,0,i,ce,r)}var Ze=o(-t.activity*Pe*5,5),He=o(Ze,2),$e=o(6*(_e-He));$e<0&&($e=o(6*(xe-He)))<0&&($e=o(6*(e.long_avgdelta-He)));var Je,Ke=(Je=t.iob>0?o(Me-t.iob*Pe):o(Me-t.iob*Math.min(Pe,j)))+$e;if(void 0===Ke||isNaN(Ke))return ce.error="Error: could not calculate eventualBG. Sensitivity: "+Pe+" Deviation: "+$e,ce;var Qe,Ve=function(e,r,t){return o(t+(e-r)/24,1)}(ye,Ke,He);ce={temp:"absolute",bg:Me,tick:Be,eventualBG:Ke,insulinReq:0,reservoir:m,deliverAt:ge,sensitivityRatio,CR:o(E,1),current_target:ye,insulinForManualBolus:T,manualBolusErrorString:0,minDelta:_e,expectedDelta:Ve,minGuardBG:Qe,minPredBG:_r,threshold:n(A,i)};var Xe=[],Ye=[],er=[],rr=[];Xe.push(Me),Ye.push(Me),rr.push(Me),er.push(Me);let tr=!1;f?(console.error("SMBs are always off."),tr=!1):tr=function(e,r,t,a,o,i,s,l){if(s.smbIsScheduledOff){let e=new Date(l.getHours()),r=s.start,t=s.end;if(r=r&&et&&(e>=r||e100?(console.error("SMB disabled due to high temptarget of "+o),!1):!0===t.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?(t.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&&t.mealCOB?(t.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 "+t.mealCOB),!0):!0===e.enableSMB_after_carbs&&t.carbs?(t.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?(t.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&&a>=i?(console.error("Checking BG to see if High for SMB enablement."),console.error("Current BG",a," | High BG ",i),t.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,d,l,Me,ye,Oe,B,F);var ar,or=i.enableUAM,nr=0;nr=o(_e-He,1);var ir=o(_e-He,1);csf=Pe/E,console.error("profile.sens:"+n(j,i)+", sens:"+n(Pe,i)+", CSF:"+o(csf,1));var sr=o(30*csf*5/60,1);nr>sr&&(console.error("Limiting carb impact from "+nr+" to "+sr+"mg/dL/5m (30g/h)"),nr=sr);var lr=3;sensitivityRatio&&(lr/=sensitivityRatio);var ur=lr;if(l.carbs){lr=Math.max(lr,l.mealCOB/20);var dr=o((new Date(F).getTime()-l.lastCarbTime)/6e4),mr=(l.carbs-l.mealCOB)/l.carbs;ur=o(ur=lr+1.5*dr/60,1),console.error("Last carbs "+dr+" minutes ago; remainingCATime:"+ur+"hours; "+o(100*mr,1)+"% carbs absorbed")}var cr=Math.max(0,nr/5*60*ur/2)/csf,gr=90,hr=1;i.remainingCarbsCap&&(gr=Math.min(90,i.remainingCarbsCap)),i.remainingCarbsFraction&&(hr=Math.min(1,i.remainingCarbsFraction));var vr=1-hr,Br=Math.max(0,l.mealCOB-cr-l.carbs*vr),pr=(Br=Math.min(gr,Br))*csf*5/60/(ur/2);pr=Math.round(1e7*pr)/1e7;var br=o(l.slopeFromMaxDeviation,2),Mr=o(l.slopeFromMinDeviation,2),fr=Math.min(br,-Mr/3);ar=0===nr?0:Math.min(60*ur/5/2,Math.max(0,l.mealCOB*csf/nr)),console.error("Carb Impact:"+nr+"mg/dL per 5m; CI Duration:"+o(5*ar/60*2,1)+"hours; remaining CI ("+ur/2+"h peak):"+o(pr,1)+"mg/dL per 5m");var _r,xr,Sr,yr,Gr,wr=999,Or=999,Cr=999,Ur=999,Dr=999,Tr=999,Ar=999,Fr=Ke,Rr=Me,Ir=Me,jr=0,Er=[],qr=[];try{Le.forEach((function(e){var r=o(-e.activity*Pe*5,2),t=o(-e.iobWithZeroTemp.activity*Pe*5,2),a=Je,n=nr*(1-Math.min(1,Ye.length/12));!0===(D&&!Z)?(Fr=Ye[Ye.length-1]+o(-e.activity*(1800/(O*z*Math.log(Math.max(Ye[Ye.length-1],39)/ne+1)))*5,2)+n,a=rr[rr.length-1]+o(-e.iobWithZeroTemp.activity*(1800/(O*z*Math.log(Math.max(rr[rr.length-1],39)/ne+1)))*5,2),console.log("Dynamic ISF (Logarithmic Formula) )adjusted predictions for IOB and ZT: IOBpredBG: "+o(Fr,2)+" , ZTpredBG: "+o(a,2))):(Fr=Ye[Ye.length-1]+r+n,a=rr[rr.length-1]+t);var i=Math.max(0,Math.max(0,nr)*(1-Xe.length/Math.max(2*ar,1))),s=Math.min(Xe.length,12*ur-Xe.length),l=Math.max(0,s/(ur/2*12)*pr);Er.push(o(l,0)),qr.push(o(i,0)),COBpredBG=Xe[Xe.length-1]+r+Math.min(0,n)+i+l;var u=Math.max(0,ir+er.length*fr),d=Math.max(0,ir*(1-er.length/Math.max(36,1))),m=Math.min(u,d);m>0&&(jr=o(5*(er.length+1)/60,1)),!0===(D&&!Z)?(UAMpredBG=er[er.length-1]+o(-e.activity*(1800/(O*z*Math.log(Math.max(er[er.length-1],39)/ne+1)))*5,2)+Math.min(0,n)+m,console.log("Dynamic ISF (Logarithmic Formula) adjusted prediction for UAM: UAMpredBG: "+o(UAMpredBG,2))):UAMpredBG=er[er.length-1]+r+Math.min(0,n)+m,Ye.length<48&&Ye.push(Fr),Xe.length<48&&Xe.push(COBpredBG),er.length<48&&er.push(UAMpredBG),rr.length<48&&rr.push(a),COBpredBG18&&FrRr&&(Rr=Fr),(ar||pr>0)&&Xe.length>18&&COBpredBG0)&&COBpredBG>Rr&&(Ir=COBpredBG),or&&er.length>12&&UAMpredBGRr&&UAMpredBG}))}catch(e){console.error("Problem with iobArray. Optional feature Advanced Meal Assist disabled")}l.mealCOB&&(console.error("predCIs (mg/dL/5m):"+qr.join(" ")),console.error("remainingCIs: "+Er.join(" "))),ce.predBGs={},Ye.forEach((function(e,r,t){t[r]=o(Math.min(401,Math.max(39,e)))}));for(var Wr=Ye.length-1;Wr>12&&Ye[Wr-1]===Ye[Wr];Wr--)Ye.pop();for(ce.predBGs.IOB=Ye,Sr=o(Ye[Ye.length-1]),rr.forEach((function(e,r,t){t[r]=o(Math.min(401,Math.max(39,e)))})),Wr=rr.length-1;Wr>6&&!(rr[Wr-1]>=rr[Wr]||rr[Wr]<=ye);Wr--)rr.pop();if(ce.predBGs.ZT=rr,o(rr[rr.length-1]),l.mealCOB>0&&(nr>0||pr>0)){for(Xe.forEach((function(e,r,t){t[r]=o(Math.min(1500,Math.max(39,e)))})),Wr=Xe.length-1;Wr>12&&Xe[Wr-1]===Xe[Wr];Wr--)Xe.pop();ce.predBGs.COB=Xe,yr=o(Xe[Xe.length-1]),Ke=Math.max(Ke,o(Xe[Xe.length-1])),console.error("COBpredBG: "+o(Xe[Xe.length-1]))}if(nr>0||pr>0){if(or){for(er.forEach((function(e,r,t){t[r]=o(Math.min(401,Math.max(39,e)))})),Wr=er.length-1;Wr>12&&er[Wr-1]===er[Wr];Wr--)er.pop();ce.predBGs.UAM=er,Gr=o(er[er.length-1]),er[er.length-1]&&(Ke=Math.max(Ke,o(er[er.length-1])))}ce.eventualBG=Ke}console.error("UAM Impact:"+ir+"mg/dL per 5m; UAM Duration:"+jr+"hours"),wr=Math.max(39,wr),Or=Math.max(39,Or),Cr=Math.max(39,Cr),_r=o(wr);var Pr=l.mealCOB/l.carbs;xr=o(Cr<999&&Or<999?(1-Pr)*UAMpredBG+Pr*COBpredBG:Or<999?(Fr+COBpredBG)/2:Cr<999?(Fr+UAMpredBG)/2:Fr),Ar>xr&&(xr=Ar),Qe=o(Qe=ar||pr>0?or?Pr*Ur+(1-Pr)*Dr:Ur:or?Dr:Tr);var kr=Cr;if(ArCr&&(kr=(Cr+Ar)/2);if(kr=o(kr),l.carbs)if(!or&&Or<999)_r=o(Math.max(wr,Or));else if(Or<999){var zr=Pr*Or+(1-Pr)*kr;_r=o(Math.max(wr,Or,zr))}else _r=or?kr:Qe;else or&&(_r=o(Math.max(wr,kr)));_r=Math.min(_r,xr),process.stderr.write("minPredBG: "+_r+" minIOBPredBG: "+wr+" minZTGuardBG: "+Ar),Or<999&&process.stderr.write(" minCOBPredBG: "+Or),Cr<999&&process.stderr.write(" minUAMPredBG: "+Cr),console.error(" avgPredBG:"+xr+" COB/Carbs:"+l.mealCOB+"/"+l.carbs),Ir>Me&&(_r=Math.min(_r,Ir)),ce.COB=l.mealCOB,ce.IOB=t.iob,ce.BGI=n(He,i),ce.deviation=n($e,i),ce.ISF=n(Pe,i),ce.CR=o(E,1),ce.target_bg=n(ye,i),ce.current_target=o(ye,0),ce.reason=We+", COB: "+ce.COB+", Dev: "+ce.deviation+", BGI: "+ce.BGI+", CR: "+ce.CR+", Target: "+Re+", minPredBG "+n(_r,i)+", minGuardBG "+n(Qe,i)+", IOBpredBG "+n(Sr,i),yr>0&&(ce.reason+=", COBpredBG "+n(yr,i)),Gr>0&&(ce.reason+=", UAMpredBG "+n(Gr,i)),ce.reason+=U,ce.reason+="; ";var Nr=Je;Nr<40&&(Nr=Math.min(Qe,Nr));var Zr,Hr=A-Nr,$r=240,Jr=240;if(l.mealCOB>0&&(nr>0||pr>0)){for(Wr=0;WrZr*Me&&(console.error("maxDelta "+n(Se,i)+" > "+100*Zr+"% of BG "+n(Me,i)+" - disabling SMB"),ce.reason+="maxDelta "+n(Se,i)+" > "+100*Zr+"% of BG "+n(Me,i)+" - SMB disabled!, ",tr=!1),console.error("BG projected to remain above "+n(Ge,i)+" for "+$r+"minutes"),(Jr<240||$r<60)&&console.error("BG projected to remain above "+n(A,i)+" for "+Jr+"minutes");var Kr=Jr,Qr=i.current_basal*I*Pe*Kr/60,Vr=Math.max(0,l.mealCOB-.25*l.carbs),Xr=(Hr-Qr)/csf-Vr;Qr=o(Qr),Xr=o(Xr),console.error("naive_eventualBG:",Je,"bgUndershoot:",Hr,"zeroTempDuration:",Kr,"zeroTempEffect:",Qr,"carbsReq:",Xr),"Could not parse clock data"==l.reason?console.error("carbsReq unknown: Could not parse clock data"):Xr>=i.carbsReqThreshold&&Jr<=45&&(ce.carbsReq=Xr,ce.reason+=Xr+" add'l carbs req w/in "+Jr+"m; ");var Yr=0;if(Me0&&_e>Ve)ce.reason+="IOB "+t.iob+" < "+o(-i.current_basal*I*20/60,2),ce.reason+=" and minDelta "+n(_e,i)+" > expectedDelta "+n(Ve,i)+"; ";else if(Me=55){if(!tr)return ce.reason+="; Canceling temp at "+(60-ce.deliverAt.getMinutes())+"min before turn of the hour to avoid beeping of MDT. SMB are disabled anyways.",u.setTempBasal(0,0,i,ce,r);console.error(60-ce.deliverAt.getMinutes()+"min before turn of the hour, but SMB's are enabled - not skipping neutral temps.")}var et=0,rt=ve,tt=0;if(KeVe&&_e>0&&!Xr)return Je<40?(ce.reason+=", naive_eventualBG < 40. ",u.setTempBasal(0,30,i,ce,r)):(e.delta>_e?ce.reason+=", but Delta "+n(Be,i)+" > expectedDelta "+n(Ve,i):ce.reason+=", but Min. Delta "+_e.toFixed(2)+" > Exp. Delta "+n(Ve,i),r.duration>15&&a(ve,i)===a(r.rate,i)?(ce.reason+=", temp "+r.rate+" ~ req "+ve+"U/hr. ",ce):(ce.reason+="; setting current basal of "+ve+" as temp. ",u.setTempBasal(ve,30,i,ce,r)));et=o(et=2*Math.min(0,(Ke-ye)/Pe),2);var at=Math.min(0,(Je-ye)/Pe);at=o(at,2),_e<0&&_e>Ve&&(et=o(et*(_e/Ve),2)),rt=a(rt=ve+2*et,i),tt=r.duration*(r.rate-ve)/60;var ot=Math.min(et,at);if(console.log("naiveInsulinReq:"+at),tt5&&rt>=.8*r.rate)return ce.reason+=", temp "+r.rate+" ~< req "+rt+"U/hr. ",ce;if(rt<=0){if((Yr=o((Hr=ye-Je)/Pe*60/i.current_basal*I))<0?Yr=0:(Yr=30*o(Yr/30),Yr=Math.min(120,Math.max(0,Yr))),Yr>0)return ce.reason+=", setting "+Yr+"m zero temp. ",u.setTempBasal(rt,Yr,i,ce,r)}else ce.reason+=", setting "+rt+"U/hr. ";return u.setTempBasal(rt,30,i,ce,r)}if(_e=2||Ve+-1*_e>=2)&&(ce.manualBolusErrorString=_e>=0&&Ve>0?3:_e<0&&Ve<=0||_e<0&&Ve>=0?4:5),ce.insulinForManualBolus=o((ce.eventualBG-ce.target_bg)/Pe,2),!d||!tr))return e.delta<_e?ce.reason+="Eventual BG "+n(Ke,i)+" > "+n(Ge,i)+" but Delta "+n(Be,i)+" < Exp. Delta "+n(Ve,i):ce.reason+="Eventual BG "+n(Ke,i)+" > "+n(Ge,i)+" but Min. Delta "+_e.toFixed(2)+" < Exp. Delta "+n(Ve,i),r.duration>15&&a(ve,i)===a(r.rate,i)?(ce.reason+=", temp "+r.rate+" ~ req "+ve+"U/hr. ",ce):(ce.reason+="; setting current basal of "+ve+" as temp. ",u.setTempBasal(ve,30,i,ce,r));if(Math.min(Ke,_r)Ge&&(ce.manualBolusErrorString=6,ce.insulinForManualBolus=o((ce.eventualBG-ce.target_bg)/Pe,2)),ce.minPredBG=_r,!d||!tr))return ce.reason+=n(Ke,i)+"-"+n(_r,i)+" in range: no temp required",r.duration>15&&a(ve,i)===a(r.rate,i)?(ce.reason+=", temp "+r.rate+" ~ req "+ve+"U/hr. ",ce):(ce.reason+="; setting current basal of "+ve+" as temp. ",u.setTempBasal(ve,30,i,ce,r));if(Ke>=we&&(ce.reason+="Eventual BG "+n(Ke,i)+" >= "+n(we,i)+", ",Ke>we&&(ce.insulinForManualBolus=o((Ke-ye)/Pe,2))),t.iob>Ce)return ce.reason+="IOB "+o(t.iob,2)+" > max_iob "+Ce,r.duration>15&&a(ve,i)===a(r.rate,i)?(ce.reason+=", temp "+r.rate+" ~ req "+ve+"U/hr. ",ce):(ce.reason+="; setting current basal of "+ve+" as temp. ",u.setTempBasal(ve,30,i,ce,r));et=o((Math.min(_r,Ke)-ye)/Pe,2),T=o((Ke-ye)/Pe,2),et>Ce-t.iob?(console.error("SMB limited by maxIOB: "+Ce-t.iob+" (. insulinReq: "+et+" U)"),ce.reason+="max_iob "+Ce+", ",et=Ce-t.iob):console.error("SMB not limited by maxIOB ( insulinReq: "+et+" U)."),T>Ce-t.iob?(console.error("Ev. Bolus limited by maxIOB: "+Ce-t.iob+" (. insulinForManualBolus: "+T+" U)"),ce.reason+="max_iob "+Ce+", "):console.error("Ev. Bolus would not be limited by maxIOB ( insulinForManualBolus: "+T+" U)."),rt=a(rt=ve+2*et,i),et=o(et,3),ce.insulinReq=et;var nt=o((new Date(F).getTime()-t.lastBolusTime)/6e4,1);if(d&&tr&&Me>A){var it=30;void 0!==i.maxSMBBasalMinutes&&(it=i.maxSMBBasalMinutes);var st=30;void 0!==i.maxUAMSMBBasalMinutes&&(st=i.maxUAMSMBBasalMinutes),B.useOverride&&_&&G!==it&&(console.error("SMB Max Minutes - setting overriden from "+it+" to "+G),it=G),B.useOverride&&_&&w!==st&&(console.error("UAM Max Minutes - setting overriden from "+st+" to "+w),st=w);var lt=o(l.mealCOB/E,3),ut=0;void 0===it?(ut=o(i.current_basal*I*30/60,1),console.error("smbMinutesSetting undefined: defaulting to 30m"),et>ut&&console.error("SMB limited by maxBolus: "+ut+" ( "+et+" U)")):t.iob>lt&&t.iob>0?(console.error("IOB"+t.iob+"> COB"+l.mealCOB+"; mealInsulinReq ="+lt),st?(console.error("maxUAMSMBBasalMinutes: "+st+", profile.current_basal: "+i.current_basal*I),ut=o(i.current_basal*I*st/60,1)):(console.error("maxUAMSMBBasalMinutes undefined: defaulting to 30m"),ut=o(i.current_basal*I*30/60,1)),et>ut?console.error("SMB limited by maxUAMSMBBasalMinutes [ "+st+"m ]: "+ut+"U ( "+et+"U )"):console.error("SMB is not limited by maxUAMSMBBasalMinutes. ( insulinReq: "+et+"U )")):(console.error(".maxSMBBasalMinutes: "+it+", profile.current_basal: "+i.current_basal*I),et>(ut=o(i.current_basal*I*it/60,1))?console.error("SMB limited by maxSMBBasalMinutes: "+it+"m ]: "+ut+"U ( insulinReq: "+et+"U )"):console.error("SMB is not limited by maxSMBBasalMinutes. ( insulinReq: "+et+"U )"));var dt=i.bolus_increment,mt=1/dt,ct=Math.min(i.smb_delivery_ratio,1);.5!=ct&&console.error("SMB Delivery Ratio changed from default 0.5 to "+o(ct,2));var gt=Math.min(et*ct,ut);gt=Math.floor(gt*mt)/mt,Yr=o((ye-(Je+wr)/2)/Pe*60/i.current_basal*I),et>0&>=30?(Yr=30*o(Yr/30),Yr=Math.min(60,Math.max(0,Yr))):(ht=o(ve*Yr/30,2),Yr=30),ce.reason+=" insulinReq "+et,gt>=ut&&(ce.reason+="; maxBolus "+ut),Yr>0&&(ce.reason+="; setting "+Yr+"m low temp of "+ht+"U/h"),ce.reason+=". ";var vt=3;i.SMBInterval&&(vt=Math.min(10,Math.max(1,i.SMBInterval)));var Bt=o(vt-nt,0),pt=o(60*(vt-nt),0)%60;if(console.error("naive_eventualBG "+Je+","+Yr+"m "+ht+"U/h temp needed; last bolus "+nt+"m ago; maxBolus: "+ut),nt>vt?gt>0&&(ce.units=gt,ce.reason+="Microbolusing "+gt+"U. "):ce.reason+="Waiting "+Bt+"m "+pt+"s to microbolus again. ",Yr>0)return ce.rate=ht,ce.duration=Yr,ce}var bt=u.getMaxSafeBasal(i);return rt>bt&&(ce.reason+="adj. req. rate: "+rt+" to maxSafeBasal: "+o(bt,2)+", ",rt=a(bt,i)),(tt=r.duration*(r.rate-ve)/60)>=2*et?(ce.reason+=r.duration+"m@"+r.rate.toFixed(2)+" > 2 * insulinReq. Setting temp basal of "+rt+"U/hr. ",u.setTempBasal(rt,30,i,ce,r)):void 0===r.duration||0===r.duration?(ce.reason+="no temp, setting "+rt+"U/hr. ",u.setTempBasal(rt,30,i,ce,r)):r.duration>5&&a(rt,i)<=a(r.rate,i)?(ce.reason+="temp "+r.rate+" >~ req "+rt+"U/hr. ",ce):(ce.reason+="temp "+r.rate+"<"+rt+"U/hr. ",u.setTempBasal(rt,30,i,ce,r))}},3531:(e,r,t)=>{var a=t(2296);e.exports=function(e,r){var t=20;return void 0!==r&&"string"==typeof r.model&&(a(r.model,"54")||a(r.model,"23"))&&(t=40),e<1?Math.round(e*t)/t:e<10?Math.round(20*e)/20:Math.round(10*e)/10}},1873:(e,r,t)=>{var a=t(9325).Symbol;e.exports=a},4932:e=>{e.exports=function(e,r){for(var t=-1,a=null==e?0:e.length,o=Array(a);++t{e.exports=function(e,r,t){return e==e&&(void 0!==t&&(e=e<=t?e:t),void 0!==r&&(e=e>=r?e:r)),e}},2552:(e,r,t)=>{var a=t(1873),o=t(659),n=t(9350),i=a?a.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)}},7556:(e,r,t)=>{var a=t(1873),o=t(4932),n=t(6449),i=t(4394),s=a?a.prototype:void 0,l=s?s.toString:void 0;e.exports=function e(r){if("string"==typeof r)return r;if(n(r))return o(r,e)+"";if(i(r))return l?l.call(r):"";var t=r+"";return"0"==t&&1/r==-1/0?"-0":t}},4128:(e,r,t)=>{var a=t(1800),o=/^\s+/;e.exports=function(e){return e?e.slice(0,a(e)+1).replace(o,""):e}},4840:(e,r,t)=>{var a="object"==typeof t.g&&t.g&&t.g.Object===Object&&t.g;e.exports=a},659:(e,r,t)=>{var a=t(1873),o=Object.prototype,n=o.hasOwnProperty,i=o.toString,s=a?a.toStringTag:void 0;e.exports=function(e){var r=n.call(e,s),t=e[s];try{e[s]=void 0;var a=!0}catch(e){}var o=i.call(e);return a&&(r?e[s]=t:delete e[s]),o}},9350:e=>{var r=Object.prototype.toString;e.exports=function(e){return r.call(e)}},9325:(e,r,t)=>{var a=t(4840),o="object"==typeof self&&self&&self.Object===Object&&self,n=a||o||Function("return this")();e.exports=n},1800:e=>{var r=/\s/;e.exports=function(e){for(var t=e.length;t--&&r.test(e.charAt(t)););return t}},2296:(e,r,t)=>{var a=t(7133),o=t(7556),n=t(1489),i=t(3222);e.exports=function(e,r,t){e=i(e),r=o(r);var s=e.length,l=t=void 0===t?s:a(n(t),0,s);return(t-=r.length)>=0&&e.slice(t,l)==r}},6449:e=>{var r=Array.isArray;e.exports=r},3805:e=>{e.exports=function(e){var r=typeof e;return null!=e&&("object"==r||"function"==r)}},346:e=>{e.exports=function(e){return null!=e&&"object"==typeof e}},4394:(e,r,t)=>{var a=t(2552),o=t(346);e.exports=function(e){return"symbol"==typeof e||o(e)&&"[object Symbol]"==a(e)}},7400:(e,r,t)=>{var a=t(6993),o=1/0;e.exports=function(e){return e?(e=a(e))===o||e===-1/0?17976931348623157e292*(e<0?-1:1):e==e?e:0:0===e?e:0}},1489:(e,r,t)=>{var a=t(7400);e.exports=function(e){var r=a(e),t=r%1;return r==r?t?r-t:r:0}},6993:(e,r,t)=>{var a=t(4128),o=t(3805),n=t(4394),i=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,l=/^0o[0-7]+$/i,u=parseInt;e.exports=function(e){if("number"==typeof e)return e;if(n(e))return NaN;if(o(e)){var r="function"==typeof e.valueOf?e.valueOf():e;e=o(r)?r+"":r}if("string"!=typeof e)return 0===e?e:+e;e=a(e);var t=s.test(e);return t||l.test(e)?u(e.slice(2),t?2:8):i.test(e)?NaN:+e}},3222:(e,r,t)=>{var a=t(7556);e.exports=function(e){return null==e?"":a(e)}}},r={};function t(a){var o=r[a];if(void 0!==o)return o.exports;var n=r[a]={exports:{}};return e[a](n,n.exports,t),n.exports}t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}();var a=t(2982);trio_determineBasal=a})();