var freeaps_glucoseGetLast;(()=>{var e={5941:e=>{function a(e){return e.date||Date.parse(e.display_time)||Date.parse(e.dateString)}function o(e,a){a||(a=0);var o=Math.pow(10,a);return Math.round(e*o)/o}e.exports=function(e){for(var r=(e=e.filter((function(e){return e.glucose||e.sgv})).map((function(e){if(e.glucose=e.glucose||e.sgv,null!==e.glucose)return e})))[0],t=a(r),u=[],n=[],l=[],s=0,c=1;c<e.length;c++){if(void 0!==e[c]&&"cal"===e[c].type){s=c;break}if(void 0!==e[c]&&e[c].glucose>38&&e[c].device===r.device){var g,d=0;void 0!==(E=a(ee=e[c]))&&void 0!==t?(g=Math.round((t-E)/6e4),d=(r.glucose-ee.glucose)/g*5):console.error("Error: date field not found: cannot calculate avgdelta"),-2<g&&g<2.5?(r.glucose=(r.glucose+ee.glucose)/2,t=(t+E)/2):2.5<g&&g<17.5?(n.push(d),2.5<g&&g<7.5&&u.push(d)):17.5<g&&g<42.5&&l.push(d)}}var h,i,f=0,v=0,p=0,M=0,_=0,b=0,w=0,k=0,x=0,S=0,F=0,D=0,I=0,m=0,y="autoISF Mod14-Debug: ";u.length>0&&(f=u.reduce((function(e,a){return e+a}))/u.length),n.length>0&&(v=n.reduce((function(e,a){return e+a}))/n.length),l.length>0&&(p=l.reduce((function(e,a){return e+a}))/l.length);var G=r.glucose,L=r.glucose,q=0;for(c=1;c<e.length;c++){var E=a(ee=e[c]);if(Math.round((t-E)/6e4)-q>13)break;if(!(ee.glucose>.95*L&&ee.glucose<1.05*L))break;L=(G+=ee.glucose)/(c+1),q=Math.round((t-E)/6e4)}i=L,h=q,M=1.05,_=1.15,b=1.4,G=0;var P,j,z=0,A=0,B=0,C=7.5;for(c=0;c<e.length;c++){if(P=c*A==z*z?0:(c*B-z*G)/(c*A-z*z),(j=(t-(E=a(ee=e[c])))/6e4)>C&&7.5==C&&(M=5*-P,C=17.5),j>C&&17.5==C&&(_=5*-P,C=42.5),j>C&&42.5==C){b=5*-P;break}z+=j,A+=j*j,G+=ee.glucose,ee.glucose,ee.glucose,B+=ee.glucose*j}w=0,k=0,x=0,F=0,S=0;var H=0,J=0,K=0;if(D=0,I=0,m=0,e.length<=3)w=0,k=0,x=0,F=0,S=0,D=0,I=0,m=0;else{var N=0,O=0,Q=0,R=0,T=0,U=0,V=0,W=0,X=a(e[0]),Y=0,Z=300,$=50;for(c=0;c<e.length;c++){var ee,ae=((E=a(ee=e[c]))-X)/1e3/Z;if(-ae*Z>2820)break;if(ae<Y-1.5){c<3&&(w=-Y/60,k=0,x=0,F=0,S=0,D=0,I=0,m=0);break}Y=ae;var oe=ee.glucose/$;O+=ae,Q+=Math.pow(ae,2),R+=Math.pow(ae,3),T+=Math.pow(ae,4),N+=oe,U+=ae*oe,V+=Math.pow(ae,2)*oe;var re=c+1,te=0,ue=0,ne=0,le=0;if(re>3&&(te=T*(Q*re-O*O)-R*(R*re-O*Q)+Q*(R*O-Q*Q),ue=V*(Q*re-O*O)-U*(R*re-O*Q)+N*(R*O-Q*Q),ne=T*(U*re-N*O)-R*(V*re-N*Q)+Q*(V*O-U*Q),le=T*(Q*N-O*U)-R*(R*N-O*V)+Q*(R*U-Q*V)),0!=te){var se=ue/te;P=ne/te;for(var ce=le/te,ge=N/re,de=0,he=0,ie=0;ie<=c;ie++){var fe=e[ie],ve=a(fe);de+=Math.pow(fe.glucose/$-ge,2);var pe=(ve-X)/1e3/Z,Me=se*Math.pow(pe,2)+P*pe+ce;he+=Math.pow(fe.glucose/$-Me,2)}S=.64,0!=de&&(S=1-he/de),re>3&&S>=W&&(W=S,w=-ae*Z/60,k=-50*(se*Math.pow(-1,2)-1*P),x=$*(se*Math.pow(1,2)+1*P),F=2*se*$,D=ce*$,I=P*$,m=se*$,H=se*$,J=P*$,K=ce*$)}}y+="coeffs a/b/c=("+o(H,2)+" / "+o(J,2)+" / "+o(K,2)+"); bg date="+X+"; ",y+="Parabola Fits a0/a1/a2=("+o(D,2)+" / "+o(I,2)+" / "+o(m,2)+"); "}return y+="Slopes 05/15/40=("+o(M,2)+" / "+o(_,2)+" / "+o(b,2)+"); ",{delta:Math.round(1e4*f)/1e4,glucose:Math.round(1e4*r.glucose)/1e4,noise:Math.round(r.noise),short_avgdelta:Math.round(1e4*v)/1e4,long_avgdelta:Math.round(1e4*p)/1e4,autoISF_average:Math.round(1e4*i)/1e4,autoISF_duration:Math.round(1e4*h)/1e4,dura_p:Math.round(1e4*w)/1e4,delta_pl:Math.round(1e4*k)/1e4,delta_pn:Math.round(1e4*x)/1e4,bg_acceleration:F,r_squ:Math.round(1e4*W)/1e4,parabola_fit_a0:Math.round(1e4*D)/1e4,parabola_fit_a1:Math.round(1e4*I)/1e4,parabola_fit_a2:Math.round(1e4*m)/1e4,pp_debug:y,date:t,last_cal:s,device:r.device}}}},a={},o=function o(r){var t=a[r];if(void 0!==t)return t.exports;var u=a[r]={exports:{}};return e[r](u,u.exports,o),u.exports}(5941);freeaps_glucoseGetLast=o})();