glucose-get-last.js 3.2 KB

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