determine-basal.js 35 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,x,S,w,C,D,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=D[0].rate;for(let e=0;e<D.length;e++){var u=D[e].start;if(l==u){if(e+1<D.length){o>=(s=$(D[e+1].start,D[e].start))?i=s:o<s&&(i=o)}else if(e+1==D.length){let a=D[0].start;o>=(s=24-$(D[e].start,a))?i=s:o<s&&(i=o)}r+=Z((m=D[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<D.length){var d=D[e+1].start;l<d&&(o>=(s=$(d,l))?i=s:o<s&&(i=o),r+=Z((m=D[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==D.length-1){o>=(s=$("23:59:59",l))?i=s:o<s&&(i=o),r+=Z((m=D[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)<24&&G>21)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=C.enableChris,le=C.enableDynamicCR;const me=Math.min(v.autosens_min,v.autosens_max),ue=Math.max(v.autosens_min,v.autosens_max),de=C.adjustmentFactor,ce=v.min_bg;var ge=!1,he="",fe=1,pe="";z>0&&(fe=E/z),pe=fe>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: "+(fe=i(fe=Math.min(fe,v.autosens_max),2))+". Upper limit = Autosens max ("+v.autosens_max+")":fe<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: "+(fe=i(fe=Math.max(fe,v.autosens_min),2))+". Lower limit = Autosens min ("+v.autosens_min+")":"Basal adjusted with a 24 hour to total average (up to 14 days of data) TDD ratio: "+fe,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=C.curve,xe=C.insulinPeakTime,Se=C.useCustomPeakTime;var we=55,Ce=65;switch(ye){case"rapid-acting":Ce=65;break;case"ultra-rapid":Ce=50}if(Se?(we=120-xe,console.log("Custom insulinpeakTime set to :"+xe+", insulinFactor: "+we)):(we=120-Ce,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"),C.useNewFormula){var De=v.sens*de*F*Math.log(ne/we+1)/1800;_e=", Logarithmic formula"}else{De=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/",De>ue?(he=", Dynamic ISF limited by autosens_max setting: "+ue+" ("+i(De,2)+"), ",Ge=", Autosens/Dynamic Limit: "+ue+" ("+i(De,2)+")",De=ue):De<me&&(he=", Dynamic ISF limjted by autosens_min setting: "+me+" ("+i(De,2)+"). ",Ge=", Autosens/Dynamic Limit: "+me+" ("+i(De,2)+")",De=me),le){Ie+="On";var Te=" CR: "+(Fe=i(Fe/De,2))+" g/U";v.carb_ratio=Fe}else Te=" CR: "+Fe+" g/U",Ie+="Off";var Ue=v.sens/De;he+=", Dynamic autosens.ratio set to "+i(De,2)+" with ISF: "+Ue.toPrecision(3)+" mg/dl/U ("+(.0555*Ue).toPrecision(3)+" mmol/l/U)"+Ie,B.ratio=De,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(S&&(Re=S),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;S&&(je=S);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+"), Total data of TDDs (up to 14 days) average = "+i(z,2)+"U. "),Pe!==Ae?process.stderr.write("Adjusting basal from "+Ae+" U/h to "+Pe+" U/h; "):process.stderr.write("Basal unchanged: "+Pe+" U/h; ")),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=v.threshold_setting;sa>na&&sa<=120&&sa>=65?(console.error("Threshold changed in settings from "+n(na,v)+" to "+n(sa,v)+". "),na=sa):console.error("Current threshold: "+n(na,v));var la=i(v.sens,1),ma=v.sens;if(void 0!==B&&B&&((ma=i(ma=v.sens/sensitivityRatio,1))!==la?process.stderr.write("ISF from "+n(la,v)+" to "+n(ma,v)):process.stderr.write("ISF unchanged: "+n(ma,v)),s+="Autosens ratio: "+i(sensitivityRatio,2)+", ISF: "+n(la,v)+"→"+n(ma,v)),console.error("CR:"+v.carb_ratio),ma=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,x=t.delta_pn,S=t.r_squ,w=t.bg_acceleration,C=t.parabola_fit_a0,D=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(S,4)+", PF-nextDelta: "+n(x,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=-D/2/F*5,q=i(C-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=S;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(x,r)+", Corr "+i(S,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))}(ma,He,v,e,_,S,0,sensitivityRatio),void 0===t)return Oe.error="Error: iob_data undefined. ",Oe;var ua,da=t;if(t.length,t.length>1&&(t=da[0]),void 0===t.activity||void 0===t.iob)return Oe.error="Error: iob_data missing some property. ",Oe;var ca=((ua=void 0!==t.lastTemp?i((new Date(je).getTime()-t.lastTemp.date)/6e4):0)+r.duration)%30;if(console.error("currenttemp:"+r.rate+" lastTempAge:"+ua+"m, tempModulus:"+ca+"m"),Oe.temp="absolute",Oe.deliverAt=Re,y&&r&&t.lastTemp&&r.rate!==t.lastTemp.rate&&ua>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 ga=ua-t.lastTemp.duration;if(ga>5&&ua>10)return Oe.reason="Warning: currenttemp running but lastTemp from pumphistory ended "+ga+"m ago; canceling temp",M.setTempBasal(0,0,v,Oe,r)}var ha=i(-t.activity*ma*5,2),fa=i(6*(ze-ha));fa<0&&(fa=i(6*(Ne-ha)))<0&&(fa=i(6*(e.long_avgdelta-ha)));var pa=Ee,ba=(pa=t.iob>0?i(Ee-t.iob*ma):i(Ee-t.iob*Math.min(ma,v.sens)))+fa;if(void 0===ba||isNaN(ba))return Oe.error="Error: could not calculate eventualBG. Sensitivity: "+ma+" Deviation: "+fa,Oe;var va=function(e,a,r){return i(r+(e-a)/24,1)}(He,ba,ha);Oe={temp:"absolute",bg:Ee,tick:ke,eventualBG:ba,insulinReq:0,reservoir:x,deliverAt:Re,sensitivityRatio,TDD:ie};var Ba=[],_a=[],Ma=[],ya=[];Ba.push(Ee),_a.push(Ee),ya.push(Ee),Ma.push(Ee);var xa=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,wa=0,Ca=0;wa=i(ze-ha,1);var Da=i(ze-ha,1);csf=ma/v.carb_ratio,console.error("profile.sens:"+n(v.sens,v)+", sens:"+n(ma,v)+", CSF:"+i(csf,1));var Fa=i(30*csf*5/60,1);wa>Fa&&(console.error("Limiting carb impact from "+wa+" to "+Fa+"mg/dL/5m (30g/h)"),wa=Fa);var Ia=3;sensitivityRatio&&(Ia/=sensitivityRatio);var Ga=Ia;if(_.carbs){Ia=Math.max(Ia,_.mealCOB/20);var Ta=i((new Date(je).getTime()-_.lastCarbTime)/6e4),Ua=(_.carbs-_.mealCOB)/_.carbs;Ga=i(Ga=Ia+1.5*Ta/60,1),console.error("Last carbs "+Ta+" minutes ago; remainingCATime:"+Ga+"hours; "+i(100*Ua,1)+"% carbs absorbed")}var Oa=Math.max(0,wa/5*60*Ga/2)/csf,Ra=90,Aa=1;v.remainingCarbsCap&&(Ra=Math.min(90,v.remainingCarbsCap)),v.remainingCarbsFraction&&(Aa=Math.min(1,v.remainingCarbsFraction));var Pa=1-Aa,ja=Math.max(0,_.mealCOB-Oa-_.carbs*Pa),ka=(ja=Math.min(Ra,ja))*csf*5/60/(Ga/2),Wa=i(_.slopeFromMaxDeviation,2),qa=i(_.slopeFromMinDeviation,2),Ea=Math.min(Wa,-qa/3),La=0;0===wa?Ca=0:!0===v.floating_carbs?(Ca=Math.min(60*Ga/5/2,Math.max(0,_.carbs*csf/wa)),La=Math.min(60*Ga/5/2,Math.max(0,_.mealCOB*csf/wa)),_.carbs>0&&(s+=", Floating Carbs:, CID: "+i(Ca,1)+", MealCarbs: "+i(_.carbs,1)+", Not Floating:, CID: "+i(La,1)+", MealCOB: "+i(_.mealCOB,1),console.error("Floating Carbs CID: "+i(Ca,1)+" / MealCarbs: "+i(_.carbs,1)+" vs. Not Floating:"+i(La,1)+" / MealCOB:"+i(_.mealCOB,1)))):Ca=Math.min(60*Ga/5/2,Math.max(0,_.mealCOB*csf/wa)),console.error("Carb Impact:"+wa+"mg/dL per 5m; CI Duration:"+i(5*Ca/60*2,1)+"hours; remaining CI ("+Ga/2+"h peak):"+i(ka,1)+"mg/dL per 5m");var za,Na,Za,Ha,$a,Ja=999,Ka=999,Qa=999,Va=Ee,Xa=999,Ya=999,er=999,ar=999,rr=ba,tr=Ee,or=Ee,ir=0,nr=[],sr=[];try{da.forEach((function(e){var a=i(-e.activity*ma*5,2),r=i(-e.iobWithZeroTemp.activity*ma*5,2),t=wa*(1-Math.min(1,_a.length/12));if(!0==(1==se&&1==C.useNewFormula)){rr=_a[_a.length-1]+i(-e.activity*(1800/(F*de*Math.log(Math.max(_a[_a.length-1],39)/we+1)))*5,2)+t;var o=ya[ya.length-1]+i(-e.iobWithZeroTemp.activity*(1800/(F*de*Math.log(Math.max(ya[ya.length-1],39)/we+1)))*5,2);console.log("Dynamic ISF (Logarithmic Formula) )adjusted predictions for IOB and ZT: IOBpredBG: "+i(rr,2)+" , ZTpredBG: "+i(o,2))}else{rr=_a[_a.length-1]+a+t;o=ya[ya.length-1]+r}var n=Math.max(0,Math.max(0,wa)*(1-Ba.length/Math.max(2*Ca,1))),s=Math.min(Ba.length,12*Ga-Ba.length),l=Math.max(0,s/(Ga/2*12)*ka);n+l,nr.push(i(l,0)),sr.push(i(n,0)),COBpredBG=Ba[Ba.length-1]+a+Math.min(0,t)+n+l;var m=Math.max(0,Da+Ma.length*Ea),u=Math.max(0,Da*(1-Ma.length/Math.max(36,1))),d=Math.min(m,u);if(d>0&&(ir=i(5*(Ma.length+1)/60,1)),!0==(1==se&&1==C.useNewFormula))UAMpredBG=Ma[Ma.length-1]+i(-e.activity*(1800/(F*de*Math.log(Math.max(Ma[Ma.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=Ma[Ma.length-1]+a+Math.min(0,t)+d;_a.length<48&&_a.push(rr),Ba.length<48&&Ba.push(COBpredBG),Ma.length<48&&Ma.push(UAMpredBG),ya.length<48&&ya.push(o),COBpredBG<Xa&&(Xa=i(COBpredBG)),UAMpredBG<Ya&&(Ya=i(UAMpredBG)),rr<er&&(er=i(rr)),o<ar&&(ar=i(o));_a.length>18&&rr<Ja&&(Ja=i(rr)),rr>tr&&(tr=rr),(Ca||ka>0)&&Ba.length>18&&COBpredBG<Ka&&(Ka=i(COBpredBG)),(Ca||ka>0)&&COBpredBG>tr&&(or=COBpredBG),Sa&&Ma.length>12&&UAMpredBG<Qa&&(Qa=i(UAMpredBG)),Sa&&UAMpredBG>tr&&UAMpredBG}))}catch(e){console.error("Problem with iobArray. Optional feature Advanced Meal Assist disabled")}_.mealCOB&&(console.error("predCIs (mg/dL/5m):"+sr.join(" ")),console.error("remainingCIs: "+nr.join(" "))),Oe.predBGs={},_a.forEach((function(e,a,r){r[a]=i(Math.min(401,Math.max(39,e)))}));for(var lr=_a.length-1;lr>12&&_a[lr-1]===_a[lr];lr--)_a.pop();for(Oe.predBGs.IOB=_a,Za=i(_a[_a.length-1]),ya.forEach((function(e,a,r){r[a]=i(Math.min(401,Math.max(39,e)))})),lr=ya.length-1;lr>6&&!(ya[lr-1]>=ya[lr]||ya[lr]<=He);lr--)ya.pop();if(Oe.predBGs.ZT=ya,i(ya[ya.length-1]),_.mealCOB>0&&(wa>0||ka>0)){for(Ba.forEach((function(e,a,r){r[a]=i(Math.min(401,Math.max(39,e)))})),lr=Ba.length-1;lr>12&&Ba[lr-1]===Ba[lr];lr--)Ba.pop();Oe.predBGs.COB=Ba,Ha=i(Ba[Ba.length-1]),ba=Math.max(ba,i(Ba[Ba.length-1]))}if(wa>0||ka>0){if(Sa){for(Ma.forEach((function(e,a,r){r[a]=i(Math.min(401,Math.max(39,e)))})),lr=Ma.length-1;lr>12&&Ma[lr-1]===Ma[lr];lr--)Ma.pop();Oe.predBGs.UAM=Ma,$a=i(Ma[Ma.length-1]),Ma[Ma.length-1]&&(ba=Math.max(ba,i(Ma[Ma.length-1])))}Oe.eventualBG=ba}console.error("UAM Impact:"+Da+"mg/dL per 5m; UAM Duration:"+ir+"hours"),Ja=Math.max(39,Ja),Ka=Math.max(39,Ka),Qa=Math.max(39,Qa),za=i(Ja);var mr=_.mealCOB/_.carbs;Na=i(Qa<999&&Ka<999?(1-mr)*UAMpredBG+mr*COBpredBG:Ka<999?(rr+COBpredBG)/2:Qa<999?(rr+UAMpredBG)/2:rr),ar>Na&&(Na=ar),Va=i(Va=Ca||ka>0?Sa?mr*Xa+(1-mr)*Ya:Xa:Sa?Ya:er);var ur=Qa;if(ar<na)ur=(Qa+ar)/2;else if(ar<He){var dr=(ar-na)/(He-na);ur=(Qa+(Qa*dr+ar*(1-dr)))/2}else ar>Qa&&(ur=(Qa+ar)/2);if(ur=i(ur),_.carbs)if(!Sa&&Ka<999)za=i(Math.max(Ja,Ka));else if(Ka<999){var cr=mr*Ka+(1-mr)*ur;za=i(Math.max(Ja,Ka,cr))}else za=Sa?ur:Va;else Sa&&(za=i(Math.max(Ja,ur)));za=Math.min(za,Na),process.stderr.write("minPredBG: "+za+" minIOBPredBG: "+Ja+" minZTGuardBG: "+ar),Ka<999&&process.stderr.write(" minCOBPredBG: "+Ka),Qa<999&&process.stderr.write(" minUAMPredBG: "+Qa),console.error(" avgPredBG:"+Na+" COB/Carbs:"+_.mealCOB+"/"+_.carbs),or>Ee&&(za=Math.min(za,or)),Oe.COB=_.mealCOB,Oe.IOB=t.iob,Oe.BGI=n(ha,v),Oe.deviation=n(fa,v),Oe.ISF=n(ma,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(za,v)+", minGuardBG "+n(Va,v)+", IOBpredBG "+n(Za,v),Ha>0&&(Oe.reason+=", COBpredBG "+n(Ha,v)),$a>0&&(Oe.reason+=", UAMpredBG "+n($a,v)),Oe.reason+=tddReason,Oe.reason+="; ";var gr=pa;gr<40&&(gr=Math.min(Va,gr));var hr,fr=na-gr,pr=240,br=240;if(_.mealCOB>0&&(wa>0||ka>0)){for(lr=0;lr<Ba.length;lr++)if(Ba[lr]<$e){pr=5*lr;break}for(lr=0;lr<Ba.length;lr++)if(Ba[lr]<na){br=5*lr;break}}else{for(lr=0;lr<_a.length;lr++)if(_a[lr]<$e){pr=5*lr;break}for(lr=0;lr<_a.length;lr++)if(_a[lr]<na){br=5*lr;break}}xa&&Va<na&&(console.error("minGuardBG "+n(Va,v)+" projected below "+n(na,v)+" - disabling SMB"),xa=!1),void 0===v.maxDelta_bg_threshold&&(hr=.2),void 0!==v.maxDelta_bg_threshold&&(hr=Math.min(v.maxDelta_bg_threshold,.4)),Ze>hr*Ee&&(console.error("maxDelta "+n(Ze,v)+" > "+100*hr+"% of BG "+n(Ee,v)+" - disabling SMB"),Oe.reason+="maxDelta "+n(Ze,v)+" > "+100*hr+"% of BG "+n(Ee,v)+" - SMB disabled!, ",xa=!1),console.error("BG projected to remain above "+n($e,v)+" for "+pr+"minutes"),(br<240||pr<60)&&console.error("BG projected to remain above "+n(na,v)+" for "+br+"minutes");var vr=br,Br=v.current_basal*ma*vr/60,_r=Math.max(0,_.mealCOB-.25*_.carbs),Mr=(fr-Br)/csf-_r;Br=i(Br),Mr=i(Mr),console.error("naive_eventualBG:",pa,"bgUndershoot:",fr,"zeroTempDuration:",vr,"zeroTempEffect:",Br,"carbsReq:",Mr),"Could not parse clock data"==_.reason?console.error("carbsReq unknown: Could not parse clock data"):Mr>=v.carbsReqThreshold&&br<=45&&(Oe.carbsReq=Mr,Oe.reason+=Mr+" add'l carbs req w/in "+br+"m; ");var yr=0;if(Ee<na&&t.iob<20*-v.current_basal/60&&ze>0&&ze>va)Oe.reason+="IOB "+t.iob+" < "+i(20*-v.current_basal/60,2),Oe.reason+=" and minDelta "+n(ze,v)+" > expectedDelta "+n(va,v)+"; ";else if(Ee<na||Va<na)return Oe.reason+="minGuardBG "+n(Va,v)+"<"+n(na,v),yr=i(60*((fr=He-Va)/ma)/v.current_basal),yr=30*i(yr/30),yr=Math.min(120,Math.max(30,yr)),M.setTempBasal(0,yr,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 xr=0,Sr=Pe;if(ba<$e){if(Oe.reason+="Eventual BG "+n(ba,v)+" < "+n($e,v),ze>va&&ze>0&&!Mr)return pa<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(va,v):Oe.reason+=", but Min. Delta "+ze.toFixed(2)+" > Exp. Delta "+n(va,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)));xr=i(xr=2*Math.min(0,(ba-He)/ma),2);var wr=Math.min(0,(pa-He)/ma);if(wr=i(wr,2),ze<0&&ze>va)xr=i(xr*(ze/va),2);if(Sr=o(Sr=Pe+2*xr,v),r.duration*(r.rate-Pe)/60<Math.min(xr,wr)-.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((yr=i(60*((fr=He-pa)/ma)/v.current_basal))<0?yr=0:(yr=30*i(yr/30),yr=Math.min(120,Math.max(0,yr))),yr>0)return Oe.reason+=", setting "+yr+"m zero temp. ",M.setTempBasal(Sr,yr,v,Oe,r)}else Oe.reason+=", setting "+Sr+"U/hr. ";return M.setTempBasal(Sr,30,v,Oe,r)}if(ze<va&&(!y||!xa))return e.delta<ze?Oe.reason+="Eventual BG "+n(ba,v)+" > "+n($e,v)+" but Delta "+n(ke,v)+" < Exp. Delta "+n(va,v):Oe.reason+="Eventual BG "+n(ba,v)+" > "+n($e,v)+" but Min. Delta "+ze.toFixed(2)+" < Exp. Delta "+n(va,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(ba,za)<Je&&(!y||!xa))return Oe.reason+=n(ba,v)+"-"+n(za,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(ba>=Je&&(Oe.reason+="Eventual BG "+n(ba,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));(xr=i((Math.min(za,ba)-He)/ma,2))>Qe-t.iob?(console.error("SMB limited by maxIOB: "+Qe-t.iob+" (. insulinReq: "+xr+" U)"),Oe.reason+="max_iob "+Qe+", ",xr=Qe-t.iob):console.error("SMB not limited by maxIOB ( insulinReq: "+xr+" U)."),Sr=o(Sr=Pe+2*xr,v),xr=i(xr,3),Oe.insulinReq=xr;var Cr=i((new Date(je).getTime()-t.lastBolusTime)/6e4,1);if(y&&xa&&Ee>na){var Dr=i(_.mealCOB/v.carb_ratio,3);if(v.use_autoisf)Fr=v.smb_max_range_extension;else{console.error("autoISF disabled, SMB range extension disabled");var Fr=1}Fr>1&&console.error("SMB max range extended from default by factor "+Fr);var Ir=0;void 0===v.maxSMBBasalMinutes?(Ir=i(Fr*v.current_basal*30/60,1),console.error("profile.maxSMBBasalMinutes undefined: defaulting to 30m"),xr>Ir&&(console.error("SMB limited by maxBolus: "+Ir+" ( "+xr+" 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),Ir=i(Fr*v.current_basal*v.maxUAMSMBBasalMinutes/60,1)):(console.error("profile.maxUAMSMBBasalMinutes undefined: defaulting to 30m"),Ir=i(30*v.current_basal/60,1)),xr>Ir?console.error("SMB limited by maxUAMSMBBasalMinutes [ "+v.maxUAMSMBBasalMinutes+"m ]: "+Ir+"U ( "+xr+"U )"):console.error("SMB is not limited by maxUAMSMBBasalMinutes. ( insulinReq: "+xr+"U )")):(console.error("profile.maxSMBBasalMinutes: "+v.maxSMBBasalMinutes+", profile.current_basal: "+v.current_basal),xr>(Ir=i(Fr*v.current_basal*v.maxSMBBasalMinutes/60,1))?console.error("SMB limited by maxSMBBasalMinutes: "+v.maxSMBBasalMinutes+"m ]: "+Ir+"U ( insulinReq: "+xr+"U )"):console.error("SMB is not limited by maxSMBBasalMinutes. ( insulinReq: "+xr+"U )"));var Gr=v.bolus_increment,Tr=1/Gr,Ur=b(v,Ee,He);Ur>.5&&console.error("SMB Delivery Ratio increased from default 0.5 to "+i(Ur,2));var Or=Math.min(xr*Ur,Ir);Or=Math.floor(Or*Tr)/Tr,yr=i(60*((He-(pa+Ja)/2)/ma)/v.current_basal),xr>0&&Or<Gr&&(yr=0);var Rr=0;yr<=0?yr=0:yr>=30?(yr=30*i(yr/30),yr=Math.min(60,Math.max(0,yr))):(Rr=i(Pe*yr/30,2),yr=30),Oe.reason+=" insulinReq "+xr,Or>=Ir&&(Oe.reason+="; maxBolus "+Ir),yr>0&&(Oe.reason+="; setting "+yr+"m low temp of "+Rr+"U/h"),Oe.reason+=". ";var Ar=3;v.SMBInterval&&(Ar=Math.min(10,Math.max(1,v.SMBInterval)));var Pr=i(Ar-Cr,0),jr=i(60*(Ar-Cr),0)%60;if(console.error("naive_eventualBG "+pa+","+yr+"m "+Rr+"U/h temp needed; last bolus "+Cr+"m ago; maxBolus: "+Ir),Cr>Ar?Or>0&&(Oe.units=Or,Oe.reason+="Microbolusing "+Or+"U. "):Oe.reason+="Waiting "+Pr+"m "+jr+"s to microbolus again. ",yr>0)return Oe.rate=Rr,Oe.duration=yr,Oe}var kr=M.getMaxSafeBasal(v);return Sr>kr&&(Oe.reason+="adj. req. rate: "+Sr+" to maxSafeBasal: "+i(kr,2)+", ",Sr=o(kr,v)),r.duration*(r.rate-Pe)/60>=2*xr?(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})();