determine-basal.js 34 KB

1
  1. var freeaps_determineBasal;(()=>{var e={5546:(e,r,t)=>{var o=t(6880);function i(e,a){a||(a=0);var r=Math.pow(10,a);return Math.round(e*r)/r}function n(e,a){return"mmol/L"===a.out_units?i(.0555*e,1):Math.round(e)}var s="",l="",m="",u="",d="",c="",g="",h="",f="";function p(e,a){var r=[2,7,12,16,20,50,60,80,90,100,110,150,180,200],t=[0,0,.4,.7,.7,-.5,-.5,-.3,-.2,0,0,.5,.7,.7],o=r.length-1,i=r[0],n=t[0],s=r[o],l=t[o],m=1,u=1,d=1,c=i;if(i>e)m=(u=n)+((l=t[1])-u)/((s=r[1])-(d=i))*(e-d);else if(s<e)m=(u=n=t[o-1])+(l-u)/(s-(d=i=r[o-1]))*(e-d);else for(var g=0;g<=o;g++){if(n=t[g],(i=r[g])==e){m=n;break}if(i>e){m=u+(n-u)/(i-(d=c))*(e-d);break}u=n,c=i}return m*=e>100?a.higher_ISFrange_weight:e>40?a.lower_ISFrange_weight:a.delta_ISFrange_weight}function b(e,a,r){if(void 0===e.smb_delivery_ratio_bg_range||0===e.smb_delivery_ratio_bg_range)return console.error("SMB delivery ratio set to fixed value "+e.smb_delivery_ratio),e.smb_delivery_ratio;var t=Math.min(e.smb_delivery_ratio_min,e.smb_delivery_ratio_max);if(a<=r)return console.error("SMB delivery ratio limited by minimum value "+t),t;var o=Math.max(e.smb_delivery_ratio_min,e.smb_delivery_ratio_max);if(a>=r+e.smb_delivery_ratio_bg_range)return console.error("SMB delivery ratio limited by maximum value "+o),o;var n=t+(o-t)*(a-r)/e.smb_delivery_ratio_bg_range;return console.error("SMB delivery ratio set to interpolated value "+i(n,2)),n}e.exports=function(e,r,t,v,B,_,M,y,S,x,w,D,C,F,I){var G=0,T="",U="",O="",R="",A="",P=0,j=(F=0,0),k=0,W=0,q=0;const E=I.weightedAverage,L=v.weightPercentage,z=I.average_total_data;function N(e,a){var r=e.getTime();return new Date(r+36e5*a)}function Z(e){var a=v.bolus_increment;.05!=a&&(a=.1);var r=e/a;return r>=1?i(Math.floor(r)*a,5):0}function H(e){function a(e){return e<10&&(e="0"+e),e}return a(e.getHours())+":"+a(e.getMinutes())+":00"}function $(e,a){var r=new Date("1/1/1999 "+e),t=new Date("1/1/1999 "+a);return(r.getTime()-t.getTime())/36e5}function J(e,a){var r=0,t=a,o=(e-a)/36e5,i=0,n=o,s=0;do{if(o>0){var l=H(t),m=C[0].rate;for(let e=0;e<C.length;e++){var u=C[e].start;if(l==u){if(e+1<C.length){o>=(s=$(C[e+1].start,C[e].start))?i=s:o<s&&(i=o)}else if(e+1==C.length){let a=C[0].start;o>=(s=24-$(C[e].start,a))?i=s:o<s&&(i=o)}r+=Z((m=C[e].rate)*i),o-=i,console.log("Dynamic ratios log: scheduled insulin added: "+Z(m*i)+" U. Bas duration: "+i.toPrecision(3)+" h. Base Rate: "+m+" U/h. Time :"+l),t=N(t,i)}else if(l>u)if(e+1<C.length){var d=C[e+1].start;l<d&&(o>=(s=$(d,l))?i=s:o<s&&(i=o),r+=Z((m=C[e].rate)*i),o-=i,console.log("Dynamic ratios log: scheduled insulin added: "+Z(m*i)+" U. Bas duration: "+i.toPrecision(3)+" h. Base Rate: "+m+" U/h. Time :"+l),t=N(t,i))}else if(e==C.length-1){o>=(s=$("23:59:59",l))?i=s:o<s&&(i=o),r+=Z((m=C[e].rate)*i),o-=i,console.log("Dynamic ratios log: scheduled insulin added: "+Z(m*i)+" U. Bas duration: "+i.toPrecision(3)+" h. Base Rate: "+m+" U/h. Time :"+l),t=N(t,i)}}}}while(o>0&&o<n);return r}if(w.length){let e=w.length-1;var K=new Date(w[e].timestamp),Q=new Date(w[0].timestamp);if("TempBasalDuration"==w[0]._type&&(Q=new Date),(G=(Q-K)/36e5)>21&&G<24)W=J(K,(V=24-G,X=K.getTime(),new Date(X-36e5*V))),R="24 hours of data is required for an accurate tdd calculation. Currently only "+G.toPrecision(3)+" hours of pump history data are available. Using your pump scheduled basals to fill in the missing hours. Scheduled basals added: "+W.toPrecision(5)+" U. ";else R=""}else console.log("Pumphistory is empty!"),se=!1,enableDynamicCR=!1;var V,X;for(let e=0;e<w.length;e++)"Bolus"==w[e]._type&&(k+=w[e].amount);for(let e=1;e<w.length;e++)if("TempBasal"==w[e]._type&&w[e].rate>0){P=e,q=w[e].rate;var Y=w[e-1]["duration (min)"]/60,ee=Y,ae=new Date(w[e-1].timestamp),re=ae;do{if(e--,0==e){re=new Date;break}if("TempBasal"==w[e]._type||"PumpSuspend"==w[e]._type){re=new Date(w[e].timestamp);break}}while(e>0);var te=(re-ae)/36e5;te<ee&&(Y=te),j+=Z(q*Y),e=P}for(let e=0;e<w.length;e++)if(0,0==w[e]["duration (min)"]||"PumpResume"==w[e]._type){let a=new Date(w[e].timestamp),r=a,t=e;do{if(t>0&&(--t,"TempBasal"==w[t]._type)){r=new Date(w[t].timestamp);break}}while(t>0);(r-a)/36e5>0&&(W+=J(r,a))}for(let e=w.length-1;e>0;e--)if("TempBasalDuration"==w[e]._type){let a=w[e]["duration (min)"]/60,r=new Date(w[e].timestamp);var oe=r;let t=e;do{if(--t,t>=0&&("TempBasal"==w[t]._type||"PumpSuspend"==w[t]._type)){oe=new Date(w[t].timestamp);break}}while(t>0);if(0==e&&"TempBasalDuration"==w[0]._type&&(oe=new Date,a=w[e]["duration (min)"]/60),(oe-r)/36e5-a>0){W+=J(oe,N(r,a))}}var ie=F=k+j+W;G>21?(U=". Bolus insulin: "+k.toPrecision(5)+" U",O=". Temporary basal insulin: "+j.toPrecision(5)+" U",T=". Insulin with scheduled basal rate: "+W.toPrecision(5)+" U",A=R+(" TDD past 24h is: "+F.toPrecision(5)+" U")+U+O+T,tddReason=E>0&&z>0?", TDD: "+i(F,1)+" U, Weighted avg: "+i(E,1)+" U, Total data avg: "+i(z,1)+" U":", TDD: "+i(F,2)):tddReason=", TDD: Not enough pumpData (< 21h)";const ne=e.glucose;var se=D.enableChris,le=D.enableDynamicCR;const me=v.autosens_min,ue=v.autosens_max,de=D.adjustmentFactor,ce=v.min_bg;var ge=!1,he="",fe=1;z>0&&(fe=E/z),fe>1?(fe=i(fe=Math.min(fe,v.autosens_max),2),console.log("Basal adjustment with a 24 hour to 7 day average TDD ratio (limited by Autosens max setting). Basal Ratio: "+fe+". Upper limit = Autosens max ("+v.autosens_max+")")):fe<1?(fe=i(fe=Math.max(fe,v.autosens_min),2),console.log("Basal adjustment with a 24 hour to 7 day average TDD ratio (limited by Autosens min setting). Basal Ratio: "+fe+". Lower limit = Autosens min ("+v.autosens_min+")")):console.log("Basal adjusted with a 24 hour to 7 day average TDD ratio: "+fe);var pe=", Basal ratio: "+fe;1!=v.high_temptarget_raises_sensitivity&&1!=v.exercise_mode||(ge=!0),se&&(v.use_autoisf=!1,console.log("autoISF is off. dynISF is on")),ce>=118&&1==ge&&(v.use_autoisf=!1,se=!1,he="Dynamic ISF temporarily off due to a high temp target/exercising. Current min target: "+ce);var be=", Dynamic ratios log: ",ve=", AF: "+de,Be="BG: "+ne+" mg/dl ("+(.0555*ne).toPrecision(2)+" mmol/l)",_e="",Me="";const ye=D.curve,Se=D.insulinPeakTime,xe=D.useCustomPeakTime;var we=55,De=65;switch(ye){case"rapid-acting":De=65;break;case"ultra-rapid":De=50}if(xe?(we=120-Se,console.log("Custom insulinpeakTime set to :"+Se+", insulinFactor: "+we)):(we=120-De,console.log("insulinFactor set to : "+we)),ie=F,L<1&&E>0&&(F=E,console.log("Using weighted TDD average: "+i(F,2)+" U, instead of past 24 h ("+i(ie,2)+" U), weight: "+L),Me=", Weighted TDD: "+i(F,2)+" U"),D.useNewFormula){var Ce=v.sens*de*F*Math.log(ne/we+1)/1800;_e=", Logarithmic formula"}else{Ce=v.sens*de*F*ne/277700;_e=", Original formula"}var Fe=v.carb_ratio,Ie="",Ge="";if(1==se&&F>0){if(Ie=", Dynamic ISF/CR: On/",Ce>ue?(he=", Dynamic ISF limited by autosens_max setting: "+ue+" ("+i(Ce,2)+"), ",Ge=", Autosens/Dynamic Limit: "+ue+" ("+i(Ce,2)+")",Ce=ue):Ce<me&&(he=", Dynamic ISF limjted by autosens_min setting: "+me+" ("+i(Ce,2)+"). ",Ge=", Autosens/Dynamic Limit: "+me+" ("+i(Ce,2)+")",Ce=me),le){Ie+="On";var Te=" CR: "+(Fe=i(Fe/Ce,2))+" g/U";v.carb_ratio=Fe}else Te=" CR: "+Fe+" g/U",Ie+="Off";var Ue=v.sens/Ce;he+=", Dynamic autosens.ratio set to "+i(Ce,2)+" with ISF: "+Ue.toPrecision(3)+" mg/dl/U ("+(.0555*Ue).toPrecision(3)+" mmol/l/U)"+Ie,B.ratio=Ce,A+=be+Be+ve+_e+he+Te+Me}else A+=0==se&&1==le?be+Be+ve+_e+"Dynamic ISF is off."+Te+Me:be+"Dynamic ISF is off. Dynamic CR is off.";console.log(A),tddReason+=0==se&&0==le?"":Ie+_e+Ge+ve+pe;var Oe={},Re=new Date;if(x&&(Re=x),void 0===v||void 0===v.current_basal)return Oe.error="Error: could not get current basal rate",Oe;var Ae=o(v.current_basal,v),Pe=Ae,je=new Date;x&&(je=x);var ke,We=new Date(e.date),qe=i((je-We)/60/1e3,1),Ee=e.glucose,Le=e.noise;ke=e.delta>-.5?"+"+i(e.delta,0):i(e.delta,0);var ze=Math.min(e.delta,e.short_avgdelta),Ne=Math.min(e.short_avgdelta,e.long_avgdelta),Ze=Math.max(e.delta,e.short_avgdelta,e.long_avgdelta);(Ee<=10||38===Ee||Le>=3)&&(Oe.reason="CGM is calibrating, in ??? state, or noise is high");if(Ee>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(Ee,v)+"+"+n(e.delta,v)+") for 5m w/ "+n(e.short_avgdelta,v)+" mg/dL ~15m change & "+n(e.long_avgdelta,2)+" mg/dL ~45m change"),console.error("Simulator mode detected ("+e.device+"): continuing anyway")):!0),qe>12||qe<-5?Oe.reason="If current system time "+je+" is correct, then BG data is too old. The last BG data was read "+qe+"m ago at "+We:0===e.short_avgdelta&&0===e.long_avgdelta&&(e.last_cal&&e.last_cal<3?Oe.reason="CGM was just calibrated":Oe.reason="CGM data is unchanged ("+n(Ee,v)+"+"+n(e.delta,v)+") for 5m w/ "+n(e.short_avgdelta,v)+" mg/dL ~15m change & "+n(e.long_avgdelta,v)+" mg/dL ~45m change"),Ee<=10||38===Ee||Le>=3||qe>12||qe<-5||0===e.short_avgdelta&&0===e.long_avgdelta)return r.rate>=Pe?(Oe.reason+=". Canceling high temp basal of "+r.rate,Oe.deliverAt=Re,Oe.temp="absolute",Oe.duration=0,Oe.rate=0,Oe):0===r.rate&&r.duration>30?(Oe.reason+=". Shortening "+r.duration+"m long zero temp to 30m. ",Oe.deliverAt=Re,Oe.temp="absolute",Oe.duration=30,Oe.rate=0,Oe):(Oe.reason+=". Temp "+r.rate+" <= current basal "+Pe+"U/hr; doing nothing. ",Oe);var He,$e,Je,Ke,Qe=v.max_iob;if(void 0!==v.min_bg&&($e=v.min_bg),void 0!==v.max_bg&&(Je=v.max_bg),void 0!==v.enableSMB_high_bg_target&&(Ke=v.enableSMB_high_bg_target),void 0===v.min_bg||void 0===v.max_bg)return Oe.error="Error: could not determine target_bg. ",Oe;He=(v.min_bg+v.max_bg)/2;var Ve=v.exercise_mode||v.high_temptarget_raises_sensitivity,Xe=100,Ye=160;if(v.half_basal_exercise_target&&(Ye=v.half_basal_exercise_target),Ve&&v.temptargetSet&&He>Xe||v.low_temptarget_lowers_sensitivity&&v.temptargetSet&&He<Xe){var ea=Ye-Xe;sensitivityRatio=ea*(ea+He-Xe)<=0?v.autosens_max:ea/(ea+He-Xe),sensitivityRatio=Math.min(sensitivityRatio,v.autosens_max),sensitivityRatio=i(sensitivityRatio,2),process.stderr.write("Sensitivity ratio set to "+sensitivityRatio+" based on temp target of "+He+"; ")}else void 0!==B&&B&&(sensitivityRatio=B.ratio,process.stderr.write("Autosens ratio: "+sensitivityRatio+"; "));if(sensitivityRatio&&0==v.enableChris?(Pe=v.current_basal*sensitivityRatio,Pe=o(Pe,v)):1==v.enableChris&&1==v.tddAdjBasal&&(Pe=v.current_basal*fe,Pe=o(Pe,v),process.stderr.write("TDD-adjustment of basals activated, using tdd24h_14d_Ratio "+i(fe,2)+", TDD 24h = "+i(ie,2)+"U, Weighted average TDD = "+i(E,2)+"U, (Weight percentage = "+L+"), 7-day average TDD = "+i(z,2)+"U. "),Pe!==Ae?process.stderr.write("Adjusting basal from "+Ae+" to "+Pe+"; "):process.stderr.write("Basal unchanged: "+Pe+"; ")),v.temptargetSet);else if(void 0!==B&&B&&(v.sensitivity_raises_target&&B.ratio<1||v.resistance_lowers_target&&B.ratio>1)){$e=i(($e-60)/B.ratio)+60,Je=i((Je-60)/B.ratio)+60;var aa=i((He-60)/B.ratio)+60;He===(aa=Math.max(80,aa))?process.stderr.write("target_bg unchanged: "+aa+"; "):process.stderr.write("target_bg from "+He+" to "+aa+"; "),He=aa}var ra=200,ta=200,oa=200;if(e.noise>=2){var ia=Math.max(1.1,v.noisyCGMTargetMultiplier);Math.min(250,v.maxRaw);ra=i(Math.min(200,$e*ia)),ta=i(Math.min(200,He*ia)),oa=i(Math.min(200,Je*ia)),process.stderr.write("Raising target_bg for noisy / raw CGM data, from "+He+" to "+ta+"; "),$e=ra,He=ta,Je=oa}var na=$e-.5*($e-40),sa=i(v.sens,1),la=v.sens;if(void 0!==B&&B&&((la=i(la=v.sens/sensitivityRatio,1))!==sa?process.stderr.write("ISF from "+n(sa,v)+" to "+n(la,v)):process.stderr.write("ISF unchanged: "+n(la,v)),s+="Autosens ratio: "+i(sensitivityRatio,2)+", ISF: "+n(sa,v)+"→"+n(la,v)),console.error("CR:"+v.carb_ratio),la=function(e,a,r,t,o,v,B,_){if(!r.use_autoisf)return console.error("autoISF disabled in Preferences"),e;var M=t.dura_p,y=t.delta_pl,S=t.delta_pn,x=t.r_squ,w=t.bg_acceleration,D=t.parabola_fit_a0,C=t.parabola_fit_a1,F=t.parabola_fit_a2,I=t.autoISF_duration,G=t.autoISF_average,T=r.autoisf_max,U=!1,O=1,R=1,A=1,P=a+10-G;if(!(o.mealCOB>0)||r.enableautoisf_with_COB){var j=t.pp_debug;if(c+="BG-accel: "+i(w,3)+", PF-minutes: "+M+", PF-corr: "+i(x,4)+", PF-nextDelta: "+n(S,r)+", PF-lastDelta: "+n(y,r)+", regular Delta: "+n(t.delta,r),console.error(j+c+" , Weights Accel/Brake: "+r.bgAccel_ISF_weight+" / "+r.bgBrake_ISF_weight),r.enable_BG_acceleration){var k=w;if(0!=t.parabola_fit_a2){var W=-C/2/F*5,q=i(D-W*W/25*F,1);(W=i(W,1))<0&&k<0?(f="saw max of "+n(q,r)+", about "+-W+" min ago",console.error("Parabolic fit "+f)):W<0&&k>0?(f="saw min of "+n(q,r)+", about "+-W+" min ago",console.error("Parabolic fit "+f)):W>0&&k<0?(f="predicts max of "+n(q,r)+", in about "+W+"min",console.error("Parabolic fit "+f)):W>0&&k>0&&(f="predicts min of "+n(q,r)+", in about "+W+" min",console.error("Parabolic fit "+f))}var E=x;if(E<=.9)f="acce_ISF by-passed, as correlation, "+i(E,3)+", is too low",console.error("Parabolic fit "+f),g+=", Parabolic Fit, "+f;else{g+=", Parabolic Fit, "+f+", lastΔ: "+n(y,r)+", nextΔ: "+n(S,r)+", Corr "+i(x,3)+", BG-Accel: "+i(k,2);var L=10*(E-.9),z=1;t.glucose<r.target_bg&&k>1&&(z=.5),A=1+k*z*(k<0?r.bgBrake_ISF_weight:r.bgAccel_ISF_weight)*L,console.error("Original result for acce_ISF: "+i(A,2)),1!=A&&(U=!0,g+=", acce-ISF Ratio: "+i(A,2))}}else console.error("autoISF BG accelertion adaption disabled in Preferences");var N=b(r,t.glucose,a);s+=", SMB Delivery Ratio:, "+i(N,2)+g+", autoISF";var Z=1+p(100-P,r);console.error("bg_ISF adaptation is "+i(Z,2)),Z<1&&A>1&&(h="bg-ISF adaptation lifted to "+i(Z*=A,2)+", as BG accelerates already",l="(lifted by "+i(A,2)+")",console.error(h));var H=1;if(Z<1)return(H=Math.min(Z,A))<r.autoisf_min&&(h="final ISF factor "+i(H,2)+" limited by autoisf_min "+r.autoisf_min,console.error(h),H=r.autoisf_min),l=" (lmtd.)",earlysens=Math.min(720,i(r.sens/Math.min(_,H),1)),console.error("early Return autoISF: "+n(earlysens,r)),s+=", bg-ISF Ratio: "+i(Z,2)+l+", ISF: "+n(earlysens,r),earlysens;Z>1&&(U=!0,s+=", bg-ISF Ratio: "+i(Z,2));var $=t.delta;P>0?console.error("delta_ISF adaptation by-passed as average glucose < "+n(a+10,r)):t.short_avgdelta<0?console.error("delta_ISF adaptation by-passed as no rise or too short lived"):r.enableppisf_always||r.postmeal_ISF_duration>=(v-o.lastCarbTime)/1e3/3600?(O=1+Math.max(0,$*r.postmeal_ISF_weight),console.error("pp_ISF adaptation is "+i(O,2)),u=", pp-ISF Ratio: "+i(O,2),1!=O&&(U=!0)):(R=p($,r),P>-20&&(R*=.5),R=1+R,console.error("delta_ISF adaptation is "+i(R,2)),d=", Δ-ISF Ratio: "+i(R,2),1!=R&&(U=!0));var J=1,K=r.autoisf_hourlychange;return o.mealCOB>0&&!r.enableautoisf_with_COB?console.error("dura_ISF by-passed; preferences disabled mealCOB of "+i(o.mealCOB,1)):I<10?console.error("dura_ISF by-passed; BG is only "+I+"m at level "+G):G<=a?console.error("dura_ISF by-passed; avg. glucose "+G+" below target "+n(a,r)):(J+=I/60*(K/a)*(G-a),U=!0,m=", Duration: "+I+", Avg: "+n(G,r)+", dura-ISF Ratio: "+i(J,2),console.error("dura_ISF adaptation is "+i(J,2)+" because ISF "+e+" did not do it for "+i(I,1)+"m")),H=1,U?(H=Math.max(J,Z,R,A,O),console.error("autoISF adaption ratios:"),console.error(" dura "+i(J,2)),console.error(" bg "+i(Z,2)),console.error(" delta "+i(R,2)),console.error(" pp "+i(O,2)),console.error(" accel "+i(A,2)),A<1&&(console.error("strongest ISF factor "+i(H,2)+" weakened to "+i(H*A,2)+" as bg decelerates already"),H*=A),H<r.autoisf_min?(console.error("final ISF factor "+i(H,2)+" limited by autoisf_min "+r.autoisf_min),H=r.autoisf_min):H>T&&(console.error("final ISF factor "+i(H,2)+" limited by autoisf_max "+T),H=T),H>=1&&(e=i(r.sens/Math.max(H,_),1)),H<1&&(e=i(r.sens/Math.min(H,_),1))):H=_,s+=u+d+m+", Ratio: "+i(H,2)+", ISF: "+n(e,r),console.error("Inside autoISF: Ratio "+i(H,2)+" resulting in "+n(e,r)),e}console.error("BG dependant autoISF by-passed; preferences disabled mealCOB of "+i(o.mealCOB,1))}(la,He,v,e,_,x,0,sensitivityRatio),void 0===t)return Oe.error="Error: iob_data undefined. ",Oe;var ma,ua=t;if(t.length,t.length>1&&(t=ua[0]),void 0===t.activity||void 0===t.iob)return Oe.error="Error: iob_data missing some property. ",Oe;var da=((ma=void 0!==t.lastTemp?i((new Date(je).getTime()-t.lastTemp.date)/6e4):0)+r.duration)%30;if(console.error("currenttemp:"+r.rate+" lastTempAge:"+ma+"m, tempModulus:"+da+"m"),Oe.temp="absolute",Oe.deliverAt=Re,y&&r&&t.lastTemp&&r.rate!==t.lastTemp.rate&&ma>10&&r.duration)return Oe.reason="Warning: currenttemp rate "+r.rate+" != lastTemp rate "+t.lastTemp.rate+" from pumphistory; canceling temp",M.setTempBasal(0,0,v,Oe,r);if(r&&t.lastTemp&&r.duration>0){var ca=ma-t.lastTemp.duration;if(ca>5&&ma>10)return Oe.reason="Warning: currenttemp running but lastTemp from pumphistory ended "+ca+"m ago; canceling temp",M.setTempBasal(0,0,v,Oe,r)}var ga=i(-t.activity*la*5,2),ha=i(6*(ze-ga));ha<0&&(ha=i(6*(Ne-ga)))<0&&(ha=i(6*(e.long_avgdelta-ga)));var fa=Ee,pa=(fa=t.iob>0?i(Ee-t.iob*la):i(Ee-t.iob*Math.min(la,v.sens)))+ha;if(void 0===pa||isNaN(pa))return Oe.error="Error: could not calculate eventualBG. Sensitivity: "+la+" Deviation: "+ha,Oe;var ba=function(e,a,r){return i(r+(e-a)/24,1)}(He,pa,ga);Oe={temp:"absolute",bg:Ee,tick:ke,eventualBG:pa,insulinReq:0,reservoir:S,deliverAt:Re,sensitivityRatio,TDD:ie};var va=[],Ba=[],_a=[],Ma=[];va.push(Ee),Ba.push(Ee),Ma.push(Ee),_a.push(Ee);var ya=function(e,a,r,t,o,i){return a?!e.allowSMB_with_high_temptarget&&e.temptargetSet&&o>100?(console.error("SMB disabled due to high temptarget of "+o),!1):!0===r.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?(r.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&&r.mealCOB?(r.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 "+r.mealCOB),!0):!0===e.enableSMB_after_carbs&&r.carbs?(r.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?(r.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&&t>=i?(console.error("Checking BG to see if High for SMB enablement."),console.error("Current BG",t," | High BG ",i),r.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)}(v,y,_,Ee,He,Ke),Sa=v.enableUAM,xa=0,wa=0;xa=i(ze-ga,1);var Da=i(ze-ga,1);csf=la/v.carb_ratio,console.error("profile.sens:"+n(v.sens,v)+", sens:"+n(la,v)+", CSF:"+i(csf,1));var Ca=i(30*csf*5/60,1);xa>Ca&&(console.error("Limiting carb impact from "+xa+" to "+Ca+"mg/dL/5m (30g/h)"),xa=Ca);var Fa=3;sensitivityRatio&&(Fa/=sensitivityRatio);var Ia=Fa;if(_.carbs){Fa=Math.max(Fa,_.mealCOB/20);var Ga=i((new Date(je).getTime()-_.lastCarbTime)/6e4),Ta=(_.carbs-_.mealCOB)/_.carbs;Ia=i(Ia=Fa+1.5*Ga/60,1),console.error("Last carbs "+Ga+" minutes ago; remainingCATime:"+Ia+"hours; "+i(100*Ta,1)+"% carbs absorbed")}var Ua=Math.max(0,xa/5*60*Ia/2)/csf,Oa=90,Ra=1;v.remainingCarbsCap&&(Oa=Math.min(90,v.remainingCarbsCap)),v.remainingCarbsFraction&&(Ra=Math.min(1,v.remainingCarbsFraction));var Aa=1-Ra,Pa=Math.max(0,_.mealCOB-Ua-_.carbs*Aa),ja=(Pa=Math.min(Oa,Pa))*csf*5/60/(Ia/2),ka=i(_.slopeFromMaxDeviation,2),Wa=i(_.slopeFromMinDeviation,2),qa=Math.min(ka,-Wa/3),Ea=0;0===xa?wa=0:!0===v.floating_carbs?(wa=Math.min(60*Ia/5/2,Math.max(0,_.carbs*csf/xa)),Ea=Math.min(60*Ia/5/2,Math.max(0,_.mealCOB*csf/xa)),_.carbs>0&&(s+=", Floating Carbs:, CID: "+i(wa,1)+", MealCarbs: "+i(_.carbs,1)+", Not Floating:, CID: "+i(Ea,1)+", MealCOB: "+i(_.mealCOB,1),console.error("Floating Carbs CID: "+i(wa,1)+" / MealCarbs: "+i(_.carbs,1)+" vs. Not Floating:"+i(Ea,1)+" / MealCOB:"+i(_.mealCOB,1)))):wa=Math.min(60*Ia/5/2,Math.max(0,_.mealCOB*csf/xa)),console.error("Carb Impact:"+xa+"mg/dL per 5m; CI Duration:"+i(5*wa/60*2,1)+"hours; remaining CI ("+Ia/2+"h peak):"+i(ja,1)+"mg/dL per 5m");var La,za,Na,Za,Ha,$a=999,Ja=999,Ka=999,Qa=Ee,Va=999,Xa=999,Ya=999,er=999,ar=pa,rr=Ee,tr=Ee,or=0,ir=[],nr=[];try{ua.forEach((function(e){var a=i(-e.activity*la*5,2),r=i(-e.iobWithZeroTemp.activity*la*5,2),t=xa*(1-Math.min(1,Ba.length/12));if(!0==(1==se&&1==D.useNewFormula)){ar=Ba[Ba.length-1]+i(-e.activity*(1800/(F*de*Math.log(Math.max(Ba[Ba.length-1],39)/we+1)))*5,2)+t;var o=Ma[Ma.length-1]+i(-e.iobWithZeroTemp.activity*(1800/(F*de*Math.log(Math.max(Ma[Ma.length-1],39)/we+1)))*5,2);console.log("Dynamic ISF (Logarithmic Formula) )adjusted predictions for IOB and ZT: IOBpredBG: "+i(ar,2)+" , ZTpredBG: "+i(o,2))}else{ar=Ba[Ba.length-1]+a+t;o=Ma[Ma.length-1]+r}var n=Math.max(0,Math.max(0,xa)*(1-va.length/Math.max(2*wa,1))),s=Math.min(va.length,12*Ia-va.length),l=Math.max(0,s/(Ia/2*12)*ja);n+l,ir.push(i(l,0)),nr.push(i(n,0)),COBpredBG=va[va.length-1]+a+Math.min(0,t)+n+l;var m=Math.max(0,Da+_a.length*qa),u=Math.max(0,Da*(1-_a.length/Math.max(36,1))),d=Math.min(m,u);if(d>0&&(or=i(5*(_a.length+1)/60,1)),!0==(1==se&&1==D.useNewFormula))UAMpredBG=_a[_a.length-1]+i(-e.activity*(1800/(F*de*Math.log(Math.max(_a[_a.length-1],39)/we+1)))*5,2)+Math.min(0,t)+d,console.log("Dynamic ISF (Logarithmic Formula) adjusted prediction for UAM: UAMpredBG: "+i(UAMpredBG,2));else UAMpredBG=_a[_a.length-1]+a+Math.min(0,t)+d;Ba.length<48&&Ba.push(ar),va.length<48&&va.push(COBpredBG),_a.length<48&&_a.push(UAMpredBG),Ma.length<48&&Ma.push(o),COBpredBG<Va&&(Va=i(COBpredBG)),UAMpredBG<Xa&&(Xa=i(UAMpredBG)),ar<Ya&&(Ya=i(ar)),o<er&&(er=i(o));Ba.length>18&&ar<$a&&($a=i(ar)),ar>rr&&(rr=ar),(wa||ja>0)&&va.length>18&&COBpredBG<Ja&&(Ja=i(COBpredBG)),(wa||ja>0)&&COBpredBG>rr&&(tr=COBpredBG),Sa&&_a.length>12&&UAMpredBG<Ka&&(Ka=i(UAMpredBG)),Sa&&UAMpredBG>rr&&UAMpredBG}))}catch(e){console.error("Problem with iobArray. Optional feature Advanced Meal Assist disabled")}_.mealCOB&&(console.error("predCIs (mg/dL/5m):"+nr.join(" ")),console.error("remainingCIs: "+ir.join(" "))),Oe.predBGs={},Ba.forEach((function(e,a,r){r[a]=i(Math.min(401,Math.max(39,e)))}));for(var sr=Ba.length-1;sr>12&&Ba[sr-1]===Ba[sr];sr--)Ba.pop();for(Oe.predBGs.IOB=Ba,Na=i(Ba[Ba.length-1]),Ma.forEach((function(e,a,r){r[a]=i(Math.min(401,Math.max(39,e)))})),sr=Ma.length-1;sr>6&&!(Ma[sr-1]>=Ma[sr]||Ma[sr]<=He);sr--)Ma.pop();if(Oe.predBGs.ZT=Ma,i(Ma[Ma.length-1]),_.mealCOB>0&&(xa>0||ja>0)){for(va.forEach((function(e,a,r){r[a]=i(Math.min(401,Math.max(39,e)))})),sr=va.length-1;sr>12&&va[sr-1]===va[sr];sr--)va.pop();Oe.predBGs.COB=va,Za=i(va[va.length-1]),pa=Math.max(pa,i(va[va.length-1]))}if(xa>0||ja>0){if(Sa){for(_a.forEach((function(e,a,r){r[a]=i(Math.min(401,Math.max(39,e)))})),sr=_a.length-1;sr>12&&_a[sr-1]===_a[sr];sr--)_a.pop();Oe.predBGs.UAM=_a,Ha=i(_a[_a.length-1]),_a[_a.length-1]&&(pa=Math.max(pa,i(_a[_a.length-1])))}Oe.eventualBG=pa}console.error("UAM Impact:"+Da+"mg/dL per 5m; UAM Duration:"+or+"hours"),$a=Math.max(39,$a),Ja=Math.max(39,Ja),Ka=Math.max(39,Ka),La=i($a);var lr=_.mealCOB/_.carbs;za=i(Ka<999&&Ja<999?(1-lr)*UAMpredBG+lr*COBpredBG:Ja<999?(ar+COBpredBG)/2:Ka<999?(ar+UAMpredBG)/2:ar),er>za&&(za=er),Qa=i(Qa=wa||ja>0?Sa?lr*Va+(1-lr)*Xa:Va:Sa?Xa:Ya);var mr=Ka;if(er<na)mr=(Ka+er)/2;else if(er<He){var ur=(er-na)/(He-na);mr=(Ka+(Ka*ur+er*(1-ur)))/2}else er>Ka&&(mr=(Ka+er)/2);if(mr=i(mr),_.carbs)if(!Sa&&Ja<999)La=i(Math.max($a,Ja));else if(Ja<999){var dr=lr*Ja+(1-lr)*mr;La=i(Math.max($a,Ja,dr))}else La=Sa?mr:Qa;else Sa&&(La=i(Math.max($a,mr)));La=Math.min(La,za),process.stderr.write("minPredBG: "+La+" minIOBPredBG: "+$a+" minZTGuardBG: "+er),Ja<999&&process.stderr.write(" minCOBPredBG: "+Ja),Ka<999&&process.stderr.write(" minUAMPredBG: "+Ka),console.error(" avgPredBG:"+za+" COB/Carbs:"+_.mealCOB+"/"+_.carbs),tr>Ee&&(La=Math.min(La,tr)),Oe.COB=_.mealCOB,Oe.IOB=t.iob,Oe.BGI=n(ga,v),Oe.deviation=n(ha,v),Oe.ISF=n(la,v),Oe.CR=i(v.carb_ratio,2),Oe.target_bg=n(He,v),Oe.TDD=i(ie,2),Oe.reason=s+", COB: "+Oe.COB+", Dev: "+Oe.deviation+", BGI: "+Oe.BGI+", CR: "+Oe.CR+", Target: "+Oe.target_bg+", minPredBG "+n(La,v)+", minGuardBG "+n(Qa,v)+", IOBpredBG "+n(Na,v),Za>0&&(Oe.reason+=", COBpredBG "+n(Za,v)),Ha>0&&(Oe.reason+=", UAMpredBG "+n(Ha,v)),Oe.reason+=tddReason,Oe.reason+="; ";var cr=fa;cr<40&&(cr=Math.min(Qa,cr));var gr,hr=na-cr,fr=240,pr=240;if(_.mealCOB>0&&(xa>0||ja>0)){for(sr=0;sr<va.length;sr++)if(va[sr]<$e){fr=5*sr;break}for(sr=0;sr<va.length;sr++)if(va[sr]<na){pr=5*sr;break}}else{for(sr=0;sr<Ba.length;sr++)if(Ba[sr]<$e){fr=5*sr;break}for(sr=0;sr<Ba.length;sr++)if(Ba[sr]<na){pr=5*sr;break}}ya&&Qa<na&&(console.error("minGuardBG "+n(Qa,v)+" projected below "+n(na,v)+" - disabling SMB"),ya=!1),void 0===v.maxDelta_bg_threshold&&(gr=.2),void 0!==v.maxDelta_bg_threshold&&(gr=Math.min(v.maxDelta_bg_threshold,.4)),Ze>gr*Ee&&(console.error("maxDelta "+n(Ze,v)+" > "+100*gr+"% of BG "+n(Ee,v)+" - disabling SMB"),Oe.reason+="maxDelta "+n(Ze,v)+" > "+100*gr+"% of BG "+n(Ee,v)+" - SMB disabled!, ",ya=!1),console.error("BG projected to remain above "+n($e,v)+" for "+fr+"minutes"),(pr<240||fr<60)&&console.error("BG projected to remain above "+n(na,v)+" for "+pr+"minutes");var br=pr,vr=v.current_basal*la*br/60,Br=Math.max(0,_.mealCOB-.25*_.carbs),_r=(hr-vr)/csf-Br;vr=i(vr),_r=i(_r),console.error("naive_eventualBG:",fa,"bgUndershoot:",hr,"zeroTempDuration:",br,"zeroTempEffect:",vr,"carbsReq:",_r),"Could not parse clock data"==_.reason?console.error("carbsReq unknown: Could not parse clock data"):_r>=v.carbsReqThreshold&&pr<=45&&(Oe.carbsReq=_r,Oe.reason+=_r+" add'l carbs req w/in "+pr+"m; ");var Mr=0;if(Ee<na&&t.iob<20*-v.current_basal/60&&ze>0&&ze>ba)Oe.reason+="IOB "+t.iob+" < "+i(20*-v.current_basal/60,2),Oe.reason+=" and minDelta "+n(ze,v)+" > expectedDelta "+n(ba,v)+"; ";else if(Ee<na||Qa<na)return Oe.reason+="minGuardBG "+n(Qa,v)+"<"+n(na,v),Mr=i(60*((hr=He-Qa)/la)/v.current_basal),Mr=30*i(Mr/30),Mr=Math.min(120,Math.max(30,Mr)),M.setTempBasal(0,Mr,v,Oe,r);if(v.skip_neutral_temps&&Oe.deliverAt.getMinutes()>=55)return Oe.reason+="; Canceling temp at "+Oe.deliverAt.getMinutes()+"m past the hour. ",M.setTempBasal(0,0,v,Oe,r);var yr=0,Sr=Pe;if(pa<$e){if(Oe.reason+="Eventual BG "+n(pa,v)+" < "+n($e,v),ze>ba&&ze>0&&!_r)return fa<40?(Oe.reason+=", naive_eventualBG < 40. ",M.setTempBasal(0,30,v,Oe,r)):(e.delta>ze?Oe.reason+=", but Delta "+n(ke,v)+" > expectedDelta "+n(ba,v):Oe.reason+=", but Min. Delta "+ze.toFixed(2)+" > Exp. Delta "+n(ba,v),r.duration>15&&o(Pe,v)===o(r.rate,v)?(Oe.reason+=", temp "+r.rate+" ~ req "+Pe+"U/hr. ",Oe):(Oe.reason+="; setting current basal of "+Pe+" as temp. ",M.setTempBasal(Pe,30,v,Oe,r)));yr=i(yr=2*Math.min(0,(pa-He)/la),2);var xr=Math.min(0,(fa-He)/la);if(xr=i(xr,2),ze<0&&ze>ba)yr=i(yr*(ze/ba),2);if(Sr=o(Sr=Pe+2*yr,v),r.duration*(r.rate-Pe)/60<Math.min(yr,xr)-.3*Pe)return Oe.reason+=", "+r.duration+"m@"+r.rate.toFixed(2)+" is a lot less than needed. ",M.setTempBasal(Sr,30,v,Oe,r);if(void 0!==r.rate&&r.duration>5&&Sr>=.8*r.rate)return Oe.reason+=", temp "+r.rate+" ~< req "+Sr+"U/hr. ",Oe;if(Sr<=0){if((Mr=i(60*((hr=He-fa)/la)/v.current_basal))<0?Mr=0:(Mr=30*i(Mr/30),Mr=Math.min(120,Math.max(0,Mr))),Mr>0)return Oe.reason+=", setting "+Mr+"m zero temp. ",M.setTempBasal(Sr,Mr,v,Oe,r)}else Oe.reason+=", setting "+Sr+"U/hr. ";return M.setTempBasal(Sr,30,v,Oe,r)}if(ze<ba&&(!y||!ya))return e.delta<ze?Oe.reason+="Eventual BG "+n(pa,v)+" > "+n($e,v)+" but Delta "+n(ke,v)+" < Exp. Delta "+n(ba,v):Oe.reason+="Eventual BG "+n(pa,v)+" > "+n($e,v)+" but Min. Delta "+ze.toFixed(2)+" < Exp. Delta "+n(ba,v),r.duration>15&&o(Pe,v)===o(r.rate,v)?(Oe.reason+=", temp "+r.rate+" ~ req "+Pe+"U/hr. ",Oe):(Oe.reason+="; setting current basal of "+Pe+" as temp. ",M.setTempBasal(Pe,30,v,Oe,r));if(Math.min(pa,La)<Je&&(!y||!ya))return Oe.reason+=n(pa,v)+"-"+n(La,v)+" in range: no temp required",r.duration>15&&o(Pe,v)===o(r.rate,v)?(Oe.reason+=", temp "+r.rate+" ~ req "+Pe+"U/hr. ",Oe):(Oe.reason+="; setting current basal of "+Pe+" as temp. ",M.setTempBasal(Pe,30,v,Oe,r));if(pa>=Je&&(Oe.reason+="Eventual BG "+n(pa,v)+" >= "+n(Je,v)+", "),t.iob>Qe)return Oe.reason+="IOB "+i(t.iob,2)+" > max_iob "+Qe,r.duration>15&&o(Pe,v)===o(r.rate,v)?(Oe.reason+=", temp "+r.rate+" ~ req "+Pe+"U/hr. ",Oe):(Oe.reason+="; setting current basal of "+Pe+" as temp. ",M.setTempBasal(Pe,30,v,Oe,r));(yr=i((Math.min(La,pa)-He)/la,2))>Qe-t.iob?(console.error("SMB limited by maxIOB: "+Qe-t.iob+" (. insulinReq: "+yr+" U)"),Oe.reason+="max_iob "+Qe+", ",yr=Qe-t.iob):console.error("SMB not limited by maxIOB ( insulinReq: "+yr+" U)."),Sr=o(Sr=Pe+2*yr,v),yr=i(yr,3),Oe.insulinReq=yr;var wr=i((new Date(je).getTime()-t.lastBolusTime)/6e4,1);if(y&&ya&&Ee>na){var Dr=i(_.mealCOB/v.carb_ratio,3);if(v.use_autoisf)Cr=v.smb_max_range_extension;else{console.error("autoISF disabled, SMB range extension disabled");var Cr=1}Cr>1&&console.error("SMB max range extended from default by factor "+Cr);var Fr=0;void 0===v.maxSMBBasalMinutes?(Fr=i(Cr*v.current_basal*30/60,1),console.error("profile.maxSMBBasalMinutes undefined: defaulting to 30m"),yr>Fr&&(console.error("SMB limited by maxBolus: "+Fr+" ( "+yr+" U)"),a)):t.iob>Dr&&t.iob>0?(console.error("IOB"+t.iob+"> COB"+_.mealCOB+"; mealInsulinReq ="+Dr),v.maxUAMSMBBasalMinutes?(console.error("profile.maxUAMSMBBasalMinutes: "+v.maxUAMSMBBasalMinutes+", profile.current_basal: "+v.current_basal),Fr=i(Cr*v.current_basal*v.maxUAMSMBBasalMinutes/60,1)):(console.error("profile.maxUAMSMBBasalMinutes undefined: defaulting to 30m"),Fr=i(30*v.current_basal/60,1)),yr>Fr?console.error("SMB limited by maxUAMSMBBasalMinutes [ "+v.maxUAMSMBBasalMinutes+"m ]: "+Fr+"U ( "+yr+"U )"):console.error("SMB is not limited by maxUAMSMBBasalMinutes. ( insulinReq: "+yr+"U )")):(console.error("profile.maxSMBBasalMinutes: "+v.maxSMBBasalMinutes+", profile.current_basal: "+v.current_basal),yr>(Fr=i(Cr*v.current_basal*v.maxSMBBasalMinutes/60,1))?console.error("SMB limited by maxSMBBasalMinutes: "+v.maxSMBBasalMinutes+"m ]: "+Fr+"U ( insulinReq: "+yr+"U )"):console.error("SMB is not limited by maxSMBBasalMinutes. ( insulinReq: "+yr+"U )"));var Ir=v.bolus_increment,Gr=1/Ir,Tr=b(v,Ee,He);Tr>.5&&console.error("SMB Delivery Ratio increased from default 0.5 to "+i(Tr,2));var Ur=Math.min(yr*Tr,Fr);Ur=Math.floor(Ur*Gr)/Gr,Mr=i(60*((He-(fa+$a)/2)/la)/v.current_basal),yr>0&&Ur<Ir&&(Mr=0);var Or=0;Mr<=0?Mr=0:Mr>=30?(Mr=30*i(Mr/30),Mr=Math.min(60,Math.max(0,Mr))):(Or=i(Pe*Mr/30,2),Mr=30),Oe.reason+=" insulinReq "+yr,Ur>=Fr&&(Oe.reason+="; maxBolus "+Fr),Mr>0&&(Oe.reason+="; setting "+Mr+"m low temp of "+Or+"U/h"),Oe.reason+=". ";var Rr=3;v.SMBInterval&&(Rr=Math.min(10,Math.max(1,v.SMBInterval)));var Ar=i(Rr-wr,0),Pr=i(60*(Rr-wr),0)%60;if(console.error("naive_eventualBG "+fa+","+Mr+"m "+Or+"U/h temp needed; last bolus "+wr+"m ago; maxBolus: "+Fr),wr>Rr?Ur>0&&(Oe.units=Ur,Oe.reason+="Microbolusing "+Ur+"U. "):Oe.reason+="Waiting "+Ar+"m "+Pr+"s to microbolus again. ",Mr>0)return Oe.rate=Or,Oe.duration=Mr,Oe}var jr=M.getMaxSafeBasal(v);return Sr>jr&&(Oe.reason+="adj. req. rate: "+Sr+" to maxSafeBasal: "+i(jr,2)+", ",Sr=o(jr,v)),r.duration*(r.rate-Pe)/60>=2*yr?(Oe.reason+=r.duration+"m@"+r.rate.toFixed(2)+" > 2 * insulinReq. Setting temp basal of "+Sr+"U/hr. ",M.setTempBasal(Sr,30,v,Oe,r)):void 0===r.duration||0===r.duration?(Oe.reason+="no temp, setting "+Sr+"U/hr. ",M.setTempBasal(Sr,30,v,Oe,r)):r.duration>5&&o(Sr,v)<=o(r.rate,v)?(Oe.reason+="temp "+r.rate+" >~ req "+Sr+"U/hr. ",Oe):(Oe.reason+="temp "+r.rate+"<"+Sr+"U/hr. ",M.setTempBasal(Sr,30,v,Oe,r))}},6880:(e,a,r)=>{var t=r(6654);e.exports=function(e,a){var r=20;void 0!==a&&"string"==typeof a.model&&(t(a.model,"54")||t(a.model,"23"))&&(r=40);return e<1?Math.round(e*r)/r:e<10?Math.round(20*e)/20:Math.round(10*e)/10}},2705:(e,a,r)=>{var t=r(5639).Symbol;e.exports=t},9932:e=>{e.exports=function(e,a){for(var r=-1,t=null==e?0:e.length,o=Array(t);++r<t;)o[r]=a(e[r],r,e);return o}},9750:e=>{e.exports=function(e,a,r){return e==e&&(void 0!==r&&(e=e<=r?e:r),void 0!==a&&(e=e>=a?e:a)),e}},4239:(e,a,r)=>{var t=r(2705),o=r(9607),i=r(2333),n=t?t.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":n&&n in Object(e)?o(e):i(e)}},531:(e,a,r)=>{var t=r(2705),o=r(9932),i=r(1469),n=r(3448),s=t?t.prototype:void 0,l=s?s.toString:void 0;e.exports=function e(a){if("string"==typeof a)return a;if(i(a))return o(a,e)+"";if(n(a))return l?l.call(a):"";var r=a+"";return"0"==r&&1/a==-Infinity?"-0":r}},7561:(e,a,r)=>{var t=r(7990),o=/^\s+/;e.exports=function(e){return e?e.slice(0,t(e)+1).replace(o,""):e}},1957:(e,a,r)=>{var t="object"==typeof r.g&&r.g&&r.g.Object===Object&&r.g;e.exports=t},9607:(e,a,r)=>{var t=r(2705),o=Object.prototype,i=o.hasOwnProperty,n=o.toString,s=t?t.toStringTag:void 0;e.exports=function(e){var a=i.call(e,s),r=e[s];try{e[s]=void 0;var t=!0}catch(e){}var o=n.call(e);return t&&(a?e[s]=r:delete e[s]),o}},2333:e=>{var a=Object.prototype.toString;e.exports=function(e){return a.call(e)}},5639:(e,a,r)=>{var t=r(1957),o="object"==typeof self&&self&&self.Object===Object&&self,i=t||o||Function("return this")();e.exports=i},7990:e=>{var a=/\s/;e.exports=function(e){for(var r=e.length;r--&&a.test(e.charAt(r)););return r}},6654:(e,a,r)=>{var t=r(9750),o=r(531),i=r(554),n=r(9833);e.exports=function(e,a,r){e=n(e),a=o(a);var s=e.length,l=r=void 0===r?s:t(i(r),0,s);return(r-=a.length)>=0&&e.slice(r,l)==a}},1469:e=>{var a=Array.isArray;e.exports=a},3218:e=>{e.exports=function(e){var a=typeof e;return null!=e&&("object"==a||"function"==a)}},7005:e=>{e.exports=function(e){return null!=e&&"object"==typeof e}},3448:(e,a,r)=>{var t=r(4239),o=r(7005);e.exports=function(e){return"symbol"==typeof e||o(e)&&"[object Symbol]"==t(e)}},8601:(e,a,r)=>{var t=r(4841),o=1/0;e.exports=function(e){return e?(e=t(e))===o||e===-1/0?17976931348623157e292*(e<0?-1:1):e==e?e:0:0===e?e:0}},554:(e,a,r)=>{var t=r(8601);e.exports=function(e){var a=t(e),r=a%1;return a==a?r?a-r:a:0}},4841:(e,a,r)=>{var t=r(7561),o=r(3218),i=r(3448),n=/^[-+]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(i(e))return NaN;if(o(e)){var a="function"==typeof e.valueOf?e.valueOf():e;e=o(a)?a+"":a}if("string"!=typeof e)return 0===e?e:+e;e=t(e);var r=s.test(e);return r||l.test(e)?m(e.slice(2),r?2:8):n.test(e)?NaN:+e}},9833:(e,a,r)=>{var t=r(531);e.exports=function(e){return null==e?"":t(e)}}},r={};function t(a){var o=r[a];if(void 0!==o)return o.exports;var i=r[a]={exports:{}};return e[a](i,i.exports,t),i.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 o=t(5546);freeaps_determineBasal=o})();