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;if(void 0!==t.lastTemp){var ze=new Date(t.lastTemp.timestamp).getTime();ke=o((new Date(F).getTime()-ze)/6e4)}else ke=0;var Ne=(ke+r.duration)%30;if(console.error("currenttemp:"+r.rate+" lastTempAge:"+ke+"m, tempModulus:"+Ne+"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 Ze=ke-t.lastTemp.duration;if(Ze>5&&ke>10)return ce.reason="Warning: currenttemp running but lastTemp from pumphistory ended "+o(Ze,2)+"m ago; canceling temp",u.setTempBasal(0,0,i,ce,r)}var He=o(-t.activity*Pe*5,5),$e=o(He,2),Je=o(6*(_e-$e));Je<0&&(Je=o(6*(xe-$e)))<0&&(Je=o(6*(e.long_avgdelta-$e)));var Ke,Qe=(Ke=t.iob>0?o(Me-t.iob*Pe):o(Me-t.iob*Math.min(Pe,j)))+Je;if(void 0===Qe||isNaN(Qe))return ce.error="Error: could not calculate eventualBG. Sensitivity: "+Pe+" Deviation: "+Je,ce;var Ve,Xe=function(e,r,t){return o(t+(e-r)/24,1)}(ye,Qe,$e);ce={temp:"absolute",bg:Me,tick:Be,eventualBG:Qe,insulinReq:0,reservoir:m,deliverAt:ge,sensitivityRatio,CR:o(E,1),current_target:ye,insulinForManualBolus:T,manualBolusErrorString:0,minDelta:_e,expectedDelta:Xe,minGuardBG:Ve,minPredBG:xr,threshold:n(A,i)};var Ye=[],er=[],rr=[],tr=[];Ye.push(Me),er.push(Me),tr.push(Me),rr.push(Me);let ar=!1;f?(console.error("SMBs are always off."),ar=!1):ar=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 or,nr=i.enableUAM,ir=0;ir=o(_e-$e,1);var sr=o(_e-$e,1);csf=Pe/E,console.error("profile.sens:"+n(j,i)+", sens:"+n(Pe,i)+", CSF:"+o(csf,1));var lr=o(30*csf*5/60,1);ir>lr&&(console.error("Limiting carb impact from "+ir+" to "+lr+"mg/dL/5m (30g/h)"),ir=lr);var ur=3;sensitivityRatio&&(ur/=sensitivityRatio);var dr=ur;if(l.carbs){ur=Math.max(ur,l.mealCOB/20);var mr=o((new Date(F).getTime()-l.lastCarbTime)/6e4),cr=(l.carbs-l.mealCOB)/l.carbs;dr=o(dr=ur+1.5*mr/60,1),console.error("Last carbs "+mr+" minutes ago; remainingCATime:"+dr+"hours; "+o(100*cr,1)+"% carbs absorbed")}var gr=Math.max(0,ir/5*60*dr/2)/csf,hr=90,vr=1;i.remainingCarbsCap&&(hr=Math.min(90,i.remainingCarbsCap)),i.remainingCarbsFraction&&(vr=Math.min(1,i.remainingCarbsFraction));var Br=1-vr,pr=Math.max(0,l.mealCOB-gr-l.carbs*Br),br=(pr=Math.min(hr,pr))*csf*5/60/(dr/2);br=Math.round(1e7*br)/1e7;var Mr=o(l.slopeFromMaxDeviation,2),fr=o(l.slopeFromMinDeviation,2),_r=Math.min(Mr,-fr/3);or=0===ir?0:Math.min(60*dr/5/2,Math.max(0,l.mealCOB*csf/ir)),console.error("Carb Impact:"+ir+"mg/dL per 5m; CI Duration:"+o(5*or/60*2,1)+"hours; remaining CI ("+dr/2+"h peak):"+o(br,1)+"mg/dL per 5m");var xr,Sr,yr,Gr,wr,Or=999,Cr=999,Ur=999,Dr=999,Tr=999,Ar=999,Fr=999,Rr=Qe,Ir=Me,jr=Me,Er=0,qr=[],Wr=[];try{Le.forEach((function(e){var r=o(-e.activity*Pe*5,2),t=o(-e.iobWithZeroTemp.activity*Pe*5,2),a=Ke,n=ir*(1-Math.min(1,er.length/12));!0===(D&&!Z)?(Rr=er[er.length-1]+o(-e.activity*(1800/(O*z*Math.log(Math.max(er[er.length-1],39)/ne+1)))*5,2)+n,a=tr[tr.length-1]+o(-e.iobWithZeroTemp.activity*(1800/(O*z*Math.log(Math.max(tr[tr.length-1],39)/ne+1)))*5,2),console.log("Dynamic ISF (Logarithmic Formula) )adjusted predictions for IOB and ZT: IOBpredBG: "+o(Rr,2)+" , ZTpredBG: "+o(a,2))):(Rr=er[er.length-1]+r+n,a=tr[tr.length-1]+t);var i=Math.max(0,Math.max(0,ir)*(1-Ye.length/Math.max(2*or,1))),s=Math.min(Ye.length,12*dr-Ye.length),l=Math.max(0,s/(dr/2*12)*br);qr.push(o(l,0)),Wr.push(o(i,0)),COBpredBG=Ye[Ye.length-1]+r+Math.min(0,n)+i+l;var u=Math.max(0,sr+rr.length*_r),d=Math.max(0,sr*(1-rr.length/Math.max(36,1))),m=Math.min(u,d);m>0&&(Er=o(5*(rr.length+1)/60,1)),!0===(D&&!Z)?(UAMpredBG=rr[rr.length-1]+o(-e.activity*(1800/(O*z*Math.log(Math.max(rr[rr.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=rr[rr.length-1]+r+Math.min(0,n)+m,er.length<48&&er.push(Rr),Ye.length<48&&Ye.push(COBpredBG),rr.length<48&&rr.push(UAMpredBG),tr.length<48&&tr.push(a),COBpredBG18&&RrIr&&(Ir=Rr),(or||br>0)&&Ye.length>18&&COBpredBG0)&&COBpredBG>Ir&&(jr=COBpredBG),nr&&rr.length>12&&UAMpredBGIr&&UAMpredBG}))}catch(e){console.error("Problem with iobArray. Optional feature Advanced Meal Assist disabled")}l.mealCOB&&(console.error("predCIs (mg/dL/5m):"+Wr.join(" ")),console.error("remainingCIs: "+qr.join(" "))),ce.predBGs={},er.forEach((function(e,r,t){t[r]=o(Math.min(401,Math.max(39,e)))}));for(var Pr=er.length-1;Pr>12&&er[Pr-1]===er[Pr];Pr--)er.pop();for(ce.predBGs.IOB=er,yr=o(er[er.length-1]),tr.forEach((function(e,r,t){t[r]=o(Math.min(401,Math.max(39,e)))})),Pr=tr.length-1;Pr>6&&!(tr[Pr-1]>=tr[Pr]||tr[Pr]<=ye);Pr--)tr.pop();if(ce.predBGs.ZT=tr,o(tr[tr.length-1]),l.mealCOB>0&&(ir>0||br>0)){for(Ye.forEach((function(e,r,t){t[r]=o(Math.min(1500,Math.max(39,e)))})),Pr=Ye.length-1;Pr>12&&Ye[Pr-1]===Ye[Pr];Pr--)Ye.pop();ce.predBGs.COB=Ye,Gr=o(Ye[Ye.length-1]),Qe=Math.max(Qe,o(Ye[Ye.length-1])),console.error("COBpredBG: "+o(Ye[Ye.length-1]))}if(ir>0||br>0){if(nr){for(rr.forEach((function(e,r,t){t[r]=o(Math.min(401,Math.max(39,e)))})),Pr=rr.length-1;Pr>12&&rr[Pr-1]===rr[Pr];Pr--)rr.pop();ce.predBGs.UAM=rr,wr=o(rr[rr.length-1]),rr[rr.length-1]&&(Qe=Math.max(Qe,o(rr[rr.length-1])))}ce.eventualBG=Qe}console.error("UAM Impact:"+sr+"mg/dL per 5m; UAM Duration:"+Er+"hours"),Or=Math.max(39,Or),Cr=Math.max(39,Cr),Ur=Math.max(39,Ur),xr=o(Or);var kr=l.mealCOB/l.carbs;Sr=o(Ur<999&&Cr<999?(1-kr)*UAMpredBG+kr*COBpredBG:Cr<999?(Rr+COBpredBG)/2:Ur<999?(Rr+UAMpredBG)/2:Rr),Fr>Sr&&(Sr=Fr),Ve=o(Ve=or||br>0?nr?kr*Dr+(1-kr)*Tr:Dr:nr?Tr:Ar);var Lr=Ur;if(FrUr&&(Lr=(Ur+Fr)/2);if(Lr=o(Lr),l.carbs)if(!nr&&Cr<999)xr=o(Math.max(Or,Cr));else if(Cr<999){var Nr=kr*Cr+(1-kr)*Lr;xr=o(Math.max(Or,Cr,Nr))}else xr=nr?Lr:Ve;else nr&&(xr=o(Math.max(Or,Lr)));xr=Math.min(xr,Sr),process.stderr.write("minPredBG: "+xr+" minIOBPredBG: "+Or+" minZTGuardBG: "+Fr),Cr<999&&process.stderr.write(" minCOBPredBG: "+Cr),Ur<999&&process.stderr.write(" minUAMPredBG: "+Ur),console.error(" avgPredBG:"+Sr+" COB/Carbs:"+l.mealCOB+"/"+l.carbs),jr>Me&&(xr=Math.min(xr,jr)),ce.COB=l.mealCOB,ce.IOB=t.iob,ce.BGI=n($e,i),ce.deviation=n(Je,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(xr,i)+", minGuardBG "+n(Ve,i)+", IOBpredBG "+n(yr,i),Gr>0&&(ce.reason+=", COBpredBG "+n(Gr,i)),wr>0&&(ce.reason+=", UAMpredBG "+n(wr,i)),ce.reason+=U,ce.reason+="; ";var Zr=Ke;Zr<40&&(Zr=Math.min(Ve,Zr));var Hr,$r=A-Zr,Jr=240,Kr=240;if(l.mealCOB>0&&(ir>0||br>0)){for(Pr=0;PrHr*Me&&(console.error("maxDelta "+n(Se,i)+" > "+100*Hr+"% of BG "+n(Me,i)+" - disabling SMB"),ce.reason+="maxDelta "+n(Se,i)+" > "+100*Hr+"% of BG "+n(Me,i)+" - SMB disabled!, ",ar=!1),console.error("BG projected to remain above "+n(Ge,i)+" for "+Jr+"minutes"),(Kr<240||Jr<60)&&console.error("BG projected to remain above "+n(A,i)+" for "+Kr+"minutes");var Qr=Kr,Vr=i.current_basal*I*Pe*Qr/60,Xr=Math.max(0,l.mealCOB-.25*l.carbs),Yr=($r-Vr)/csf-Xr;Vr=o(Vr),Yr=o(Yr),console.error("naive_eventualBG:",Ke,"bgUndershoot:",$r,"zeroTempDuration:",Qr,"zeroTempEffect:",Vr,"carbsReq:",Yr),"Could not parse clock data"==l.reason?console.error("carbsReq unknown: Could not parse clock data"):Yr>=i.carbsReqThreshold&&Kr<=45&&(ce.carbsReq=Yr,ce.reason+=Yr+" add'l carbs req w/in "+Kr+"m; ");var et=0;if(Me0&&_e>Xe)ce.reason+="IOB "+t.iob+" < "+o(-i.current_basal*I*20/60,2),ce.reason+=" and minDelta "+n(_e,i)+" > expectedDelta "+n(Xe,i)+"; ";else if(Me=55){if(!ar)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 rt=0,tt=ve,at=0;if(QeXe&&_e>0&&!Yr)return Ke<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(Xe,i):ce.reason+=", but Min. Delta "+_e.toFixed(2)+" > Exp. Delta "+n(Xe,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)));rt=o(rt=2*Math.min(0,(Qe-ye)/Pe),2);var ot=Math.min(0,(Ke-ye)/Pe);ot=o(ot,2),_e<0&&_e>Xe&&(rt=o(rt*(_e/Xe),2)),tt=a(tt=ve+2*rt,i),at=r.duration*(r.rate-ve)/60,at=Math.round(1e6*at)/1e6;var nt=Math.min(rt,ot);if(console.log("naiveInsulinReq:"+ot),at5&&tt>=Math.round(.8*r.rate*1e6)/1e6)return ce.reason+=", temp "+r.rate+" ~< req "+tt+"U/hr. ",ce;if(tt<=0){if((et=o(($r=ye-Ke)/Pe*60/i.current_basal*I))<0?et=0:(et=30*o(et/30),et=Math.min(120,Math.max(0,et))),et>0)return ce.reason+=", setting "+et+"m zero temp. ",u.setTempBasal(tt,et,i,ce,r)}else ce.reason+=", setting "+tt+"U/hr. ";return u.setTempBasal(tt,30,i,ce,r)}if(_e=2||Xe+-1*_e>=2)&&(ce.manualBolusErrorString=_e>=0&&Xe>0?3:_e<0&&Xe<=0||_e<0&&Xe>=0?4:5),ce.insulinForManualBolus=o((ce.eventualBG-ce.target_bg)/Pe,2),!d||!ar))return e.delta<_e?ce.reason+="Eventual BG "+n(Qe,i)+" > "+n(Ge,i)+" but Delta "+n(Be,i)+" < Exp. Delta "+n(Xe,i):ce.reason+="Eventual BG "+n(Qe,i)+" > "+n(Ge,i)+" but Min. Delta "+_e.toFixed(2)+" < Exp. Delta "+n(Xe,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(Qe,xr)Ge&&(ce.manualBolusErrorString=6,ce.insulinForManualBolus=o((ce.eventualBG-ce.target_bg)/Pe,2)),ce.minPredBG=xr,!d||!ar))return ce.reason+=n(Qe,i)+"-"+n(xr,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(Qe>=we&&(ce.reason+="Eventual BG "+n(Qe,i)+" >= "+n(we,i)+", ",Qe>we&&(ce.insulinForManualBolus=o((Qe-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));rt=o((Math.min(xr,Qe)-ye)/Pe,2),T=o((Qe-ye)/Pe,2),rt>Ce-t.iob?(console.error("SMB limited by maxIOB: "+Ce-t.iob+" (. insulinReq: "+rt+" U)"),ce.reason+="max_iob "+Ce+", ",rt=Ce-t.iob):console.error("SMB not limited by maxIOB ( insulinReq: "+rt+" U)."),T>Ce-t.iob?console.error("Ev. Bolus limited by maxIOB: "+Ce-t.iob+" (. insulinForManualBolus: "+T+" U)"):console.error("Ev. Bolus would not be limited by maxIOB ( insulinForManualBolus: "+T+" U)."),tt=a(tt=ve+2*rt,i),rt=o(rt,3),ce.insulinReq=rt;var it=o((new Date(F).getTime()-t.lastBolusTime)/6e4,1);if(d&&ar&&Me>A){var st=30;void 0!==i.maxSMBBasalMinutes&&(st=i.maxSMBBasalMinutes);var lt=30;void 0!==i.maxUAMSMBBasalMinutes&&(lt=i.maxUAMSMBBasalMinutes),B.useOverride&&_&&G!==st&&(console.error("SMB Max Minutes - setting overriden from "+st+" to "+G),st=G),B.useOverride&&_&&w!==lt&&(console.error("UAM Max Minutes - setting overriden from "+lt+" to "+w),lt=w);var ut=o(l.mealCOB/E,3),dt=0;void 0===st?(dt=o(i.current_basal*I*30/60,1),console.error("smbMinutesSetting undefined: defaulting to 30m"),rt>dt&&console.error("SMB limited by maxBolus: "+dt+" ( "+rt+" U)")):t.iob>ut&&t.iob>0?(console.error("IOB"+t.iob+"> COB"+l.mealCOB+"; mealInsulinReq ="+ut),lt?(console.error("maxUAMSMBBasalMinutes: "+lt+", profile.current_basal: "+i.current_basal*I),dt=o(i.current_basal*I*lt/60,1)):(console.error("maxUAMSMBBasalMinutes undefined: defaulting to 30m"),dt=o(i.current_basal*I*30/60,1)),rt>dt?console.error("SMB limited by maxUAMSMBBasalMinutes [ "+lt+"m ]: "+dt+"U ( "+rt+"U )"):console.error("SMB is not limited by maxUAMSMBBasalMinutes. ( insulinReq: "+rt+"U )")):(console.error(".maxSMBBasalMinutes: "+st+", profile.current_basal: "+i.current_basal*I),rt>(dt=o(i.current_basal*I*st/60,1))?console.error("SMB limited by maxSMBBasalMinutes: "+st+"m ]: "+dt+"U ( insulinReq: "+rt+"U )"):console.error("SMB is not limited by maxSMBBasalMinutes. ( insulinReq: "+rt+"U )"));var mt=i.bolus_increment,ct=1/mt,gt=Math.min(i.smb_delivery_ratio,1);.5!=gt&&console.error("SMB Delivery Ratio changed from default 0.5 to "+o(gt,2));var ht=Math.min(rt*gt,dt);ht=Math.floor(ht*ct)/ct,et=o((ye-(Ke+Or)/2)/Pe*60/i.current_basal*I),rt>0&&ht=30?(et=30*o(et/30),et=Math.min(60,Math.max(0,et))):(vt=o(ve*et/30,2),et=30),ce.reason+=" insulinReq "+rt,ht>=dt&&(ce.reason+="; maxBolus "+dt),et>0&&(ce.reason+="; setting "+et+"m low temp of "+vt+"U/h"),ce.reason+=". ";var Bt=3;i.SMBInterval&&(Bt=Math.min(10,Math.max(1,i.SMBInterval)));var pt=o(Bt-it,0),bt=o(60*(Bt-it),0)%60;if(console.error("naive_eventualBG "+Ke+","+et+"m "+vt+"U/h temp needed; last bolus "+it+"m ago; maxBolus: "+dt),it>Bt?ht>0&&(ce.units=ht,ce.reason+="Microbolusing "+ht+"U. "):ce.reason+="Waiting "+pt+"m "+bt+"s to microbolus again. ",et>0)return ce.rate=vt,ce.duration=et,ce}var Mt=u.getMaxSafeBasal(i);return tt>(Mt=Math.round(1e6*Mt)/1e6)&&(ce.reason+="adj. req. rate: "+tt+" to maxSafeBasal: "+o(Mt,2)+", ",tt=a(Mt,i)),at=r.duration*(r.rate-ve)/60,(at=Math.round(1e6*at)/1e6)>=2*rt?(ce.reason+=r.duration+"m@"+r.rate.toFixed(2)+" > 2 * insulinReq. Setting temp basal of "+tt+"U/hr. ",u.setTempBasal(tt,30,i,ce,r)):void 0===r.duration||0===r.duration?(ce.reason+="no temp, setting "+tt+"U/hr. ",u.setTempBasal(tt,30,i,ce,r)):r.duration>5&&a(tt,i)<=a(r.rate,i)?(ce.reason+="temp "+r.rate+" >~ req "+tt+"U/hr. ",ce):(ce.reason+="temp "+r.rate+"<"+tt+"U/hr. ",u.setTempBasal(tt,30,i,ce,r))}},3531:(e,r,t)=>{var a=t(2296);e.exports=function(e,r){e=Math.round(1e6*e)/1e6;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})();