var freeaps_determineBasal;(()=>{var e={5546:(e,t,a)=>{var r=a(6880);function o(e,t){t||(t=0);var a=Math.pow(10,t);return Math.round(e*a)/a}function n(e,t){return"mmol/L"===t.out_units?o(.0555*e,1):Math.round(e)}e.exports=function(e,t,a,i,s,l,m,u,d,c,g,h,p,f){var b=i.min_bg,v=0,B="",M="",_="",y="",x="",w=0,D=0,S=0,T=0,C=0,U=0;const G=f.weightedAverage,R=i.weightPercentage,O=f.average_total_data;function A(e,t){var a=e.getTime();return new Date(a+36e5*t)}function I(e){var t=i.bolus_increment;.05!=t&&(t=.1);var a=e/t;return a>=1?o(Math.floor(a)*t,5):0}function j(e){function t(e){return e<10&&(e="0"+e),e}return t(e.getHours())+":"+t(e.getMinutes())+":00"}function F(e,t){var a=new Date("1/1/1999 "+e),r=new Date("1/1/1999 "+t);return(a.getTime()-r.getTime())/36e5}function P(e,t){var a=0,r=t,o=(e-t)/36e5,n=0,i=o,s=0;do{if(o>0){var l=j(r),m=p[0].rate;for(let e=0;e
=(s=F(p[e+1].start,p[e].start))?n=s:o=(s=24-F(p[e].start,t))?n=s:ou)if(e+1=(s=F(d,l))?n=s:o=(s=F("23:59:59",l))?n=s:o0&&o21)C=P(q,(k=24-v,E=q.getTime(),new Date(E-36e5*k))),y="24 hours of data is required for an accurate tdd calculation. Currently only "+v.toPrecision(3)+" hours of pump history data are available. Using your pump scheduled basals to fill in the missing hours. Scheduled basals added: "+C.toPrecision(5)+" U. ";else v<21?(Y=!1,enableDynamicCR=!1):y=""}else console.log("Pumphistory is empty!"),Y=!1,enableDynamicCR=!1;var k,E;for(let e=0;e0){w=e,U=g[e].rate;var L=g[e-1]["duration (min)"]/60,z=L,N=new Date(g[e-1].timestamp),Z=N,H=0;do{if(e--,0==e){Z=new Date;break}if("TempBasal"==g[e]._type||"PumpSuspend"==g[e]._type){Z=new Date(g[e].timestamp);break}var $=e-2;if($>=0&&"Rewind"==g[$]._type){let e=g[$].timestamp;for(;$-1>=0&&"Prime"==g[$-=1]._type;)H=(g[$].timestamp-e)/36e5;H>=L&&(Z=e,H=0)}}while(e>0);var J=(Z-N)/36e5;J0&&(--r,"TempBasal"==g[r]._type)){a=new Date(g[r].timestamp);break}}while(r>0);(a-t)/36e5>0&&(C+=P(a,t))}for(let e=g.length-1;e>0;e--)if("TempBasalDuration"==g[e]._type){let t=g[e]["duration (min)"]/60,a=new Date(g[e].timestamp);var K=a;let r=e;do{if(--r,r>=0&&("TempBasal"==g[r]._type||"PumpSuspend"==g[r]._type)){K=new Date(g[r].timestamp);break}}while(r>0);if(0==e&&"TempBasalDuration"==g[0]._type&&(K=new Date,t=g[e]["duration (min)"]/60),(K-a)/36e5-t>0){C+=P(K,A(a,t))}}var Q,V={TDD:o(D=T+S+C,5),bolus:o(T,5),temp_basal:o(S,5),scheduled_basal:o(C,5)};v>21?(M=". Bolus insulin: "+T.toPrecision(5)+" U",_=". Temporary basal insulin: "+S.toPrecision(5)+" U",B=". Insulin with scheduled basal rate: "+C.toPrecision(5)+" U",x=y+(" TDD past 24h is: "+D.toPrecision(5)+" U")+M+_+B,tddReason=", Total insulin: "+o(D,2)+" U, "+o(T/D*100,0)+"% Bolus "+o((S+C)/D*100,0)+"% Basal"):tddReason=", TDD: Not enough pumpData (< 21h)";const X=e.glucose;var Y=h.useNewFormula;const ee=h.enableDynamicCR,te=Math.min(i.autosens_min,i.autosens_max),ae=Math.max(i.autosens_min,i.autosens_max),re=h.adjustmentFactor,oe=i.min_bg;var ne=!1,ie="",se=1,le="";O>0&&(se=G/O),le=se>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: "+(se=o(se=Math.min(se,i.autosens_max),2))+". Upper limit = Autosens max ("+i.autosens_max+")":se<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: "+(se=o(se=Math.max(se,i.autosens_min),2))+". Lower limit = Autosens min ("+i.autosens_min+")":"Basal adjusted with a 24 hour to total average (up to 14 days of data) TDD ratio: "+se,le=", Basal ratio: "+se,(i.high_temptarget_raises_sensitivity||i.exercise_mode)&&(ne=!0),oe>=118&&ne&&(Y=!1,ie="Dynamic ISF temporarily off due to a high temp target/exercising. Current min target: "+oe);var me=", Dynamic ratios log: ",ue=", AF: "+re,de="BG: "+X+" mg/dl ("+(.0555*X).toPrecision(2)+" mmol/l)",ce="",ge="";const he=h.curve,pe=h.insulinPeakTime,fe=h.useCustomPeakTime;var be=55,ve=65;switch(he){case"rapid-acting":ve=65;break;case"ultra-rapid":ve=50}fe?(be=120-pe,console.log("Custom insulinpeakTime set to :"+pe+", insulinFactor: "+be)):(be=120-ve,console.log("insulinFactor set to : "+be)),Q=D,R<1&&G>0&&(D=G,console.log("Using weighted TDD average: "+o(D,2)+" U, instead of past 24 h ("+o(Q,2)+" U), weight: "+R),ge=", Weighted TDD: "+o(D,2)+" U");const Be=h.sigmoid;var Me="";if(Y){var _e=i.sens*re*D*Math.log(X/be+1)/1800;ce=", Logarithmic formula"}var ye="";if(Y&&Be){const e=te,t=ae-e,a=.0555*(X-i.min_bg);var xe=se;ye=", tdd_factor: "+o(xe,1);const r=ae-1,n=Math.log10(1/r-e/r)/Math.log10(Math.E),s=a*re*xe+n;_e=t/(1+Math.exp(-s))+e,ce=", Sigmoid function"}var we=i.carb_ratio;const De=o(i.carb_ratio,1);var Se="",Te="";if(Y&&D>0){if(Se=", Dynamic ISF/CR: On/",_e>ae?(ie=", Dynamic ISF limited by autosens_max setting: "+ae+" ("+o(_e,2)+"), ",Te=", Autosens/Dynamic Limit: "+ae+" ("+o(_e,2)+")",_e=ae):_e1&&(Ce=(_e-1)/2+1);var Ue=" CR: "+(we=o(we/Ce,2))+" g/U";i.carb_ratio=we}else Ue=" CR: "+we+" g/U",Se+="Off";const e=i.sens/_e;Me=". Using Sigmoid function, the autosens ratio has been adjusted with sigmoid factor to: "+o(s.ratio,2)+". New ISF = "+o(e,2)+" mg/dl ("+o(.0555*e,2)+" (mmol/l). CR adjusted from "+o(we,2)+" to "+o(i.carb_ratio,2)+" ("+o(.0555*i.carb_ratio,2)+" mmol/l).",ie+=Be?Me:", Dynamic autosens.ratio set to "+o(_e,2)+" with ISF: "+e.toPrecision(3)+" mg/dl/U ("+(.0555*e).toPrecision(3)+" mmol/l/U)",s.ratio=_e,x+=me+de+ue+ce+ie+Se+Ue+ge}else x+=me+"Dynamic Settings disabled";console.log(x),Y||ee?Y&&i.tddAdjBasal?tddReason+=Se+ce+Te+ue+le:Y&&!i.tddAdjBasal&&(tddReason+=Se+ce+Te+ue):tddReason+="";var Ge={},Re=new Date;if(c&&(Re=c),void 0===i||void 0===i.current_basal)return Ge.error="Error: could not get current basal rate",Ge;var Oe=r(i.current_basal,i),Ae=Oe,Ie=new Date;c&&(Ie=c);var je,Fe=new Date(e.date),Pe=o((Ie-Fe)/60/1e3,1),qe=e.glucose,We=e.noise;je=e.delta>-.5?"+"+o(e.delta,0):o(e.delta,0);var ke=Math.min(e.delta,e.short_avgdelta),Ee=Math.min(e.short_avgdelta,e.long_avgdelta),Le=Math.max(e.delta,e.short_avgdelta,e.long_avgdelta);(qe<=10||38===qe||We>=3)&&(Ge.reason="CGM is calibrating, in ??? state, or noise is high");if(qe>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(qe,i)+"+"+n(e.delta,i)+") for 5m w/ "+n(e.short_avgdelta,i)+" mg/dL ~15m change & "+n(e.long_avgdelta,2)+" mg/dL ~45m change"),console.error("Simulator mode detected ("+e.device+"): continuing anyway")):!0),Pe>12||Pe<-5?Ge.reason="If current system time "+Ie+" is correct, then BG data is too old. The last BG data was read "+Pe+"m ago at "+Fe:0===e.short_avgdelta&&0===e.long_avgdelta&&(e.last_cal&&e.last_cal<3?Ge.reason="CGM was just calibrated":Ge.reason="CGM data is unchanged ("+n(qe,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"),qe<=10||38===qe||We>=3||Pe>12||Pe<-5||0===e.short_avgdelta&&0===e.long_avgdelta)return t.rate>=Ae?(Ge.reason+=". Canceling high temp basal of "+t.rate,Ge.deliverAt=Re,Ge.temp="absolute",Ge.duration=0,Ge.rate=0,Ge):0===t.rate&&t.duration>30?(Ge.reason+=". Shortening "+t.duration+"m long zero temp to 30m. ",Ge.deliverAt=Re,Ge.temp="absolute",Ge.duration=30,Ge.rate=0,Ge):(Ge.reason+=". Temp "+t.rate+" <= current basal "+Ae+"U/hr; doing nothing. ",Ge);var ze,Ne,Ze,He,$e=i.max_iob;if(void 0!==i.min_bg&&(Ne=i.min_bg),void 0!==i.max_bg&&(Ze=i.max_bg),void 0!==i.enableSMB_high_bg_target&&(He=i.enableSMB_high_bg_target),void 0===i.min_bg||void 0===i.max_bg)return Ge.error="Error: could not determine target_bg. ",Ge;ze=(i.min_bg+i.max_bg)/2;var Je=i.exercise_mode||i.high_temptarget_raises_sensitivity,Ke=100,Qe=160;if(i.half_basal_exercise_target&&(Qe=i.half_basal_exercise_target),Je&&i.temptargetSet&&ze>Ke||i.low_temptarget_lowers_sensitivity&&i.temptargetSet&&ze=ze&&sensitivityRatio<_e&&(s.ratio=_e*(Ke/ze),s.ratio=Math.min(s.ratio,i.autosens_max),sensitivityRatio=o(s.ratio,2),console.log("Dynamic ratio increased from "+o(_e,2)+" to "+o(s.ratio,2)+" due to a low temp target ("+ze+").")),sensitivityRatio&&!Y?(Ae=i.current_basal*sensitivityRatio,Ae=r(Ae,i)):Y&&i.tddAdjBasal&&(Ae=i.current_basal*se,Ae=r(Ae,i),process.stderr.write("TDD-adjustment of basals activated, using tdd24h_14d_Ratio "+o(se,2)+", TDD 24h = "+o(Q,2)+"U, Weighted average TDD = "+o(G,2)+"U, (Weight percentage = "+R+"), Total data of TDDs (up to 14 days) average = "+o(O,2)+"U. "),Ae!==Oe?process.stderr.write("Adjusting basal from "+Oe+" U/h to "+Ae+" U/h; "):process.stderr.write("Basal unchanged: "+Ae+" U/h; ")),i.temptargetSet);else if(void 0!==s&&s&&(i.sensitivity_raises_target&&s.ratio<1||i.resistance_lowers_target&&s.ratio>1)){Ne=o((Ne-60)/s.ratio)+60,Ze=o((Ze-60)/s.ratio)+60;var Xe=o((ze-60)/s.ratio)+60;ze===(Xe=Math.max(80,Xe))?process.stderr.write("target_bg unchanged: "+Xe+"; "):process.stderr.write("target_bg from "+ze+" to "+Xe+"; "),ze=Xe}var Ye=200,et=200,tt=200;if(e.noise>=2){var at=Math.max(1.1,i.noisyCGMTargetMultiplier);Math.min(250,i.maxRaw);Ye=o(Math.min(200,Ne*at)),et=o(Math.min(200,ze*at)),tt=o(Math.min(200,Ze*at)),process.stderr.write("Raising target_bg for noisy / raw CGM data, from "+ze+" to "+et+"; "),Ne=Ye,ze=et,Ze=tt}var rt=Ne-.5*(Ne-40),ot=i.threshold_setting;ot>rt&&ot<=120&&ot>=65?(console.error("Threshold changed in settings from "+n(rt,i)+" to "+n(ot,i)+". "),rt=ot):console.error("Current threshold: "+n(rt,i));var nt="",it=o(i.sens,1),st=i.sens;if(void 0!==s&&s&&((st=o(st=i.sens/sensitivityRatio,1))!==it?process.stderr.write("ISF from "+n(it,i)+" to "+n(st,i)):process.stderr.write("ISF unchanged: "+n(st,i)),nt+="Autosens ratio: "+o(sensitivityRatio,2)+", ISF: "+n(it,i)+"→"+n(st,i)),console.error("CR:"+i.carb_ratio),void 0===a)return Ge.error="Error: iob_data undefined. ",Ge;var lt,mt=a;if(a.length,a.length>1&&Q>0&&(a=mt[0]),void 0===a.activity||void 0===a.iob)return Ge.error="Error: iob_data missing some property. ",Ge;var ut=((lt=void 0!==a.lastTemp?o((new Date(Ie).getTime()-a.lastTemp.date)/6e4):0)+t.duration)%30;if(console.error("currenttemp:"+t.rate+" lastTempAge:"+lt+"m, tempModulus:"+ut+"m"),Ge.temp="absolute",Ge.deliverAt=Re,u&&t&&a.lastTemp&&t.rate!==a.lastTemp.rate&<>10&&t.duration)return Ge.reason="Warning: currenttemp rate "+t.rate+" != lastTemp rate "+a.lastTemp.rate+" from pumphistory; canceling temp",m.setTempBasal(0,0,i,Ge,t);if(t&&a.lastTemp&&t.duration>0){var dt=lt-a.lastTemp.duration;if(dt>5&<>10)return Ge.reason="Warning: currenttemp running but lastTemp from pumphistory ended "+dt+"m ago; canceling temp",m.setTempBasal(0,0,i,Ge,t)}var ct=o(-a.activity*st*5,2),gt=o(6*(ke-ct));gt<0&&(gt=o(6*(Ee-ct)))<0&&(gt=o(6*(e.long_avgdelta-ct)));var ht=qe,pt=(ht=a.iob>0?o(qe-a.iob*st):o(qe-a.iob*Math.min(st,i.sens)))+gt;if(void 0===pt||isNaN(pt))return Ge.error="Error: could not calculate eventualBG. Sensitivity: "+st+" Deviation: "+gt,Ge;var ft=function(e,t,a){return o(a+(e-t)/24,1)}(ze,pt,ct);Ge={temp:"absolute",bg:qe,tick:je,eventualBG:pt,insulinReq:0,reservoir:d,deliverAt:Re,sensitivityRatio,TDD:Q,insulin:V};var bt=[],vt=[],Bt=[],Mt=[];bt.push(qe),vt.push(qe),Mt.push(qe),Bt.push(qe);var _t=function(e,t,a,r,o,i){return t?!e.allowSMB_with_high_temptarget&&e.temptargetSet&&o>100?(console.error("SMB disabled due to high temptarget of "+o),!1):!0===a.bwFound&&!1===e.A52_risk_enable?(console.error("SMB disabled due to Bolus Wizard activity in the last 6 hours."),!1):!0===e.enableSMB_always?(a.bwFound?console.error("Warning: SMB enabled within 6h of using Bolus Wizard: be sure to easy bolus 30s before using Bolus Wizard"):console.error("SMB enabled due to enableSMB_always"),!0):!0===e.enableSMB_with_COB&&a.mealCOB?(a.bwCarbs?console.error("Warning: SMB enabled with Bolus Wizard carbs: be sure to easy bolus 30s before using Bolus Wizard"):console.error("SMB enabled for COB of "+a.mealCOB),!0):!0===e.enableSMB_after_carbs&&a.carbs?(a.bwCarbs?console.error("Warning: SMB enabled with Bolus Wizard carbs: be sure to easy bolus 30s before using Bolus Wizard"):console.error("SMB enabled for 6h after carb entry"),!0):!0===e.enableSMB_with_temptarget&&e.temptargetSet&&o<100?(a.bwFound?console.error("Warning: SMB enabled within 6h of using Bolus Wizard: be sure to easy bolus 30s before using Bolus Wizard"):console.error("SMB enabled for temptarget of "+n(o,e)),!0):!0===e.enableSMB_high_bg&&null!==i&&r>=i?(console.error("Checking BG to see if High for SMB enablement."),console.error("Current BG",r," | High BG ",i),a.bwFound?console.error("Warning: High BG SMB enabled within 6h of using Bolus Wizard: be sure to easy bolus 30s before using Bolus Wizard"):console.error("High BG detected. Enabling SMB."),!0):(console.error("SMB disabled (no enableSMB preferences active or no condition satisfied)"),!1):(console.error("SMB disabled (!microBolusAllowed)"),!1)}(i,u,l,qe,ze,He),yt=i.enableUAM,xt=0,wt=0;xt=o(ke-ct,1);var Dt=o(ke-ct,1);csf=st/i.carb_ratio,console.error("profile.sens:"+n(i.sens,i)+", sens:"+n(st,i)+", CSF:"+o(csf,1));var St=o(30*csf*5/60,1);xt>St&&(console.error("Limiting carb impact from "+xt+" to "+St+"mg/dL/5m (30g/h)"),xt=St);var Tt=3;sensitivityRatio&&(Tt/=sensitivityRatio);var Ct=Tt;if(l.carbs){Tt=Math.max(Tt,l.mealCOB/20);var Ut=o((new Date(Ie).getTime()-l.lastCarbTime)/6e4),Gt=(l.carbs-l.mealCOB)/l.carbs;Ct=o(Ct=Tt+1.5*Ut/60,1),console.error("Last carbs "+Ut+" minutes ago; remainingCATime:"+Ct+"hours; "+o(100*Gt,1)+"% carbs absorbed")}var Rt=Math.max(0,xt/5*60*Ct/2)/csf,Ot=90,At=1;i.remainingCarbsCap&&(Ot=Math.min(90,i.remainingCarbsCap)),i.remainingCarbsFraction&&(At=Math.min(1,i.remainingCarbsFraction));var It=1-At,jt=Math.max(0,l.mealCOB-Rt-l.carbs*It),Ft=(jt=Math.min(Ot,jt))*csf*5/60/(Ct/2),Pt=o(l.slopeFromMaxDeviation,2),qt=o(l.slopeFromMinDeviation,2),Wt=Math.min(Pt,-qt/3);wt=0===xt?0:Math.min(60*Ct/5/2,Math.max(0,l.mealCOB*csf/xt)),console.error("Carb Impact:"+xt+"mg/dL per 5m; CI Duration:"+o(5*wt/60*2,1)+"hours; remaining CI ("+Ct/2+"h peak):"+o(Ft,1)+"mg/dL per 5m");var kt,Et,Lt,zt,Nt,Zt=999,Ht=999,$t=999,Jt=qe,Kt=999,Qt=999,Vt=999,Xt=999,Yt=pt,ea=qe,ta=qe,aa=0,ra=[],oa=[];try{mt.forEach((function(e){var t=o(-e.activity*st*5,2),a=o(-e.iobWithZeroTemp.activity*st*5,2),r=ht,n=xt*(1-Math.min(1,vt.length/12));if(!0===(Y&&!Be))Yt=vt[vt.length-1]+o(-e.activity*(1800/(D*re*Math.log(Math.max(vt[vt.length-1],39)/be+1)))*5,2)+n,r=Mt[Mt.length-1]+o(-e.iobWithZeroTemp.activity*(1800/(D*re*Math.log(Math.max(Mt[Mt.length-1],39)/be+1)))*5,2),console.log("Dynamic ISF (Logarithmic Formula) )adjusted predictions for IOB and ZT: IOBpredBG: "+o(Yt,2)+" , ZTpredBG: "+o(r,2));else Yt=vt[vt.length-1]+t+n,r=Mt[Mt.length-1]+a;var i=Math.max(0,Math.max(0,xt)*(1-bt.length/Math.max(2*wt,1))),s=Math.min(bt.length,12*Ct-bt.length),l=Math.max(0,s/(Ct/2*12)*Ft);i+l,ra.push(o(l,0)),oa.push(o(i,0)),COBpredBG=bt[bt.length-1]+t+Math.min(0,n)+i+l;var m=Math.max(0,Dt+Bt.length*Wt),u=Math.max(0,Dt*(1-Bt.length/Math.max(36,1))),d=Math.min(m,u);if(d>0&&(aa=o(5*(Bt.length+1)/60,1)),!0===(Y&&!Be))UAMpredBG=Bt[Bt.length-1]+o(-e.activity*(1800/(D*re*Math.log(Math.max(Bt[Bt.length-1],39)/be+1)))*5,2)+Math.min(0,n)+d,console.log("Dynamic ISF (Logarithmic Formula) adjusted prediction for UAM: UAMpredBG: "+o(UAMpredBG,2));else UAMpredBG=Bt[Bt.length-1]+t+Math.min(0,n)+d;vt.length<48&&vt.push(Yt),bt.length<48&&bt.push(COBpredBG),Bt.length<48&&Bt.push(UAMpredBG),Mt.length<48&&Mt.push(r),COBpredBG18&&Ytea&&(ea=Yt),(wt||Ft>0)&&bt.length>18&&COBpredBG0)&&COBpredBG>ea&&(ta=COBpredBG),yt&&Bt.length>12&&UAMpredBG<$t&&($t=o(UAMpredBG)),yt&&UAMpredBG>ea&&UAMpredBG}))}catch(e){console.error("Problem with iobArray. Optional feature Advanced Meal Assist disabled")}l.mealCOB&&(console.error("predCIs (mg/dL/5m):"+oa.join(" ")),console.error("remainingCIs: "+ra.join(" "))),Ge.predBGs={},vt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))}));for(var na=vt.length-1;na>12&&vt[na-1]===vt[na];na--)vt.pop();for(Ge.predBGs.IOB=vt,Lt=o(vt[vt.length-1]),Mt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),na=Mt.length-1;na>6&&!(Mt[na-1]>=Mt[na]||Mt[na]<=ze);na--)Mt.pop();if(Ge.predBGs.ZT=Mt,o(Mt[Mt.length-1]),l.mealCOB>0&&(xt>0||Ft>0)){for(bt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),na=bt.length-1;na>12&&bt[na-1]===bt[na];na--)bt.pop();Ge.predBGs.COB=bt,zt=o(bt[bt.length-1]),pt=Math.max(pt,o(bt[bt.length-1]))}if(xt>0||Ft>0){if(yt){for(Bt.forEach((function(e,t,a){a[t]=o(Math.min(401,Math.max(39,e)))})),na=Bt.length-1;na>12&&Bt[na-1]===Bt[na];na--)Bt.pop();Ge.predBGs.UAM=Bt,Nt=o(Bt[Bt.length-1]),Bt[Bt.length-1]&&(pt=Math.max(pt,o(Bt[Bt.length-1])))}Ge.eventualBG=pt}console.error("UAM Impact:"+Dt+"mg/dL per 5m; UAM Duration:"+aa+"hours"),Zt=Math.max(39,Zt),Ht=Math.max(39,Ht),$t=Math.max(39,$t),kt=o(Zt);var ia=l.mealCOB/l.carbs;Et=o($t<999&&Ht<999?(1-ia)*UAMpredBG+ia*COBpredBG:Ht<999?(Yt+COBpredBG)/2:$t<999?(Yt+UAMpredBG)/2:Yt),Xt>Et&&(Et=Xt),Jt=o(Jt=wt||Ft>0?yt?ia*Kt+(1-ia)*Qt:Kt:yt?Qt:Vt);var sa=$t;if(Xt